Skip to content

Commit

Permalink
perf: strengthen code block patterns (#906)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Medvedev <[email protected]>
  • Loading branch information
antongolub and antonmedv authored Sep 19, 2024
1 parent 971cbfc commit 9354a39
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
Expand Down

0 comments on commit 9354a39

Please sign in to comment.