mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.52k stars 238 forks source link

Why does Mermaid CLI require a browser for image generation? #750

Open JockeM opened 2 months ago

JockeM commented 2 months ago

I was surprised to encounter an error running the Mermaid CLI, stating that I need a browser to generate an image. I’m wondering why this is necessary. For a CLI tool, it feels counterintuitive to rely on a browser for something like image generation.

Is there a technical reason for this? I’d prefer the tool not require a browser at all. Are there any plans to make this dependency optional or to provide a pure Node.js solution for generating images without a browser?

I’d appreciate any insights or future plans around this.

Thanks!

aloisklink commented 2 months ago

Unfortunately, Mermaid requires a CSS layout engine to correctly calculate the width/heights of boxes, and there doesn't seem to yet be a pure Node.JS/WASM solution for this. Only browsers have it:

Once that's done, the mermaid-cli project shouldn't need a browser to render an SVG, but we might still need one for SVG to PNG/PDF conversion. Although, we could make a separate library called something like mermaid-cli-svg so that most users can use just that instead, if they don't want a browser.