Created
August 3, 2023 19:25
-
-
Save JTRNS/fc6b96807dedc4d799fff6db33dfefed to your computer and use it in GitHub Desktop.
GitHub Flavoured Markdown Parsing in Deno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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