fix(serve): mermaid fenced blocks broken by HTML-entity escaping#273
Merged
Conversation
`render_markdown` injected synthetic `<pre class="mermaid">` wrappers but
still let the fenced body flow through pulldown-cmark's `html::push_html`,
which HTML-entity-escapes Event::Text — so mermaid's core `-->` arrow
rendered as `-->` (and class-diagram `<|--` as `<|--`), and
mermaid.js rejected the diagram with "Syntax error in text". Reported by
a user against v0.6.0 and v0.8.0.
Re-tag the in-mermaid Text segments as Event::Html so they pass through
unescaped. Mermaid diagram source contains no HTML tags; a `</pre>`
smuggled into a ```mermaid block would at worst close the block early,
and `<script>` etc. are still stripped by the `sanitize_html` pass.
(`document.rs`'s separate document renderer already emits the body
verbatim via `join("\n")` — only `render_markdown` had the bug.)
Coverage:
- two markdown.rs unit tests: stateDiagram `[*] -->` arrows survive
verbatim with no `-->`; classDiagram `<|--` survives with no `<|--`.
- new tests/playwright/mermaid.spec.ts: ARCH-CORE-001's embedded
```mermaid flowchart serves with `Config --> Store` verbatim, and
mermaid.js renders it to an SVG with no "Syntax error" box.
Fixes REQ-032.
Implements: REQ-032
Verifies: REQ-032
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📐 Rivet artifact deltaNo artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph. |
Wraps an over-long assert!() the formatter flagged. No behaviour change. Trace: skip Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 90bb1a1 | Previous: 02b9328 | Ratio |
|---|---|---|---|
validate/10000 |
20318603 ns/iter (± 1714130) |
16904098 ns/iter (± 1013276) |
1.20 |
query/10000 |
138521 ns/iter (± 410) |
91811 ns/iter (± 267) |
1.51 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-reported bug (v0.6.0 + v0.8.0): a
\``mermaidfenced block inside a YAML artifact description renders-->as-->in the dashboard's[*] -->arrows survive verbatim with no-->; classDiagram<|--survives with no<|--./artifacts/ARCH-CORE-001hasConfig --> Storeverbatim and no-->; mermaid.js renders it to an<svg>with no "Syntax error" box.Follow-up (not in this PR)
The fix is diagram-type-agnostic (it just stops escaping the body), so it covers flowchart/state/class/sequence/ER/gantt/etc. at once. A broader Playwright matrix that exercises one fixture artifact per diagram type would be nice belt-and-suspenders but is its own task — flagging per the request to "test all kinds of mermaid graphics".
Test plan
cargo test -p rivet-core markdowngreen (incl. 2 new tests)mermaid.spec.tsgreen in the E2E job🤖 Generated with Claude Code