chore(tools): Fix Wikipedia section extraction for wrapped headings - #913
Merged
Conversation
MediaWiki nests each heading in a `<div class="mw-heading">` together with its "[edit]" link, so a section's prose is a sibling of that wrapper div, not of the heading itself. Walking the heading's own siblings only picked up the edit-link chrome, so `web fetch` section extraction and previews for Wikipedia (and other MediaWiki) pages returned empty or chrome-only content instead of the actual prose. `extract_heading_section` and `extract_preview_after_heading` now walk from a `heading_walk_origin`, which hoists through wrapper elements (div/header/hgroup) whose only other children are inline chrome. Section-boundary checks use `wrapped_heading_level` so a wrapper div around the next heading still stops the walk. Hoisting is conservative: containers that mix a heading with real block content (callout boxes, nested sections) are never promoted, so their content stays attached to the section it belongs to. Covers both MediaWiki output shapes: Parsoid's nested `<section>` elements and the flat legacy parser layout. Signed-off-by: Jean Mertz <git@jeanmertz.com>
JeanMertz
force-pushed
the
web-fetch-wikipedia
branch
from
July 30, 2026 13:36
4f29809 to
dd515bc
Compare
…dings Signed-off-by: Jean Mertz <git@jeanmertz.com>
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.
MediaWiki nests each heading in a
<div class="mw-heading">together with its "[edit]" link, so a section's prose is a sibling of that wrapper div, not of the heading itself. Walking the heading's own siblings only picked up the edit-link chrome, soweb fetchsection extraction and previews for Wikipedia (and other MediaWiki) pages returned empty or chrome-only content instead of the actual prose.extract_heading_sectionandextract_preview_after_headingnow walk from aheading_walk_origin, which hoists through wrapper elements (div/header/hgroup) whose only other children are inline chrome. Section-boundary checks usewrapped_heading_levelso a wrapper div around the next heading still stops the walk. Hoisting is conservative: containers that mix a heading with real block content (callout boxes, nested sections) are never promoted, so their content stays attached to the section it belongs to.Covers both MediaWiki output shapes: Parsoid's nested
<section>elements and the flat legacy parser layout.