mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-03 07:26:45 +00:00
@@ -41,36 +41,36 @@ const PrismMac = () => {
|
|||||||
* 将mermaid语言 渲染成图片
|
* 将mermaid语言 渲染成图片
|
||||||
*/
|
*/
|
||||||
const renderMermaid = async() => {
|
const renderMermaid = async() => {
|
||||||
// 支持 Mermaid
|
const observer = new MutationObserver(async mutationsList => {
|
||||||
const mermaidPres = document.querySelectorAll('pre.notion-code.language-mermaid')
|
for (const m of mutationsList) {
|
||||||
if (mermaidPres) {
|
if (m.target.className === 'notion-code language-mermaid') {
|
||||||
for (const e of mermaidPres) {
|
const chart = m.target.querySelector('code').textContent
|
||||||
const chart = e.querySelector('code').textContent
|
if (chart && !m.target.querySelector('.mermaid')) {
|
||||||
if (chart && !e.querySelector('.mermaid')) {
|
const mermaidChart = document.createElement('div')
|
||||||
const m = document.createElement('div')
|
mermaidChart.className = 'mermaid'
|
||||||
m.className = 'mermaid'
|
mermaidChart.innerHTML = chart
|
||||||
m.innerHTML = chart
|
m.target.appendChild(mermaidChart)
|
||||||
e.appendChild(m)
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mermaidsSvg = document.querySelectorAll('.mermaid')
|
const mermaidsSvg = document.querySelectorAll('.mermaid')
|
||||||
if (mermaidsSvg) {
|
if (mermaidsSvg) {
|
||||||
let needLoad = false
|
let needLoad = false
|
||||||
for (const e of mermaidsSvg) {
|
for (const e of mermaidsSvg) {
|
||||||
if (e?.firstChild?.nodeName !== 'svg') {
|
if (e?.firstChild?.nodeName !== 'svg') {
|
||||||
needLoad = true
|
needLoad = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needLoad) {
|
||||||
|
const url = await loadExternalResource(BLOG.MERMAID_CDN, 'js')
|
||||||
|
const mermaid = window.mermaid
|
||||||
|
console.log('mermaid加载成功', url, mermaid)
|
||||||
|
mermaid.contentLoaded()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needLoad) {
|
})
|
||||||
// const asyncMermaid = await import('mermaid')
|
observer.observe(document.querySelector('#container'), { attributes: true, subtree: true })
|
||||||
const url = await loadExternalResource(BLOG.MERMAID_CDN, 'js')
|
|
||||||
const mermaid = window.mermaid
|
|
||||||
console.log('mermaid加载成功', url, mermaid)
|
|
||||||
mermaid.contentLoaded()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderPrismMac() {
|
function renderPrismMac() {
|
||||||
|
|||||||
Reference in New Issue
Block a user