From 1d815c46868a5cd806a59ba27d517aa028d6778d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Thu, 15 Jun 2023 20:33:02 -0300 Subject: [PATCH] feat(lib): create markdown-to-html converter --- src/app/(blog)/feed/markdown-to-html.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/app/(blog)/feed/markdown-to-html.ts diff --git a/src/app/(blog)/feed/markdown-to-html.ts b/src/app/(blog)/feed/markdown-to-html.ts new file mode 100644 index 00000000..799eada0 --- /dev/null +++ b/src/app/(blog)/feed/markdown-to-html.ts @@ -0,0 +1,25 @@ +import { unified } from 'unified' + +import remarkParse from 'remark-parse' +import remarkRehype from 'remark-rehype' +import rehypeStringify from 'rehype-stringify' +import remarkGfm from 'remark-gfm' +import remarkMath from 'remark-math' +import remarkBreaks from 'remark-breaks' +import remarkHint from 'remark-hint' +import rehypeKatex from 'rehype-katex' + +export function markdownToHtml(markdown: string) { + const file = unified() + .use(remarkParse) + .use(remarkGfm) + .use(remarkMath) + .use(remarkBreaks) + .use(remarkHint) + .use(remarkRehype) + .use(rehypeKatex) + .use(rehypeStringify) + .processSync(markdown) + + return String(file) +}