Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions layouts/partials/scripts/mermaid.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@

var settings = norm(mermaid.mermaidAPI.defaultConfig, params);
settings.startOnLoad = true;
const isDark = $('html[data-bs-theme="dark"]').length;
settings.theme = isDark ? 'dark' : 'base';
mermaid.initialize(settings);

// Handle light/dark mode theme changes
const lightDarkModeThemeChangeHandler = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'data-bs-theme') {
// Mermaid doesn't currently support reinitialization, see
// https://github.com/mermaid-js/mermaid/issues/1945. Until then,
// just reload the page.
location.reload();
}
}
};

const observer = new MutationObserver(lightDarkModeThemeChangeHandler);
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['data-bs-theme']
});
// observer.disconnect();

})(jQuery);
</script>