File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,24 @@ import { dataURLFileLoader } from "../../utils/fileLoaders";
6
6
const HTMLRenderer : DocRenderer = ( { mainState : { currentDocument } } ) => {
7
7
useEffect ( ( ) => {
8
8
const b64String = currentDocument ?. fileData as string ;
9
- const bodyBase64 = b64String ?. replace ( "data:text/html;base64," , "" ) || "" ;
10
- const body : string = window . atob ( bodyBase64 ) ;
9
+
10
+ let encoding = "" ;
11
+ const bodyBase64 =
12
+ b64String ?. replace (
13
+ / ^ d a t a : t e x t \/ h t m l ; (?: c h a r s e t = ( [ ^ ; ] * ) ; ) ? b a s e 6 4 , / ,
14
+ ( _ , charset ) => {
15
+ encoding = charset ;
16
+ return "" ;
17
+ } ,
18
+ ) || "" ;
19
+ let body : string = window . atob ( bodyBase64 ) ;
20
+
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
+ }
11
27
12
28
const iframeCont = document . getElementById (
13
29
"html-body" ,
You can’t perform that action at this time.
0 commit comments