@@ -286,14 +286,14 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
286286 < div class =menu-label >
287287 autosave
288288 </ div >
289- < input type =checkbox >
289+ < input type =checkbox checked >
290290 < input value =300 style ='width:60px '>
291291 </ div >
292292 < div id =trim class =menu-item >
293293 < div class =menu-label >
294294 trim on save
295295 </ div >
296- < input type =checkbox >
296+ < input type =checkbox checked >
297297 </ div >
298298 </ div >
299299 </ div >
@@ -344,6 +344,7 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
344344
345345 var ui = { } ;
346346 ui . mode = 'vert' ;
347+ ui . trim = null ;
347348
348349 var savemenu ;
349350 var savetimer = { } ;
@@ -378,6 +379,8 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
378379 filemod . initdom ( root ) ;
379380
380381
382+ autosave = $ ( root , '#autosave' ) ;
383+
381384 $ ( root , '#save' ) . onclick = btn . save ;
382385
383386 savemenu = $ ( root , '#save-root .menu' ) ;
@@ -388,7 +391,7 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
388391 savetimer . time = $ ( savemenu , ':scope>div:nth-of-type(2) input:not([type])' ) ;
389392 savetimer . chk . onclick = savetimer . onclick ;
390393
391- autosave = $ ( root , '#autosave ') ;
394+ ui . trim = $ ( savemenu , ':scope>div:nth-of-type(3) [type=checkbox] ') ;
392395
393396
394397 publish . initdom ( ) ;
@@ -472,6 +475,10 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
472475
473476
474477 function fn ( ) {
478+
479+ if ( ! autosave . checked ) {
480+ return ;
481+ }
475482 debug ( 'savetimer' , value ) ;
476483 btn . save ( ) ;
477484 if ( savetimer . chk . checked ) {
@@ -586,6 +593,24 @@ <h1 slot=seo-hdr class=visually-hidden>html editor</h1>
586593 function source ( file ) {
587594
588595 var txt = editor . getValue ( ) ;
596+
597+ if ( ui . trim . checked ) {
598+ var indent = 0 ;
599+ var lines = txt . split ( '\n' ) ;
600+ lines = lines . map ( line => {
601+
602+ line = line . trimEnd ( ) ;
603+ if ( line . length == 0 ) {
604+ line = line . padStart ( indent , ' ' ) ;
605+ }
606+ var match = line . match ( / ^ \s * / ) ;
607+ indent = match ? match [ 0 ] . length : indent ;
608+ return line ;
609+
610+ } ) ;
611+ txt = lines . join ( '\n' ) ;
612+ }
613+
589614 var blob = new Blob ( [ txt ] ) ;
590615 return blob ;
591616
0 commit comments