summaryrefslogtreecommitdiff
path: root/src/utils/markdown.ts
blob: eaac6e75c9e295da2b7d0311691dbb33d65ba3fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";
import { rehypeImageCaptions } from "@/plugins/rehype-image-captions";

export function markdownToHtml(markdown: string): string {
	const result = unified()
		.use(remarkParse)
		.use(remarkRehype, { allowDangerousHtml: true })
		.use(rehypeImageCaptions)
		.use(rehypeStringify, { allowDangerousHtml: true })
		.processSync(markdown);

	return String(result);
}