feat: add linkable heading anchors to PSF pages#2966
Open
nagasrisai wants to merge 4 commits intopython:mainfrom
Open
feat: add linkable heading anchors to PSF pages#2966nagasrisai wants to merge 4 commits intopython:mainfrom
nagasrisai wants to merge 4 commits intopython:mainfrom
Conversation
Adds a custom template filter that post-processes rendered page HTML to inject id attributes and pilcrow self-link anchors into h2-h4 headings. Duplicate slugs get a -N suffix to prevent id collisions. Headings that already carry an id are left untouched. Part of python#2349
Loads the new page_tags library and pipes page content through the add_heading_anchors filter so that every h2-h4 in a PSF page (including the board resolutions listing) gets a stable id attribute and a pilcrow anchor link for direct linking. Part of python#2349
10 test cases covering: h2/h3/h4 processing, h1/h5 exclusion, duplicate-slug deduplication, existing-id passthrough, nested HTML stripping, non-heading passthrough, empty string, empty text, and anchor placement inside the heading element.
Author
|
@JacobCoffee @ewdurbin @sethmlarson — could one of you review when you get a chance? This adds anchor IDs to headings on PSF pages so sections like the board resolutions can be linked to directly. 10 tests included. Thanks! |
Author
|
The Actions workflows need maintainer approval to run since this is coming from a fork. Could @JacobCoffee or @ewdurbin approve the CI, Lint, and Check collectstatic runs from the Checks tab when you get a chance? Thanks! |
Member
|
@nagasrisai hi please dont @ specific people, CODEOWNERS will handle assignment for review |
hugovk
reviewed
Mar 19, 2026
|
|
||
| register = template.Library() | ||
|
|
||
| # Match h2–h4 elements; capture tag name, existing attributes, and inner HTML. |
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.
Adds linkable anchor IDs to headings on PSF pages so that individual sections can be shared as direct URLs, which is what #2349 is asking for.
Added a
add_heading_anchorstemplate filter inapps/pages/templatetags/page_tags.py. It processes the rendered page HTML and injects anidattribute into each h2, h3, and h4 element based on the slugified heading text, along with a small pilcrow (¶) anchor link. Applied the filter intemplates/psf/default.htmlso it covers the board resolutions page and all other PSF pages automatically.Duplicate heading texts get a
-2,-3suffix to keep IDs unique, and headings that already carry anidare left untouched. Ten tests included inapps/pages/tests/test_templatetags.py.Closes #2349