[MDX] Syntax highlighting after user plugins (#6050)

* fix: load MDX syntax highlighting after user plugins

* chore: changeset
This commit is contained in:
Ben Holmes 2023-01-31 17:46:59 -05:00 committed by GitHub
parent 474ecc7be6
commit 2ab32b59ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': minor
---
Fix: load syntax highlighters after MDX remark plugins. This keeps MDX consistent with Astro's markdown behavior.

View file

@ -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);
}
@ -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));