Skip to content

feat: add linkable heading anchors to PSF pages#2966

Open
nagasrisai wants to merge 5 commits intopython:mainfrom
nagasrisai:feature/issue-2349-heading-anchors-for-psf-pages
Open

feat: add linkable heading anchors to PSF pages#2966
nagasrisai wants to merge 5 commits intopython:mainfrom
nagasrisai:feature/issue-2349-heading-anchors-for-psf-pages

Conversation

@nagasrisai
Copy link

@nagasrisai nagasrisai commented Mar 18, 2026

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_anchors template filter in apps/pages/templatetags/page_tags.py. It processes the rendered page HTML and injects an id attribute into each h2, h3, and h4 element based on the slugified heading text, along with a small pilcrow (¶) anchor link. Applied the filter in templates/psf/default.html so it covers the board resolutions page and all other PSF pages automatically.

Duplicate heading texts get a -2, -3 suffix to keep IDs unique, and headings that already carry an id are left untouched. Ten tests included in apps/pages/tests/test_templatetags.py.

Closes #2349

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.
@nagasrisai
Copy link
Author

nagasrisai commented Mar 18, 2026

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

@nagasrisai
Copy link
Author

nagasrisai commented Mar 18, 2026

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!

@JacobCoffee
Copy link
Member

@nagasrisai hi please dont @ specific people, CODEOWNERS will handle assignment for review


register = template.Library()

# Match h2–h4 elements; capture tag name, existing attributes, and inner HTML.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip H1?

Copy link
Author

@nagasrisai nagasrisai Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk h1 is the page title ,there's only ever one per page and the page URL already points to it, so an anchor on it wouldn't be useful. The sections people actually want to link into are h2 and below (e.g. individual board resolutions or meeting minutes). This is also the convention most docs sites follow, including GitHub's own markdown renderer.

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.

Enhancement: Add page anchor tags for easy sharing of PSF Board resolutions

3 participants