Last active
December 4, 2024 05:45
-
-
Save quantizor/5b3d08eee7b572c0838b3148166b79d5 to your computer and use it in GitHub Desktop.
Use markdown-to-jsx with SolidJS
This file contains hidden or 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
import { compiler, type MarkdownToJSX } from 'markdown-to-jsx'; | |
import { Component, JSX } from 'solid-js'; | |
import h from 'solid-js/h'; | |
/** | |
* A simple HOC for use with SolidJS. Feed the markdown content as a direct child | |
* and the rest is taken care of automatically. | |
*/ | |
const Markdown: Component<{ children?: string }> = ({ children = '' }) => { | |
return compiler(children, { | |
createElement: h as unknown as NonNullable<MarkdownToJSX.Options['createElement']>, | |
}) as unknown as JSX.Element; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment