Skip to content

fix(md): parse indented fenced code blocks inside lists (fixes #1389) - #1518

Closed
swaraj792725 wants to merge 1 commit into
google:mainfrom
swaraj792725:fix/md-nested-list-fenced-code-blocks
Closed

swaraj792725 wants to merge 1 commit into
google:mainfrom
swaraj792725:fix/md-nested-list-fenced-code-blocks

Conversation

@swaraj792725

Copy link
Copy Markdown

Fixes #1389

Description

When fenced code blocks (```bash or ```js) are nested inside lists, list items, or blocks, they are often indented with 4 or more spaces.

Previously, fenceRe restricted the opening fence indentation to {0,3} spaces, which caused code fences indented with 4+ spaces to fail fence recognition, fall into the indented code block branch, and emit raw markdown backticks into the generated JavaScript file (e.g. ```bash ... ```), resulting in syntax errors or TypeError: $(...) is not a function during script execution.

This PR:

  1. Updates fenceRe to accept any leading space indentation ((?<indent> *)) so indented code fences nested in lists are recognized.
  2. Updates endRe to match closing code fences with any leading space indentation (^ *${fenceChar}{${g.fence.length},}[ \t]*$).
  3. Uses the existing stripRe mechanism to strip the fence's indentation level from code lines while preserving relative indentation inside the code.
  4. Adds a unit test in test/md.test.ts verifying that indented code fences inside lists are transformed to executable commands without emitting raw markdown fences.

@antonmedv antonmedv closed this Oct 6, 2026
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]: TypeError: $(...) is not a function

2 participants