Skip to content

Commit 36029ea

Browse files
authored
Merge pull request cyntler#305 from wangyinyuan/main
fix: correct Chinese and special characters display in HTML renderer
2 parents fa591ca + c358c9d commit 36029ea

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/renderers/html/index.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ const HTMLRenderer: DocRenderer = ({ mainState: { currentDocument } }) => {
88
const b64String = currentDocument?.fileData as string;
99

1010
let encoding = "";
11-
const bodyBase64 =
12-
b64String?.replace(
13-
/^data:text\/html;(?:charset=([^;]*);)?base64,/,
14-
(_, charset) => {
15-
encoding = charset;
16-
return "";
17-
},
18-
) || "";
11+
const bodyBase64 = b64String?.replace(
12+
/^data:text\/html;(?:charset=([^;]*);)?base64,/,
13+
(_, charset) => {
14+
encoding = charset || "utf-8";
15+
return "";
16+
},
17+
);
1918
let body: string = window.atob(bodyBase64);
2019

21-
if (encoding) {
22-
// decode charset
23-
const buffer = new Uint8Array(body.length);
24-
for (let i = 0; i < body.length; i++) buffer[i] = body.charCodeAt(i);
25-
body = new TextDecoder(encoding).decode(buffer);
26-
}
20+
// decode charset
21+
const buffer = Uint8Array.from(body, (c) => c.charCodeAt(0));
22+
body = new TextDecoder(encoding).decode(buffer);
2723

2824
const iframeCont = document.getElementById(
2925
"html-body",

0 commit comments

Comments
 (0)