Skip to content

Instantly share code, notes, and snippets.

@morisono
Forked from wazeerc/markdown-parser.ts
Created September 7, 2025 15:18
Show Gist options
  • Save morisono/f95fbacf48703f649acdd9a7b0b783aa to your computer and use it in GitHub Desktop.
Save morisono/f95fbacf48703f649acdd9a7b0b783aa 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