fix: mermaid图渲染有问题 #310

This commit is contained in:
kangfenmao 2024-11-09 14:16:42 +08:00
parent bac3bad8db
commit 68fa2bad15
2 changed files with 10 additions and 1 deletions

View File

@ -36,7 +36,7 @@ export const SyntaxHighlighterProvider: React.FC<PropsWithChildren> = ({ 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()

View File

@ -26,6 +26,15 @@ const runtimeSlice = createSlice({
},
setGenerating: (state, action: PayloadAction<boolean>) => {
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<boolean>) => {
state.minappShow = action.payload