Repository navigation
fix(parser): stop section extraction at any heading or thematic break (#2555 task 2) - #2557
Merged
Merged
Conversation
…#2555) extractSection / extractBulletList bounded a section only at the next `## `/`### ` heading, so a Prerequisites or You-will-learn block over-captured everything down to EOF when the following content was an `#### ` sub-heading, a `# H1`, or a bare `---`-separated intro paragraph with no h2/h3 after it. Widen the boundary lookahead to stop at any ATX heading (`#`..`######`) or a thematic break (`---`/`***`/`___` alone on a line). Every added alternative is an earlier-or-equal stop point, so the change can only shrink an over-capturing section, never grow one — sections correctly bounded by `## Steps` are unaffected (covered by a control test). Follow-up to #2556 (task 2 of #2555).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2556. Addresses the second, rarer parse-time issue in #2555.
Problem
extractSectionandextractBulletList(scripts/parsers/frontmatter.ts) bounded a section only at the next##/###heading:So a
## Prerequisites/## You will learnblock over-captured everything down to EOF whenever the content that followed it had no h2/h3 — e.g. an####sub-heading, a# H1, or a bare----separated intro paragraph. Rare in practice because authors almost always put## Stepsor a### Step 1right after, which correctly bounds the section.Distinct from #2556, which was a render-time heading duplication; this is a parse-time boundary in the frontmatter extractor.
Fix
Widen the boundary to stop at any ATX heading (
#..######) or a thematic break (---/***/___alone on a line):Applied to both extractors via a shared
SECTION_ENDconstant.Safety invariant: every new alternative is an earlier-or-equal stop point, so the change can only ever shrink an over-capturing section, never grow one. A section correctly bounded by
## Stepstoday still stops there — no correctly-rendering tutorial can regress.Testing
npx vitest run— 19/19 pass:extract-section-boundary.test.ts(5 cases): stops at####, at bare---, at# H1, a control proving## Steps-bounded prereqs still capture fully, and the same boundary honoured byextractBulletList.comment-aware-extraction.test.ts+frontmatter-utils.test.tsstay green.No local corpus diff was possible (no
.tutorial-cache/present); the "can only shrink" invariant plus CI + the post-DEV e2e job are the backstop.