Skip to content

fix(md): comment out tab-indented blocks instead of executing them#1485

Closed
Fmarzochi wants to merge 1 commit into
google:mainfrom
Fmarzochi:fix/md-comment-indented-blocks
Closed

fix(md): comment out tab-indented blocks instead of executing them#1485
Fmarzochi wants to merge 1 commit into
google:mainfrom
Fmarzochi:fix/md-comment-indented-blocks

Conversation

@Fmarzochi

Copy link
Copy Markdown

Fixes #1388 / regression: SyntaxError when running zx on markdown files with indented prose

Tab-indented blocks (4 spaces or tab, per CommonMark spec) were pushed verbatim to the JS output and executed. Any prose text in those blocks caused a SyntaxError at runtime. For example, a README with:

This assumes the environment is configured.

produced: SyntaxError: Unexpected identifier 'assumes'

The fix mirrors the behavior already used for non-JS fenced blocks: prefix each indented line with '// ' so it becomes a comment. Two places in md.ts needed the change: the transition from root to tab state, and the tab state itself.

Updated the existing legacy-behavior test to reflect the new output and added a regression test for the prose-text case.

  • Setup Set the latest Node.js LTS version.
  • Build: I've run npm build before committing and verified the bundle updates correctly.
  • Tests: I've run test and confirmed all tests succeed. Added tests to cover my changes.
  • Docs: No documentation change needed for this fix.
  • Sign Commits follow conventional commits spec.
  • CoC: My changes follow the project coding guidelines and Code of Conduct.
  • Review: This PR represents original work and is not solely generated by AI tools.

Tab-indented blocks in Markdown (4 spaces or tab) were being pushed
verbatim to the output and executed as JavaScript. Any prose text in
those blocks caused a SyntaxError at runtime, e.g.:

    This assumes the environment is configured.

yields: SyntaxError: Unexpected identifier 'assumes'

The fix mirrors the behavior already used for non-JS fenced blocks:
prefix each indented line with '// ' so it becomes a comment.

Updated the existing legacy-behavior test to reflect the new output
and added a regression test for the prose-text SyntaxError case.

Fixes #1388

Signed-off-by: Felipe Marzochi <fmarzochi@gmail.com>
@Fmarzochi Fmarzochi closed this by deleting the head repository Jun 12, 2026
@google-cla

google-cla Bot commented Jun 12, 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.

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