Skip to content

gh-83156: Add dedicated anchor for regexp syntax elements - #17470

Merged
ambv merged 7 commits into
python:mainfrom
bmispelon:regex-syntax-anchors
Oct 23, 2026
Merged

ambv merged 7 commits into
python:mainfrom
bmispelon:regex-syntax-anchors

Conversation

@bmispelon

@bmispelon bmispelon commented Dec 4, 2019 •

Copy link
Copy Markdown
Contributor

@the-knights-who-say-ni

This comment was marked as resolved.

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rebased this and build the docs:

cd Doc
make clean venv html

And it does add anchors like syntax-dollar which you can visit by going to re.html#syntax-dollar:

image

But there's no hyperlink to click on and it's not obvious unless you know they exist or inspect the source. Should they be made more obvious?

@JelleZijlstra

Copy link
Copy Markdown
Member

Thanks for your PR, and sorry it has been open for so long!

I think these anchors are useful, but agree with @hugovk that it's hard to discover them with no available to click on. Is it possible to add that?

@bmispelon

Copy link
Copy Markdown
Contributor Author

Is it possible to add that?

Thanks for getting back to the PR eventually. I will look into how to add the pillcrow to the links.

@bmispelon

Copy link
Copy Markdown
Contributor Author

I added a new commit that turns all the headings into <h3> which automatically gives them a nice ¶ on hover.

It does change the look of the page a little bit but I don't think it's for the worse personally. Here's the before/after on my machine:

Before:
Screenshot 2022-05-11 at 20-48-53 re — Regular expression operations — Python 3 12 0a0 documentation

After:
Screenshot 2022-05-11 at 20-47-44 re — Regular expression operations — Python 3 12 0a0 documentation

I also took the opportunity to add an ..index reference to the new (?>...) syntax which seemed to be missing, I hope that's ok.

@hugovk

hugovk commented May 11, 2022

Copy link
Copy Markdown
Member

Also a long list in the menu on the left.

Before:

image

After:

image

@AlexWaygood AlexWaygood changed the title bpo-38975: Add dedicated anchor for regexp syntax elements gh-83156: Add dedicated anchor for regexp syntax elements Oct 30, 2022
@CAM-Gerlach

Copy link
Copy Markdown
Member

Adding :name: s to the index directives will generate a stable cross-reference target label that can be referenced internally or via Intersphinx with the :ref: role, as well as externally by copying the URL in the index, or manually grabbing the id of the anchor span inspecting the HTML. This means that anyone referencing this in Sphinx documentation, or with a bit of HTML-fu, can reference each term, and they will also be searchable with Sphinx 5.2.0+ due to sphinx-doc/sphinx#10819 .

However, if we do want easily-clickable and copyable external links with the fragment id in the rendered document, section headings would need to be added. I'm not sure a way around them also being in the ToC without hacks or pushing them down 2+ heading levels, but maybe @AA-Turner knows a way? This hopefully won't be an issue in the future, though, as if we adopt a Sphinx theme like Lutra that separates the inter- and intra-document ToC into left and right sidebars, and for which we can limit the ToC depth of the latter to 2, we could avoid displaying them by only adding one layer of higher level sections (which seems quite appropriate to the current document content) and limiting page ToCs to displaying only up to h3 heading levels.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
@hugovk

hugovk commented Oct 21, 2026

Copy link
Copy Markdown
Member

It's been a while!

OK, let's do this:

  • Apply :tocdepth: 3 at the top of the file
  • Add a h3 "Special characters" just above "The special characters are:"
  • Add a h3 "Special sequences" just above "The special sequences consist of..."
  • Demote term headings (like .) to h4

This way the terms can be linked, we get pilcrow hovers, and the sidebar isn't too busy.

@bmispelon Would you like to bring this up-to-date and do this? Or shall I?

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Oct 22, 2026
ambv added 2 commits October 23, 2026 23:08
Co-authored-by: Muse Code (Meta Muse Spark)
Apply :tocdepth: 3, add "Special characters" and "Special sequences" h3 sections, and demote the syntax term headings to h4. This keeps pilcrow permalinks for every term while keeping the sidebar compact.

Co-authored-by: Muse Code (Meta Muse Spark)
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 23, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35366895 | 📁 Comparing b9d9e8b against main (2507a7f)

  🔍 Preview build  

2 files changed
± library/re.html
± whatsnew/changelog.html

Comment thread Doc/library/re.rst Outdated
Co-authored-by: Hugo van Kemenade <[email protected]>
@ambv
ambv merged commit 321925c into python:main Oct 23, 2026
33 of 34 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Oct 23, 2026
@hugovk hugovk added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @bmispelon for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @bmispelon for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @bmispelon and @ambv, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 321925c92c9e67864cafa1566840927f6f07e90a 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @bmispelon and @ambv, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 321925c92c9e67864cafa1566840927f6f07e90a 3.15

@bedevere-app

bedevere-app Bot commented Oct 24, 2026

Copy link
Copy Markdown

GH-160606 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 24, 2026
@bedevere-app

bedevere-app Bot commented Oct 24, 2026

Copy link
Copy Markdown

GH-160607 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news topic-regex type-feature A feature request or enhancement

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

10 participants