Skip to content

fix(md): require 4+ spaces for indented code blocks (CommonMark)#1471

Open
kiwigitops wants to merge 3 commits into
google:mainfrom
kiwigitops:fix/md-indented-code-block-requires-4-spaces
Open

fix(md): require 4+ spaces for indented code blocks (CommonMark)#1471
kiwigitops wants to merge 3 commits into
google:mainfrom
kiwigitops:fix/md-indented-code-block-requires-4-spaces

Conversation

@kiwigitops
Copy link
Copy Markdown

@kiwigitops kiwigitops commented May 19, 2026

Fixes #1388.

Problem

transformMarkdown() in src/md.ts treats any line indented with 2 or more spaces (after a blank line) as a markdown indented code block — i.e. raw JS to execute. CommonMark requires 4 or more spaces for an indented code block.

The 2-space cutoff incorrectly captures list-item continuation lines, which are conventionally indented 2 spaces to align with the content after - . Those continuation lines are prose, not code, but the parser hands them to the JS engine as raw code and the script blows up with SyntaxError: Unexpected identifier '<word>'.

The reporter's case is a README with prose continuation under a list item followed by a fenced shell block. The prose line begins with two spaces, so the old regex treated it as executable code.

Fix

-  const tabRe = /^(  +|\t)/
+  const tabRe = /^( {4,}|\t)/

Aligns the indented-code-block threshold with CommonMark: 4+ spaces or 1 tab. Tab-indented blocks keep working unchanged.

Test plan

  • Updated the existing tab-indented block test to assert the new CommonMark-compliant 4-space behavior.
  • Added a regression test for 2-space indented list-item continuation prose from [Bug]: cannot parse indented content #1388.
  • Existing fenced-code-block and plain-line transform tests still pass.

@antonmedv
Copy link
Copy Markdown
Collaborator

@antongolub LGTM

@antongolub
Copy link
Copy Markdown
Collaborator

I'd prefer more explicit form: /^( {4,}|\t)/

@antongolub antongolub self-requested a review May 20, 2026 06:11
@kiwigitops
Copy link
Copy Markdown
Author

Updated in 5b2f8e5 to use the explicit regex form you suggested:

/^( {4,}|\t)/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cannot parse indented content

3 participants