_includes/mermaid.html in jekyll-theme-chirpy-5.6.1 vs _includes/mermaid.html in jekyll-theme-chirpy-6.0.0
- old
+ new
@@ -1,59 +1,58 @@
-<!--
- mermaid-js loader
--->
-
-<script src="{{ site.data.assets[origin].mermaid.js | relative_url }}"></script>
-
-<script>
+<!-- mermaid-js loader -->
+<script type="text/javascript">
(function () {
-
function updateMermaid(event) {
- if (event.source === window && event.data &&
- event.data.direction === ModeToggle.ID) {
-
+ if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
const mode = event.data.message;
- if (typeof mermaid === "undefined") {
+ if (typeof mermaid === 'undefined') {
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).removeAttr('data-processed');
$(this).html(svgCode);
});
mermaid.initialize(config);
- mermaid.init(undefined, ".mermaid");
+ mermaid.init(undefined, '.mermaid');
}
}
- let initTheme = "default";
+ let initTheme = 'default';
+ const html = document.documentElement;
- if ($("html[data-mode=dark]").length > 0
- || ($("html[data-mode]").length == 0
- && window.matchMedia("(prefers-color-scheme: dark)").matches)) {
- initTheme = "dark";
+ if (
+ (html.hasAttribute('data-mode') && html.getAttribute('data-mode') === 'dark') ||
+ (!html.hasAttribute('data-mode') && window.matchMedia('(prefers-color-scheme: dark)').matches)
+ ) {
+ initTheme = 'dark';
}
let mermaidConf = {
- theme: initTheme /* <default|dark|forest|neutral> */
+ theme: initTheme /* <default|dark|forest|neutral> */
};
/* Create mermaid tag */
- $("pre").has("code.language-mermaid").each(function () {
- let svgCode = $(this).children().html();
- $(this).addClass("unloaded");
- $(this).after(`<pre class=\"mermaid\">${svgCode}</pre>`);
+ document.querySelectorAll('pre>code.language-mermaid').forEach((elem) => {
+ const svgCode = elem.textContent;
+ const backup = elem.parentElement;
+ backup.classList.add('unloaded');
+ /* create mermaid node */
+ let mermaid = document.createElement('pre');
+ mermaid.classList.add('mermaid');
+ const text = document.createTextNode(svgCode);
+ mermaid.appendChild(text);
+ backup.after(mermaid);
});
mermaid.initialize(mermaidConf);
- window.addEventListener("message", updateMermaid);
+ window.addEventListener('message', updateMermaid);
})();
-
</script>