Skip to content

Commit

Permalink
[MDX] Syntax highlighting after user plugins (#6050)
Browse files Browse the repository at this point in the history
* fix: load MDX syntax highlighting after user plugins

* chore: changeset
  • Loading branch information
bholmesdev committed Jan 31, 2023
1 parent 474ecc7 commit 2ab32b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-carpets-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': minor
---

Fix: load syntax highlighters after MDX remark plugins. This keeps MDX consistent with Astro's markdown behavior.
15 changes: 9 additions & 6 deletions packages/integrations/mdx/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,7 @@ export async function getRemarkPlugins(
config: AstroConfig
): Promise<MdxRollupPluginOptions['remarkPlugins']> {
let remarkPlugins: PluggableList = [];
if (mdxOptions.syntaxHighlight === 'shiki') {
remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
}
if (mdxOptions.syntaxHighlight === 'prism') {
remarkPlugins.push(remarkPrism);
}

if (mdxOptions.gfm) {
remarkPlugins.push(remarkGfm);
}
Expand All @@ -144,6 +139,14 @@ export async function getRemarkPlugins(

remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)];

// Apply syntax highlighters after user plugins to match `markdown/remark` behavior
if (mdxOptions.syntaxHighlight === 'shiki') {
remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
}
if (mdxOptions.syntaxHighlight === 'prism') {
remarkPlugins.push(remarkPrism);
}

// Apply last in case user plugins resolve relative image paths
remarkPlugins.push(toRemarkContentRelImageError(config));

Expand Down

0 comments on commit 2ab32b5

Please sign in to comment.