mermaid-cli

Command-line tool (mmdc) that renders Mermaid diagram definitions and Markdown files with Mermaid code blocks to SVG, PNG, or PDF.

install

mermaid-cli is the command-line interface for the Mermaid diagramming library. Its executable, mmdc, takes a Mermaid definition file (.mmd) as input and writes an SVG, PNG, or PDF file. For example, mmdc -i input.mmd -o output.svg renders a diagram, and mmdc -i input.mmd -o output.png -t dark -b transparent produces a PNG with a dark theme and transparent background. Input can also be piped from stdin with --input -, such as from a heredoc.

It can also process Markdown files. Running mmdc -i readme.template.md -o readme.md finds the mermaid code blocks, renders each one to an SVG file, and replaces the blocks with image references in the output Markdown. Accessibility title and description set in the diagram (accTitle, accDescr) become the image title and alt text. The README describes this Markdown support as basic.

Other options include --cssFile to inline custom CSS (for example, to animate an SVG) through Mermaid's themeCSS setting, and --size to try to produce a PNG of a given size. Custom icon packs can be loaded either from npm packages with --iconPacks or from URLs and file:// URIs with --iconPacksAndUrls. A Node.js API exposes a run(input, output, options) function, but it isn't covered by semver, because the package follows Mermaid's versioning.

It suits developers, documentation authors, and CI pipelines that need to generate diagram images from text definitions. Besides the global npm install, it can be installed locally, run through npx -p @mermaid-js/mermaid-cli mmdc, or run from Docker or Podman images that read input files from /data. The Homebrew install is no longer supported and only provides an old version.

Installation

# via npm
npm install -g @mermaid-js/mermaid-cli
# via Docker
docker pull minlag/mermaid-cli
# via npx
npx -p @mermaid-js/mermaid-cli mmdc -h

Alternatives & related tools

add a badge to your README

Maintain mermaid-cli? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/mermaid-cli.svg)](https://www.trmn.sh/tools/mermaid-cli?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/mermaid-cli?utm_source=badge"><img src="https://www.trmn.sh/badge/mermaid-cli.svg" alt="Featured on trmn" height="20"></a>