mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-23 15:09:46 +00:00
mermaid-async
This commit is contained in:
@@ -8,7 +8,6 @@ import 'prismjs/plugins/line-numbers/prism-line-numbers.css'
|
|||||||
// 所有语言的prismjs 使用autoloader引入
|
// 所有语言的prismjs 使用autoloader引入
|
||||||
import 'prismjs/plugins/autoloader/prism-autoloader'
|
import 'prismjs/plugins/autoloader/prism-autoloader'
|
||||||
// mermaid图
|
// mermaid图
|
||||||
import mermaid from 'mermaid'
|
|
||||||
import BLOG from '@/blog.config'
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,6 +17,7 @@ import BLOG from '@/blog.config'
|
|||||||
const PrismMac = () => {
|
const PrismMac = () => {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
renderPrismMac()
|
renderPrismMac()
|
||||||
|
renderMermaid()
|
||||||
|
|
||||||
// 折叠代码行号bug
|
// 折叠代码行号bug
|
||||||
const observer = new MutationObserver(mutationsList => {
|
const observer = new MutationObserver(mutationsList => {
|
||||||
@@ -35,21 +35,10 @@ const PrismMac = () => {
|
|||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderPrismMac() {
|
/**
|
||||||
const container = document?.getElementById('container-inner')
|
* 将mermaid语言 渲染成图片
|
||||||
const codeToolBars = container?.getElementsByClassName('code-toolbar')
|
*/
|
||||||
|
const renderMermaid = async() => {
|
||||||
// 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'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 支持 Mermaid
|
// 支持 Mermaid
|
||||||
const mermaidPres = document.querySelectorAll('pre.notion-code.language-mermaid')
|
const mermaidPres = document.querySelectorAll('pre.notion-code.language-mermaid')
|
||||||
if (mermaidPres) {
|
if (mermaidPres) {
|
||||||
@@ -73,9 +62,26 @@ function renderPrismMac() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needLoad) {
|
if (needLoad) {
|
||||||
mermaid.contentLoaded()
|
const asyncMermaid = await import('mermaid')
|
||||||
|
asyncMermaid.default.contentLoaded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPrismMac() {
|
||||||
|
const container = document?.getElementById('container-inner')
|
||||||
|
const codeToolBars = container?.getElementsByClassName('code-toolbar')
|
||||||
|
|
||||||
|
// 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'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 重新渲染之前检查所有的多余text
|
// 重新渲染之前检查所有的多余text
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user