diff --git a/src/md.ts b/src/md.ts index 2b6932e8ad..47cc032d7c 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,}| {0,3}\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..a081662f60 100644 --- a/test/md.test.ts +++ b/test/md.test.ts @@ -23,7 +23,32 @@ describe('transformMarkdown()', () => { }) test('preserves tab-indented blocks after a blank line (legacy behavior)', () => { - assert.equal(transformMarkdown(' \n '), ' \n ') + assert.equal( + transformMarkdown('\n\tconsole.log("hello")'), + '// \n\tconsole.log("hello")' + ) + }) + + test('preserves 4-space indented blocks after a blank line', () => { + assert.equal( + transformMarkdown('\n console.log("hello")'), + '// \n console.log("hello")' + ) + }) + + test('preserves blocks indented with spaces and a tab (equivalent to 4 spaces)', () => { + assert.equal( + transformMarkdown('\n \tconsole.log("hello")'), + '// \n \tconsole.log("hello")' + ) + }) + + test('does not treat indented list/paragraph text with <4 spaces as code blocks (#1388)', () => { + const input = + '- item 1\n- item 2\n\n This template assumes you have pnpm installed.' + const expected = + '// - item 1\n// - item 2\n// \n// This template assumes you have pnpm installed.' + assert.equal(transformMarkdown(input), expected) }) test('does not treat a mid-paragraph fence as a fenced block (legacy behavior)', () => {