Support mermaid inside backtick code block

* See: https://github.com/next-theme/hexo-theme-next/issues/347
This commit is contained in:
Mimi 2022-03-07 12:25:08 +08:00
parent 358a3c080d
commit a396c61a0a

View File

@ -10,7 +10,14 @@ document.addEventListener('page:loaded', () => {
const newElement = document.createElement('div');
newElement.innerHTML = element.innerHTML;
newElement.className = element.className;
element.parentNode.replaceChild(newElement, element);
const parent = element.parentNode;
// Fix issue #347
// Support mermaid inside backtick code block
if (parent.matches('pre')) {
parent.parentNode.replaceChild(newElement, parent);
} else {
parent.replaceChild(newElement, element);
}
});
mermaid.initialize({
theme : CONFIG.darkmode && window.matchMedia('(prefers-color-scheme: dark)').matches ? CONFIG.mermaid.theme.dark : CONFIG.mermaid.theme.light,