-
-
Save morisono/f95fbacf48703f649acdd9a7b0b783aa to your computer and use it in GitHub Desktop.
Markdown Parser using remark
This file contains hidden or 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
//#region: Markdown parsing utils | |
import rehypeFormat from "rehype-format"; | |
import rehypeStringify from 'rehype-stringify'; | |
import remarkGfm from "remark-gfm"; | |
import remarkParse from 'remark-parse'; | |
import remarkRehype from 'remark-rehype'; | |
import { unified } from 'unified'; | |
export async function parseMarkdown(textToParseIntoMarkdown: string): Promise<unknown> { | |
const markdownProcessor = unified() | |
.use(remarkParse) | |
.use(remarkGfm) | |
.use(remarkRehype, { allowDangerousHtml: true }) | |
.use(rehypeFormat) | |
.use(rehypeStringify); | |
const processedMarkdownValue = (await markdownProcessor.process(textToParseIntoMarkdown)); | |
return processedMarkdownValue; | |
}; | |
//#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment