Sequence diagrams using the "actor" keyword don't render

#1 · closed · 1 comments

View on GitHub ↗

io-george

## Summary Mermaid sequence diagrams whose participants are declared with `actor` (instead of `participant`) fail to render. The diagram is silently left as raw Mermaid source in the output instead of being drawn as box-drawing ASCII art. ## Reproduction Render a file containing: ```` ```mermaid sequenceDiagram actor U as User participant CU as Gateway check user U->>CU: Click AskJLR button ``` ```` Expected: an ASCII sequence diagram. Actual: the raw Mermaid text is shown. ## Analysis The sequence parser only recognizes the `participant` keyword. The declaration regex at `viewmd/mermaid/sequence/parser.py:15` is: ```python _PARTICIPANT_RE = re.compile( r'(?i)^\s*participant\s+(?:"([^"]+)"|(\S+))(?:\s+as\s+(.+))?$' ) ``` An `actor` line matches no rule in the parse loop and hits the catch-all at `parser.py:304`, raising: ``` MermaidError: line 2: invalid syntax: "actor U as User" ``` Per the fallback in `viewmd/mermaid/preprocess.py:60`, a diagram that fails to parse is left untouched — so a single unrecognized `actor` line drops the *entire* diagram back to raw source. Diagrams commonly lead with `actor U as User`, so this is the only blocker for otherwise-valid documents (confirmed: swapping `actor` → `participant` renders correctly). ## Proposed fix Accept `actor` as a synonym for `participant`. In Mermaid the two are semantically identical for a sequence diagram — `actor` only changes the glyph to a stick figure — so the parser should treat an `actor` declaration exactly as a `participant`. One-line change, using a non-capturing group so the existing capture indices (and `_parse_participant`) are untouched: ```python _PARTICIPANT_RE = re.compile( r'(?i)^\s*(?:participant|actor)\s+(?:"([^"]+)"|(\S+))(?:\s+as\s+(.+))?$' ) ``` The trailing `\s+` after the keyword already prevents collisions with a participant literally named `actor` in a message (e.g. `actor->>B: hi` has no space, so it falls through to the message rule — same protection `participant` already relies on). Verified with the reproduction above plus an `alt` fragment: participants render as boxes with correct labels, fragments still draw. ## Scope note This renders actors as boxes, identical to participants. Drawing actual stick-figure glyphs for `actor` would be a larger, separate change; this issue only covers making `actor` diagrams render at all. ## Tests Add a parser test that an `actor` declaration produces a participant (with `as` label), and a render/golden test for a small `actor`-led diagram.

Comments

mo6

Fixed as [VIEWMD-0017](https://github.com/mo6/viewmd/blob/develop/issues/archive/VIEWMD-0017-actor-keyword-sequence-diagrams.md): `actor` is now accepted as a synonym for `participant` in sequence-diagram declarations (quoted-name and `as`-label forms included), so a diagram no longer falls back to raw source when it uses `actor`. Fix commit: 5a9255a67858e61d2d0f8ab1dc0d2a00ee8465c7 Landed on `develop`, changelog entry: [1.3.1] (pending release — not yet merged/tagged on `main`). A follow-up ([VIEWMD-0020](https://github.com/mo6/viewmd/blob/develop/issues/VIEWMD-0020-actor-stick-figure-glyphs.md)) tracks giving `actor` participants their own stick-figure glyph instead of rendering as a plain box.