Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/streamdown/lib/mermaid/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* Ensure SVG string has required XML namespaces for canvas rendering
*/
function normalizeSvg(svg: string): string {
if (svg.includes("xlink:href") && !svg.includes("xmlns:xlink")) {
return svg.replace("<svg", '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
}
return svg;
}

/**
* Convert SVG string to PNG blob for export
*/
Expand All @@ -8,9 +18,11 @@ export const svgToPngBlob = (
const scale = options?.scale ?? 5;

return new Promise((resolve, reject) => {
const normalized = normalizeSvg(svgString);

const encoded =
"data:image/svg+xml;base64," +
btoa(unescape(encodeURIComponent(svgString)));
btoa(unescape(encodeURIComponent(normalized)));

const img = new Image();
img.crossOrigin = "anonymous";
Expand Down