Skip to content

Fix nested code fence parsing in lists - #103

Merged
dacharyc merged 2 commits into
agent-ecosystem:mainfrom
nathan-contino:fix-list-code-fence-parsing
Aug 23, 2026
Merged

Fix nested code fence parsing in lists#103
dacharyc merged 2 commits into
agent-ecosystem:mainfrom
nathan-contino:fix-list-code-fence-parsing

Conversation

@nathan-contino

@nathan-contino nathan-contino commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

I noticed that YAML code fences in lists don't get proper parsing. Here's a fix.

The test uses a truncated version of the actual file where I noticed the problem in my employer's docs.

nathan-contino and others added 2 commits August 18, 2026 14:50
The {0,3} indent tolerance can't match fences inside list items, which
are indented by the list marker width (4 spaces for Turndown's numbered
lists). Capture the opener's indentation instead and require the closer
at the same indent plus CommonMark's 0-3 slack, so deeper-indented
literal fences inside a block can't close it early.

Also extend the test fixture past the 10-segment comparison threshold
(9 segments auto-pass regardless of the markdown), and revert the
unrelated package-lock.json changes.
@dacharyc

Copy link
Copy Markdown
Member

Hey Nate - thanks for the PR, it's good to see your name and avatar pop up 😁

Good catch on the bug here, and your fixture reproduced the right scenario, but I've pushed a follow-up commit to your branch (edc0662) that adjusts two things:

  1. The regex needed a different indent strategy. ^ {0,3} can't match fences inside list items, because they're indented by the list marker width (4 spaces for Turndown's 1. item style), so the new pattern never matched the case in your test fixture. The pushed version captures the opener's indentation (^( *)) and requires the closer at the same indent plus CommonMark's 0-3 slack, which handles any marker width while keeping a deeper-indented literal ``` inside the block from closing it early.

  2. The test fixture was one segment short of being exercised. The check auto-passes pages with fewer than 10 unique segments of 20+ chars (MIN_SEGMENTS_FOR_COMPARISON), and the truncated fixture produced exactly 9, so the test passed on main even without the fix. I added one paragraph to each side so it now fails without the regex change and passes with it.

I also reverted the package-lock.json changes since they were unrelated to the fix (a different npm version rewriting peer entries).

I appreciate you taking the time to make the PR, and it's cool that you're using afdocs and finding it useful enough to contribute! We should catch up sometime and compare notes. 😀

@dacharyc
dacharyc merged commit 2faa561 into agent-ecosystem:main Aug 23, 2026
2 checks passed
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.

2 participants