From 8dd60f4c912220421e4a8e8ac9734dee462e0284 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Tue, 19 May 2026 02:11:02 -0400 Subject: [PATCH 1/3] fix(md): require 4+ spaces for indented code blocks (CommonMark) --- src/md.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/md.ts b/src/md.ts index 2b6932e8ad..beb3c0bd43 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 = /^( +|\t)/ const fenceRe = /^(? {0,3})(?(`{3,20}|~{3,20}))(?:(?js|javascript|ts|typescript)|(?sh|shell|bash)|.*)$/ From 418e5709d380b4e35825b86f0d2f90fb911a16a8 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Tue, 19 May 2026 02:12:31 -0400 Subject: [PATCH 2/3] test(md): update legacy test to 4-space + add regression for #1388 --- test/md.test.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/md.test.ts b/test/md.test.ts index d37b9c9f6e..9f8833aa92 100644 --- a/test/md.test.ts +++ b/test/md.test.ts @@ -22,8 +22,21 @@ 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 4+ space indented blocks after a blank line (CommonMark)', () => { + assert.equal(transformMarkdown(' \n '), ' \n ') + }) + + test('does NOT treat 2-space indented list-item continuation as code (#1388)', () => { + // CommonMark: indented code blocks require 4+ spaces. A 2-space-indented + // line after a blank line under a list item is list continuation prose, + // not code. Treating it as code throws SyntaxError on the next eval. + const input = `- on localhost + + This assumes you have a local node running +` + const result = transformMarkdown(input) + // Prose line must be commented, not left as raw code. + assert.ok(!/^ This assumes/m.test(result), 'expected prose line to not be left as raw code') }) test('does not treat a mid-paragraph fence as a fenced block (legacy behavior)', () => { From 13f99175514ecd7721d392a311506871cec36420 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Wed, 20 May 2026 14:42:20 -0400 Subject: [PATCH 3/3] fix(md): use explicit 4-space indent regex --- src/md.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/md.ts b/src/md.ts index beb3c0bd43..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)|.*)$/