fix(mermaid): inject xmlns:xlink namespace if missing before PNG export#542
Open
sleitor wants to merge 1 commit into
Open
fix(mermaid): inject xmlns:xlink namespace if missing before PNG export#542sleitor wants to merge 1 commit into
sleitor wants to merge 1 commit into
Conversation
Mermaid can emit SVG containing xlink-prefixed attributes (e.g. xlink:href in C4Context and sequence diagrams) without declaring the xmlns:xlink namespace on the root <svg> element. The resulting SVG is not valid XML, so browsers refuse to load it as an image, causing PNG export to fail silently. Add addXlinkNamespaceIfMissing() which detects the missing declaration via lightweight string checks and injects it onto the root <svg> tag. svgToPngBlob() now normalises the input before base64-encoding it as a data URI, matching the existing pattern for other Mermaid SVG normalisation fixes (see vercel#516). Fixes vercel#541
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
Mermaid can emit SVG containing xlink-prefixed attributes (e.g.
xlink:hrefin C4Context and sequence diagrams) without declaring thexmlns:xlinknamespace on the root<svg>element. The resulting SVG is not valid XML, so browsers refuse to load it as an image, causing PNG export to fail silently.Minimal reproduction (C4Context diagram):
Fix
Add
addXlinkNamespaceIfMissing()inpackages/streamdown/lib/mermaid/utils.tswhich:xlink:prefixed attributesxmlns:xlinknamespace is already declaredxmlns:xlink="http://www.w3.org/1999/xlink"onto the root<svg>tag via a lightweight string replacementsvgToPngBlob()now normalises the input before base64-encoding it as a data URI, following the same pattern as other Mermaid SVG normalisation fixes (see #516).Testing
Added 6 new unit tests covering:
<svg>tag is modified (not nested)Fixes #541