-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Configurable HTML class for initialisation #3055
Comments
This is possible by calling the init method: mermaid.init(undefined,document.querySelectorAll(".language-mermaid")); but this method is marked as deprecated, there should be a way via the mermaidAPI: <script>
mermaid.mermaidAPI.initialize({ startOnLoad:false }); $(function(){ // Example of using the API var
element = document.querySelector("#graphDiv"); var insertSvg = function(svgCode, bindFunctions){
element.innerHTML = svgCode; }; var graphDefinition = 'graph TB\na-->b'; var graph =
mermaid.mermaidAPI.render('graphDiv', graphDefinition, insertSvg); });
</script> but Iam also looking for a simple example how to only change the target class without adjusting anything else like graphDefinition etc. |
We should do it! |
@PMunch, calling The difference between
I'm not sure why |
The idea was to replace the init function with a run function. This to keep the addition of config and starting the execution apart. This as you sometimes want to separate the to, as in when you want to trigger the rendering manually. |
<script>document.querySelectorAll('.language-mermaid').forEach(s => s.classList.add("mermaid"))</script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.min.js"></script>
<script>mermaid.initialize({ startOnLoad:true })</script> |
How this problem has been fixed by version 10? |
Is your feature request related to a problem? Please describe.
I have a Markdown parser which generates HTML. I've added loading of Mermaid in the header and set it up to initialise on load. However the HTML my Markdown parser outputs appends
language-
to the tags for code blocks. So when I do:The output is:
This prevents Mermaid from turning the blocks into SVGs
Describe the solution you'd like
A configuration option to select which class Mermaid will consider Mermaid diagrams and turn into graphs.
Describe alternatives you've considered
Modifying the Markdown parser to not add the
language-
prefix does work, but simply having a configuration option in Mermaid would be a much more flexible option.The text was updated successfully, but these errors were encountered: