From bb776bd1ab6c6f7bfa6547093911b8946da4cfed Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 7 Dec 2022 21:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=98=E5=8F=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/PrismMac.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/PrismMac.js b/components/PrismMac.js index fbfd42cd..a379dc36 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -18,6 +18,19 @@ import BLOG from '@/blog.config' const PrismMac = () => { React.useEffect(() => { renderPrismMac() + + // 折叠代码行号bug + const observer = new MutationObserver(mutationsList => { + for (const m of mutationsList) { + if (m.target.nodeName === 'DETAILS') { + const preCode = m.target.querySelector('pre.notion-code') + if (preCode) { + Prism.plugins.lineNumbers.resize(preCode) + } + } + } + }) + observer.observe(document.querySelector('article'), { attributes: true, subtree: true }) }, []) return <> } @@ -42,7 +55,6 @@ function renderPrismMac() { 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'