Skip to content

fix: ignore headings inside fenced code blocks in splitIntoChunks#5

Open
Sufyr wants to merge 1 commit into
vercel-labs:mainfrom
Sufyr:main
Open

fix: ignore headings inside fenced code blocks in splitIntoChunks#5
Sufyr wants to merge 1 commit into
vercel-labs:mainfrom
Sufyr:main

Conversation

@Sufyr

@Sufyr Sufyr commented May 15, 2026

Copy link
Copy Markdown

What changed

Fixed splitIntoChunks in @mdxg/parser to properly track code fence state and ignore H1/H2 headings inside fenced code blocks (``` and ~~~).

Why

SPEC Section 6.1 requires: "Headings inside fenced code blocks (``` or ~~~) MUST NOT be treated as page boundaries. The tool MUST track code fence open/close state when scanning for headings."

Previously, splitIntoChunks did not track code fence state, causing headings inside code blocks to be incorrectly treated as page boundaries.

How

Added inCodeFence tracking to splitIntoChunks, matching the existing pattern in extractHeadings.

Before & After

Before After
PixPin_2026-05-15_09-43-41 PixPin_2026-05-15_09-43-54

Tests

Added 4 test cases:

  • Ignores H1/H2 headings inside fenced code blocks
  • Ignores H1/H2 headings inside tilde code blocks
  • Ignores setext headings inside code blocks
  • Handles multiple code blocks with headings

@vercel

vercel Bot commented May 15, 2026

Copy link
Copy Markdown

@Sufyr is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant