From 68fa2bad156203a83a31fd34c54cd170bb198557 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sat, 9 Nov 2024 14:16:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mermaid=E5=9B=BE=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98=20#310?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/context/SyntaxHighlighterProvider.tsx | 2 +- src/renderer/src/store/runtime.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/context/SyntaxHighlighterProvider.tsx b/src/renderer/src/context/SyntaxHighlighterProvider.tsx index 11e5cac5..1ad72151 100644 --- a/src/renderer/src/context/SyntaxHighlighterProvider.tsx +++ b/src/renderer/src/context/SyntaxHighlighterProvider.tsx @@ -36,7 +36,7 @@ export const SyntaxHighlighterProvider: React.FC = ({ childre if (!window.mermaid) { await loadScript('https://unpkg.com/mermaid@11.4.0/dist/mermaid.min.js') window.mermaid.initialize({ - startOnLoad: true, + startOnLoad: false, theme: theme === ThemeMode.dark ? 'dark' : 'default' }) window.mermaid.contentLoaded() diff --git a/src/renderer/src/store/runtime.ts b/src/renderer/src/store/runtime.ts index 06eb72d3..df7a19f0 100644 --- a/src/renderer/src/store/runtime.ts +++ b/src/renderer/src/store/runtime.ts @@ -26,6 +26,15 @@ const runtimeSlice = createSlice({ }, setGenerating: (state, action: PayloadAction) => { state.generating = action.payload + if (!state.generating) { + const mermaidElements = document.querySelectorAll('.mermaid') + for (const element of mermaidElements) { + if (!element.querySelector('svg')) { + element.removeAttribute('data-processed') + } + } + setTimeout(() => window.mermaid.contentLoaded(), 100) + } }, setMinappShow: (state, action: PayloadAction) => { state.minappShow = action.payload