From 8a07af847c583abbe4698214d1160036bd578bf9 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 14:07:28 +0800 Subject: [PATCH] =?UTF-8?q?mermaid=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/PrismMac.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/PrismMac.js b/components/PrismMac.js index 9193cfa6..f6e82542 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -9,15 +9,17 @@ 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 <> } @@ -46,9 +48,9 @@ function renderPrismMac() { // 支持 Mermaid const mermaids = document.querySelectorAll('.notion-code .language-mermaid') + console.log('检查 mermaids', mermaids) if (mermaids) { for (const e of mermaids) { - e.parentElement.classList.remove('code-toolbar') const chart = e.firstChild.textContent if (e.firstElementChild) { e.parentElement.remove() @@ -60,6 +62,14 @@ function renderPrismMac() { } } + // mermaid 样式 + const mermaidsCodeBar = document.querySelectorAll('.language-mermaid') + if (mermaidsCodeBar) { + for (const e of mermaidsCodeBar) { + e.parentElement.classList.replace('code-toolbar', 'w-full') + } + } + const mermaidsSvg = document.querySelectorAll('.mermaid') if (mermaidsSvg) { for (const e of mermaidsSvg) {