fix: mermaid
occasionally fails to initialize (#536)
This commit is contained in:
parent
6774e0e1fb
commit
48f14e39ac
1 changed files with 12 additions and 10 deletions
|
@ -5,10 +5,11 @@
|
|||
<script src="{{ site.data.assets[origin].mermaid.js | relative_url }}"></script>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
(function () {
|
||||
|
||||
function updateMermaid(event) {
|
||||
if (event.source === window && event.data &&
|
||||
event.data.direction === ModeToggle.ID) {
|
||||
event.data.direction === ModeToggle.ID) {
|
||||
|
||||
const mode = event.data.message;
|
||||
|
||||
|
@ -16,11 +17,11 @@
|
|||
return;
|
||||
}
|
||||
|
||||
let expectedTheme = (mode === ModeToggle.DARK_MODE? "dark" : "default");
|
||||
let config = { theme: expectedTheme };
|
||||
let expectedTheme = (mode === ModeToggle.DARK_MODE ? "dark" : "default");
|
||||
let config = {theme: expectedTheme};
|
||||
|
||||
/* Re-render the SVG › <https://github.com/mermaid-js/mermaid/issues/311#issuecomment-332557344> */
|
||||
$(".mermaid").each(function() {
|
||||
$(".mermaid").each(function () {
|
||||
let svgCode = $(this).prev().children().html();
|
||||
$(this).removeAttr("data-processed");
|
||||
$(this).html(svgCode);
|
||||
|
@ -35,7 +36,7 @@
|
|||
|
||||
if ($("html[data-mode=dark]").length > 0
|
||||
|| ($("html[data-mode]").length == 0
|
||||
&& window.matchMedia("(prefers-color-scheme: dark)").matches ) ) {
|
||||
&& window.matchMedia("(prefers-color-scheme: dark)").matches)) {
|
||||
initTheme = "dark";
|
||||
}
|
||||
|
||||
|
@ -43,15 +44,16 @@
|
|||
theme: initTheme /* <default|dark|forest|neutral> */
|
||||
};
|
||||
|
||||
/* Markdown converts to HTML */
|
||||
$("pre").has("code.language-mermaid").each(function() {
|
||||
/* Create mermaid tag */
|
||||
$("pre").has("code.language-mermaid").each(function () {
|
||||
let svgCode = $(this).children().html();
|
||||
$(this).addClass("unloaded");
|
||||
$(this).after(`<div class=\"mermaid\">${svgCode}</div>`);
|
||||
$(this).after(`<pre class=\"mermaid\">${svgCode}</pre>`);
|
||||
});
|
||||
|
||||
mermaid.initialize(mermaidConf);
|
||||
|
||||
window.addEventListener("message", updateMermaid);
|
||||
});
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue