From e946591c0b4076042a48698a551311b2c648276c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sun, 27 Nov 2022 14:12:13 +0800 Subject: [PATCH] 3.6.0.hotfix-prism --- components/PrismMac.js | 51 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/components/PrismMac.js b/components/PrismMac.js index 06520495..0a2bf4ec 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -51,35 +51,36 @@ function renderPrismMac() { } }) } + // Add line numbers + const codeBlocks = container?.getElementsByTagName('pre') + if (codeBlocks) { + Array.from(codeBlocks).forEach(item => { + if (!item.classList.contains('line-numbers')) { + item.classList.add('line-numbers') + item.style.whiteSpace = 'pre-wrap' + } + }) + } + + setTimeout(() => { + // Add pre-mac element for Mac Style UI + if (codeToolBars) { + Array.from(codeToolBars).forEach(item => { + const existPreMac = item.getElementsByClassName('pre-mac') + if (existPreMac.length < codeToolBars.length) { + const preMac = document.createElement('div') + preMac.classList.add('pre-mac') + preMac.innerHTML = '' + item?.appendChild(preMac, item) + } + }) + } + }, 10) + // 重新渲染之前检查所有的多余text try { Prism.highlightAll() - // Add line numbers - const codeBlocks = container?.getElementsByTagName('pre') - if (codeBlocks) { - Array.from(codeBlocks).forEach(item => { - if (!item.classList.contains('line-numbers')) { - item.classList.add('line-numbers') - item.style.whiteSpace = 'pre-wrap' - } - }) - } - - setTimeout(() => { - // Add pre-mac element for Mac Style UI - if (codeToolBars) { - Array.from(codeToolBars).forEach(item => { - const existPreMac = item.getElementsByClassName('pre-mac') - if (existPreMac.length < codeToolBars.length) { - const preMac = document.createElement('div') - preMac.classList.add('pre-mac') - preMac.innerHTML = '' - item?.appendChild(preMac, item) - } - }) - } - }, 10) } catch (err) { console.log('代码渲染', err) }