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): allow whitespace in compact dotted-link labels (#210)
Kumaresan-AI-Engineer767595db721e
diff --git a/scripts/verify-mermaid-import.py b/scripts/verify-mermaid-import.pyindex 5fbe420..9384486 100644--- a/scripts/verify-mermaid-import.py+++ b/scripts/verify-mermaid-import.py@@ -433,6 +433,40 @@ E-->|maybe|x--next-->F]:fail("chained x/o endpoint IDs were consumed as left edge markers")+ compact_dotted_space_file = tmp / "compact-dotted-space-labels.mmd"+ compact_dotted_space_file.write_text(+ """flowchart LR+Q-.next candidate.->R+S<-.both ways.->T+U o-.circle marker.-o V+W----->X+""",+ encoding="utf-8",+ )+ compact_dotted_space = json.loads(+ run_extract([str(compact_dotted_space_file), "--json"])+ )["diagrams"][0]+ compact_dotted_space_ids = sorted(node["id"] for node in compact_dotted_space["nodes"])+ if compact_dotted_space_ids != ["Q", "R", "S", "T", "U", "V", "W", "X"]:+ fail(+ "a whitespace-bearing compact dotted label materialized phantom "+ f"nodes: {compact_dotted_space_ids}"+ )+ compact_dotted_space_edges = [+ (edge["label"], edge["style"], edge["bidirectional"])+ for edge in compact_dotted_space["edges"]+ ]+ if compact_dotted_space_edges != [+ ("next candidate", "dashed", False),+ ("both ways", "dashed", True),+ ("circle marker", "dashed", True),+ ("", "solid", False),+ ]:+ fail(+ "a compact dotted link's label lost internal whitespace or its "+ f"style/bidirectional semantics: {compact_dotted_space_edges}"+ )+modern_file = tmp / "modern-flowchart.mmd"modern_file.write_text('''flowchart LRdiff --git a/skills/diagram-design/scripts/mermaid_extract.py b/skills/diagram-design/scripts/mermaid_extract.pyindex 4599f34..86595e8 100644--- a/skills/diagram-design/scripts/mermaid_extract.py+++ b/skills/diagram-design/scripts/mermaid_extract.py@@ -629,51 +629,67 @@ def _edge_operators(text: str) -> list[_Operator]:# `A<--yes-->B` or `A o--yes--o B`. The spaced form consumes exactly one# whitespace character next to each operator; any further padding falls# inside the label span, which `clean_label` strips, so the operator- # boundaries are never ambiguous. The compact label may not contain whitespace,- # and the operator characters themselves may not open one (keeping- # `A----->B` unlabeled and `A --o B --> C` two separate links).+ # boundaries are never ambiguous. For the dash and equals forms, the+ # compact label may not contain whitespace, and the operator characters+ # themselves may not open one (keeping `A----->B` unlabeled and+ # `A --o B --> C` two separate links). The dotted form's closing operator+ # always opens with a literal `.`, which a dash/equals label can't+ # produce, so its compact label may contain internal whitespace (as in+ # `A-.next candidate.->B`) without that ambiguity.text_edge = re.compile(r"(?P<opening>"- r"<(?:--|-\.|==)"- r"|(?<![\w.:-])[xo](?:--|-\.|==)"- r"|(?:--|-\.|==)"+ r"<(?:--|==)"+ r"|(?<![\w.:-])[xo](?:--|==)"+ r"|(?:--|==)"r")"r"(?:\s(?P<spaced>.+?)\s|(?![-=.\s])(?P<compact>[^\s|<>]+?))"- r"(?P<closing>\.-+[>xo]|\.-+|-{2,}>|--[xo]|=+>|={2,}|-{3,})"+ r"(?P<closing>-{2,}>|--[xo]|=+>|={2,}|-{3,})"+ )+ dotted_edge = re.compile(+ r"(?P<opening>"+ r"<-\."+ r"|(?<![\w.:-])[xo]-\."+ r"|-\."+ r")"+ r"(?:\s(?P<spaced>.+?)\s|(?![-=.\s])(?P<compact>[^\n|<>]+?))"+ r"(?P<closing>\.-+[>xo]|\.-+)")trailing_operator = re.compile(r"(?:\.-+[>xo]|\.-+|-{2,}>|--[xo]|=+>|={2,}|-{3,})"r"(?:\|[^|\n]*\|)?\s*$")- for match in text_edge.finditer(mask):- opening = match.group("opening")- operator_start = match.start()- if opening.startswith(("x", "o")):- prefix = mask[:operator_start]- if not prefix.strip() or trailing_operator.search(prefix):- # Here x/o is the endpoint before a regular opening operator,- # not a left marker: `x--yes-->B` or `A-->x--go-->B`.- operator_start += 1- opening = opening[1:]- token = opening + match.group("closing")- style, arrowhead, bidirectional, undirected = _operator_style(token)- # Read the label from the whole span between the operators rather than- # from the matched group. The mask blanks quoted spans, so a quoted- # label — `A-- "text" -->B` — leaves the spaced group nothing but- # blanks to settle on, and slicing that group returns a stray quote- # instead of the text. `clean_label` strips the padding and quotes.- operators.append(- _Operator(- operator_start,- match.end(),- clean_label(text[match.end("opening") : match.start("closing")]),- style,- arrowhead,- bidirectional,- undirected,+ for edge_pattern in (text_edge, dotted_edge):+ for match in edge_pattern.finditer(mask):+ opening = match.group("opening")+ operator_start = match.start()+ if opening.startswith(("x", "o")):+ prefix = mask[:operator_start]+ if not prefix.strip() or trailing_operator.search(prefix):+ # Here x/o is the endpoint before a regular opening+ # operator, not a left marker: `x--yes-->B` or+ # `A-->x--go-->B`.+ operator_start += 1+ opening = opening[1:]+ token = opening + match.group("closing")+ style, arrowhead, bidirectional, undirected = _operator_style(token)+ # Read the label from the whole span between the operators rather+ # than from the matched group. The mask blanks quoted spans, so a+ # quoted label — `A-- "text" -->B` — leaves the spaced group+ # nothing but blanks to settle on, and slicing that group returns+ # a stray quote instead of the text. `clean_label` strips the+ # padding and quotes.+ operators.append(+ _Operator(+ operator_start,+ match.end(),+ clean_label(text[match.end("opening") : match.start("closing")]),+ style,+ arrowhead,+ bidirectional,+ undirected,+ ))- )- occupied.append((operator_start, match.end()))+ occupied.append((operator_start, match.end()))pattern = re.compile(r"[xo][-=.]+[xo]|<[-=.]+>|-+\.-+>|=+>|-+(?:>|x|o)|-+\.-+|={3,}|-{3,}"