mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
feat: 支持以代碼塊形式書寫 mermaid closed #1479
This commit is contained in:
13
layout/includes/third-party/math/mermaid.pug
vendored
13
layout/includes/third-party/math/mermaid.pug
vendored
@@ -26,7 +26,20 @@ script.
|
||||
})
|
||||
}
|
||||
|
||||
const codeToMermaid = () => {
|
||||
const codeMermaidEle = document.querySelectorAll('pre > code.mermaid')
|
||||
if (codeMermaidEle.length === 0) return
|
||||
|
||||
codeMermaidEle.forEach(ele => {
|
||||
const newEle = document.createElement('div')
|
||||
newEle.className = 'mermaid-wrap'
|
||||
newEle.innerHTML = `<pre class="mermaid-src" hidden>${ele.textContent}</pre>`
|
||||
ele.parentNode.replaceWith(newEle)
|
||||
})
|
||||
}
|
||||
|
||||
const loadMermaid = () => {
|
||||
if (!{theme.mermaid.code_write}) codeToMermaid()
|
||||
const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
|
||||
if ($mermaid.length === 0) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user