Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Add custom list rendering for body frontmatter
Browse files Browse the repository at this point in the history
- Set the list style type based on whether the list is ordered or
  unordered
- Set list-style-position to inside to avoid weird layouts when text is
  centered
  • Loading branch information
Eric Dattore committed Sep 8, 2023
1 parent 58f3022 commit 15671be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pages/c/[configKind]/[tip].astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function getStaticPaths() {
});
return `<div class="rounded-md px-2 bg-gray-800 w-full overflow-x-auto"><pre><code class="language-${lang}">${html}</code></pre></div>`;
};
return marked(markdown, { renderer });
}
Expand Down
13 changes: 11 additions & 2 deletions src/pages/c/[configKind]/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import type { BreadCrumbList } from '../../../components/Navigation/BreadCrumb.a
export async function getStaticPaths() {
const configKinds = await getCollection("configKinds");
const renderer = new marked.Renderer();
// Custom render lists in the body
renderer.list = (body, ordered) => {
const type = ordered ? 'ol' : 'ul';
const className = ordered ? 'list-decimal' : 'list-disc';
return `<${type} class="${className} list-inside">${body}</${type}>`
};
const paths = await Promise.all(configKinds.map(async (configKind) => {
const allTips = await getCollection("tips");
const tips = allTips.filter(tip => tip.data.kind.id === configKind.id);
const htmlBody = marked(configKind.data.body);
const htmlBody = marked(configKind.data.body, { renderer });
return {
params: { configKind: configKind.id },
props: { configKind, tips, htmlBody },
Expand Down Expand Up @@ -67,4 +76,4 @@ const breadCrumbList: BreadCrumbList = [
))}
</div>
</div>
</Layout>
</Layout>

0 comments on commit 15671be

Please sign in to comment.