@@ -27,8 +27,6 @@ const verifyMermaid = (content: string) => {
2727export const mermaidPlugin = ( md , options = { } ) => {
2828 // 缓存渲染结果
2929 const cache = new Map ( )
30- // 记录正在渲染中的图表
31- const pendingQueue = new Map ( )
3230
3331 const defaultFence = md . renderer . rules . fence
3432 md . renderer . rules . fence = ( tokens , idx , opts , env , self ) => {
@@ -66,12 +64,7 @@ export const mermaidPlugin = (md, options = {}) => {
6664 const content = decodeURIComponent ( encodedContent )
6765 const hash = container . dataset . mermaidHash
6866
69-
70- // 如果已经在渲染队列中,则直接返回
71- if ( pendingQueue . has ( hash ) ) return
72-
7367 try {
74- pendingQueue . set ( hash , true )
7568 let svg
7669
7770 // 检查缓存
@@ -104,8 +97,6 @@ export const mermaidPlugin = (md, options = {}) => {
10497 console . error ( 'Mermaid 渲染失败:' , err )
10598 container . dataset . mermaidStatus = 'error'
10699 container . innerHTML = `<pre>渲染失败:\n${ content } \n</pre>`
107- } finally {
108- pendingQueue . delete ( hash )
109100 }
110101 }
111102
@@ -124,7 +115,9 @@ export const mermaidPlugin = (md, options = {}) => {
124115 if ( container . dataset . mermaidStatus !== 'pending' ) {
125116 container . dataset . mermaidStatus = 'pending'
126117 }
127- renderMermaid ( container )
118+ nextTick ( ( ) => {
119+ renderMermaid ( container )
120+ } )
128121 } )
129122 }
130123
0 commit comments