Skip to content

Commit d59c2f8

Browse files
committed
[docs] Fix Mermaid
md-book was not rendering mermaid diagrams due to missing javascript dependencies. This change adds the javascript files under `docs/src/third_party`. Signed-off-by: Miguel Osorio <[email protected]>
1 parent 6d69615 commit d59c2f8

File tree

3 files changed

+2654
-0
lines changed

3 files changed

+2654
-0
lines changed

docs/book.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ title = "OpenProt Documentation"
99
command = "mdbook-mermaid"
1010

1111
[output.html]
12+
additional-js = ["src/third_party/mermaid.min.js", "src/third_party/mermaid-init.js"]
13+
default-theme = "light"
14+
15+
[output.html.fold]
16+
enable = true
17+
level = 1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
(() => {
6+
const darkThemes = ['ayu', 'navy', 'coal'];
7+
const lightThemes = ['light', 'rust'];
8+
9+
const classList = document.getElementsByTagName('html')[0].classList;
10+
11+
let lastThemeWasLight = true;
12+
for (const cssClass of classList) {
13+
if (darkThemes.includes(cssClass)) {
14+
lastThemeWasLight = false;
15+
break;
16+
}
17+
}
18+
19+
const theme = lastThemeWasLight ? 'default' : 'dark';
20+
mermaid.initialize({ startOnLoad: true, theme });
21+
22+
// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
23+
24+
for (const darkTheme of darkThemes) {
25+
document.getElementById(darkTheme).addEventListener('click', () => {
26+
if (lastThemeWasLight) {
27+
window.location.reload();
28+
}
29+
});
30+
}
31+
32+
for (const lightTheme of lightThemes) {
33+
document.getElementById(lightTheme).addEventListener('click', () => {
34+
if (!lastThemeWasLight) {
35+
window.location.reload();
36+
}
37+
});
38+
}
39+
})();

0 commit comments

Comments
 (0)