|
5 | 5 | <script src="{{ site.data.assets[origin].mermaid.js | relative_url }}"></script> |
6 | 6 |
|
7 | 7 | <script> |
8 | | - $(function() { |
| 8 | + (function () { |
| 9 | + |
9 | 10 | function updateMermaid(event) { |
10 | 11 | if (event.source === window && event.data && |
11 | | - event.data.direction === ModeToggle.ID) { |
| 12 | + event.data.direction === ModeToggle.ID) { |
12 | 13 |
|
13 | 14 | const mode = event.data.message; |
14 | 15 |
|
15 | 16 | if (typeof mermaid === "undefined") { |
16 | 17 | return; |
17 | 18 | } |
18 | 19 |
|
19 | | - let expectedTheme = (mode === ModeToggle.DARK_MODE? "dark" : "default"); |
20 | | - let config = { theme: expectedTheme }; |
| 20 | + let expectedTheme = (mode === ModeToggle.DARK_MODE ? "dark" : "default"); |
| 21 | + let config = {theme: expectedTheme}; |
21 | 22 |
|
22 | 23 | /* Re-render the SVG › <https://github.com/mermaid-js/mermaid/issues/311#issuecomment-332557344> */ |
23 | | - $(".mermaid").each(function() { |
| 24 | + $(".mermaid").each(function () { |
24 | 25 | let svgCode = $(this).prev().children().html(); |
25 | 26 | $(this).removeAttr("data-processed"); |
26 | 27 | $(this).html(svgCode); |
|
35 | 36 |
|
36 | 37 | if ($("html[data-mode=dark]").length > 0 |
37 | 38 | || ($("html[data-mode]").length == 0 |
38 | | - && window.matchMedia("(prefers-color-scheme: dark)").matches ) ) { |
| 39 | + && window.matchMedia("(prefers-color-scheme: dark)").matches)) { |
39 | 40 | initTheme = "dark"; |
40 | 41 | } |
41 | 42 |
|
42 | 43 | let mermaidConf = { |
43 | 44 | theme: initTheme /* <default|dark|forest|neutral> */ |
44 | 45 | }; |
45 | 46 |
|
46 | | - /* Markdown converts to HTML */ |
47 | | - $("pre").has("code.language-mermaid").each(function() { |
| 47 | + /* Create mermaid tag */ |
| 48 | + $("pre").has("code.language-mermaid").each(function () { |
48 | 49 | let svgCode = $(this).children().html(); |
49 | 50 | $(this).addClass("unloaded"); |
50 | | - $(this).after(`<div class=\"mermaid\">${svgCode}</div>`); |
| 51 | + $(this).after(`<pre class=\"mermaid\">${svgCode}</pre>`); |
51 | 52 | }); |
52 | 53 |
|
53 | 54 | mermaid.initialize(mermaidConf); |
54 | 55 |
|
55 | 56 | window.addEventListener("message", updateMermaid); |
56 | | - }); |
| 57 | + })(); |
| 58 | + |
57 | 59 | </script> |
0 commit comments