diff --git a/components/PrismMac.js b/components/PrismMac.js index f6e82542..0180069a 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -9,17 +9,15 @@ import 'prismjs/plugins/line-numbers/prism-line-numbers.css' // mermaid图 import mermaid from 'mermaid' -import { useGlobal } from '@/lib/global' /** * @author https://github.com/txs/ * @returns */ const PrismMac = () => { - const { theme } = useGlobal() React.useEffect(() => { renderPrismMac() - }, [theme]) + }, []) return <>> } @@ -27,14 +25,6 @@ function renderPrismMac() { const container = document?.getElementById('container-inner') const codeToolBars = container?.getElementsByClassName('code-toolbar') - if (codeToolBars) { - Array.from(codeToolBars).forEach(item => { - const codeBlocks = item.getElementsByTagName('pre') - if (codeBlocks.length === 0) { - item.remove() - } - }) - } // Add line numbers const codeBlocks = container?.getElementsByTagName('pre') if (codeBlocks) { @@ -47,36 +37,31 @@ function renderPrismMac() { } // 支持 Mermaid - const mermaids = document.querySelectorAll('.notion-code .language-mermaid') - console.log('检查 mermaids', mermaids) - if (mermaids) { - for (const e of mermaids) { - const chart = e.firstChild.textContent - if (e.firstElementChild) { - e.parentElement.remove() - continue + const mermaidPres = document.querySelectorAll('pre.notion-code.language-mermaid') + if (mermaidPres) { + for (const e of mermaidPres) { + const chart = e.querySelector('code').textContent + console.log(e.parentElement) + if (chart && !e.querySelector('.mermaid')) { + const m = document.createElement('div') + m.className = 'mermaid' + m.innerHTML = chart + e.appendChild(m) } - if (chart) { - e.parentElement.innerHTML = `