fix: resolve cross-page fragment links in markdown - #1300
Conversation
Markdown links with both a page reference and a fragment anchor like `[text](page-b.md#section-two)` failed to resolve, producing a warning: "Reference page-b.md#section-two could not be resolved". Two independent bugs caused this: 1. `LinkParser` checked `str_ends_with($url, '.md')` on the full URL including the fragment, so `page-b.md#section-two` did not match and the `.md` extension was never stripped. Fix: split the fragment off before the `.md` check, then reattach it afterward. 2. `PageHyperlinkResolver` passed the full target reference (including `#fragment`) to `findDocumentEntry()`, which always returned `null` since no document is keyed with a fragment suffix. Fix: split the fragment before the document lookup and append it to the generated URL, matching the pattern already used by `DocReferenceResolver`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I verified this against the latest upstream The PHP SDK links from
On current I also reproduced the old PHP 8.5 / lowest-dependencies failure on the original PR head. It was unrelated to this fix: PHPUnit exited non-zero on 100 dependency deprecations from the lowest Symfony and Because I cannot push directly to the contributor branch, I opened a clean, mergeable refresh PR here: jonathanhefner#2 @jonathanhefner, could you merge that refresh PR into this branch? Once it lands, this PR will be current with upstream and ready for a fresh CI run. Maintainers, a review after that refresh would help unblock the PHP SDK documentation links affected by this bug. |
Markdown links with both a page reference and a fragment anchor like
[text](page-b.md#section-two)failed to resolve, producing a warning: "Reference page-b.md#section-two could not be resolved".Two independent bugs caused this:
LinkParsercheckedstr_ends_with($url, '.md')on the full URL including the fragment, sopage-b.md#section-twodid not match and the.mdextension was never stripped. Fix: split the fragment off before the.mdcheck, then reattach it afterward.PageHyperlinkResolverpassed the full target reference (including#fragment) tofindDocumentEntry(), which always returnednullsince no document is keyed with a fragment suffix. Fix: split the fragment before the document lookup and append it to the generated URL, matching the pattern already used byDocReferenceResolver.