-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b379650
WIP
delucis 02a325b
Add `markdown.headingLinks` flag to disable the feature
delucis 271b916
Add virtual module for optional CSS like anchor link styles
delucis 29e01ab
Add anchor link styles
delucis 368bc29
Fix anchor link label replacement
delucis 43b3a8e
Remove `is:raw` attribute
delucis 25c420d
Delete leftover example markup
delucis f34c491
Fix double escaping of accessible anchor labels
delucis f4f2f8a
Add `AnchorHeading` component
delucis a633ab4
Add anchor heading support to Markdoc preset
delucis 445c6d7
More config reference detail
delucis 4d75b05
Use Astro’s built-in heading slugger instead of `rehype-slug`
delucis 2c60647
Update config snapshot test
delucis 9ee3508
Fix dependency
delucis f4fc43d
Actually pass Astro config to headings plugin
delucis 04f0cd1
Add French translation of accessible anchor label UI string
delucis 28ff839
Add basic tests
delucis 6f7347c
Remove superfluous `tabindex="-1"` in anchor link wrapper
delucis 36d9b82
Remove unnecessary change
delucis 2183885
Remove `rehype-autolink-headings` in favour of doing all the manipula…
delucis 6763bbf
Bring across a few more translations from the Astro docs
delucis 9b387f0
Move where “required” is specified in the AnchorHeading docs
delucis 0757ea3
Add simple examples for `StarlightPage` and `AnchorHeading`
delucis c17af3c
Also move “required” in `frontmatter` prop heading
delucis 7c8475b
Don’t infer `HeadingLevel` type
delucis 7a72829
Ensure `<AnchorHeading>` output matches rehype output
delucis 693809b
Merge branch 'main' into chris/anchor-headings
delucis b53da1f
Merge anchor heading and tabs tests into single file
delucis 25fb28a
Small component refactor for readability
delucis e668881
Bump Starlight peer dependency version in Markdoc package
delucis 9709134
Bump Astro peer dependency in Starlight package
delucis bbf898a
Add changesets
delucis 5af8110
fix capitalisation
delucis a13aa9d
Merge branch 'main' into chris/anchor-headings
delucis 9210441
Increase CSS size limit by 250 bytes
delucis 85c9eed
Wrap anchor link CSS in `@layer starlight.content`
delucis 9af5fae
Merge branch 'main' into chris/anchor-headings
delucis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| '@astrojs/starlight': minor | ||
| --- | ||
|
|
||
| Adds support for generating clickable anchor links for headings. | ||
|
|
||
| By default, Starlight now renders an anchor link beside headings in Markdown and MDX content. A new `<AnchorHeading>` component is available to achieve the same thing in custom pages built using `<StarlightPage>`. | ||
|
|
||
| If you want to disable this new Markdown processing set the `markdown.headingLinks` option in your Starlight config to `false`: | ||
|
|
||
| ```js | ||
| starlight({ | ||
| title: 'My docs', | ||
| markdown: { | ||
| headingLinks: false, | ||
| }, | ||
| }), | ||
| ``` | ||
|
|
||
| ⚠️ **BREAKING CHANGE:** The minimum supported version of Astro is now v5.5.0. | ||
|
|
||
| Please update Starlight and Astro together: | ||
|
|
||
| ```sh | ||
| npx @astrojs/upgrade | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| '@astrojs/starlight-markdoc': minor | ||
| --- | ||
|
|
||
| Adds support for generating clickable anchor links for headings. | ||
|
|
||
| By default, the Starlight Markdoc preset now includes a default `heading` node, which renders an anchor link beside headings in your Markdoc content. | ||
|
|
||
| If you want to disable this new feature, pass `headingLinks: false` in your Markdoc config: | ||
|
|
||
| ```js | ||
| export default defineMarkdocConfig({ | ||
| // Disable the default heading anchor link support | ||
| extends: [starlightMarkdoc({ headingLinks: false })], | ||
| }); | ||
| ``` | ||
|
|
||
| ⚠️ **BREAKING CHANGE:** The minimum supported peer version of Starlight is now v0.34.0. | ||
|
|
||
| Please update Starlight and the Starlight Markdoc preset together: | ||
|
|
||
| ```sh | ||
| npx @astrojs/upgrade | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export { default as Code } from './Code.astro'; | ||
| export { default as Heading } from '@astrojs/starlight/components/AnchorHeading.astro'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...starlight/__e2e__/fixtures/basics/src/content/docs/anchor-heading-component.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| title: Anchor Headings Component | ||
| --- | ||
|
|
||
| import AnchorHeading from '@astrojs/starlight/components/AnchorHeading.astro'; | ||
|
|
||
| <AnchorHeading level="2" id="an-anchor-heading">An anchor heading</AnchorHeading> | ||
|
|
||
| <AnchorHeading level="3" id="another-anchor-heading">Another anchor heading</AnchorHeading> |
7 changes: 7 additions & 0 deletions
7
packages/starlight/__e2e__/fixtures/basics/src/content/docs/anchor-heading.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| title: Anchor Headings | ||
| --- | ||
|
|
||
| ## An anchor heading | ||
|
|
||
| ### Another anchor heading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.