@@ -23,7 +23,7 @@ for (let file of fs.readdirSync(".").sort()) {
23
23
start_code : getStartCode ( text , includes ) ,
24
24
exercises : [ ] ,
25
25
include : includes } ;
26
- let zip = chapterZipFile ( text , chapter ) ;
26
+ let zip = chapterZipFile ( meta , chapter ) ;
27
27
let extraLinks = meta . match ( / \b c o d e _ l i n k s : ( \[ .* ?\] ) / ) ;
28
28
if ( extraLinks ) extraLinks = JSON . parse ( extraLinks [ 1 ] ) ;
29
29
if ( extraLinks || zip )
@@ -180,12 +180,13 @@ function getStartCode(text, includes) {
180
180
return snippet ;
181
181
}
182
182
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 : ( " (?: \\ . | [ ^ " \\ ] ) * " ) / ) ;
185
185
if ( ! spec ) return null ;
186
186
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 ] ) )
187
188
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 ] ) : [ ] ) ;
189
190
let exists = fs . existsSync ( name ) && fs . statSync ( name ) . mtime ;
190
191
if ( exists && files . every ( file => fs . statSync ( "html/" + file ) . mtime < exists ) )
191
192
return name ;
@@ -194,13 +195,13 @@ function chapterZipFile(text, chapter) {
194
195
for ( let file of files ) {
195
196
zip . file ( chapter . id + "/" + file , fs . readFileSync ( "html/" + file ) ) ;
196
197
}
197
- if ( spec [ 1 ] . indexOf ( "html" ) != - 1 ) {
198
+ if ( data [ 1 ] . indexOf ( "html" ) != - 1 ) {
198
199
let html = chapter . start_code ;
199
200
if ( guessType ( html ) != "html" )
200
201
html = prepareHTML ( "<body><script>\n" + html . trim ( ) + "\n</script></body>" , chapter . include ) ;
201
202
zip . file ( chapter . id + "/index.html" , html ) ;
202
203
}
203
- if ( spec [ 1 ] . indexOf ( "node" ) != - 1 ) {
204
+ if ( data [ 1 ] . indexOf ( "node" ) != - 1 ) {
204
205
zip . file ( chapter . id + "/code/load.js" , fs . readFileSync ( "code/load.js" , "utf8" ) ) ;
205
206
let js = chapter . start_code ;
206
207
if ( chapter . include ) js = "// load dependencies\nrequire(\"./code/load\")(" + chapter . include . map ( JSON . stringify ) . join ( ", " ) + ");\n\n" + js ;
0 commit comments