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): accept UTF-8 BOM in Mermaid sources (#418)

ammann3a856cd967c2
diff --git a/README.md b/README.md
index e155f71..951c9b0 100644
--- a/README.md
+++ b/README.md
@@ -426,7 +426,7 @@ Already have diagrams in draw.io / diagrams.net, Mermaid, or Excalidraw? Point t
Or just ask: *"redraw this drawio file for my deck"*, *"make this Mermaid block editorial"*, *"make this whiteboard sketch presentable"*, or *"この Mermaid をスライド用にきれいにして"*.
Reads the common containers draw.io writes (`.drawio`, `.drawio.xml`, `.drawio.png` with an embedded diagram, and `.drawio.svg`), including compressed payloads that look like base64 garbage in an editor.
-For Mermaid, it accepts `.mmd`, `.mermaid`, and one or more fenced `mermaid` blocks in Markdown.
+For Mermaid, it accepts `.mmd`, `.mermaid`, and one or more fenced `mermaid` blocks in Markdown. UTF-8 files may include a byte-order mark.
For Excalidraw, it accepts `.excalidraw` and `.excalidraw.json` scene files (not `.excalidraw.png`/`.excalidraw.svg` exports). It parses text only: no rendering, JavaScript, browser, network, or followed click targets.
### The four dials
diff --git a/scripts/verify-mermaid-import.py b/scripts/verify-mermaid-import.py
index 4ab3f5f..0238623 100644
--- a/scripts/verify-mermaid-import.py
+++ b/scripts/verify-mermaid-import.py
@@ -126,6 +126,21 @@ def check_legacy_stdout_encoding(tmp: Path) -> None:
ok("Mermaid stdout stays lossless UTF-8 under a legacy Windows encoding")
+def check_utf8_bom(tmp: Path) -> None:
+ for suffix, source in (
+ ("mmd", "flowchart TD\nA --> B\n"),
+ ("md", "```mermaid\nflowchart TD\nA --> B\n```\n"),
+ ):
+ path = tmp / f"bom-source.{suffix}"
+ path.write_bytes(source.encode("utf-8"))
+ expected = json.loads(run_extract([str(path), "--json"]))
+ path.write_bytes(b"\xef\xbb\xbf" + source.encode("utf-8"))
+ actual = json.loads(run_extract([str(path), "--json"]))
+ if actual != expected:
+ fail(f"UTF-8 BOM changed the {suffix} extraction")
+ ok("UTF-8 BOM does not prevent Mermaid or Markdown import")
+
+
def expect_error(args: list[str], message: str) -> None:
process = invoke(args)
if process.returncode != 2 or message not in process.stderr:
@@ -1288,6 +1303,7 @@ def main() -> int:
check_state_descriptions(tmp)
check_named_composite_states(tmp)
check_selection_before_parse(tmp)
+ check_utf8_bom(tmp)
check_legacy_stdout_encoding(tmp)
check_sequence_grammar_forms(tmp)
check_adversarial(tmp)
diff --git a/skills/diagram-design/references/import-mermaid.md b/skills/diagram-design/references/import-mermaid.md
index e0d468f..54847a9 100644
--- a/skills/diagram-design/references/import-mermaid.md
+++ b/skills/diagram-design/references/import-mermaid.md
@@ -7,6 +7,7 @@ Turn Mermaid source into an editorial-quality diagram at the format, size, and d
## Trigger
Load this file for `.mmd`, `.mermaid`, or Markdown containing fenced `mermaid` blocks when the user asks to convert, redraw, simplify, or present the diagram, or uses `/diagram-design:import-mermaid`.
+UTF-8 source files with or without a byte-order mark are accepted.
---
diff --git a/skills/diagram-design/scripts/mermaid_extract.py b/skills/diagram-design/scripts/mermaid_extract.py
index efcf1b2..2340953 100644
--- a/skills/diagram-design/scripts/mermaid_extract.py
+++ b/skills/diagram-design/scripts/mermaid_extract.py
@@ -253,7 +253,7 @@ def _read_bounded(path: Path) -> str:
f"source exceeds the {MAX_SOURCE_BYTES // (1024 * 1024)} MiB limit"
)
try:
- return data.decode("utf-8")
+ return data.decode("utf-8-sig")
except UnicodeDecodeError:
_fail(f"{path.name}: source is not valid UTF-8 text")