diff --git a/src/md.ts b/src/md.ts index 2b6932e8ad..60f703768c 100644 --- a/src/md.ts +++ b/src/md.ts @@ -17,7 +17,7 @@ import { bufToString } from './util.ts' export function transformMarkdown(buf: Buffer | string): string { const out: string[] = [] - const tabRe = /^( +|\t)/ + const tabRe = /^( {4,}|\t)/ const fenceRe = /^(? {0,3})(?(`{3,20}|~{3,20}))(?:(?js|javascript|ts|typescript)|(?sh|shell|bash)|.*)$/ diff --git a/test/md.test.ts b/test/md.test.ts index d37b9c9f6e..53e96221c4 100644 --- a/test/md.test.ts +++ b/test/md.test.ts @@ -22,8 +22,38 @@ describe('transformMarkdown()', () => { assert.equal(transformMarkdown('\n'), '// \n// ') }) - test('preserves tab-indented blocks after a blank line (legacy behavior)', () => { - assert.equal(transformMarkdown(' \n '), ' \n ') + test('preserves four-space and tab-indented blocks after a blank line', () => { + assert.equal( + transformMarkdown('\n code\n\tmore'), + '// \n code\n\tmore' + ) + }) + + test('comments two-space indented list continuation prose', () => { + const result = transformMarkdown(` +- on localhost + + This assumes you have a local node running. + + \`\`\`bash + pnpm run contracts:deploy localhost + \`\`\` +`) + + assert.equal( + result, + [ + '// ', + '// - on localhost', + '// ', + '// This assumes you have a local node running.', + '// ', + 'await $`', + 'pnpm run contracts:deploy localhost', + '`', + '// ', + ].join('\n') + ) }) test('does not treat a mid-paragraph fence as a fenced block (legacy behavior)', () => {