-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly renders custom markdown elements
Correctly renders the custom markdown elements
- Loading branch information
Showing
4 changed files
with
177 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import { createElement, Fragment } from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import { createElement } from 'react'; | ||
import { unified } from 'unified'; | ||
import parse from 'remark-parse'; | ||
import remarkRehype from 'remark-rehype'; | ||
import rehypeReact from 'rehype-react'; | ||
import stringify from 'rehype-stringify'; | ||
import rehype from 'remark-rehype'; | ||
import react from 'rehype-react'; | ||
import slug from 'rehype-slug'; | ||
import { Link } from '@components/atoms/Link'; | ||
import { Divider } from '@components/atoms/Divider'; | ||
|
||
export async function markdownToHtml(markdown) { | ||
const result = unified() | ||
const file = unified() | ||
.use(parse) | ||
.use(remarkRehype, { allowDangerousHtml: true }) | ||
.use(rehypeReact, { | ||
.use(rehype) | ||
.use(slug) | ||
.use(react, { | ||
createElement, | ||
Fragment, | ||
a: Link, | ||
components: { | ||
a: Link, | ||
hr: Divider, | ||
}, | ||
}) | ||
.use(stringify) | ||
.processSync(markdown); | ||
|
||
return result.toString(); | ||
const string = ReactDOMServer.renderToStaticMarkup(file.result); | ||
|
||
return string; | ||
} | ||
|
||
export default markdownToHtml; |
930265e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://www.angusp.com as production
🚀 Deployed on https://637991586be9ca5dedc8282a--serene-ride-008670.netlify.app