Skip to content

fix(mermaid): accept a hyphen in a flowchart node id - #53

Merged
hebus merged 1 commit into
mainfrom
fix/hyphenated-node-ids
Aug 21, 2026
Merged

hebus merged 1 commit into
mainfrom
fix/hyphenated-node-ids

Conversation

@hebus

@hebus hebus commented Aug 21, 2026

Copy link
Copy Markdown
Owner

You asked whether every open point was fixed. Auditing that turned up two defects in the published package, and this fixes both.

user-service --> api-gateway raised

Hyphenated ids are everywhere in real Mermaid — api-gateway, load-balancer, user-service. The id scan stopped at the hyphen and -service --> api-gateway was read as a broken link:

flowchart-syntax: Expected a link on line 2, found `-service --> api-gateway`.

I had this on the open list as "node ids exclude -", framed as a documented subset limit. It is not a limit, it is a bug: probably the first thing a real diagram would have hit.

A hyphen now continues an id when a word character follows it. Two things make that narrow enough to be safe, and both are fixtures:

  • two hyphens in a row cannot, so A-->B and a-b-->c-d are still links;
  • the lookahead is word characters rather than the id set, because a dot is an id character — without that, x-.->y would parse as an id called x-. and then fail on the remainder.

A -- a--b --> B produced a phantom node

Three nodes out of two: A, b, B. The -- inside the label closed the link, and the remainder became a node. That is the one failure this package explicitly says it will not commit — a drawing that lies instead of an error — and the readme's advice ("cannot use the inline-label form") did not point anywhere that worked.

A -- "a--b" --> B works now: the scanner steps over a quoted span, which makes quoting a real escape hatch, and it is Mermaid's own convention for a label with special characters. A -->|a--b| B already worked. Unquoted is still read as a link, and the readme now says exactly that instead of implying it fails.

Still open, and deliberately

  • sequenceDiagram, classDiagram, stateDiagram, erDiagram — a hand-written parser each; fallback covers them meanwhile
  • a richer icon set, per-diagram theme overrides, an Excalidraw renderer — the roadmap
  • architecture-beta edge labels — blocked upstream, recorded last pull request

Verification

628 tests (3 new), lint, fmt:check, typecheck, build, typecheck:packaged, build:docs. Ten spellings checked by hand before writing the tests, including every link form that the change could have broken.

- user-service --> api-gateway is idiomatic Mermaid and raised: the id
  stopped at the hyphen and the rest was read as a broken link. Almost
  certainly the first thing a real diagram would have hit
- A hyphen continues an id only when a word character follows it, so a
  link written without spaces is still a link. The lookahead is word
  characters and not the id set, because a dot is an id character and
  x-.->y is a dotted link, not an id called x-.
- A -- "a--b" --> B works too. Unquoted it produced a phantom node —
  three nodes out of two — which is the one failure this package says
  it will not commit: a drawing that lies instead of an error
- Three fixtures in regressions, including the link forms the fix
  could have broken
@hebus
hebus merged commit c628376 into main Aug 21, 2026
3 checks passed
@hebus
hebus deleted the fix/hyphenated-node-ids branch August 21, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant