Skip to content

Commit

Permalink
Fix error svg output when no xmlns attr
Browse files Browse the repository at this point in the history
  • Loading branch information
zunsthy committed Oct 16, 2024
1 parent 1e1a144 commit e385f5f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/js/page/ui/svg-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ export default class SvgOutput {
}

setSvg({ text, width, height }) {
// TODO: revisit this
// I would rather use blob urls, but they don't work in Firefox
// All the internal refs break.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1125667
const nextLoad = this._nextLoadPromise();
this._svgFrame.src = `data:image/svg+xml,${encodeURIComponent(text)}`;
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'image/svg+xml');
const noNamespace = !doc.documentElement.attributes.xmlns;
if (noNamespace) {
this._svgFrame.src = `data:text/html,${encodeURIComponent(
'<html>' +
'<head><style>body { margin: 0 }</style></head>' +
`<body>${text}</body>` +
'</html>'
)}`;
} else {
const blob = new Blob([text], { type: 'image/svg+xml' });
this._svgFrame.src = URL.createObjectURL(blob);
}
this._svgFrame.style.width = `${width}px`;
this._svgFrame.style.height = `${height}px`;
return nextLoad;
Expand Down

0 comments on commit e385f5f

Please sign in to comment.