Skip to content

Commit

Permalink
feat: markdown mermaid support (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrgzs authored Dec 27, 2024
1 parent e3eed1d commit 5738a39
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ const insertKatexCSS = once(() => {
document.head.appendChild(link)
})

const insertMermaidJS = once(() => {
const script = document.createElement("script")
script.src =
"https://registry.npmmirror.com/mermaid/11/files/dist/mermaid.min.js"
document.body.appendChild(script)
})

export function Markdown(props: {
children?: string | ArrayBuffer
class?: string
Expand Down Expand Up @@ -213,9 +220,14 @@ export function Markdown(props: {
on(md, () => {
setShow(false)
insertKatexCSS()
insertMermaidJS()
setTimeout(() => {
setShow(true)
hljs.highlightAll()
window.mermaid &&
window.mermaid.run({
querySelector: ".language-mermaid",
})
window.onMDRender && window.onMDRender()
})
}),
Expand Down

0 comments on commit 5738a39

Please sign in to comment.