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): read Mermaid invisible links without dropping their nodes (#445)

Rudy Mizrahi Celekli3f73d3157b92
diff --git a/scripts/verify-mermaid-import.py b/scripts/verify-mermaid-import.py
index 9935302..65baac7 100644
--- a/scripts/verify-mermaid-import.py
+++ b/scripts/verify-mermaid-import.py
@@ -1274,6 +1274,43 @@ def check_node_shape_updates(tmp: Path) -> None:
ok("node declarations update shapes while bare references preserve them")
+def check_invisible_links(tmp: Path) -> None:
+ flow = tmp / "invisible-links.mmd"
+ flow.write_text("flowchart TD\nJ ~~~ K\nP --> Q ~~~ R\n", encoding="utf-8")
+ diagram = json.loads(run_extract([str(flow), "--json"]))["diagrams"][0]
+ if sorted(node["id"] for node in diagram["nodes"]) != ["J", "K", "P", "Q", "R"]:
+ fail("endpoints of an invisible link must still become nodes")
+ if [(edge["source"], edge["target"]) for edge in diagram["edges"]] != [("P", "Q")]:
+ fail("an invisible link must not become an edge")
+ if diagram["notes"] != ["2 invisible layout links ignored"]:
+ fail(f"invisible links must be reported: {diagram['notes']!r}")
+ ok("invisible ~~~ links declare their nodes without becoming edges")
+
+ for endpoint in ("x", "o"):
+ for operator, style in (("--go-->", "solid"), ("==go==>", "thick"), ("-.go.->", "dashed")):
+ for invisible in ("~~~", "~~~~"):
+ flow.write_text(f"flowchart TD\nA {invisible} {endpoint}{operator}B\n", encoding="utf-8")
+ mixed = json.loads(run_extract([str(flow), "--json"]))["diagrams"][0]
+ if {node["id"] for node in mixed["nodes"]} != {"A", endpoint, "B"}:
+ fail("an invisible link must preserve a following x/o endpoint")
+ edges = [(edge["source"], edge["target"], edge["label"], edge["style"])
+ for edge in mixed["edges"]]
+ if edges != [(endpoint, "B", "go", style)]:
+ fail(f"mixed invisible/labeled chain changed its visible edge: {edges!r}")
+ if mixed["notes"] != ["1 invisible layout links ignored"]:
+ fail("mixed invisible/labeled chains must report only their layout link")
+
+ flow.write_text("flowchart TD\nA ~~~ x--go-->B ~~~ o-.next.->C\n", encoding="utf-8")
+ mixed = json.loads(run_extract([str(flow), "--json"]))["diagrams"][0]
+ if {node["id"] for node in mixed["nodes"]} != {"A", "x", "B", "o", "C"}:
+ fail("a repeated mixed chain must preserve every endpoint")
+ if [(edge["source"], edge["target"], edge["label"]) for edge in mixed["edges"]] != [
+ ("x", "B", "go"), ("o", "C", "next")
+ ] or mixed["notes"] != ["2 invisible layout links ignored"]:
+ fail("a repeated mixed chain must retain both labeled edges and no invisible edges")
+ ok("invisible links keep x/o endpoint identity in solid, thick, dotted and repeated chains")
+
+
def check_spaced_pipe_labels(tmp: Path) -> None:
flow = tmp / "spaced-pipe-labels.mmd"
flow.write_text(
@@ -1420,6 +1457,7 @@ def main() -> int:
check_flowchart()
check_bidirectional_analysis(tmp)
check_node_shape_updates(tmp)
+ check_invisible_links(tmp)
check_spaced_pipe_labels(tmp)
check_entity_label_codes(tmp)
check_shape_and_edge_vocabulary(tmp)
diff --git a/skills/diagram-design/references/import-mermaid.md b/skills/diagram-design/references/import-mermaid.md
index 958406e..4a5c20d 100644
--- a/skills/diagram-design/references/import-mermaid.md
+++ b/skills/diagram-design/references/import-mermaid.md
@@ -68,7 +68,7 @@ Load the selected `type-*.md`. Override the grammar only when the content disagr
- Start from a blank `viewBox` selected by the size preset. Mermaid positions do not exist in the source, and a renderer's positions must not be recreated.
- Use semantic treatments from the chosen type. A Mermaid cylinder becomes Store/State; a rhombus stays a decision only in a flowchart; subgraphs become zones or collapsible groups.
- Ignore init themes, `style`, `classDef`, `class`, inline `:::class` attachments, and `linkStyle`. One accent plus the ink ramp replaces the source theme. A leading `---` frontmatter block is title/config, so it is skipped with the same reasoning.
-- Reroute all connections with the SKILL.md §6 connector rules. Mermaid edge length markers are ranking hints, not content.
+- Reroute all connections with the SKILL.md §6 connector rules. Mermaid edge length markers are ranking hints, not content. Invisible `~~~` links are layout hints: their endpoints still become nodes, no edge is drawn, and the digest notes how many were ignored.
- Do not add a component merely to fill space. Imports remain bounded by source meaning.
## Step 6 — Deliver
diff --git a/skills/diagram-design/scripts/mermaid_extract.py b/skills/diagram-design/scripts/mermaid_extract.py
index a0d670b..c86d846 100644
--- a/skills/diagram-design/scripts/mermaid_extract.py
+++ b/skills/diagram-design/scripts/mermaid_extract.py
@@ -645,6 +645,9 @@ class _Operator:
def _operator_style(token: str) -> tuple[str, str, bool, bool]:
+ if token.startswith("~"):
+ # `A ~~~ B` is an invisible link: it only places B near A.
+ return "invisible", "none", False, True
style = "dashed" if "." in token else "thick" if "=" in token else "solid"
arrowhead = "cross" if token.endswith("x") else "circle" if token.endswith("o") else "arrow"
undirected = ">" not in token and not token.endswith(("x", "o"))
@@ -692,7 +695,7 @@ def _edge_operators(text: str) -> list[_Operator]:
r"(?P<closing>\.-+[>xo]|\.-+)"
)
trailing_operator = re.compile(
- r"(?:\.-+[>xo]|\.-+|-{2,}>|--[xo]|=+>|={2,}|-{3,})"
+ r"(?:\.-+[>xo]|\.-+|-{2,}>|--[xo]|=+>|={2,}|-{3,}|~{3,})"
r"(?:\|[^|\n]*\|)?\s*$"
)
for edge_pattern in (text_edge, dotted_edge):
@@ -729,7 +732,7 @@ def _edge_operators(text: str) -> list[_Operator]:
occupied.append((operator_start, match.end()))
pattern = re.compile(
- r"[xo][-=.]+[xo]|<[-=.]+>|-+\.-+>|=+>|-+(?:>|x|o)|-+\.-+|={3,}|-{3,}"
+ r"[xo][-=.]+[xo]|<[-=.]+>|-+\.-+>|=+>|-+(?:>|x|o)|-+\.-+|={3,}|-{3,}|~{3,}"
)
for match in pattern.finditer(mask):
if any(start <= match.start() < end for start, end in occupied):
@@ -789,6 +792,7 @@ def _parse_flowchart(
diagram: Diagram, lines: list[tuple[int, str]], header_position: int
) -> None:
containers: list[str] = []
+ invisible_links = 0
for line_number, raw in _logical_statements(lines[header_position + 1 :]):
text = raw.strip()
if not text:
@@ -835,6 +839,11 @@ def _parse_flowchart(
_fail(f"malformed edge at line {line_number}")
valid_groups = [group for group in groups if group is not None]
for index, operator in enumerate(operators):
+ if operator.style == "invisible":
+ # The endpoints were declared above; the link itself is a
+ # layout hint with no meaning of its own.
+ invisible_links += 1
+ continue
for source in valid_groups[index]:
for target in valid_groups[index + 1]:
diagram.add_edge(
@@ -853,6 +862,8 @@ def _parse_flowchart(
if parsed is not None:
node_id, label, shape = parsed
diagram.add_node(node_id, label, shape, parent)
+ if invisible_links:
+ diagram.notes.append(f"{invisible_links} invisible layout links ignored")
def _parse_sequence(