-
-
Notifications
You must be signed in to change notification settings - Fork 836
Add built-in heading anchor link support #3033
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
Conversation
🦋 Changeset detectedLatest commit: 9af5fae The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
size-limit report 📦
|
Co-authored-by: HiDeoo <[email protected]>
|
@delucis thanks for your work, and will it be possible to change the icon to another one, for example this one # |
…tion ourselves `rehype-autolink-headings` handles a lot of options and variants we have no need for, so this should be a bit more performant by avoiding a bunch of unnecessary logic and also avoids pulling in several extra dependencies.
Probably not in this initial version. I will wait for #3024 first as that will make supporting configurable icons much easier. |
The Astro docs already uses the “Section titled…” accessible label format and this commit brings across those where I was confident I could get the quotation style right.
Ah yeah, I think it should behave the same (fortunately so, as I’m not sure how to do it if they shouldn’t 😅). Not documented currently (maybe it should be?), but anchor links by definition are only added to headings that have an |
|
Got a failing size limit check when updating branch. Looks like the Expressive Code update in #3109 bumped CSS size by ~600 bytes taking the additions in this PR over the edge, so I bumped our budget up by 250 bytes. |
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.
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.
I would not think so. The import 'virtual:starlight/optional-css'; import in Page.astro should still be near the end after import '../style/util.css'; so no change required here.
Altho, we should definitely confirm that before merging the last one of the two.
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.
Just tested locally merging this branch into #2322 for sanity and indeed, I only had to wrap the styles in the starlight.content layer, couldn't spot any issue.
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.
Awesome, thank you for testing! Pushed that change up so it’s ready to merge.
|
Merged in the cascade layer changes and tested the deploy preview and all looking good 👍 |
* main: [ci] release (withastro#3124) Fix E2E tests broken by formatter [ci] format Add built-in heading anchor link support (withastro#3033) i18n(fr): update `environmental-impact` (withastro#3123) Cascade Layers (withastro#2322) Fix image metadata validation in StarlightPage schema (withastro#3118) Don’t set defaults for `attrs` and `content` in head entries (withastro#3122) [ci] format i18n(es) Translate `route-data` (withastro#3071)
Co-authored-by: HiDeoo <[email protected]>

Description
Where does this apply?
rehypeplugins. This can be disabled withmarkdown: { headingLinks: false }in Starlight config.headingnode. This can be disabled by passing{ headingLinks: false }to the Starlight Markdoc preset.<AnchorHeading>component.The anchor link approach
The HTML mark-up approach the anchor links follow is based on Amber Wilson’s Are your Anchor Links Accessible? blog post. (Thank you for sharing your research, Amber!)
The output looks a little like this:
<a>link is placed after the heading element rather than inside it or even wrapping it as some sites do. This ensures that the heading doesn’t contain any additional text (for screenreaders listing headings for example) and also avoids the potentially confusing situation of a link which links to itself.<div>so that we can position the icon link inline at the end of the heading as desired.anchor-links.cssin this PR.To-do
rehypeSlugand use Astro’s built-in heading slugger instead.