---
title: Diagrams
date: 2026-02-02
authors: [you]
category: Tutorials
comments: false
tags: [guide, diagrams]
summary: Mermaid fences become SVG at build time, in both light and dark, so readers download no diagramming library.
---

A fence tagged `mermaid` becomes a diagram:

```mermaid
flowchart LR
    A[Markdown] --> B[unified pipeline]
    B --> C[HTML + KaTeX + highlighting]
    B --> D[Mermaid SVG]
    C --> E[Prerendered pages]
    D --> E
```

Caption: What the build does to a post. A diagram is captioned like anything
else, by following it with a paragraph that starts with `Caption:`.

Mermaid is about 3 MB of JavaScript. Rather than send that to readers, the
build renders each diagram twice — once against the light palette, once against
the dark one — and inlines both as SVG. CSS shows whichever matches the
reader's theme, so switching theme swaps the diagram with no request and no
flash. During `npm run dev` the diagrams render in the browser instead, which
keeps the edit loop fast.

## Other diagram types

Anything Mermaid supports works. A state machine:

```mermaid
stateDiagram-v2
    [*] --> Draft
    Draft --> Review: date set
    Review --> Published: build runs
    Review --> Draft: changes needed
    Published --> [*]
```

A sequence:

```mermaid
sequenceDiagram
    participant W as Workflow
    participant B as Build
    participant P as Pages
    W->>B: npm run build
    B->>B: render diagrams
    B->>B: prerender routes
    B->>P: upload artifact
    P-->>W: deployment URL
```

## When a diagram fails

A diagram Mermaid cannot parse does not break the build. The failure is
reported on the console with the post it came from, and the block falls back to
rendering in the browser, where the error appears in place with the source
underneath it. That way a typo in one diagram costs you one diagram.
