From 9354a39d7f8af63c9c5903040974d62ded6a64f3 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 19 Sep 2024 17:49:10 +0300 Subject: [PATCH] perf: strengthen code block patterns (#906) Co-authored-by: Anton Medvedev --- src/cli.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 7de25e044f..f68607ca0e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -218,10 +218,10 @@ export function transformMarkdown(buf: Buffer) { let state = 'root' let codeBlockEnd = '' let prevLineIsEmpty = true - const jsCodeBlock = /^(```+|~~~+)(js|javascript)$/ - const shCodeBlock = /^(```+|~~~+)(sh|bash)$/ - const otherCodeBlock = /^(```+|~~~+)(.*)$/ - for (let line of source.split(/\r?\n/)) { + const jsCodeBlock = /^(```{1,20}|~~~{1,20})(js|javascript)$/ + const shCodeBlock = /^(```{1,20}|~~~{1,20})(sh|shell|bash)$/ + const otherCodeBlock = /^(```{1,20}|~~~{1,20})(.*)$/ + for (const line of source.split(/\r?\n/)) { switch (state) { case 'root': if (/^( {4}|\t)/.test(line) && prevLineIsEmpty) { @@ -245,10 +245,10 @@ export function transformMarkdown(buf: Buffer) { } break case 'tab': - if (/^( +|\t)/.test(line)) { - output.push(line) - } else if (line === '') { + if (line === '') { output.push('') + } else if (/^( +|\t)/.test(line)) { + output.push(line) } else { output.push('// ' + line) state = 'root'