Skip to content

fix: align indented code block detection with CommonMark - #1512

Open
amansri-30 wants to merge 1 commit into
google:mainfrom
amansri-30:fix/md-indent-commonmark
Open

amansri-30 wants to merge 1 commit into
google:mainfrom
amansri-30:fix/md-indent-commonmark

Conversation

@amansri-30

Copy link
Copy Markdown

Fixes #1388

What

transformMarkdown() now detects indented code blocks per CommonMark: only indentation of 4+ spaces (or a tab) after a blank line is treated as code. Previously any 2+ space indented line was emitted raw, which broke markdown docs containing indented prose inside list items:

- on localhost

  This assumes you have a local node running ...

was emitted verbatim as JS, producing SyntaxError: Unexpected identifier 'assumes' (repro: template-ethereum-contracts README).

Now such 2-space paragraph/list continuations are handled as text (commented out), while fenced code blocks indented up to 3 spaces inside the same list item still run.

Checklist

  • Setup Node.js v24 LTS used.
  • Build — could not run npm run build locally: the repo's build/test scripts rely on POSIX rm and derive paths via new URL(import.meta.url).pathname, which on Windows yields C:\C:\... (pre-existing portability issue). GitHub CI runs the full build + npm test on Linux.
  • Tests — test/md.test.ts passes locally (7/7) via node --experimental-transform-types --test test/md.test.ts; added a regression test for this issue. Full npm test blocked on Windows by the same pre-existing path bugs (license/madge/size hooks).
  • Docs — not needed (behavioral fix).
  • Sign — commits are not GPG-signed.
  • CoC — change follows project guidelines.
  • Review — this change was developed with AI assistance and has been reviewed; leaving this box unchecked so reviewers can judge on their own.

Only 4-space (or tab) indentation after a blank line denotes an
indented code block. 2-space indented lines are paragraph/list
continuations and were previously emitted raw, producing invalid JS
(e.g. SyntaxError: Unexpected identifier) when running markdown docs
with indented prose inside list items.

Closes google#1388
@google-cla

google-cla Bot commented Sep 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
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

1 participant