Skip to content

Instantly share code, notes, and snippets.

@brianrodri
Last active June 9, 2024 21:06
Show Gist options
  • Save brianrodri/dd318b706198b2e777370d4d8c3bd50d to your computer and use it in GitHub Desktop.
Save brianrodri/dd318b706198b2e777370d4d8c3bd50d to your computer and use it in GitHub Desktop.
export interface ObsidianMarkdownProps {
markdown: string;
}
export function ObsidianMarkdown({ markdown }: ObsidianMarkdownProps) {
const { plugin, notePath } = usePluginContext();
const [html, setHTML] = useState("");
useEffect(() => {
let mounted = true;
async function resolveHTML() {
const el = document.createElement("div");
await MarkdownRenderer.render(plugin.app, markdown, el, notePath, plugin);
if (mounted) setHTML(el.innerHTML);
}
resolveHTML();
return () => (mounted = false);
}, [markdown, notePath, plugin]);
return createElement("div", { dangerouslySetInnerHTML: { __html: html } });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment