A Go port of mermaid 12.2.0

Mermaid diagrams,
without the browser.

mmdg renders Mermaid to SVG, PNG, and vector PDF in pure Go. Compare its SVG output with mermaid in Chromium below. KaTeX math works on both page modes. ZenUML is available on the mermaid-cli page. No headless browser, no Node, no cgo.

go get github.com/bvolpato/mermaid-go-renderer
Same bytes as mermaid
2143 of 2145

diagrams of mermaid's own test suite

Warm render
13× faster

0.88 ms against 11.5 ms in Chromium

Command line
16× faster

than mmdc, which starts a browser

Browsers needed
0

one static binary, or one Go import

01 Proof

The same bytes, not a look-alike

A label that is one pixel wider moves a node, and then an edge. So the only useful measure is the output itself. Each square is one diagram of mermaid's own test suite. mmdg renders it, and the SHA-256 of the result is compared with the output of mermaid in Chromium 156.

The string that mermaid.render() returns in a plain Chromium page.

  • Same bytes 2142
  • Same error as the reference 1
  • Other result 2

The end-to-end tests of mermaid

2143 of 2145

The examples of the mermaid documentation

594 of 596

Generated large diagrams

70 of 70

These results compare the current renderer with the recorded reference manifests. KaTeX math renders in diagram labels. ZenUML is available when the page is set to mermaid-cli.

go test -run TestCorpusParity .

The test needs no browser, no Node and no system fonts. The repository has the hash of every reference file.

View as a table
ReferenceCorpusDiagramsSame bytesSame errorOther result
mermaid.render()The end-to-end tests of mermaid2145214212
mermaid.render()The examples of the mermaid documentation596576182
mermaid.render()Generated large diagrams707000
mmdc 12The end-to-end tests of mermaid2145214302
mmdc 12The examples of the mermaid documentation59659222
mmdc 12Generated large diagrams707000

02 Speed

Milliseconds, because nothing has to start

mermaid needs a page to measure text, so every tool around it carries a browser. mmdg has its own measurement engine. A render is a function call.

One render in a warm process

13× faster

mermaid in Chromium11.5 ms
mmdg0.88 ms

Median of 2076 diagrams. Both sides are warm: a Chromium page that stays open, and a Go process that stays running.

Command-line run, flowchart to SVG

16× faster

mmdc729 ms
mmdg46.8 ms

Whole processes, same input and same output file. The measured command was mmdc 12.0.0. It starts a browser in each run.

Warm render time by diagram type

Median time of one render, in milliseconds, on a logarithmic axis. Each row is one diagram type of the corpus.

  • mermaid in Chromium
  • mmdg
View as a table
Diagram typeDiagramsmermaid, msmmdg, ms
flowchart-v240413.91.34
classDiagram22716.01.19
er20613.51.59
sequence1938.600.48
requirement17013.31.06
stateDiagram14421.01.06
gitGraph1357.900.19
block589.400.39
gantt523.000.18
xychart483.800.25
swimlane4621.72.47
agentflow3813.81.48
mindmap3313.90.55
c4323.900.68
timeline303.700.94
usecase2812.31.26
treemap262.200.27
pie242.100.10
venn212.200.46
architecture2014.31.20
journey184.800.26
sankey182.600.07
treeView151.700.12
quadrantChart144.100.12
ishikawa133.700.12
cynefin123.200.18
kanban114.100.22
wardley102.000.19
eventmodeling62.600.28
packet62.600.06
radar62.400.11
railroad56.000.26
info31.300.02
railroadEbnf26.200.24
railroadAbnf15.300.20
railroadPeg17.200.29

Measured on 2026-11-09 on one machine, with mermaid 12.2.0 in Chromium 156.0.8078.4 and mmdc 12.0.0 for the command-line comparison. How they were measured.

04 Playground

Run it in this page

The renderer also compiles to WebAssembly. Load it and edit the diagram. The SVG comes from the same Go code, in your browser. Nothing is sent to a server.

The renderer is not loaded.

Renderer

no

yes

miss

hit

Request

Token valid?

401 Unauthorized

In cache?

Diagram store

Render diagram

Write cache

Response

05 Inside

How the renderer works

The renderer combines Go ports of Mermaid and browser code with bundled JavaScript for KaTeX and ZenUML and an original vector PDF writer. Tests compare renderer output with recorded results from upstream code. Some features and output paths have documented limits.

Mermaid text

Parser

Diagram code

Layout engines

SVG

PNG

Measurement engine

The diagram code

The parsers, the databases and the renderers of mermaid 12.2.0, for every diagram type, look and theme.

A small browser engine

DOM, CSS cascade, font matching, HarfBuzz shaping with the arithmetic of Blink, and the float geometry of Skia. It answers the size questions that mermaid asks a page.

Native layout engines

dagre, the layered algorithm of Eclipse ELK, cose-bilkent and fcose of cytoscape, swimlanes and tidy-tree. Each returns the bits of the original.

JavaScript semantics

Number formatting, object key order, the sort of V8, the order of promises, and Math functions with the results of Chromium.

06 Use it

One import, or one binary

Install the library with go get github.com/bvolpato/mermaid-go-renderer. Install the command with Go or Homebrew below, or download a binary archive from the latest release. The renderer follows Mermaid 12.2.0. mmdg has its own release version. Run mmdg --version to check both versions.

Go
import mermaid "github.com/bvolpato/mermaid-go-renderer"

src := `flowchart LR
  A[Start] --> B{Done?}
  B -->|yes| C[Stop]`
svg, err := mermaid.Render(src)

png, err := mermaid.RenderPNG(src, mermaid.WithScale(2))
pdf, err := mermaid.RenderPDF(src, mermaid.WithPDFPaperFormat("A4"))
pdfFromSVG, err := mermaid.SVGToPDF(svg)

RenderPDF creates a PDF from Mermaid source. SVGToPDF converts an existing SVG. WithPDFPaperFormat selects a fixed page size. Without it, the page fits the diagram. PDF uses vector paths and TrueType fonts or Type 3 glyph subsets where possible. Unsupported fonts are outlined, and some contextual glyphs or ligatures may not extract as the original text. Drop shadows are flat silhouettes. Other filter graphs and image elements, including data URLs, are omitted. It needs Go 1.27.

Command line
go install github.com/bvolpato/mermaid-go-renderer/cmd/mmdg@latest
brew install bvolpato/tap/mmdg

mmdg -i diagram.mmd -o diagram.svg
mmdg -i diagram.mmd -o diagram.png -s 2
mmdg -i diagram.mmd -e pdf -o diagram.pdf --pdf-paper-format A4
mmdg -i README.md -o README.out.md -a images

Use --pdf-paper-format to select a fixed page size. Without it, the PDF page fits the diagram. The -f flag remains accepted for compatibility.