mersinvald / aquamarine

Inline diagrams for rustdoc with mermaid.js
MIT License
508 stars 28 forks source link

Fix/27 location mermaid script #29

Closed frehberg closed 1 year ago

frehberg commented 1 year ago

place mermiad.min.js in target/docs even if invoked as

cargo doc --no-deps

frehberg commented 1 year ago

Any comments? For each module a subfolder is created, containing an index.html. So, to load the mermaid script, the depth needs to be known. Sadly proc_macro_attr does not provide this information. Therefor the html page has got to try to load mermaid script until the number of "../" matches the module depth.

    let mermaid_js_load_fallback1 = format!(r#"<script>window.mermaid || document.write('<script src="{}"><\/script>')</script>"#, MERMAID_JS_LOCAL_UP1);
    let mermaid_js_load_fallback2 = format!(r#"<script>window.mermaid || document.write('<script src="{}"><\/script>')</script>"#, MERMAID_JS_LOCAL_UP2);
    let mermaid_js_load_fallback3 = format!(r#"<script>window.mermaid || document.write('<script src="{}"><\/script>')</script>"#, MERMAID_JS_LOCAL_UP3);
    let mermaid_js_load_fallback4 = format!(r#"<script>window.mermaid || document.write('<script src="{}"><\/script>')</script>"#, MERMAID_JS_LOCAL_UP4);
    let mermaid_js_load_fallback5 = format!(r#"<script>window.mermaid || document.write('<script src="{}"><\/script>')</script>"#, MERMAID_JS_LOCAL_UP5);
    let mermaid_js_load_fallback = format!(r#"<script>window.mermaid || document.write('<script src="{}" crossorigin="anonymous"><\/script>')</script>"#, MERMAID_JS_CDN);
frehberg commented 1 year ago

the aquamarine/build.rs does place the mermaid.min.js CUSTOMER_CRATE/target/docs/ if "cargo doc" is invoked (see for example https://github.com/frehberg/rust-vue-demo/issues) Aquamarine did fallback to unpack always. But this fails if network access is blocked. The solution is to embed the mermaid.min.js into the macro-library and dumping to target/doc/mermaid.min.js