Skip to content

Commit 4456f87

Browse files
fix: svg render issue (Acode-Foundation#1530)
1 parent afad88b commit 4456f87

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lib/run.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,21 @@ async function run(
8383
try {
8484
const fs = fsOperation(activeFile.uri);
8585
const res = await fs.readFile();
86-
const blob = new Blob([new Uint8Array(res)], {
87-
type: mimeType.lookup(extension),
88-
});
86+
let text = new TextDecoder().decode(res);
87+
88+
if (!/^<\?xml/.test(text)) {
89+
text = `<?xml version="1.0" encoding="UTF-8"?>\n` + text;
90+
}
8991

90-
box(filename, `<img src='${URL.createObjectURL(blob)}'>`);
92+
const blob = new Blob([text], { type: mimeType.lookup(extension) });
93+
const url = URL.createObjectURL(blob);
94+
95+
box(
96+
filename,
97+
`<div style="display:flex;justify-content:center;align-items:center;height:100%">
98+
<img src="${url}" alt="${filename}" style="max-width:100%;max-height:100%">
99+
</div>`,
100+
);
91101
} catch (err) {
92102
helpers.error(err);
93103
}

0 commit comments

Comments
 (0)