Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators/HTML: improve anchor links #859

Merged
merged 3 commits into from
Mar 10, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 7, 2025

Description

Generators/HTML: move section link creation to own function

Move the creation of in-page anchor link text to a separate function as this was done in two separate places.
The separate function will make it more straight-forward to safeguard that the anchors and the links to these anchors stay in sync.

Generators/HTML: improve anchor links

As things were, the TOC would link to the section headers, but there was no straight-forward way to copy the link to a particular section once a user was viewing the section.

This small change adds an invisible § character after each section title, which becomes visible when the user hovers over the title and allows for copying the permalink to that section.

Includes updated test expectations.

🆕 Generators/HTML: slugify anchor links

... to prevent issues with URL encoding.

Note: as this may result in duplicate anchor links, this commit includes a protection against this by adding a numeric suffix to the anchor if a duplicate is detected.

Includes a test with a variety of non-ascii chars and duplicate titles.
Includes updated test expectations for various other tests.

Screenshot

10-anchor-hover-link

Suggested changelog entry

Generators/HTML: each section title now has a proper and unique anchor link, allowing for copying the link to a specific section of the documentation.

Related issues/external references

This PR is part of a series of PRs which will add a complete set of tests (and improvements) for the Generator feature.

Also see: #671 and other PRs with the Core Component: Generators label.

@jrfnl
Copy link
Member Author

jrfnl commented Mar 7, 2025

Rebased without changes - branch protection requirement have changed.

@jrfnl jrfnl force-pushed the feature/generators-improve-anchor-links branch from 226875a to c7bb306 Compare March 7, 2025 00:44
@jrfnl jrfnl force-pushed the feature/generators-improve-anchor-links branch 2 times, most recently from 10b2d4e to b2fba89 Compare March 8, 2025 00:59
@jrfnl jrfnl requested a review from fredden March 9, 2025 20:45
@jrfnl
Copy link
Member Author

jrfnl commented Mar 10, 2025

Thanks @fredden for reviewing this one again. I've fixed up both your remarks (locally) and will put them in the correct "originating" commit and rebase the PR (without any other changes but those mentioned above) before merging.

jrfnl added 3 commits March 10, 2025 22:53
Move the creation of in-page anchor link text to a separate function as this was done in two separate places.
The separate function will make it more straight-forward to safeguard that the anchors and the links to these anchors stay in sync.
As things were, the TOC would link to the section headers, but there was no straight-forward way to copy the link to a particular section once a user was viewing the section.

This small change adds an invisible `§` character after each section title, which becomes visible when the user hovers over the title and allows for copying the permalink to that section.

Includes updated test expectations.
... to prevent issues with URL encoding.

Note: as this _may_ result in duplicate anchor links, this commit includes a protection against this by adding a numeric suffix to the anchor if a duplicate is detected.

Includes a test with a variety of non-ascii chars and duplicate titles.
Includes updated test expectations for various other tests.
@jrfnl jrfnl force-pushed the feature/generators-improve-anchor-links branch from b2fba89 to 462ff5f Compare March 10, 2025 21:55
@jrfnl jrfnl merged commit 08a864f into master Mar 10, 2025
59 checks passed
@jrfnl jrfnl deleted the feature/generators-improve-anchor-links branch March 10, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants