-
-
Notifications
You must be signed in to change notification settings - Fork 245
feat: add clickable anchor links to readme headings #1417
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
base: main
Are you sure you want to change the base?
feat: add clickable anchor links to readme headings #1417
Conversation
essenmitsosse
commented
Feb 12, 2026
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughAdds CSS to render and reveal an internal hash-link indicator for README headings and preserves existing external-link styling. On the server, headings are now rendered wrapped in anchor links pointing to a generated slug (IDs remain prefixed with Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
|
There is a still a bug for certain headings, that were luckily caught by lighthouse. I am on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/utils/readme.ts (1)
375-381:⚠️ Potential issue | 🟠 MajorPreserve inline heading markup in anchor text.
Line 381 uses
plainTextfor the anchor body, which strips inline formatting (e.g., emphasis, code spans, inline links) from headings. Use the already-renderedtextfor the anchor contents and keepplainTextonly for TOC text and slug safety.Proposed fix
- return `<h${semanticLevel} id="${id}" data-level="${depth}"><a href="#${uniqueSlug}">${plainText}</a></h${semanticLevel}>\n` + return `<h${semanticLevel} id="${id}" data-level="${depth}"><a href="#${uniqueSlug}">${text}</a></h${semanticLevel}>\n`
|
Just marking as draft as it's not ready yet and a couple of us are going down the list to see what we can review! |
|
@whitep4nth3r it is ready now. |
|
Couple of things. I tested on mobile.
trim.DB6685A2-F41D-4DD3-AD40-6D5367FE0082.MOV |
we probably need to add scroll margin if you haven't already |
|
honestly I thought this had already been done (including scroll-margin!) - maybe it was somehow reverted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of thoughts:
- Should the link icon be always visible on mobile? It’s not totally clear that there are links there.
- It is possible for a README to already have a link in a heading (e.g.
## A [link](https://example.com) in a heading) which means there could be nested links. So, that could be a reason to avoid making the entire heading clickable, though I do like the idea of doing something to increase the touch target size.
|
|
Ok. Let's not copy npmsjs. This is completely broken: https://www.npmjs.com/package/nuxt#local-development |
|
@whitep4nth3r I created an issue #1428 for the scroll margin problem because that also affects other things (like toc) and I have no idea why it is not working. |
|
I think GitHub does it fine: Anchor is before the heading, always visible on mobile and if the heading has a link only the anchor is clickable. Good example: https://github.com/facebook/react |
|
In #1417 (comment), @essenmitsosse said,
In the React GitHub example, the full heading is never clickable though. Visually, it’d be fine to put the anchor before, but for assistive tech discoverability (e.g. navigating by heading), it would be good to place it after in the DOM (GitHub also does this). This is an exception to the DOM order matches visual order rule. In #1417 (comment), @essenmitsosse said,
Nuxt README is using an old school technique. I’m less worried for the It could be ok if we strip out the |
|
I honestly struggle to find any package that has links in their readme heading. Would it be too farfetched to assume that is not a feature we need to support or should we support it just because it is possible? If we ingore this case, I think the anchor after the heading is fine. It also makes it less tricky to place it on mobile without having to much spacing or indenting the headings. In which case I would assume the current version is good enough for now? |