Skip to content

Ferrigura 0.9, a diagram renderer for Rust, Node.js and the command line

Mermaid diagrams, drawn without a browser.Fonts included, labels still text.

Ferrigura turns Mermaid diagram text into standalone SVG files for documentation sites, build tools and servers. It is a port of Mermaid 12.2.0 to Rust: no browser starts, the fonts the labels were measured with travel inside the file, and every label stays real text.

  • 33 of 33diagram types of Mermaid 12.2.0
  • 2,232 of 2,232drawings within 0.05 px of Mermaid’s
  • 8,636inputs read the way Mermaid reads them
  • Rust 1.95+Node.js 22.13+, MIT license

A few lines of text become a drawing.

A diagram in a document is usually a picture: drawn in one tool, exported, pasted in, and out of date by the next release. Mermaid took another road. You write the diagram as text, a box here, an arrow there, right beside the prose that explains it. The text lives in the repository, changes in the same review as the code, and a renderer turns it into a drawing.

That renderer has always needed a browser. Mermaid measures its labels with the page’s fonts and lays out the drawing inside a web page. In a reader’s browser that costs a script download. In a documentation build, a server or a test, it means starting a headless browser for every batch of diagrams, and the result depends on the fonts installed on the machine that drew it.

Ferrigura is Mermaid’s drawing, carried over to Rust. It reads the same diagram text, lays it out with the same engines and writes a standalone SVG file, with no browser in the process. Pick a type and compare the text with the drawing it became.

Each drawing is an ordinary SVG file. It can be written next to the page that shows it, inlined into HTML, or served as an image, and it looks the same wherever it goes. Render your first diagram

A flowchart that looks designed.

Ferrigura draws a flowchart the way Mermaid does, so that nothing moves when you switch. One option draws it Ferrigura’s own way: calm, with room, and with color that means something.

A layout engine decides where a box stands in its layer by keeping the arrows short. By that measure a step of a few pixels in an arrow costs almost nothing, and it is the first thing the eye catches. A box with two arrows out stands over one of them, not between them. And an arrow that runs back to the start can take the straight line from the main flow.

With design: true, Ferrigura places the boxes itself, in the layers and the order the same engine decided. A chain stands on one line. A decision stands between its branches, and the box where they meet again stands under it. The arrows of a box leave together from the middle of its side, and the one that carries the main flow runs straight.

Defaultdesign: false
Design modedesign: true

Real output of Ferrigura (repository source), the same diagram text rendered twice. Only the option differs.

Show the diagram text
flowchart LR
  text([Diagram text]) --> parse[Parse]
  parse --> measure[Measure the labels]
  measure --> flow[Lay out a flowchart]
  measure --> sequence[Lay out a sequence]
  measure --> other[Lay out another type]
  flow --> paint[Paint the SVG]
  sequence --> paint
  other --> paint
  paint --> file[(SVG file)]
  parse -. syntax error .-> report[Report the line]

The look changes with the layout. Outlines are thin, corners are round, and the boxes have room. A label sits in a gap of its arrow and needs no background. Color follows what a shape stands for, not the order of the boxes: where a flow starts and ends, where it decides, where data is kept. The mode has a light and a dark set of colors.

Lightdesign: true, colorScheme: 'light'
Darkdesign: true, colorScheme: 'dark'

Real output of Ferrigura (repository source). Each set is checked for contrast: 4.5 to 1 for text, 3 to 1 for lines.

The design mode draws flowcharts; another diagram type reports an error when the mode is asked for. It is an option of each render, like compat, and the two exclude each other. Your theme variables and class definitions keep the last word. How the design mode decides

Labels stay text. Their font comes along.

Ferrigura measures every label with fonts it brings along, then embeds exactly the letters the drawing uses.

The size of a box depends on the words inside it. To place a node, an edge or a line break, a renderer must know how wide each label will be, and that width depends on the font. Measure with one font and display with another, and labels spill out of their boxes or wrap where they should not.

Ferrigura measures with the fonts it ships: Lexica Ultralegible for text and Atkinson Hyperlegible Mono for code. It then writes the letters each drawing uses into the file as a font subset. The viewer draws the text with the very font it was measured with, whatever is installed on the reader’s machine.

The labels stay text. By default, Mermaid places its labels as HTML inside the SVG, which PDF converters, Inkscape and many other SVG tools do not show at all. Ferrigura writes them as SVG text, so they look the same everywhere, and a reader can still select and copy them, a search engine index them, and a screen reader read them out.

One label in the file, the decision nodeflowchart.svg
<g class="label" style="" transform="translate(0, -8.5)">
  <rect></rect>
  <g>
    <rect class="background" style="stroke: none"></rect>
    <text y="-10.1" text-anchor="start" style="">
      <tspan class="text-outer-tspan row" x="-32.8828125" y="14" text-anchor="start">
        <tspan font-style="normal" class="text-inner-tspan" font-weight="normal" x="-32.8828125">Signed</tspan>
        <tspan font-style="normal" class="text-inner-tspan" font-weight="normal" x="10.1328125"> in?</tspan>
      </tspan>
    </text>
  </g>
</g>
  • The whole file30.5 kB
  • Embedded font data, one face3.7 kB
  • Labels as SVG text10
  • HTML inside the drawingnone
  • Scriptsnone
  • A second renderthe same bytes

Real output of Ferrigura (repository source): the flowchart from the top of the page. The markup is indented for reading; in the file it stands on one line.

Each word sits at the position its measured width gives it. Colors are CSS custom properties, scoped to the diagram’s own id, so several drawings can share one page without their styles leaking into each other. How the text is measured

Two ways to draw a flowchart.

By default, Ferrigura straightens the small steps Mermaid leaves in simple flowcharts. One option brings Mermaid’s drawing back.

Mermaid spreads the ports of a box across its side. When two boxes of different widths are joined, their ports rarely line up, and the arrow between them takes a small step. Its edge labels are also only half opaque, so a line shows through the text that sits on it.

Ferrigura’s adaptive mode centers the ports and leaves room for the labels, so the layout engine can draw those arrows straight. It also gives the labels a solid background. Necessary bends remain, and in a complex graph the nodes can move. Use compat: true to preserve Mermaid-compatible geometry.

Adaptive, the defaultcompat: false
Mermaid-compatiblecompat: true

Real output of Ferrigura (repository source), the same diagram text rendered twice.

Show the diagram text
flowchart TD
  write[Write the guide] --> review{Review}
  review -->|Approved| publish[Publish]
  review -->|Changes requested| write
  publish --> announce[Announce the release]

The mode is an option of each render, not a setting in the diagram text, so one renderer can draw both. The same compat switch also controls compact sequence participant boxes. Why adaptive is the default

Light, dark, or the reader’s choice.

Choose the colors when you render, or let each reader’s system choose them.

A drawing that sits on a documentation page has to suit the page around it. Ferrigura renders in a light or a dark scheme. With the automatic scheme, the SVG carries both and follows the reader’s system setting, with no script and no second file.

LightcolorScheme: 'light'
DarkcolorScheme: 'dark'

Real output of Ferrigura (repository source). The dark drawing has no ground of its own; it stands on the page behind it.

Every color is a CSS custom property, and each element also carries its color as an attribute, for viewers that do not read custom properties. How themes work

Checked against Mermaid itself.

Every diagram type is compared with Mermaid 12.2.0, run unchanged in a browser: first what it reads, then what it draws.

A port is only useful if it behaves like the original. So Ferrigura does not take Mermaid’s word for it, and does not ask you to take ours. A test harness runs the original next to the port and compares them, type by type.

The first comparison is about reading. Fixtures, Mermaid’s own test cases and the examples from its documentation go through both parsers, and the structures they produce must agree. The second is about drawing. Both sides draw the same diagrams in Chromium, and every box, position, edge point and text has to land within 0.05 pixels of Mermaid’s.

  • flowchart298 of 298
  • swimlanes38 of 38
  • class180 of 180
  • state140 of 140
  • er159 of 159
  • requirement146 of 146
  • block58 of 58
  • mindmap57 of 57
  • sequence193 of 193
  • gantt52 of 52
  • timeline30 of 30
  • journey18 of 18
  • gitgraph135 of 135
  • pie24 of 24
  • info2 of 2
  • xychart47 of 47
  • quadrant30 of 30
  • sankey48 of 48
  • packet29 of 29
  • treemap114 of 114
  • radar26 of 26
  • kanban30 of 30
  • architecture46 of 46
  • c432 of 32
  • ishikawa28 of 28
  • eventmodeling39 of 39
  • cynefin23 of 23
  • wardley22 of 22
  • venn32 of 32
  • tree-view32 of 32
  • railroad42 of 42
  • agentflow51 of 51
  • usecase31 of 31

Drawings of each type that agree with Mermaid’s within 0.05 px, out of those both sides draw. The figures come from the repository’s coverage table, which the test harness rewrites from its latest runs.

Show every check as a table
TypeLayoutInputs read as Mermaid reads themDrawings within 0.05 pxNot compared
flowchartELK Layered783298 of 29854
swimlanesSwimlane layout (ferrigura-swimlane)21638 of 389
classELK Layered329180 of 18067
stateELK Layered390140 of 1405
erELK Layered752159 of 15947
requirementELK Layered266146 of 14626
blockOwn, on the unified shapes26558 of 580
mindmapcose-bilkent; tidy tree25557 of 570
sequenceOwn447193 of 1930
ganttOwn, on d3's time scale12552 of 520
timelineOwn8330 of 300
journeyOwn13118 of 180
gitgraphOwn299135 of 1350
pieOwn, on d3's arcs10724 of 240
infoOwn182 of 20
xychartOwn20747 of 470
quadrantOwn34030 of 300
sankeyOwn, on d3-sankey17848 of 483
packetOwn11529 of 290
treemapOwn, on d3-hierarchy's treemap211114 of 1140
radarOwn20826 of 260
kanbanOwn35630 of 300
architecturefcose28146 of 460
c4Own17732 of 320
ishikawaOwn8128 of 281
eventmodelingOwn22039 of 390
cynefinOwn12523 of 230
wardleyOwn22222 of 220
vennVenn layout (ferrigura-venn)27732 of 323
tree-viewOwn17632 of 320
railroadOwn41842 of 420
agentflowELK Layered28751 of 512
usecaseELK Layered29131 of 311

218 drawings are left out of the comparison, each for a stated reason: a hand-drawn look Ferrigura does not draw, a script no bundled font covers, or an input on which Mermaid itself fails. The checks for each type

To judge with your own eyes, ten everyday diagrams stand side by side with Mermaid’s drawings.

Other ways to draw Mermaid diagrams.

Ferrigura is one of several renderers for Mermaid’s syntax. Which one fits depends on where the diagrams are drawn and how close to Mermaid they must look.

Choose Ferrigura when you want Mermaid’s own drawing without a browser, the same on every machine, with its fonts inside the file: in a Rust program, on the command line or in Node.js. Choose one of these when something else matters more.

Mermaid

TypeScript, in a browser

The original, and the right choice when diagrams are drawn in the reader’s browser, with click callbacks, tooltips and the newest diagram types first.

On a server it needs a headless browser, through mermaid-cli. Labels use the page’s fonts.

Pele

TypeScript, any JavaScript runtime

An independent renderer of Mermaid’s syntax, built for Obsidian, when speed matters most.

It draws a layout and style of its own rather than Mermaid’s, and faster.

merman

Rust, with many bindings

A headless Rust implementation aimed at Mermaid’s output, with PNG, PDF and ASCII as well as SVG, and bindings such as WebAssembly and Python.

By default it estimates text widths rather than measuring bundled fonts, and leaves the fonts to the viewer.

The comparison page sets these and mermaid-rs-renderer side by side, with measured sizes and render times, and says what each does better. Compare the renderers

Three ways in, one engine.

Render from Node.js, from a Rust program or from the shell. All three run the same engine.

The engine is written in Rust. The crate gives a Rust program the renderer directly. The command-line tool renders files in a build script. The npm package brings the same engine to Node.js as a native addon, with a small JavaScript API and no WebAssembly. The library and the package render synchronously and return the SVG; the tool writes it to a file or to standard output.

Node.js package

npm install @ferrigura/core

import { Renderer }
  from '@ferrigura/core';

const renderer = new Renderer();
const svg = renderer.render(text, {
  colorScheme: 'auto',
});

Node.js 22.13 or newer, on macOS (Apple silicon), Linux and Windows.

Rust crate

cargo add ferrigura

use ferrigura::{Renderer, Value};

let config = Value::empty_object();
let renderer = Renderer::new(&config);
let svg = renderer.render(text)?;

Rust 1.95 or newer. A renderer can serve several threads at once.

Command line

cargo install --locked ferrigura-cli

ferrigura --scheme auto \
  --output-dir build/diagrams \
  docs/*.mmd

Reads files or standard input; several files go through one renderer.

The drawings on this page came from the Node.js package; the crate and the command line run the same engine.

Part of a workshop of engines.

Ferrigura works on its own. These are the places where it meets the rest of the Ferramenta family.

Each Ferramenta engine has one job and its own interface, and none needs another beside it. Ardo plans to draw its diagrams with Ferrigura.

A font is part of the geometry

Change a label’s font and its width can change too. Ferrigura measures with the same fonts it embeds, keeping the line breaks and surrounding shapes tied to the typography.

Read more

Diagrams for the documentation build

Ardo is a planned consumer of Ferrigura alongside its native Markdown and highlighting engines. The Ferromark adapter already renders Mermaid fences to SVG in custom builds. That adapter is optional and is not included in the standard npm addon.

Read more

Mermaid brought diagrams into plain text. Ferrigura carries its rendering into Rust, checking parser behavior and SVG geometry against the original while removing the browser dependency. Mermaid was created by Knut Sveidqvist and is maintained by the Mermaid contributors; its license and copyright notice stay with the port. Ferrigura is one of the Ferramenta engines, made by Sebastian Software in Mainz, Germany.

Draw your next diagram in the build.

Add the crate or the npm package, hand it your diagram text and keep the SVG with the rest of your site.