Skip to content

Commit

Permalink
#35: fix javascript code
Browse files Browse the repository at this point in the history
  • Loading branch information
frehberg committed Mar 11, 2023
1 parent 9dc4a62 commit eaa088b
Showing 1 changed file with 0 additions and 72 deletions.
72 changes: 0 additions & 72 deletions src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,78 +150,6 @@ const MERMAID_INIT_SCRIPT: &str = r#"
const dataRootPathAttr = "data-root-path";
function initializeMermaid(mermaid) {
var amrn_mermaid_theme =
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'default';
mermaid.initialize({
'startOnLoad':'true',
'theme': amrn_mermaid_theme,
'logLevel': 3 });
mermaid.run();
}
function failedToLoadWarnings() {
for(var elem of document.getElementsByClassName("mermaid")) {
elem.innerHTML =
`<div> <mark>
&#9888; Cannot render diagram! Failed to import module from local file and remote location also!
Either access the rustdocs via HTTP/S using a
<a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server">
local web server
</a>, for example:
<br>
python3 -m http.server --directory target/doc/, or enable local file access in your
Safari/Firefox/Chrome browser, for example
starting Chrome with flag '--allow-file-access-from-files'.
</mark></div> `;
}
}
// If rustdoc is read from file directly, the import of mermaid module
// from file will fail. In this case falling back to remote location.
// If neither succeeds, the mermaid markdown is replaced by notice to
// enable file acecss in browser.
try {
var rootPath = document
.getElementById(rustdocVarsId)
.attributes[dataRootPathAttr]
.value;
const {
default: mermaid,
} = await import(rootPath + mermaidModuleFile);
initializeMermaid(mermaid);
} catch (e) {
try {
const {
default: mermaid,
} = await import(fallbackRemoteUrl);
initializeMermaid(mermaid);
} catch (e) {
failedToLoadWarnings();
}
}
</script>
<div class="mermaid">
graph LR
s([Source]) --> a[[aquamarine]]
r[[rustdoc]] --> f([Docs w/ Mermaid!])
subgraph rustc[Rust Compiler]
a -. inject mermaid.js .-> r
end
</div>
<p>The diagram is going to be located in place of the code snippet</p>
<script type="module">
const mermaidModuleFile = "static.files.mermaid/mermaid.esm.min.mjsx";
const fallbackRemoteUrl = "https://unpkg.com/[email protected]/dist/mermaid.esm.min.mjsx";
const rustdocVarsId= "rustdoc-vars";
const dataRootPathAttr = "data-root-path";
function initializeMermaid(mermaid) {
var amrn_mermaid_theme =
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
Expand Down

0 comments on commit eaa088b

Please sign in to comment.