@@ -154,30 +154,37 @@ core.starProblem = function(problem, starred, cb) {
154154
155155core . exportProblem = function ( problem , f , codeOnly ) {
156156 var output = '' ;
157+ problem . code = problem . code . replace ( / \r \n / g, '\n' ) ;
157158
158159 if ( codeOnly ) {
159160 output = problem . code ;
160161 } else {
161- var input = h . langToCommentStyle ( h . extToLang ( f ) ) ;
162+ var input = {
163+ comment : h . langToCommentStyle ( h . extToLang ( f ) )
164+ } ;
162165 // copy problem attrs thus we can render it in template
163166 _ . extend ( input , problem ) ;
164167 input . percent = input . percent . toFixed ( 2 ) ;
165168 input . testcase = util . inspect ( input . testcase || '' ) ;
166169
167170 // NOTE: wordwrap internally uses '\n' as EOL, so here we have to
168171 // remove all '\r' in the raw string.
169- // FIXME: while in template file we still use '\r\n' for the sake
170- // of windows, is it really necessary?
171172 var desc = input . desc . replace ( / \r \n / g, '\n' )
172173 . replace ( / ^ / mg, '' ) ;
173174
174- var wrap = require ( 'wordwrap' ) ( 79 - input . commentLine . length ) ;
175+ var wrap = require ( 'wordwrap' ) ( 79 - input . comment . line . length ) ;
175176 input . desc = wrap ( desc ) . split ( '\n' ) ;
176177
177178 var tpl = fs . readFileSync ( path . resolve ( __dirname , '../source.tpl' ) , 'utf-8' ) ;
178179 output = _ . template ( tpl ) ( input ) ;
179180 }
180181
182+ if ( h . isWindows ( ) ) {
183+ output = output . replace ( / \n / g, '\r\n' ) ;
184+ } else {
185+ output = output . replace ( / \r \n / g, '\n' ) ;
186+ }
187+
181188 fs . writeFileSync ( f , output ) ;
182189} ;
183190
0 commit comments