-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide mermaidjs rendering #762
Comments
I think this could be implemented as a preprocessor. It could transform something like this:
into this
The mermaidjs script tag could be added with |
I built this as a preprocessor: https://github.com/badboy/mdbook-mermaid |
I think this would be better written as a custom preprocessor, using a similar mechanism to custom renderers (e.g. the ... Of course users can't yet provide their own preprocessors for |
That’s exactly the issue I’m facing right now. |
I wrote up some support for custom preprocessors. The idea is It'd be awesome if someone could review the PR and see if the example is intuitive enough. |
You do not strictly need a preprocessor for this, it works with a javascript hack too. Mermaid preprocessorYou can easily use mermaid by making the following changes to your book.toml: [output.html]
additional-css = ["mermaid.css"]
additional-js = ["mermaid.min.js", "mermaid-init.js"] Where:
// mdBook creates <code> elements with the class 'language-mermaid hljs' whenever you
// define a mermaid code block.
// The mermaid javascript parser looks for elements with a class name 'mermaid'.
// So simply change the class name of the elements to 'mermaid' to make everything work.
function patchMermaidCodeElementClass() {
var elements = document.getElementsByClassName("language-mermaid");
for(var i=0; i < elements.length; i+=1) {
var element = elements.item(i);
if (element.tagName.toLowerCase() == "code") {
element.className = "mermaid";
}
}
}
patchMermaidCodeElementClass();
mermaid.initialize({startOnLoad:true}); The stylesheet borks the rendering of the TOC though. To fix this remove the opacity of the '.section' definition (line 95 in version 3cea267 dated 2 Oct 2018): .section {
stroke: none;
/*opacity: 0.2;*/
} |
I am here with a small update of @sytsereitsma's snippet. I had a problem with the original code on some browser because I have updated the code by duplicating // mdBook creates <code> elements with the class 'language-mermaid hljs' whenever you
// define a mermaid code block.
// The mermaid javascript parser looks for elements with a class name 'mermaid'.
// So simply change the class name of the elements to 'mermaid' to make everything work.
function patchMermaidCodeElementClass() {
var elements = document.getElementsByClassName("language-mermaid");
Array.from(elements).forEach(element => {
if (element.tagName.toLowerCase() == "code") {
element.className = "mermaid";
}
});
}
patchMermaidCodeElementClass();
mermaid.initialize({startOnLoad:true}); |
MermaidJS provides and excellent set of "features" for diagramming. I would like to provide this feature, similar to MathJAX into mdBook as an optional feature.
I am after some guidance regarding modularity.
hbs_renderer.rs
(adding html.mermaidjs_support) flags for example.Guidance will be appreciated.
The text was updated successfully, but these errors were encountered: