([\s\S]*?)<\/code>/g,
(match, code) => {
const decoded = decodeHtmlEntities(code);
return `${decoded}`;
},
);
},
200,
);
// Use low priority (-100) to run after the mermaid plugin injects its content
app.renderer.on(
Renderer.EVENT_END_PAGE,
(page) => {
if (!page.contents) return;
if (!page.contents.includes('class="mermaid-block"')) return;
// Remove dark-theme mermaid divs to avoid duplicate marker IDs
page.contents = page.contents.replace(
/[\s\S]*?<\/div>/g,
"",
);
// Also remove the CSS that hides light-theme divs by default
// The mermaid plugin adds visibility:hidden until JS sets display:block
// Since we only have light divs now, make them visible immediately
page.contents = page.contents.replace(
//g,
'',
);
// Add dark mode CSS filter before
const headEndIndex = page.contents.indexOf("");
if (headEndIndex !== -1) {
page.contents =
page.contents.slice(0, headEndIndex) +
darkModeStyles +
page.contents.slice(headEndIndex);
}
},
-100,
);
}