@@ -4,6 +4,7 @@ var process = require('process');
44var chalk = require ( 'chalk' ) ;
55var Match = require ( './matchers' ) ;
66var validators_1 = require ( './validators' ) ;
7+ var cleanup_1 = require ( './cleanup' ) ;
78function build ( lines ) {
89 var result = {
910 project : { } ,
@@ -116,7 +117,7 @@ function task(result, lines, index) {
116117 if ( ! inCodeBlock ) {
117118 if ( ! ! Match . taskAction ( line ) ) {
118119 var action = line . slice ( 1 ) . split ( '(' ) [ 0 ] ;
119- var target = / \( ( .* ?) \) $ / . exec ( line ) [ 1 ] ;
120+ var target = cleanup_1 . trimQuotes ( / \( ( .* ?) \) $ / . exec ( line ) [ 1 ] ) ;
120121 switch ( action ) {
121122 case 'test' :
122123 result . chapters [ index . chapter ] . pages [ index . page ] . tasks [ index . task ] . tests . push ( target ) ;
@@ -144,39 +145,14 @@ function task(result, lines, index) {
144145 }
145146 return result ;
146147}
147- function removeLineBreaks ( text ) {
148- if ( text . slice ( - 2 ) === '\n' ) {
149- return removeLineBreaks ( text . slice ( 0 , - 2 ) ) ;
150- }
151- else if ( text . slice ( 0 , 2 ) === '\n' ) {
152- return removeLineBreaks ( text . slice ( 2 ) ) ;
153- }
154- else {
155- return text . trim ( ) ;
156- }
157- }
158- function cleanup ( result ) {
159- result . project . description = removeLineBreaks ( result . project . description ) ;
160- result . chapters . map ( function ( chapter ) {
161- chapter . description = removeLineBreaks ( chapter . description ) ;
162- chapter . pages . map ( function ( page ) {
163- page . description = removeLineBreaks ( page . description ) ;
164- page . explanation = removeLineBreaks ( page . explanation ) ;
165- page . tasks . map ( function ( task ) {
166- task . description = removeLineBreaks ( task . description ) ;
167- } ) ;
168- } ) ;
169- } ) ;
170- return JSON . stringify ( result , null , 2 ) ;
171- }
172148module . exports = function ( filePath , output ) {
173149 if ( output === void 0 ) { output = './coderoad.json' ; }
174150 if ( ! filePath ) {
175151 console . log ( chalk . red ( "\n Pass in a path to your .md file\n For example: coderoad build ./src/tutorial.md\n " ) ) ;
176152 process . exit ( 1 ) ;
177153 }
178154 var lines = fs . readFileSync ( filePath , 'utf8' ) . split ( '\n' ) ;
179- var result = cleanup ( build ( lines ) ) ;
155+ var result = cleanup_1 . cleanup ( build ( lines ) ) ;
180156 if ( validators_1 . default ( result ) ) {
181157 fs . writeFileSync ( output , result , 'utf8' ) ;
182158 }
0 commit comments