Skip to content

Instantly share code, notes, and snippets.

@JTRNS
Created August 3, 2023 19:25
Show Gist options
  • Save JTRNS/fc6b96807dedc4d799fff6db33dfefed to your computer and use it in GitHub Desktop.
Save JTRNS/fc6b96807dedc4d799fff6db33dfefed to your computer and use it in GitHub Desktop.
GitHub Flavoured Markdown Parsing in Deno
import { unified } from "https://esm.sh/[email protected]";
import remarkParse from "https://esm.sh/[email protected]";
import remarkFrontmatter from "https://esm.sh/[email protected]";
import remarkGfm from "https://esm.sh/[email protected]";
import remarkRehype from "https://esm.sh/[email protected]";
import rehypeStringify from "https://esm.sh/[email protected]";
import rehypeSlug from "https://esm.sh/[email protected]";
import rehypeAutolinkHeadings from "https://esm.sh/[email protected]";
import remarkGemoji from "https://esm.sh/[email protected]";
import rehypeStarryNight from "https://esm.sh/@microflash/[email protected]";
export async function parseMarkdown(content: string) {
const file = await unified()
.use(remarkParse)
.use(remarkFrontmatter)
.use(remarkGemoji)
.use(remarkGfm)
.use(remarkRehype, {
allowDangerousHtml: true,
})
.use(rehypeSlug)
.use(rehypeAutolinkHeadings, {
properties: { ariaHidden: true, tabIndex: -1, class: "anchor" },
content: {
type: "element",
tagName: "span",
properties: { class: ["octicon", "octicon-link"] },
children: [],
},
})
.use(rehypeStarryNight)
/// @ts-ignore rehype-stringify types are wrong
.use(rehypeStringify, { allowDangerousHtml: true })
.process(content);
return file.toString("utf8");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment