Skip to content

Resolve RST anonymous heading refs against the current page first#1329

Closed
lacatoire wants to merge 1 commit into
phpDocumentor:mainfrom
lacatoire:fix/internal-anchors-prefer-current-doc
Closed

Resolve RST anonymous heading refs against the current page first#1329
lacatoire wants to merge 1 commit into
phpDocumentor:mainfrom
lacatoire:fix/internal-anchors-prefer-current-doc

Conversation

@lacatoire

Copy link
Copy Markdown
Contributor

RST anonymous references (\`Heading 1\`_) resolved to a same-named heading on another page because the project-wide anchor index silently overwrites std:title entries on duplicate keys. Stores link targets in a document-scoped index alongside the global one; AnchorHyperlinkResolver now consults the current page before falling back to the global match.

Fixes phpDocumentor/phpDocumentor#3781

`Heading 1`_ on page2 was rendering `<a href="page1.html#heading-1">`
whenever page1 happened to carry an identically named section: the
project-wide anchor index silently overwrites `std:title` entries on
duplicate keys, so the lookup returned whichever document registered
last. Store link targets in a document-scoped index alongside the
global one and let AnchorHyperlinkResolver consult the current page
before falling back to the global match, so same-named sections on
other pages no longer shadow the local one.
@lacatoire lacatoire force-pushed the fix/internal-anchors-prefer-current-doc branch from 4834ef0 to 1c689f0 Compare April 13, 2026 07:29
@jaapio

jaapio commented Apr 13, 2026

Copy link
Copy Markdown
Member

Thanks for helping out, I decided to solve this in a different way, but I did add the missing tests to the test suite.

@jaapio jaapio closed this Apr 13, 2026
@lacatoire lacatoire deleted the fix/internal-anchors-prefer-current-doc branch April 14, 2026 07:26
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.

Internal links point to external files

2 participants