-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
0 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
⚠ 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 | ||
|