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(import): keep Mermaid flowchart statements after the header semicolon (#455)

Rudy Mizrahi Celeklic633741861a8
diff --git a/scripts/verify-mermaid-import.py b/scripts/verify-mermaid-import.py
index 65baac7..464b291 100644
--- a/scripts/verify-mermaid-import.py
+++ b/scripts/verify-mermaid-import.py
@@ -217,6 +217,25 @@ def check_flowchart() -> None:
ok("flowchart parses: shapes, subgraphs, labels, cycle, budgets, tables")
+def check_flowchart_header_statements(tmp: Path) -> None:
+ # Mermaid accepts `graph TD; A-->B;` on the header line itself; the
+ # statements after the header's semicolon are diagram content.
+ for name, header in (("graph-td", "graph TD;"), ("flowchart-lr", "flowchart LR;")):
+ source = tmp / f"header-statements-{name}.mmd"
+ source.write_text(f"{header} A-->B; B-->|ok| C;\n", encoding="utf-8")
+ diagram = json.loads(run_extract([str(source), "--json"]))["diagrams"][0]
+ nodes = sorted(node["id"] for node in diagram["nodes"])
+ edges = [(e["source"], e["target"], e["label"]) for e in diagram["edges"]]
+ if nodes != ["A", "B", "C"] or edges != [("A", "B", ""), ("B", "C", "ok")]:
+ fail(f"header-line statements were dropped for {header!r}: {nodes} {edges}")
+ bare = tmp / "header-statements-bare.mmd"
+ bare.write_text("flowchart LR;\nA-->B\n", encoding="utf-8")
+ diagram = json.loads(run_extract([str(bare), "--json"]))["diagrams"][0]
+ if [edge["target"] for edge in diagram["edges"]] != ["B"]:
+ fail("a bare header semicolon changed the following statements")
+ ok("flowchart statements after the header semicolon are retained")
+
+
def check_entity_label_codes(tmp: Path) -> None:
source = tmp / "entity-labels.mmd"
source.write_text(
@@ -1459,6 +1478,7 @@ def main() -> int:
check_node_shape_updates(tmp)
check_invisible_links(tmp)
check_spaced_pipe_labels(tmp)
+ check_flowchart_header_statements(tmp)
check_entity_label_codes(tmp)
check_shape_and_edge_vocabulary(tmp)
check_frontmatter(tmp)
diff --git a/skills/diagram-design/scripts/mermaid_extract.py b/skills/diagram-design/scripts/mermaid_extract.py
index c86d846..2caf26d 100644
--- a/skills/diagram-design/scripts/mermaid_extract.py
+++ b/skills/diagram-design/scripts/mermaid_extract.py
@@ -1163,6 +1163,15 @@ def _parse_er(
def parse_block(block: SourceBlock) -> Diagram:
lines = _prepared_lines(block)
kind, direction, header_position = _kind_and_direction(lines)
+ if kind == "flowchart":
+ # `graph TD; A-->B;` is valid: statements may follow the header's
+ # semicolon on the same line, so keep them as the first statement.
+ line_number, header = lines[header_position]
+ rest = re.match(r"^\s*(?:flowchart|graph)\s+(?:TD|TB|LR|RL|BT)\b", header, re.I)
+ tail = header[rest.end() :].lstrip() if rest else ""
+ if tail.startswith(";"):
+ lines[header_position] = (line_number, header[: rest.end()])
+ lines.insert(header_position + 1, (line_number, tail[1:]))
diagram = Diagram(block.index, kind, block.source_line, direction=direction)
if kind == "flowchart":
_parse_flowchart(diagram, lines, header_position)