Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ jobs:
- name: Check d2
run: d2 --version

# Mermaid is drawn by `merman-cli`, from the same toolchain release since
# 0.7.0 (issue 0115). With it on PATH the tests against the real renderer
# run instead of skipping, and the site build below draws Mermaid cells.
- name: Check merman-cli
run: merman-cli --version

# The second consumer of the resolver (HMD-0002). A build that goes red
# here means the model works for lint but not for rendering.
- name: Build the wiki
Expand Down Expand Up @@ -149,6 +155,10 @@ jobs:
env:
HMD_REQUIRE_PARITY: "1"
HQL_BIN: ${{ steps.toolchain.outputs.bin }}/hql
# The diagram engine's tests against the real Mermaid renderer run
# when this names one: that its flags are accepted, and that labels
# come back as SVG text (issue 0115).
MERMAN_BIN: ${{ steps.toolchain.outputs.bin }}/merman-cli

- name: Package the extension
run: npm run -w tools/hmd-vsc-ext package
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
- name: Check d2
run: d2 --version

- name: Check merman-cli
run: merman-cli --version

# The cover's live editor is the TypeScript implementation, bundled. It
# is build output, so it is built here, from the lockfile, and never
# committed. A site built without it still works: the editor's tab says
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release-vsc-ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,19 @@ jobs:
# since 0.6.0, so every VSIX must carry it (issue 0117). Without it the
# extension still works, and says once that the server is absent: a
# build that lost the binary would look like a working release.
- name: Check every VSIX carries its d2 and hmd-lsp, and its hql where HQL ships one
#
# `merman-cli`, the Mermaid renderer, is in the toolchain for every
# platform since 0.7.0, so every VSIX must carry it (issue 0115). Without
# it a Mermaid cell shows its source and a reason on a fresh install.
- name: Check every VSIX carries its d2, merman-cli and hmd-lsp, and its hql where HQL ships one
run: |
set -euo pipefail
for vsix in dist-vsix/*.vsix; do
case "$vsix" in
*win32*) expected="extension/toolchain/bin/d2.exe extension/toolchain/bin/hmd-lsp.exe extension/toolchain/bin/hql.exe" ;;
*win32*) expected="extension/toolchain/bin/d2.exe extension/toolchain/bin/merman-cli.exe extension/toolchain/bin/hmd-lsp.exe extension/toolchain/bin/hql.exe" ;;
*linux-x64*|*darwin-x64*|*darwin-arm64*)
expected="extension/toolchain/bin/d2 extension/toolchain/bin/hmd-lsp extension/toolchain/bin/hql" ;;
*) expected="extension/toolchain/bin/d2 extension/toolchain/bin/hmd-lsp" ;;
expected="extension/toolchain/bin/d2 extension/toolchain/bin/merman-cli extension/toolchain/bin/hmd-lsp extension/toolchain/bin/hql" ;;
*) expected="extension/toolchain/bin/d2 extension/toolchain/bin/merman-cli extension/toolchain/bin/hmd-lsp" ;;
esac
for file in $expected; do
if ! unzip -l "$vsix" | grep -q "$file"; then
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ an error. Your prose is left alone.

### Math, diagrams, and metadata

TeX mathematics, D2 diagrams, callouts, collapsible sections, footnotes, task
TeX mathematics, D2 and Mermaid diagrams, callouts, collapsible sections, footnotes, task
lists, and tables are part of the format. A diagram is text in the file, so it
lives in version control and shows up in a diff you can read:

Expand Down
4 changes: 2 additions & 2 deletions doc/issues/0115-mermaid-diagrams-on-par-with-d2.hmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 0115 — Mermaid diagrams, on par with D2

**Column**: todo
**Column**: doing
**Opened**: 2026-11-22
**Related**: [HMD-0022](../proposals/HMD-0022/index.hmd), [the D2 card](archive/0004-math-callouts-diagrams.hmd), [the toolchain card](archive/0107-toolchain-repository-for-native-binaries.hmd), [the diagram surface card](0102-diagram-theme-surface.hmd)
**Related**: [HMD-0034](../proposals/HMD-0034/index.hmd), [HMD-0030](../proposals/HMD-0030/index.hmd), [HMD-0022](../proposals/HMD-0022/index.hmd), [the D2 card](archive/0004-math-callouts-diagrams.hmd), [the toolchain card](archive/0107-toolchain-repository-for-native-binaries.hmd), [the diagram surface card](0102-diagram-theme-surface.hmd)

## What

Expand Down
2 changes: 1 addition & 1 deletion doc/issues/kanban.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ board:
- id: "0118"
title: "Listings in a fenced block are not coloured in the preview"
file: 0118-colour-the-listings-in-a-fenced-block.hmd
doing:
- id: "0115"
title: "Mermaid diagrams, on par with D2"
file: 0115-mermaid-diagrams-on-par-with-d2.hmd
doing: []
done:
- id: "0117"
title: "A language server, written in Rust"
Expand Down
4 changes: 3 additions & 1 deletion doc/models/requirements/initial_sketch.hmd
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ grammar.
| 16 | D2 diagrams | <code>&#96;&#96;&#96;d2</code> | free — `mkdocs-d2-plugin` |
| 17 | GFM baseline | tables, task lists, fenced code, strikethrough | free |

**Explicitly excluded:** highlights (`==text==`), Mermaid (superseded by D2).
**Explicitly excluded:** highlights (`==text==`). Mermaid was excluded here
too, as superseded by D2. That is reversed: Mermaid is a diagram language with
the same standing as D2 ([HMD-0034](../../proposals/HMD-0034/index.hmd)).

**Notes on the free items.**

Expand Down
10 changes: 7 additions & 3 deletions doc/proposals/HMD-0001/index.hmd
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ block_id := ALPHA / DIGIT *63( ALPHA / DIGIT / "_" / "-" )
vocabulary (P3) — but the whole mapping is exposed in the model and in
`hmd graph` output.

**Explicitly excluded from the MVP grammar:** inline properties (`key:: value`),
highlights (`==text==`), and Mermaid. The first is deferred; the latter two are
rejected by the source.
**Explicitly excluded from the MVP grammar:** inline properties (`key:: value`)
and highlights (`==text==`). The first is deferred; the second is rejected by
the source. Mermaid was excluded here too, as superseded by D2. HMD-0034
reverses that: a `mermaid#show` fence is a diagram with the same standing as
a `d2#show` fence.

### 3. Heading anchors

Expand Down Expand Up @@ -792,6 +794,8 @@ excerpts versus block anchors (Q3), and the query grammar (Q6).

## Changelog

- 2026-11-25: Mermaid is no longer excluded from the grammar; HMD-0034 accepts
it as a diagram language beside D2.
- 2026-07-31: drafted
- 2026-07-31: §5 reworked from recursive-per-scope to the two-phase spine walk
plus single root sweep; folder-note binding added (HMD012); worked example
Expand Down
12 changes: 9 additions & 3 deletions doc/proposals/HMD-0022/index.hmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ and never as a defect in the card.
- **Changing the Python implementation**, which renders through the same binary at build
time.
- **The interactive graph view.** HMD-0021 §10 owns it; §5 fixes the boundary.
- **Mermaid**, rejected by the source sketch as superseded by D2.
- **Choosing a renderer for Mermaid.** Mermaid was rejected here as superseded
by D2. HMD-0034 reverses that: Mermaid is a diagram language with the same
standing as D2, drawn by its own native renderer under the bounds, the
cache, and the image delivery of this record.

## Specification

Expand Down Expand Up @@ -285,8 +288,8 @@ npm run -w tools/hmd-vsc-ext test
- Should a failed diagram raise a diagnostic? It is visible in the preview, and
a new rule ID would have to be allocated by the canonical implementation
(HMD-0020 §9).
- Should `DiagramBlock` generalise to other fence languages now, given
`language` is already a field, or stay D2-only until a second one is real?
- Answered by HMD-0034: `DiagramBlock` carries Mermaid as well as D2. Its
`language` field already existed, and a second language is now real.
- Does the preview honour `rsvg-convert` for a PNG fallback, as the slides style
does, or is SVG sufficient inside an editor?

Expand All @@ -300,3 +303,6 @@ npm run -w tools/hmd-vsc-ext test
- 2026-11-22: amended by HMD-0030. A diagram is a `d2#show` or
`mermaid#show` fence, matched exactly; a plain `d2` fence is a listing. The
renderer, bounds, cache, and image delivery here are unchanged.
- 2026-11-25: amended by HMD-0034. Mermaid is no longer a non-goal: it is
drawn by `merman-cli` under the bounds here, and the cache key gains the
diagram language.
112 changes: 68 additions & 44 deletions doc/proposals/HMD-0030/index.hmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ A fence whose info string opens `d2#show` or `mermaid#show` is a **diagram
cell**. The preview draws it the way it draws an `hql#eval` cell: the picture
first, the source behind a **Code** toggle, and an **Edit** button beside it.
Where an HQL cell has **Run**, a diagram cell has **Show**. A diagram cell is
drawn when the card opens. After its source is edited it keeps its last
drawing, marked stale, until the reader presses Show. The drawing lives in the
preview only; nothing is written into the card. A plain `d2` or `mermaid`
fence becomes a **listing**, shown as code, exactly as a plain `hql` fence is.
The document IR's `DiagramBlock` gains a staleness state and moves to version
4.
drawn when the card opens, and drawn again as its source is edited. When an
edit leaves source that does not draw, the cell keeps its last drawing, marked
stale, with the reason under it. The drawing lives in the preview only;
nothing is written into the card. A plain `d2` or `mermaid` fence becomes a
**listing**, shown as code, exactly as a plain `hql` fence is. The document
IR's `DiagramBlock` gains the state of its drawing and moves to version 5.

## Motivation

Expand All @@ -33,10 +33,14 @@ The document IR's `DiagramBlock` gains a staleness state and moves to version
- **A reader wants the picture; an author wants the source.** The notebook
layout already solves this for HQL: answer first, code one click away. A
diagram is the same shape of thing.
- **Mermaid cannot be drawn on every keystroke.** Its reference renderer
drives a headless browser, and a cold start does not fit the two-second
bound D2 meets. Drawing on open and on Show, and never while typing, keeps
the preview responsive whichever renderer Mermaid ends up with.
- **An author watches the diagram while typing it.** D2 has always been drawn
as its source changes, and that is the feature an author uses most. The cell
layout keeps it, for D2 and for Mermaid. Mermaid's renderer is a native
program that draws in milliseconds, so it needs no exception.
- **A broken edit should not blank the diagram.** Half-typed source does not
draw. A cell that kept nothing would flicker between a picture and an error
on every keystroke, so it keeps its last drawing until the source draws
again.

**What this must not break.** A card with diagram cells renders completely
with no renderer installed: each cell shows its source and says why it is not
Expand All @@ -46,7 +50,8 @@ drawn.

- `d2#show` and `mermaid#show` behave like HQL cells in the preview, with Show
in place of Run.
- No renderer starts while the reader types.
- A diagram follows its source as the author types, in both languages.
- A cell never loses its drawing to an edit that does not draw.
- The card stays text: showing a diagram never edits the file.

## Non-goals
Expand All @@ -55,8 +60,8 @@ drawn.
artifacts as more machinery than the problem has, and this record keeps that
decision.
- **Choosing Mermaid's renderer.** That choice, its bounds, and its security
settings belong to the Mermaid card. Until it is made, a `mermaid#show` cell
shows its source and says no renderer is available.
settings are made in HMD-0034: a native renderer, `merman-cli`, under the
bounds D2 has.
- **Interactive diagrams.** A drawing still reaches the page as an image, so
links and click handlers inside it do nothing.
- **New diagram languages.** Only `d2` and `mermaid` get a `#show` kind.
Expand Down Expand Up @@ -100,20 +105,26 @@ The first is drawn; the second is shown as code.

### When a diagram cell is drawn

A cell is drawn when the card is shown, and again when the reader asks.

- When the preview first shows a card, it MUST draw each diagram cell whose
renderer is available, within the bounds of HMD-0022. A drawing already in
the cache is used without starting a renderer.
- When a cell's source changes, the preview MUST NOT start a renderer. If the
new source is in the cache — after an undo, say — that drawing is shown and
the cell is current. Otherwise the last drawing stays on screen, marked
**stale**.
- **Show** draws the cell's current source and replaces its drawing. It is
also how a reader retries after a timeout or a failure.
- A cell whose source has never been drawn, and is not in the cache, is **not
drawn**, with the reason: no renderer, a syntax error, a timeout, or a
source over the size bound.
A cell is drawn when the card is shown, again whenever its source changes,
and again when the reader asks.

- When the preview shows a card, it MUST draw each diagram cell whose renderer
is available, within the bounds of HMD-0022. A drawing already in the cache
is used without starting a renderer.
- When a cell's source changes, the preview MUST draw the new source, on the
same delay it re-reads the card on. If the new source is in the cache —
after an undo, say — that drawing is shown without starting a renderer.
- When the new source does not draw, the last drawing MUST stay on screen,
marked **stale**, with the reason under it: a syntax error, a timeout, or a
source over the size bound. The cell is current again as soon as its source
draws.
- A cell whose source has never drawn is **not drawn**. It shows its source
and the reason.
- **Show** draws the cell's current source again. A failure is not answered
from the cache, and a renderer that was missing is looked for again, so Show
is how a reader retries after a timeout or after installing a renderer.
- A drawing kept for a stale cell belongs to one preview and one card. It is
dropped when the preview moves to another card.

The cache is HMD-0022's: in memory, keyed by source, bounded to 64 entries,
least recently used evicted.
Expand Down Expand Up @@ -167,8 +178,10 @@ DiagramBlock := {
}
```

- `IR_VERSION` becomes **4**. A webview that receives another version refuses
- `IR_VERSION` becomes **5**. A webview that receives another version refuses
to render and asks for a reload.
- `language` is `d2` for a plain `d2` fence for as long as that fence still
draws. Such a block has no cell layout and keeps its key by source.
- The key is the cell's position among diagram cells, not its content. Editing
a cell would otherwise give it a new key, and the reader's Code toggle and
the stale drawing would be lost with it.
Expand All @@ -180,8 +193,8 @@ DiagramBlock := {
The canonical implementation follows the same fence rule.

- A site build MUST draw `d2#show` cells, with the renderer and bounds it uses
today, and MUST render a plain `d2` fence as a code block. `mermaid#show`
draws once the Mermaid renderer is chosen.
today, and MUST render a plain `d2` fence as a code block. It MUST draw
`mermaid#show` cells with the renderer HMD-0034 chooses.
- How a built page shows a diagram cell's source is an open question below.
Until it is answered, the page shows the drawing only, as it does today.

Expand All @@ -197,7 +210,7 @@ The canonical implementation follows the same fence rule.
draw.
- **HQL's `mermaid` format step writes a plain `mermaid` fence**, which becomes
a listing. HQL is asked to write `mermaid#show`.
- **`IR_VERSION` moves from 3 to 4.** A stale webview shows the reload message.
- **`IR_VERSION` moves from 4 to 5.** A stale webview shows the reload message.
- No card changes on disk because of this record. Showing a diagram never
writes.

Expand All @@ -215,15 +228,16 @@ Nothing new runs, and nothing runs on new input.

## Deployment / Activation

1. In both implementations, recognise `d2#show` as a diagram, beside plain
`d2`. Both still draw, so nothing breaks.
1. In both implementations, recognise `d2#show` and `mermaid#show` as diagram
cells, beside plain `d2`. All three draw, so nothing breaks. In the same
release, land the preview's cell layout, Show, the stale state, and
`IR_VERSION` 5 for the two cell kinds.
2. Rewrite every `d2` fence in this repository as `d2#show`.
3. In one release of each tool, turn plain `d2` into a listing, and land the
preview's cell layout, Show, the stale state, and `IR_VERSION` 4. State the
3. Ask HQL to write `d2#show` and `mermaid#show` where it writes `d2` and
`mermaid` today. A cell's output is machine-written, and it would otherwise
become a listing in the next step.
4. In one release of each tool, turn plain `d2` into a listing. State the
change in each changelog, with the one-line migration: rename the fence.
4. Add `mermaid#show` to the recognised kinds. It shows its source until the
Mermaid renderer lands.
5. Ask HQL to write `mermaid#show` from its `mermaid` step.

## Reference Implementation

Expand All @@ -248,10 +262,13 @@ Unit tests MUST include:
and every other kind are not.
- A diagram cell takes no HQL cell number and is untouched by the HQL mask.
- A diagram cell's body yields no link and no edge.
- On first render the cell is drawn; after an edit no renderer starts and the
cell is stale; after an undo to a cached source it is current again without
a render.
- Show replaces the drawing and clears stale; a failed draw keeps the reason.
- On first render the cell is drawn; after an edit that draws, the new
drawing is shown and the cell is current; after an edit that does not draw,
the last drawing is kept and the cell is stale, with the reason.
- A source drawn before is answered from the cache without a render.
- Show draws a failed source again and does not answer from the cache; it
looks again for a renderer that was missing.
- One cell's last drawing is never shown under another cell.
- The Code toggle survives an edit and a redraw.
- Show is offered inside an embed, and Run is still not.
- The key of a diagram cell does not change when its source does.
Expand Down Expand Up @@ -284,12 +301,19 @@ uv run python -m pytest tools/hmd/tests/test_diagram.py
## Changelog

- 2026-11-22: drafted.
- 2026-11-25: a cell is drawn as its source is edited, in both languages. The
first draft forbade a renderer while the author types, because Mermaid was
expected to need a headless browser; HMD-0034 chose a native renderer that
draws in milliseconds. Stale now means that the edited source does not
draw. `IR_VERSION` is 5, because 4 was taken by heading keys. The cell
layout lands with the two `#show` kinds, before a plain `d2` fence becomes
a listing.

## See also

- [HMD-0026](../HMD-0026/index.hmd) — HQL cells: the layout, the Code toggle,
Edit, and the listing rule this record extends to diagrams.
- [HMD-0022](../HMD-0022/index.hmd) — the diagram block, the renderer, its
bounds, its cache, and its image delivery, all kept here.
- [The Mermaid card](../../issues/0115-mermaid-diagrams-on-par-with-d2.hmd) —
the Mermaid renderer, still to be chosen.
- [HMD-0034](../HMD-0034/index.hmd) — the Mermaid renderer, its arguments,
and its bounds.
Loading
Loading