diff --git a/src/renderers/html/index.tsx b/src/renderers/html/index.tsx index 688a864..87c18d0 100644 --- a/src/renderers/html/index.tsx +++ b/src/renderers/html/index.tsx @@ -6,9 +6,24 @@ import { dataURLFileLoader } from "../../utils/fileLoaders"; const HTMLRenderer: DocRenderer = ({ mainState: { currentDocument } }) => { useEffect(() => { const b64String = currentDocument?.fileData as string; + + let encoding = ""; const bodyBase64 = - b64String?.replace(/^data:text\/html;([^;]*?;)?base64,/, "") || ""; - const body: string = window.atob(bodyBase64); + b64String?.replace( + /^data:text\/html;(?:charset=([^;]*);)?base64,/, + (_, charset) => { + encoding = charset; + return ""; + }, + ) || ""; + let body: string = window.atob(bodyBase64); + + if (encoding) { + // decode charset + const buffer = new Uint8Array(body.length); + for (let i = 0; i < body.length; i++) buffer[i] = body.charCodeAt(i); + body = new TextDecoder(encoding).decode(buffer); + } const iframeCont = document.getElementById( "html-body",