Skip to content

Commit 41e4c98

Browse files
committed
Fixed the issue that mermaid cannot open images when it contains utf-8 characters
1 parent 62a09a2 commit 41e4c98

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

webview-ui/src/components/common/MermaidBlock.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ async function svgToPng(svgEl: SVGElement): Promise<string> {
243243

244244
const serializer = new XMLSerializer()
245245
const svgString = serializer.serializeToString(svgClone)
246-
const svgDataUrl = "data:image/svg+xml;base64," + btoa(decodeURIComponent(encodeURIComponent(svgString)))
246+
247+
// Create a data URL directly
248+
// First, ensure the SVG string is properly encoded
249+
const encodedSvg = encodeURIComponent(svgString).replace(/'/g, "%27").replace(/"/g, "%22")
250+
251+
const svgDataUrl = `data:image/svg+xml;charset=utf-8,${encodedSvg}`
247252

248253
return new Promise((resolve, reject) => {
249254
const img = new Image()

0 commit comments

Comments
 (0)