fix: match anchored WikiLinks in referencingpages example#509
Open
skirmess wants to merge 1 commit into
Open
Conversation
The referencingpages example indexed WikiLink targets verbatim, so a link with a #anchor (e.g. [[Page#section]]) or a leading slash was stored as "page#section" and never matched the anchor-less page path used for lookup. As a result such backlinks were silently missing from the sidebar. Strip the #anchor and a leading slash before normalizing the target, and skip pure in-page anchor links like [[#section]]. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
The
referencingpagesexample plugin indexes WikiLink targets verbatim. A link that carries a#anchor(e.g.[[Page#section]]) or a leading slash was stored aspage#section, which never matches the anchor-less page path used when looking up backlinks for the sidebar. The result: such backlinks are silently missing.I hit this on a real page — a referrer linking via
[[Some/Page#hello]]did not show up under "Referencing pages", while a plain[[Some/Page]]from another page did.Fix
Strip the
#anchorand a leading slash before normalizing the target, and skip pure in-page anchor links like[[#section]].Tests
Adds
tests/test_plugin_referencingpages.py, which asserts that both an anchored and a plain referrer show up as backlinks (the anchored one fails without this fix), and that a pure[[#section]]link creates no backlink. (Heads-up: the example plugins didn't have tests yet, so this introduces a small importlib-based loader for the docs/ plugin — easy to drop if you'd rather keep them test-free.)