Skip to content

Instantly share code, notes, and snippets.

@wazeerc
Created December 13, 2024 15:20
Show Gist options
  • Save wazeerc/206017e93e4f4df60b6ae0568aa8b615 to your computer and use it in GitHub Desktop.
Save wazeerc/206017e93e4f4df60b6ae0568aa8b615 to your computer and use it in GitHub Desktop.
Markdown Parser using remark
//#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