Skip to content

chore(tools): Handle anchor IDs nested inside heading elements#534

Merged
JeanMertz merged 1 commit intomainfrom
prr101
Apr 11, 2026
Merged

chore(tools): Handle anchor IDs nested inside heading elements#534
JeanMertz merged 1 commit intomainfrom
prr101

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

When fetching a web page section by anchor, the anchor id is sometimes placed on a child element inside a heading tag rather than on the heading itself. Previously extract_anchor_html only recognised the target as a heading if the matched element was directly a heading tag, causing it to fall back to returning just that inner element's HTML instead of the full heading section.

Now, when the matched element is not itself a heading, the code walks up its ancestor chain via find_heading_ancestor. If a heading ancestor is found it is used as the section root, so the correct section content (everything up to the next same-or-higher level heading) is returned.

When fetching a web page section by anchor, the anchor `id` is sometimes
placed on a child element inside a heading tag rather than on the
heading itself. Previously `extract_anchor_html` only recognised the
target as a heading if the matched element was directly a heading tag,
causing it to fall back to returning just that inner element's HTML
instead of the full heading section.

Now, when the matched element is not itself a heading, the code walks up
its ancestor chain via `find_heading_ancestor`. If a heading ancestor is
found it is used as the section root, so the correct section content
(everything up to the next same-or-higher level heading) is returned.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz merged commit dd6ac09 into main Apr 11, 2026
13 checks passed
@JeanMertz JeanMertz deleted the prr101 branch April 11, 2026 00:35
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