Skip to content

Restrict remark/rehype plugins usage#3274

Merged
delucis merged 8 commits intowithastro:mainfrom
HiDeoo:hd-remark-rehype-safeguards
Jul 16, 2025
Merged

Restrict remark/rehype plugins usage#3274
delucis merged 8 commits intowithastro:mainfrom
HiDeoo:hd-remark-rehype-safeguards

Conversation

@HiDeoo
Copy link
Copy Markdown
Member

@HiDeoo HiDeoo commented Jul 3, 2025

Description

This PR builds on top of #3241 where I cherry-picked and co-auhored the initial fix preventing errors when using the Astro renderMarkdown() content loader API.

This PR also:

  • Refactor such fix to make it easier to check if we should transform a file or not using remark and rehype plugins.
  • Apply such check to other Starlight remark and rehype plugins like Prevent heading anchor links on non-Starlight content #3181 initially did for heading anchor links, e.g. at the moment, Starlight asides are rendered in non-Starlight pages.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 3, 2025

🦋 Changeset detected

Latest commit: e06cd2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Minor

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

@netlify
Copy link
Copy Markdown

netlify bot commented Jul 3, 2025

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit e06cd2f
🔍 Latest deploy log https://app.netlify.com/projects/astro-starlight/deploys/6867e94d68a7bb0008ea1670
😎 Deploy Preview https://deploy-preview-3274--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Jul 3, 2025
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HiDeoo! Left a query. Would it be possible to split this into just the renderMarkdown() fix for now and a separate PR for the bigger changes to where our plugins run?


Previously, some of Starlight’s remark and rehype plugins, most notably the plugin transforming Starlight's custom Markdown syntax for [rendering asides](https://starlight.astro.build/guides/authoring-content/#asides), were applied to all Markdown and MDX content. This included content from [individual Markdown pages](https://docs.astro.build/en/guides/markdown-content/#individual-markdown-pages) and content from [content collections](https://docs.astro.build/en/guides/content-collections/) other than the `docs` collection used by Starlight.

This change restricts the application of Starlight’s remark and rehype plugins to only Markdown and MDX content loaded using Starlight's [`docsLoader()`](https://starlight.astro.build/reference/configuration/#docsloader). While never intended, if you were relying on this behavior, please let us know in the dedicated `#starlight` channel in the [Astro Discord](https://astro.build/chat/) or by [opening an issue](https://github.com/withastro/starlight/issues/new?template=---01-bug-report.yml).
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docsLoader() link reference the new section added in #3272.

@delucis delucis added the 🌟 minor Change that triggers a minor release label Jul 4, 2025
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great — thank you @HiDeoo!

One thought seeing this is whether a future refactor might be to move our Markdown plugins into some kind of “parent” plugin perhaps that can manage running checks like the file path one for all plugins. That would avoid running the checks three times per each file and avoid needing to remember to duplicate the check when adding something new.

@delucis delucis added the ✅ approved Pull requests that have been approved and are ready to merge when next cutting a release label Jul 4, 2025
@delucis delucis added this to the v0.35 milestone Jul 4, 2025
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@delucis delucis merged commit 80ccff7 into withastro:main Jul 16, 2025
15 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jul 16, 2025
HiDeoo added a commit to shubham-padia/starlight that referenced this pull request Jul 16, 2025
* main:
  Exclude banner content from Pagefind indexing (withastro#3276)
  Restrict remark/rehype plugins usage (withastro#3274)
  [ci] release (withastro#3307)
  Fix Astro i18n default locale regression (withastro#3306)
  i18n(de): translate `plugins.mdx` and `community-content.mdx` (withastro#3304)
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
Co-authored-by: Sgal Cheung <zhangsigao@live.com>
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ approved Pull requests that have been approved and are ready to merge when next cutting a release 🌟 core Changes to Starlight’s main package 🌟 minor Change that triggers a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Astro 5.9 new API renderMarkdown

2 participants