Fix Mermaid diagrams failing when node labels contain line breaks#37296
Fix Mermaid diagrams failing when node labels contain line breaks#37296silverwind merged 3 commits intogo-gitea:mainfrom
Conversation
|
The actual regression looks like it was introduced in #36547 (commit a60201a), which changed how the mermaid SVG string is attached to the iframe. Before that PR, the SVG was embedded via iframe iframe.srcdoc = html`<html>…<body>${htmlRaw(svg)}</body></html>`;which the browser parsed as HTML, tolerating Mermaid's After the refactor ( const svgDoc = parseDom(svgText, 'image/svg+xml');the SVG string is now parsed as strict XML, which chokes on HTML-mode void tags — hence the 1.26 regression. So
Either would fix the reported bug without the HTML-labels trade-off. Comment written by Claude Opus 4.7. |
|
Welcome to the one of the most complex parts of Gitea's code base: markup rendering. |
|
This will fix: bb25bd1 |
|
Seems ok but I'm unsure about the |
It won't. The It doesn't affect other elements (which can be put into a div element) |
|
Should merge #37297 first for green CI. |
|
No new issue caused by this change, and I have manually tested. So, I think we can merge this now and backport ASAP to help users to get a nightly build. |
|
I was able to merge with non-green CI, apparently there is no protection for that configured on the repo, so it's fine. |
thats not fine thats really bad |
|
Backport Fix Mermaid diagrams failing when node labels contain line breaks #37299 |
* 'cast' of github.com:silverwind/gitea: Fix Mermaid diagrams failing when node labels contain line breaks (go-gitea#37296) Add project column picker to issue and pull request sidebar (go-gitea#37037) Fix container auth for public instance (go-gitea#37290) Refactor frontend `tw-justify-between` layouts to `flex-left-right` (go-gitea#37291) Update Nix flake (go-gitea#37284) Workflow Artifact Info Hover (go-gitea#37100)
* main: (25 commits) Add WebKit to e2e test matrix (go-gitea#37298) Don't add useless labels which will bother changelog generation (go-gitea#37267) Fix Repository transferring page (go-gitea#37277) Stabilize issue-project e2e test, increase timeout factor (go-gitea#37297) Fix Mermaid diagrams failing when node labels contain line breaks (go-gitea#37296) Add project column picker to issue and pull request sidebar (go-gitea#37037) Fix container auth for public instance (go-gitea#37290) Refactor frontend `tw-justify-between` layouts to `flex-left-right` (go-gitea#37291) Update Nix flake (go-gitea#37284) Workflow Artifact Info Hover (go-gitea#37100) [skip ci] Updated translations via Crowdin release notes for 1.26.0 (go-gitea#37282) Enhance GetActionWorkflow to support fallback references (go-gitea#37189) Refactor LDAP tests (go-gitea#37274) Remove `SubmitEvent` polyfill (go-gitea#37276) Upgrade go-git to v5.18.0 (go-gitea#37268) Avoid top-level await (go-gitea#37272) Frontend iframe renderer framework: 3D models, OpenAPI (go-gitea#37233) pull: Fix CODEOWNERS absolute path matching. (go-gitea#37244) Swift registry metadata: preserve more JSON fields and accept empty metadata (go-gitea#37254) ...
Mermaid code blocks that use line breaks inside node labels (for example
A["line1\nline2"]or labels that resolve to multi-line text) could fail to render in Gitea. This change fixes that by disabling Mermaid’s HTML-based labels so the generated SVG stays well-formed XML for our client-side pipeline.Root cause
Gitea renders Mermaid in the browser, then parses the returned SVG string with
DOMParserusing theimage/svg+xmltype before inserting it into the page. With Mermaid’s defaulthtmlLabels: true, labels with line breaks are often emitted as HTML inside aforeignObject, including tags like<br>that are valid in HTML but not valid in XML. That output can break strict XML parsing of the SVG string (see mermaid-js/mermaid#1766).What we changed
Set
htmlLabels: falseinmermaid.initialize()so labels are drawn with SVG text instead of HTML inforeignObject, producing SVG that parses cleanly asimage/svg+xml.Trade-offs
securityLevel: 'strict'(less reliance on HTML inside diagrams).