Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

fix(mermaid): retain single-line state notes (#447)

Rudy Mizrahi Celekli880b383053b0
diff --git a/scripts/verify-mermaid-import.py b/scripts/verify-mermaid-import.py
index c136881..9935302 100644
--- a/scripts/verify-mermaid-import.py
+++ b/scripts/verify-mermaid-import.py
@@ -1372,14 +1372,20 @@ def check_standalone_state_regression(tmp: Path) -> None:
notes.write_text(
"stateDiagram-v2\nstate Idle\nnote left of Idle\nGhost\nend note\n"
"note right of Idle\nPhantom\nend note\n"
- "note left of Idle: inline annotation\n"
- "note right of Idle: inline annotation\nActive\nnote\nend\nnotebook\n",
+ "note left of Idle: first inline annotation\n"
+ "note right of Idle: second inline annotation\nActive\nnote\nend\nnotebook\n",
encoding="utf-8",
)
payload = json.loads(run_extract([str(notes), "--json"]))["diagrams"][0]
if {node["id"] for node in payload["nodes"]} != {"Idle", "Active", "note", "end", "notebook"}:
fail("State note boundaries swallowed real states or retained annotation bodies")
+ if payload["notes"] != ["first inline annotation", "second inline annotation"]:
+ fail("Single-line state notes were not retained in source order")
+ digest = run_extract([str(notes)])
+ if "notes: first inline annotation; second inline annotation" not in digest:
+ fail("Single-line state notes were not printed in the digest")
+
for side in ("left", "right"):
unterminated = tmp / f"state-note-unterminated-{side}.mmd"
unterminated.write_text(
diff --git a/skills/diagram-design/references/import-mermaid.md b/skills/diagram-design/references/import-mermaid.md
index 554808f..958406e 100644
--- a/skills/diagram-design/references/import-mermaid.md
+++ b/skills/diagram-design/references/import-mermaid.md
@@ -131,5 +131,7 @@ Markdown is the Mermaid analogue of multi-page draw.io. The header lists every f
| Silently dropping content | Every import ships a fidelity ledger |
Bare state declarations are retained even when disconnected from transitions.
+Single-line state notes are retained as inert text in the JSON `notes` array and
+the Markdown digest, in source order.
Multiline state notes are opaque annotation text through `end note`; a missing
terminator exits with the extractor's exit-2 diagnostic and the opening line number.
diff --git a/skills/diagram-design/scripts/mermaid_extract.py b/skills/diagram-design/scripts/mermaid_extract.py
index ee9592d..a0d670b 100644
--- a/skills/diagram-design/scripts/mermaid_extract.py
+++ b/skills/diagram-design/scripts/mermaid_extract.py
@@ -1013,7 +1013,10 @@ def _parse_state(
if note:
# A colon marks a single-line note; otherwise ignore its opaque body
# through `end note` before interpreting states, edges or braces.
- note_start = line_number if note.group(1) is None else None
+ if note.group(1) is None:
+ note_start = line_number
+ else:
+ diagram.notes.append(clean_label(note.group(1)))
continue
if _discard_nonsemantic(diagram, text):
continue