File tree 2 files changed +7
-14
lines changed
2 files changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -217,15 +217,14 @@ export function injectGlobalRequire(origin: string) {
217
217
}
218
218
219
219
export function transformMarkdown ( buf : Buffer | string ) : string {
220
- const source = buf . toString ( )
221
220
const output = [ ]
222
221
const tabRe = / ^ ( + | \t ) /
223
222
const codeBlockRe =
224
223
/ ^ (?< fence > ( ` { 3 , 20 } | ~ { 3 , 20 } ) ) (?: (?< js > ( j s | j a v a s c r i p t | t s | t y p e s c r i p t ) ) | (?< bash > ( s h | s h e l l | b a s h ) ) | .* ) $ /
225
224
let state = 'root'
226
225
let codeBlockEnd = ''
227
226
let prevLineIsEmpty = true
228
- for ( const line of source . split ( / \r ? \n / ) ) {
227
+ for ( const line of buf . toString ( ) . split ( / \r ? \n / ) ) {
229
228
switch ( state ) {
230
229
case 'root' :
231
230
if ( tabRe . test ( line ) && prevLineIsEmpty ) {
Original file line number Diff line number Diff line change @@ -277,23 +277,19 @@ export function formatCmd(cmd?: string): string {
277
277
}
278
278
279
279
function space ( ) {
280
- if ( / \s / . test ( ch ) ) return space
281
- return root
280
+ return / \s / . test ( ch ) ? space : root
282
281
}
283
282
284
283
function word ( ) {
285
- if ( / [ \w / . ] / i. test ( ch ) ) return word
286
- return root
284
+ return / [ \w / . ] / i. test ( ch ) ? word : root
287
285
}
288
286
289
287
function syntax ( ) {
290
- if ( isSyntax ( ch ) ) return syntax
291
- return root
288
+ return isSyntax ( ch ) ? syntax : root
292
289
}
293
290
294
291
function dollar ( ) {
295
- if ( ch === "'" ) return str
296
- return root
292
+ return ch === "'" ? str : root
297
293
}
298
294
299
295
function str ( ) {
@@ -311,13 +307,11 @@ export function formatCmd(cmd?: string): string {
311
307
}
312
308
313
309
function strDouble ( ) {
314
- if ( ch === '"' ) return strEnd
315
- return strDouble
310
+ return ch === '"' ? strEnd : strDouble
316
311
}
317
312
318
313
function strSingle ( ) {
319
- if ( ch === "'" ) return strEnd
320
- return strSingle
314
+ return ch === "'" ? strEnd : strSingle
321
315
}
322
316
323
317
function strEnd ( ) {
You can’t perform that action at this time.
0 commit comments