add mdbook-mermaid

configs are autogenerated by the configuation guide of mdbook-mermaid
This commit is contained in:
2026-01-16 09:09:28 +08:00
committed by morgan
parent 14c84c80d1
commit 6759ac6ce1
4 changed files with 2655 additions and 0 deletions

View File

@@ -4,3 +4,13 @@ language = "en"
multilingual = false
src = "src"
title = "Sinara Assembly"
[preprocessor]
[preprocessor.mermaid]
command = "mdbook-mermaid"
[output]
[output.html]
additional-js = ["mermaid.min.js", "mermaid-init.js"]

View File

@@ -22,6 +22,7 @@
buildInputs = [
pkgs.mdbook
pkgs.nodejs
pkgs.mdbook-mermaid
];
};
};

35
mermaid-init.js Normal file
View File

@@ -0,0 +1,35 @@
(() => {
const darkThemes = ['ayu', 'navy', 'coal'];
const lightThemes = ['light', 'rust'];
const classList = document.getElementsByTagName('html')[0].classList;
let lastThemeWasLight = true;
for (const cssClass of classList) {
if (darkThemes.includes(cssClass)) {
lastThemeWasLight = false;
break;
}
}
const theme = lastThemeWasLight ? 'default' : 'dark';
mermaid.initialize({ startOnLoad: true, theme });
// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
for (const darkTheme of darkThemes) {
document.getElementById(darkTheme).addEventListener('click', () => {
if (lastThemeWasLight) {
window.location.reload();
}
});
}
for (const lightTheme of lightThemes) {
document.getElementById(lightTheme).addEventListener('click', () => {
if (!lastThemeWasLight) {
window.location.reload();
}
});
}
})();

2609
mermaid.min.js vendored Normal file

File diff suppressed because one or more lines are too long