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 angle brackets in draw.io labels (#468)
Rudy Mizrahi Celekli17686b948d1d
diff --git a/scripts/verify-drawio-import.py b/scripts/verify-drawio-import.pyindex 6053378..4aa926d 100644--- a/scripts/verify-drawio-import.py+++ b/scripts/verify-drawio-import.py@@ -84,7 +84,7 @@ def check_legacy_stdout_encoding(tmp: Path) -> None:source.write_text("""<mxfile><diagram name="日本語"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>-<mxCell id="2" value="登录<br>続行 ⇒ résumé" vertex="1" parent="1">+<mxCell id="2" style="html=1;" value="登录<br>続行 ⇒ résumé" vertex="1" parent="1"><mxGeometry x="0" y="0" width="120" height="60" as="geometry"/></mxCell></root></mxGraphModel></diagram></mxfile>""",encoding="utf-8",@@ -400,6 +400,53 @@ def check_bom_prefixed(tmp: Path) -> None:ok("UTF-8 BOM-prefixed raw XML and bare compressed payload parse like their unprefixed input")+def check_plain_angle_brackets(tmp: Path) -> None:+ # XML decoding turns < into a real "<" before label cleanup. A plain+ # label such as List<String> or "a < b > c" is text, not a tag; HTML+ # wrappers and comments still have to flatten.+ source = tmp / "angle-brackets.drawio"+ source.write_text(+ '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>'+ '<mxCell id="generic" value="List<String>" vertex="1" parent="1">'+ '<mxGeometry width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="compare" value="a < b > c" vertex="1" parent="1">'+ '<mxGeometry x="100" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="html" style="html=1;" value="<div><b>List&lt;String&gt;</b><br>kept</div>" vertex="1" parent="1">'+ '<mxGeometry x="200" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="comment" style="html=1;" value="<!-- secret -->visible" vertex="1" parent="1">'+ '<mxGeometry x="300" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="u" value="List<U>" vertex="1" parent="1"/>'+ '<mxCell id="cpp" value="std::vector<std::string>" vertex="1" parent="1"/>'+ '<mxCell id="url" value="see <https://x.io> now" vertex="1" parent="1"/>'+ '<mxCell id="plainhtml" style="html=0;" value="<b>literal</b>" vertex="1" parent="1"/>'+ '<mxCell id="e" edge="1" value="List<U>" parent="1" source="generic" target="compare"/>'+ '<mxCell id="el" vertex="1" parent="e" value="std::vector<std::string>"/>'+ "</root></mxGraphModel>",+ encoding="utf-8",+ )+ payload = json.loads(run_extract([str(source), "--json"]))["pages"][0]+ for node_id, expected in {"u": "List<U>", "cpp": "std::vector<std::string>",+ "url": "see <https://x.io> now", "plainhtml": "<b>literal</b>"}.items():+ actual = next(node["label"] for node in payload["nodes"] if node["id"] == node_id)+ if actual != expected:+ fail(f"plain label {node_id} changed: {actual!r} != {expected!r}")+ if payload["edges"][0]["label"] != "List<U> / std::vector<std::string>":+ fail(f"plain edge or edge-child label changed: {payload['edges']!r}")+ nodes = {+ node["id"]: node["label"]+ for node in json.loads(run_extract([str(source), "--json"]))["pages"][0]["nodes"]+ }+ if nodes.get("generic") != "List<String>":+ fail(f"plain generic label was stripped: {nodes.get('generic')!r}")+ if nodes.get("compare") != "a < b > c":+ fail(f"plain comparison label was stripped: {nodes.get('compare')!r}")+ if nodes.get("html") != "List<String>\nkept":+ fail(f"HTML label was not flattened: {nodes.get('html')!r}")+ if nodes.get("comment") != "visible":+ fail(f"HTML comment leaked into the label: {nodes.get('comment')!r}")+ ok("plain angle brackets stay in labels and HTML tags still flatten")++def check_hidden_cells(tmp: Path) -> None:# visible="0" on a cell, a group, or a layer hides it in draw.io; the import must not resurrect it.def vertex(cid: str, parent: str, x: int, extra: str = "") -> str:@@ -890,6 +937,7 @@ def main() -> int:check_nested_geometry(tmp)check_nested_relative_geometry(tmp)check_bom_prefixed(tmp)+ check_plain_angle_brackets(tmp)check_hidden_cells(tmp)check_containers(tmp)check_legacy_stdout_encoding(tmp)diff --git a/skills/diagram-design/references/import-drawio.md b/skills/diagram-design/references/import-drawio.mdindex 67c7607..bae48ee 100644--- a/skills/diagram-design/references/import-drawio.md+++ b/skills/diagram-design/references/import-drawio.md@@ -30,6 +30,8 @@ Absolute IR geometry resolves relative child vertices using their parent width/hCells hidden in draw.io (`visible="0"` on a cell, a group, or a layer) are not part of the diagram: the extractor skips them together with everything parented beneath them, so hidden drafts never reach the digest or the IR.+HTML in a label is flattened (`<b>`, `<div>`, `<br>`, comments). Angle brackets that are not those tags stay, so `List<String>` and `a < b > c` reach the digest as written.+Each import is limited to 100 direct `<diagram>` pages and 10,000 direct children under a page's `<root>`. The extractor exits with `page limit exceeded (max 100)` or `page N: cell limit exceeded (max 10000)`, respectively. If either limit is reached, split the source into smaller draw.io files and retry.Options worth knowing:diff --git a/skills/diagram-design/scripts/drawio_extract.py b/skills/diagram-design/scripts/drawio_extract.pyindex ea3a4ef..75bf9e4 100644--- a/skills/diagram-design/scripts/drawio_extract.py+++ b/skills/diagram-design/scripts/drawio_extract.py@@ -195,7 +195,17 @@ def load_mxfile(path: Path) -> str:# --------------------------------------------------------------------------BR_RE = re.compile(r"<br\s*/?>|</p\s*>|</div\s*>", re.IGNORECASE)-TAG_RE = re.compile(r"<[^>]+>")+HTML_COMMENT_RE = re.compile(r"<!--.*?-->", re.DOTALL)+# Tags draw.io actually writes. `List<String>` and `a < b > c` are text, and a+# catch-all `<[^>]+>` scan deletes them after XML decoding turns `<` into `<`.+_HTML_TAG = (+ "a|b|blockquote|br|code|del|div|em|font|h[1-6]|hr|i|img|ins|li|mark|ol|p|pre|"+ "s|small|span|strike|strong|sub|sup|table|tbody|td|th|thead|tr|u|ul|wbr"+)+TAG_RE = re.compile(+ rf"</?(?:{_HTML_TAG})\b[^>]*>|</?[A-Za-z][\w-]*:[\w:-]*[^>]*>",+ re.IGNORECASE,+)def parse_style(style: str | None) -> dict[str, str]:@@ -211,13 +221,16 @@ def parse_style(style: str | None) -> dict[str, str]:return out-def clean_label(value: str | None) -> str:- """draw.io labels are often HTML fragments; flatten to plain text lines."""+def clean_label(value: str | None, *, is_html: bool = False) -> str:+ """Flatten HTML-enabled cells; preserve angle brackets in plain labels."""if not value:return ""- text = BR_RE.sub("\n", value)- text = TAG_RE.sub("", text)- text = html.unescape(text)+ text = value+ if is_html:+ text = HTML_COMMENT_RE.sub("", text)+ text = BR_RE.sub("\n", text)+ text = TAG_RE.sub("", text)+ text = html.unescape(text)text = text.replace("\xa0", " ")lines = [re.sub(r"[ \t]+", " ", ln).strip() for ln in text.split("\n")]return "\n".join(ln for ln in lines if ln).strip()@@ -457,7 +470,7 @@ def parse_page(diagram: ET.Element, index: int) -> Page:)if parent_is_edge or "edgeLabel" in style:if parent:- text = clean_label(entry["value"])+ text = clean_label(entry["value"], is_html=style.get("html") == "1")if text:edge_label_parts.setdefault(parent, []).append(text)continue@@ -468,7 +481,7 @@ def parse_page(diagram: ET.Element, index: int) -> Page:relative_offsets[cid] = (_num(offset, "x"), _num(offset, "y"))node = Node(id=cid,- label=clean_label(entry["value"]),+ label=clean_label(entry["value"], is_html=style.get("html") == "1"),shape=classify_shape(style),parent=parent,x=_num(geom, "x"),@@ -545,7 +558,7 @@ def parse_page(diagram: ET.Element, index: int) -> Page:waypoints = len([p for p in geom.findall(".//mxPoint") if p.get("as") is None])- label = clean_label(entry["value"])+ label = clean_label(entry["value"], is_html=style.get("html") == "1")extra = edge_label_parts.get(cid, [])if extra:label = " / ".join([p for p in ([label] + extra) if p])