Mermaid scanner: `<pre><span><svg></svg></span></pre>` skip-rule misses author-pre-rendered diagrams in unusual wrappers

Open Beginner friendly
#17 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
html, javascript, typescript

Research direction

The skip rule lives in findMermaidBlocks() in apps/api/src/companion/v1.js around line 69, which currently checks for :scope > svg and :scope > div > svg. Read that function and the regression test in apps/api/src/companion/mermaidScanner.test.ts near line 23 first. Done means a pre-rendered <pre class="mermaid"> with an svg under any intermediate element is skipped, the selector change is covered by a test case, and the existing test cases still pass.

Written by the indexing model from the issue text.

Description

triage

Surfaced by: code review on #15 (Mermaid auto-rendering).

findMermaidBlocks() in apps/api/src/companion/v1.js skips a block when it contains :scope > svg or :scope > div > svg. This covers the two common shapes:

  • Mermaid-produced post-render: <pre><svg>…</svg></pre> (mermaid puts the svg directly under the matched element).
  • Our own post-render: <pre><div class=\"primer-mermaid\"><svg>…</svg></div></pre>.

Edge case: if an author hand-rolled <pre class=\"mermaid\"><span><svg>…</svg></span></pre> (or some other intermediate element instead of <div>), the skip-rule misses it and Primer would re-render and clobber their existing SVG.

Two options:

  1. Broaden the selector to :scope svg (any descendant). Stronger skip, harder to break a pre-rendered diagram, slight risk of skipping a legitimately-empty block that happens to contain an inline icon SVG.
  2. Document as a known edge case in the spec — authors who pre-render are expected to use the canonical shape.

Lean toward option 1 since the risk of a false-positive skip is much smaller than the risk of clobbering an existing diagram.

apps/api/src/companion/v1.js:69
apps/api/src/companion/mermaidScanner.test.ts:23

Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
13h 38m
Merged PRs (30d)
24

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 0xPolygon/primer

All issues in 0xPolygon/primer

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.