Skip to content

Instantly share code, notes, and snippets.

@quantizor
Last active December 4, 2024 05:45
Show Gist options
  • Save quantizor/5b3d08eee7b572c0838b3148166b79d5 to your computer and use it in GitHub Desktop.
Save quantizor/5b3d08eee7b572c0838b3148166b79d5 to your computer and use it in GitHub Desktop.
Use markdown-to-jsx with SolidJS
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