Skip to content

Commit 4dd3820

Browse files
committed
The half working solution
1 parent 4e9d875 commit 4dd3820

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/components/mermaid.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use client';
22
import {useEffect} from 'react';
3+
import {useTheme} from 'next-themes';
34

45
export default function Mermaid() {
6+
const theme = useTheme();
57
useEffect(() => {
6-
(async function () {
8+
const renderMermaid = async () => {
79
const escapeHTML = (str: string) => {
810
return str.replace(/[&<>"']/g, function (match) {
911
const escapeMap = {
@@ -24,7 +26,7 @@ export default function Mermaid() {
2426
const {default: mermaid} = await import('mermaid');
2527
mermaid.initialize({
2628
startOnLoad: false,
27-
theme: 'neutral',
29+
theme: theme.resolvedTheme === 'light' ? 'default' : 'dark',
2830
});
2931
mermaidBlocks.forEach(block => {
3032
// get rid of code highlighting
@@ -38,7 +40,8 @@ export default function Mermaid() {
3840
}
3941
});
4042
await mermaid.run({nodes: document.querySelectorAll('.language-mermaid')});
41-
})();
42-
}, []);
43+
};
44+
renderMermaid();
45+
}, [theme]);
4346
return null;
4447
}

0 commit comments

Comments
 (0)