Skip to content

fix: register anchor collector at priority -1 to catch extension-generated anchors - #4161

Open
Mubashir78 wants to merge 1 commit into
mkdocs:masterfrom
Mubashir78:fix/anchor-validation-tabbed-extension
Open

Mubashir78 wants to merge 1 commit into
mkdocs:masterfrom
Mubashir78:fix/anchor-validation-tabbed-extension

Conversation

@Mubashir78

Copy link
Copy Markdown

Fix #3690

Problem

The _ExtractAnchorsTreeprocessor is registered at priority 5, but PyMdown Tabbed's TabbedTreeprocessor runs at priority 4. Since Python-Markdown's Registry sorts by priority descending, priority 5 runs before priority 4, causing the anchor collector to miss slugified tab IDs generated by the Tabbed extension.

When Tabbed is configured with a slugify function, readable IDs like my-tab-title or headline-tab-a (with combine_header_slug) are added to <input> elements during the treeprocessor phase -- after the anchor collector has already scanned the tree.

Any link like [see instructions](page.md#my-tab-title) then produces a false-positive anchor validation warning, even though the anchor exists in the final HTML.

Fix

Changed the registration priority of _ExtractAnchorsTreeprocessor from 5 to -1, ensuring it runs after all other treeprocessors (including TabbedTreeprocessor at priority 4 and _RelativePathTreeprocessor at priority 0) so it captures all dynamically generated anchors.

Verification

  • All 130 structure tests pass
  • All anchor-related build tests pass (test_anchor_no_warning, test_anchor_warning, etc.)
  • Manual test with pymdownx.tabbed confirms tab-a, tab-b, and headline-tab-a/headline-tab-b (with combine_header_slug) are all correctly collected

This branch has not been deployed

No deployments
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.

Anchor validation false positives after upgrading to 1.6

1 participant