Use the mermaid.render() function instead of the mermaid.run() function to parse Mermaid diagram definitions directly, without going through HTML first.
flowchart LR
subgraph a ["Removes newlines!!!"]
div["HTML <div>"]
end
MMD --> div["HTML <div>"]
div -->|"mermaid.run()"| svg["HTML <svg>"]
However, when converting the mmd code to HTML <div>, newlines and whitespace formatting may get removed. For the majority of diagrams, this is no issue, but for some diagrams (e.g. classDiagram), whitespace does matter.
The mermaid API has a mermaid.render() function that we can use instead, which parses in mmd code directly, without having to go through a HTML element first:
flowchart LR
MMD -->|"mermaid.render()"| svgText["SVG text"] -->svg["HTML <svg>"]
As an additional benefit, we get better error messages from Mermaid too!
Brilliant work! I appreciate your help very much!
BTW, I have upgraded your collaborator status for this repository to Maintain. Let me know if you would like to get Admin access ❤️
:bookmark_tabs: Summary
Use the
mermaid.render()
function instead of themermaid.run()
function to parse Mermaid diagram definitions directly, without going through HTML first.:straight_ruler: Design Decisions
Currently,
mermaid-cli
renders mermaid diagrams by:However, when converting the mmd code to HTML
<div>
, newlines and whitespace formatting may get removed. For the majority of diagrams, this is no issue, but for some diagrams (e.g.classDiagram
), whitespace does matter.The mermaid API has a
mermaid.render()
function that we can use instead, which parses in mmd code directly, without having to go through a HTML element first:As an additional benefit, we get better error messages from Mermaid too!
:clipboard: Tasks
Make sure you
master
branch