-
-
Notifications
You must be signed in to change notification settings - Fork 684
Prevent heading anchor links on non-Starlight content #3181
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: 9d798dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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. |
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.
LGTM, but I hate function in functions since the functions could be changed in the future, but it looks good.
Description
In Starlight
0.34.0
, support for generating clickable anchor links for headings was added. For Markdown and MDX content, a rehype plugin is used to generate the links.When the feature is not disabled, this plugin runs unconditionally, which means that these links are generated for non-Starlight content like individual Markdown page or content not from the Starlight
docs
content collection.This PR prevents this behavior by checking if the virtual file path is part of the Starlight
docs
content collection first, and bails if it is not.For testing, I relied on E2E tests as it seems that on Windows, file path separators are inconsistent when the rehype plugin is used on Markdown vs MDX files. I'll investigate and open a separate issue/PR for that on the Astro repo.
Here is a preview of the changes before and after the fix for an individual Markdown page: