generated from mateusfg7/nextjs-setup
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): create markdown-to-html converter
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |