Skip to content
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

Mdx/plugin unshift #4248

Merged
merged 3 commits into from
Aug 10, 2022
Merged

Mdx/plugin unshift #4248

merged 3 commits into from
Aug 10, 2022

Conversation

svemat01
Copy link
Contributor

Changes

  • What does this change?
  • Be short and concise. Bullet points can help!
  • Before/after screenshots can help as well.
  • Don't forget a changeset! pnpm exec changeset

Put built in rehype plugins before user added.

Testing

No thorough testing was done due to the complexity of testing every major rehype plugin. Changing the load order should have minimal to no effect on usage.

Docs

No visible change. No documentation mentioned builtin plugins being loaded last.

Why

Specifically the rehypeCollectHeadings impacted one of my rehype plugins.

rehypeAutolinkHeadings requires ids to be added to headings for it to work, with pre this pr configuration, these ids were added after my plugin being ran.

Context in discord thread

@bholmesdev

@changeset-bot
Copy link

changeset-bot bot commented Aug 10, 2022

🦋 Changeset detected

Latest commit: fa02b69

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

This PR includes changesets to release 5 packages
Name Type
@astrojs/mdx Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch

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

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Aug 10, 2022
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the quick work on this 👍

@bholmesdev bholmesdev merged commit 869d009 into withastro:main Aug 10, 2022
@astrobot-houston astrobot-houston mentioned this pull request Aug 10, 2022
@@ -62,10 +62,10 @@ function getRehypePlugins(
let rehypePlugins = handleExtends(mdxOptions.rehypePlugins, DEFAULT_REHYPE_PLUGINS);

if (config.markdown.syntaxHighlight === 'shiki' || config.markdown.syntaxHighlight === 'prism') {
rehypePlugins.push([rehypeRaw, { passThrough: nodeTypes }]);
rehypePlugins.unshift([rehypeRaw, { passThrough: nodeTypes }]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if there is a slightly better way of doing this, Im never a fan of unshift()

[ [rehypeRaw, { passThrough: nodeTypes}] , ...rehypePlugins ]

I feel this returning a new array would be easier, and a more performant solution

https://stackoverflow.com/a/67732664

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, It's probably a better alternative. Array#unshift was just the first thing that came to mind when I thought about this issue.

Copy link
Contributor

@aFuzzyBear aFuzzyBear left a comment

Choose a reason for hiding this comment

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

just a thought about unshifting to a new array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants