Last active
June 9, 2024 21:06
-
-
Save brianrodri/dd318b706198b2e777370d4d8c3bd50d to your computer and use it in GitHub Desktop.
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
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