Skip to content

Commit

Permalink
feat: 支持以代碼塊形式書寫 mermaid closed #1479
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryc127 committed Apr 10, 2024
1 parent 9e0dce6 commit ae35499
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 171 deletions.
10 changes: 6 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,13 @@ abcjs:
enable: false
per_page: true

# mermaid
# see https://github.com/mermaid-js/mermaid
# Mermaid
# See https://github.com/mermaid-js/mermaid
mermaid:
enable: false
# built-in themes: default/forest/dark/neutral
enable: true
# Write Mermaid diagrams using code blocks (以代碼塊形式書寫 Mermaid)
code_write: false
# Built-in themes: default/forest/dark/neutral
theme:
light: default
dark: dark
Expand Down
13 changes: 13 additions & 0 deletions layout/includes/third-party/math/mermaid.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-butterfly",
"version": "4.14.0-b1",
"version": "4.14.0-b2",
"description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json",
"scripts": {
Expand Down
Loading

0 comments on commit ae35499

Please sign in to comment.