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] Support remark-rehype options from Astro Markdown config #5427

Merged
merged 6 commits into from
Nov 22, 2022

Conversation

backflip
Copy link
Contributor

Changes

Testing

See #4138 and test/fixtures/mdx-astro-markdown-remarkRehype/src/pages/index.mdx

Docs

/cc @withastro/maintainers-docs for feedback!

@changeset-bot
Copy link

changeset-bot bot commented Nov 17, 2022

🦋 Changeset detected

Latest commit: 4151592

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

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 Nov 17, 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.

Left a note on adding remarkRehype to the MDX config. Great PR though, with tests to boot 🙌

@@ -71,6 +71,7 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
// Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
format: 'mdx',
mdExtensions: [],
remarkRehypeOptions: config.markdown.remarkRehype,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm noticing this applies remarkRehype in all cases. To stay consistent with remark and rehype plugin configs, we should only apply this when mdxOptions.extendPlugins === 'markdown'. I'd add a check for that here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably add remarkRehype to the MdxOptions as well, in keeping with how we mirror the markdown config for the MDX integration. A couple changes for this:

  • Add remarkRehype to the MdxOptions type
  • Spread mdxOptions.remarkRehype with config.markdown.remarkRehype, checking that extendPlugins option I noted above
  • Add remarkRehype to the MDX README. Feel free to link to our existing remarkRehype docs for simplicity.

A bit complex I know, and we will simplify these APIs in the future! Just want to make sure we stay consistent with extending Markdown configs into MDX.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bholmesdev, thanks for the feedback! See latest commits for an attempt to take care of this.

Three things I'm unsure of:

  • Is remarkRehype of type RemarkRehype or RemarkRehypeOptions? I would assume the latter, but the markdown options assume the former.
  • Should mdxOptions.remarkRehype be extended with config.markdown.remarkRehype or the other way round?
  • Is the README helpful enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good questions!

  1. I'd go with whatever the markdown options assume. If the types don't line up with the MDX config, try RemarkRehypeOptions!
  2. I think you would spread config.markdown.remarkRehype first, mdxOptions.remarkRehype second. So MDX options override Markdown options if there's conflicts
  3. With Sarah's suggestion, you're golden I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bholmesdev, sounds good!

  1. After finding https://github.com/mdx-js/mdx/blob/aff6de4fad5955b804d51cd109248425d786fb1c/packages/mdx/lib/core.js#L7 I have kept RemarkRehypeOptions.
  2. Fixed and additional tests added.
  3. Fixed. Thanks a lot, @sarah11918!

@backflip backflip requested a review from a team as a code owner November 17, 2022 23:29
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.

These changes look great! Thanks so much 👍
Also looks like the automated test failures are unrelated. I'll try rerunning, or just merge if we feel confident enough.

@matthewp matthewp merged commit 2a1c085 into withastro:main Nov 22, 2022
@astrobot-houston astrobot-houston mentioned this pull request Nov 22, 2022
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.

4 participants