You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bold and italic text in Mermaid diagram labels now renders as formatting instead of showing the HTML tags.
What Changed
Enable HTML labels in Markdown preview, rich editing, standalone diagrams, and comments. Keep strict rendering and the final sanitization pass, with explicit SVG, HTML, and MathML profiles plus the required XHTML integration point. SVG filter primitives remain excluded, and form controls cannot turn diagram labels into editable or submittable forms.
Why
The former SVG-only cleanup removed the HTML container used for labels. Enabling labels alone would therefore leave them blank. The shared sanitizer preserves formatted and math labels while removing unsafe markup.
Fix found while verifying: Chromium taints a canvas drawn from a blob-URL SVG that contains foreignObject labels, so Copy as PNG would have failed on every flowchart. The diagram viewer now loads the diagram from a data URL instead. Running the real renderImagePngDataUrl in Chromium on an HTML-label diagram: a blob URL throws Tainted canvases may not be exported; a data URL copies correctly.
Verified in Chromium (light and dark): inline labels keep <b>/<i>, and the expanded <img> and the copied PNG both show the labels.
pnpm tc, plus the MermaidBlock, DiagramViewerModal, mermaid-config and Chromium sanitizer suites, all pass.
Testing
Manually tested through hidden Electron CDP on macOS: rich editor, Markdown preview, standalone .mmd, ordinary labels, line breaks, and math labels. Fresh compiled app proof matches the source-backed checks.
14 tests across 4 suites pass with no skips, including real Chromium namespace handling and browser reparsing. Scripts, event handlers, encoded script URLs, nested iframe/object/embed content, and MathML namespace transitions and form controls are covered; SVG and HTML images remain allowed. Generated styles remain; SVG filter primitives are removed.
Full typechecks, lint, changed-code quality, whitespace check, and electron-vite build --mode e2e pass. The preserved contributor series and focused follow-ups now rest on reviewed support commit e6a471c8df80e1bc3e789e4a4e1a7ac7d9fed52b. This test-only ancestor refresh leaves all Mermaid source and tests byte-identical, with equal commit patches and 22 combined Mermaid checks passing again.
Review
The production diff received independent source review. This branch includes the reviewed #25540 support ancestor for the lint and test-recorder baseline. No dependency, rendering queue, cancellation, or CSP change is included.
Agent skill upstream boundary
Not applicable; no upstream skill-installer material is copied.
Notes
Preserves the two authored commits from Bing.Z (@bbingz) in #12581, including the original Cursor coauthor and cherry-pick references. The follow-ups retain explicit profiles, extend the security controls, and exclude form-control tags after an actual strict-label input/submit reproduction. Both ordinary and math labels and legitimate images remain visible. The original diagnosis is credited to @Fartown.
Cross-checked the exact Mermaid 11.17.2 final sanitization source and DOMPurify 3.4.16 namespace checks. Strict rendering remains enabled; no CSP policy changes are included. The proof does not rely on CSP blocking forms. The sanitizer admits more HTML to support labels, and label sizing or line wrapping can change.
This PR alone retains the existing same-instance invalid-to-valid recovery bug (#18370): saving, closing, and reopening renders the corrected diagram. It is handled in the separate #25575 recovery PR stacked on this change. Native Windows/Linux, live SSH, and the actual comment sidebar were not exercised; this renderer change adds no host or path behavior.
Checklist
Small, focused production change: 7 files, 41 additions and 26 deletions.
User-visible change, mechanism, and approach explained.
Before/after visual proof attached.
Self-reviewed for correctness, security, and performance.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Walkthrough
Mermaid configuration now enables HTML labels by default. MermaidBlock sanitizes rendered SVG with a shared DOMPurify configuration that supports HTML labels. Chromium tests check safe-content preservation and unsafe-content removal. Mermaid call sites and related tests no longer pass the removed htmlLabels option. DiagramViewerModal now uses an encoded SVG data URL instead of a blob URL.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to 36cbb
Crafted Mermaid content may contact attacker-controlled image URLs when opened, exposing network metadata or triggering unintended requests. Resolve this before merging.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly identifies the main change: safely rendering formatted Mermaid labels in the editor.
Description check
The description covers the required sections, including the user-facing change, rationale, linked issue, visual proof, testing, review notes, scope considerations, and checklist. It also documents unt…
Linked Issues check
Issue #12414 requires formatted Mermaid labels in Markdown preview while retaining strict security. getMermaidConfig sets htmlLabels: true and securityLevel: 'strict'. The Mermaid preview call s…
Out of Scope Changes check
The changes remain connected to issue #12414. The shared sanitizer preserves labels after HTML rendering and tests its security boundaries. The data URL in DiagramViewerModal supports PNG copying fo…
Docstring Coverage
Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Full details: Description check
Explanation
The description covers the required sections, including the user-facing change, rationale, linked issue, visual proof, testing, review notes, scope considerations, and checklist. It also documents untested platforms and the known recovery limitation.
Full details: Linked Issues check
Explanation
Issue #12414 requires formatted Mermaid labels in Markdown preview while retaining strict security. getMermaidConfig sets htmlLabels: true and securityLevel: 'strict'. The Mermaid preview call sites no longer override HTML labels to false. MermaidBlock applies sanitizeMermaidSvg, which preserves foreignObject label content and supports HTML and MathML profiles. The reported regression tests cover formatted labels and unsafe markup removal.
Full details: Out of Scope Changes check
Explanation
The changes remain connected to issue #12414. The shared sanitizer preserves labels after HTML rendering and tests its security boundaries. The data URL in DiagramViewerModal supports PNG copying for diagrams that contain foreignObject labels. Related Mermaid surfaces receive the same label behavior. No unrelated change is established.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Block remote resource loads from HTML labels before rendering.MermaidBlock calls mermaid.render before sanitizeMermaidSvg, so the later sanitizer cannot prevent requests made during rendering. The renderer has no visible img-src restriction or request filter. Do not enable htmlLabels for untrusted diagrams unless remote label resources are blocked before mermaid.render.
Run the sanitizer assertions in blocking Chromium CI.
The unit workflow discovers this file, but probeChromium() returns false when Chromium cannot launch, so describe.skipIf skips every assertion. The required orcad_browser job runs a different test. Run this suite in a blocking job with Playwright Chromium available, and make that job fail if the probe returns false.
ℹ️ Review info⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a752ae6a-50c0-4965-8fbb-094c729872a4
📥 Commits
Reviewing files that changed from the base of the PR and between 24b9d80505c56a5f4acc620a46e9cf28e9cc17ee and 91a2f2c.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
The current assertion checks only the data:image/svg+xml prefix. It would pass if the URL contained no SVG content. Decode the payload and assert that it contains the test SVG content, such as <text>A</text>. (github.com)
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 45deb141-0699-4260-95ea-98474189b4fe
Commits
Reviewing files that changed from the base of the PR and between 91a2f2c and 746d1d8.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Account for opaque ancestor backgrounds in Mermaid HTML labels.
With htmlLabels: true, nested formatted elements can be rendered inside foreignObject labels. The contrast helper compares a nested element with the node fill, even when an ancestor such as <mark> or Mermaid’s labelBkg paints the actual background. On a dark node, this can select the light foreground and produce low-contrast text on a light highlight. Walk the HTML ancestor chain before applying the node-fill correction.
Suggested fix
function contrast(a: number, b: number): number {
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
}
+function hasOpaqueHtmlBackground(label: Element, stop: Element): boolean {+ for (+ let current: Element | null = label;+ current && current !== stop;+ current = current.parentElement+ ) {+ if (luminance(getComputedStyle(current).backgroundColor) !== null) {+ return true+ }+ }+ return false+}+
...
- if (!svgText && luminance(labelStyle.backgroundColor) !== null) {+ if (!svgText && hasOpaqueHtmlBackground(label, node)) {
continue
}
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
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.
ELI5
Bold and italic text in Mermaid diagram labels now renders as formatting instead of showing the HTML tags.
What Changed
Enable HTML labels in Markdown preview, rich editing, standalone diagrams, and comments. Keep strict rendering and the final sanitization pass, with explicit SVG, HTML, and MathML profiles plus the required XHTML integration point. SVG filter primitives remain excluded, and form controls cannot turn diagram labels into editable or submittable forms.
Why
The former SVG-only cleanup removed the HTML container used for labels. Enabling labels alone would therefore leave them blank. The shared sanitizer preserves formatted and math labels while removing unsafe markup.
Linked Issue
Fixes #12414.
Visual Proof
Rebased onto main (Oct 31)
htmlLabels={false}, andMermaidBlocksanitizes withsanitizeMermaidSvgbefore main's dark-mode label recolour, which already covers HTML labels (.nodeLabel).foreignObjectlabels, so Copy as PNG would have failed on every flowchart. The diagram viewer now loads the diagram from a data URL instead. Running the realrenderImagePngDataUrlin Chromium on an HTML-label diagram: a blob URL throwsTainted canvases may not be exported; a data URL copies correctly.<b>/<i>, and the expanded<img>and the copied PNG both show the labels.pnpm tc, plus the MermaidBlock, DiagramViewerModal, mermaid-config and Chromium sanitizer suites, all pass.Testing
.mmd, ordinary labels, line breaks, and math labels. Fresh compiled app proof matches the source-backed checks.electron-vite build --mode e2epass. The preserved contributor series and focused follow-ups now rest on reviewed support commite6a471c8df80e1bc3e789e4a4e1a7ac7d9fed52b. This test-only ancestor refresh leaves all Mermaid source and tests byte-identical, with equal commit patches and 22 combined Mermaid checks passing again.Review
The production diff received independent source review. This branch includes the reviewed #25540 support ancestor for the lint and test-recorder baseline. No dependency, rendering queue, cancellation, or CSP change is included.
Agent skill upstream boundary
Notes
Preserves the two authored commits from Bing.Z (@bbingz) in #12581, including the original Cursor coauthor and cherry-pick references. The follow-ups retain explicit profiles, extend the security controls, and exclude form-control tags after an actual strict-label input/submit reproduction. Both ordinary and math labels and legitimate images remain visible. The original diagnosis is credited to @Fartown.
Cross-checked the exact Mermaid 11.17.2 final sanitization source and DOMPurify 3.4.16 namespace checks. Strict rendering remains enabled; no CSP policy changes are included. The proof does not rely on CSP blocking forms. The sanitizer admits more HTML to support labels, and label sizing or line wrapping can change.
This PR alone retains the existing same-instance invalid-to-valid recovery bug (#18370): saving, closing, and reopening renders the corrected diagram. It is handled in the separate #25575 recovery PR stacked on this change. Native Windows/Linux, live SSH, and the actual comment sidebar were not exercised; this renderer change adds no host or path behavior.
Checklist