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] Switch from Shiki Twoslash -> Astro Markdown highlighter #4292

Merged
merged 8 commits into from
Aug 15, 2022

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Aug 12, 2022

Bu-bu-but why? I like Twoslash!

We do too! Still, we've noticed a fair share of MDX + Shiki-twoslash issues being reported due to inconsistencies with Markdown. Namely:

  • 3 support threads wondering about the injected code language at the top of each code block
  • 1 issue on passing through Shiki Twoslash config via markdown.shikiConfig (which could involve breaking changes to resolve) Validation is preventing me from using shikiConfig.themes #4245
  • Inconsistencies in CSS class targeting, where MDX files generate class="shiki" while Markdown generates class="astro-code"

Due to this, we think bundling Twoslash by default has more cons than pros. We also don't feel we can migrate Markdown to Twoslash now that we've reached 1.0 stability.

Can I still use Twoslash?

Absolutely! If you like Shiki-twoslash, you can flip off our built-in highlighter and apply their remark plugin like so:

import shikiTwoslash from 'remark-shiki-twoslash';

export default {
  markdown: {
	syntaxHighlight: false,
        remarkPlugins: [shikiTwoslash], // use twoslash in .md
  },
  integrations: [mdx({
	remarkPlugins: [shikiTwoslash],  // use twoslash in .mdx
  })],

Changes

  • Replace Twoslash with Astro's existing Shiki parser
  • Always apply the rehypeRaw plugin. This makes custom syntax highlighters easier to apply, and is consistent with our Markdown defaults.

Testing

  • Update Shiki tests to correct class naming
  • Add Shiki-Twoslash test

Docs

Add "custom highlighter" section to README

@changeset-bot
Copy link

changeset-bot bot commented Aug 12, 2022

🦋 Changeset detected

Latest commit: 67669ec

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 Minor
@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 12, 2022
Copy link
Contributor

@hippotastic hippotastic left a comment

Choose a reason for hiding this comment

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

Had a test-related nit, but other than that, LGTM.

@bholmesdev bholmesdev force-pushed the feat/mdx-abandon-shiki-twoslash branch from 02c3cf3 to 67669ec Compare August 15, 2022 14:19
@bholmesdev bholmesdev merged commit f1a52c1 into main Aug 15, 2022
@bholmesdev bholmesdev deleted the feat/mdx-abandon-shiki-twoslash branch August 15, 2022 14:43
@astrobot-houston astrobot-houston mentioned this pull request Aug 15, 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.

3 participants