@@ -23,7 +23,7 @@ for (let file of fs.readdirSync(".").sort()) {
2323 start_code : getStartCode ( text , includes ) ,
2424 exercises : [ ] ,
2525 include : includes } ;
26- let zip = chapterZipFile ( text , chapter ) ;
26+ let zip = chapterZipFile ( meta , chapter ) ;
2727 let extraLinks = meta . match ( / \b c o d e _ l i n k s : ( \[ .* ?\] ) / ) ;
2828 if ( extraLinks ) extraLinks = JSON . parse ( extraLinks [ 1 ] ) ;
2929 if ( extraLinks || zip )
@@ -180,12 +180,13 @@ function getStartCode(text, includes) {
180180 return snippet ;
181181}
182182
183- function chapterZipFile ( text , chapter ) {
184- let spec = text . match ( / \n : z i p : ( \S + ) (?: i n c l u d e = ( . * ) ) ? / ) ;
183+ function chapterZipFile ( meta , chapter ) {
184+ let spec = meta . match ( / \b z i p : ( " (?: \\ . | [ ^ " \\ ] ) * " ) / ) ;
185185 if ( ! spec ) return null ;
186186 if ( ! chapter . start_code ) throw new Error ( "zip but no start code" ) ;
187+ let data = / ( \S + ) (?: \s + i n c l u d e = ( .* ) ) ? / . exec ( JSON . parse ( spec [ 1 ] ) )
187188 let name = "code/chapter/" + chapter . id + ".zip" ;
188- let files = ( chapter . include || [ ] ) . concat ( spec [ 2 ] ? JSON . parse ( spec [ 2 ] ) : [ ] ) ;
189+ let files = ( chapter . include || [ ] ) . concat ( data [ 2 ] ? JSON . parse ( data [ 2 ] ) : [ ] ) ;
189190 let exists = fs . existsSync ( name ) && fs . statSync ( name ) . mtime ;
190191 if ( exists && files . every ( file => fs . statSync ( "html/" + file ) . mtime < exists ) )
191192 return name ;
@@ -194,13 +195,13 @@ function chapterZipFile(text, chapter) {
194195 for ( let file of files ) {
195196 zip . file ( chapter . id + "/" + file , fs . readFileSync ( "html/" + file ) ) ;
196197 }
197- if ( spec [ 1 ] . indexOf ( "html" ) != - 1 ) {
198+ if ( data [ 1 ] . indexOf ( "html" ) != - 1 ) {
198199 let html = chapter . start_code ;
199200 if ( guessType ( html ) != "html" )
200201 html = prepareHTML ( "<body><script>\n" + html . trim ( ) + "\n</script></body>" , chapter . include ) ;
201202 zip . file ( chapter . id + "/index.html" , html ) ;
202203 }
203- if ( spec [ 1 ] . indexOf ( "node" ) != - 1 ) {
204+ if ( data [ 1 ] . indexOf ( "node" ) != - 1 ) {
204205 zip . file ( chapter . id + "/code/load.js" , fs . readFileSync ( "code/load.js" , "utf8" ) ) ;
205206 let js = chapter . start_code ;
206207 if ( chapter . include ) js = "// load dependencies\nrequire(\"./code/load\")(" + chapter . include . map ( JSON . stringify ) . join ( ", " ) + ");\n\n" + js ;
0 commit comments