@@ -306,14 +306,36 @@ function toggleDarkMode(): void {
306306
307307// Export editors' content as ZIP
308308async function exportAsZip ( ) {
309+ const html = editors . html . view . state . doc . toString ( ) . trim ( ) ;
310+ const css = editors . css . view . state . doc . toString ( ) . trim ( ) ;
311+ const js = editors . js . view . state . doc . toString ( ) . trim ( ) ;
312+
313+ const files : { name : string ; content : string } [ ] = [ ] ;
314+ if ( html ) files . push ( { name : "index.html" , content : html } ) ;
315+ if ( css ) files . push ( { name : "styles.css" , content : css } ) ;
316+ if ( js ) files . push ( { name : "script.js" , content : js } ) ;
317+
318+ if ( files . length === 0 ) {
319+ alert ( "Nothing to export!" ) ;
320+ return ;
321+ }
322+
323+ if ( files . length === 1 ) {
324+ const blob = new Blob ( [ files [ 0 ] . content ] , { type : "text/plain" } ) ;
325+ saveAs ( blob , files [ 0 ] . name ) ;
326+ return ;
327+ }
328+
309329 const zip = new JSZip ( ) ;
310- zip . file ( "index.html" , editors . html . view . state . doc . toString ( ) ) ;
311- zip . file ( "styles.css" , editors . css . view . state . doc . toString ( ) ) ;
312- zip . file ( "script.js" , editors . js . view . state . doc . toString ( ) ) ;
330+ for ( const file of files ) {
331+ zip . file ( file . name , file . content ) ;
332+ }
333+
313334 const content = await zip . generateAsync ( { type : "blob" } ) ;
314335 saveAs ( content , "htmlrunner-export.zip" ) ;
315336}
316337
338+
317339// Copy console content
318340function copyAllConsole ( ) : void {
319341 const entries = Array . from ( consoleOutput . children ) ;
0 commit comments