File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 11'use client' ;
22import { useEffect } from 'react' ;
3+ import { useTheme } from 'next-themes' ;
34
45export 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}
You can’t perform that action at this time.
0 commit comments