File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff 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 ( ! / ^ < \? x m l / . 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 }
You can’t perform that action at this time.
0 commit comments