Skip to content

fix: match anchored WikiLinks in referencingpages example#509

Open
skirmess wants to merge 1 commit into
redimp:mainfrom
skirmess:fix-referencingpages-anchor
Open

fix: match anchored WikiLinks in referencingpages example#509
skirmess wants to merge 1 commit into
redimp:mainfrom
skirmess:fix-referencingpages-anchor

Conversation

@skirmess

Copy link
Copy Markdown

The referencingpages example plugin indexes WikiLink targets verbatim. A link that carries a #anchor (e.g. [[Page#section]]) or a leading slash was stored as page#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 #anchor and 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.)

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>
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