forked from sinara-hw/assembly
add mdbook-mermaid
configs are autogenerated by the configuation guide of mdbook-mermaid
This commit is contained in:
10
book.toml
10
book.toml
@@ -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"]
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
buildInputs = [
|
||||
pkgs.mdbook
|
||||
pkgs.nodejs
|
||||
pkgs.mdbook-mermaid
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
35
mermaid-init.js
Normal file
35
mermaid-init.js
Normal 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
2609
mermaid.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user