0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

[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 config: AstroConfig
): Promise<MdxRollupPluginOptions['remarkPlugins']> { ): Promise<MdxRollupPluginOptions['remarkPlugins']> {
let remarkPlugins: PluggableList = []; let remarkPlugins: PluggableList = [];
if (mdxOptions.syntaxHighlight === 'shiki') {
remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]);
}
if (mdxOptions.syntaxHighlight === 'prism') {
remarkPlugins.push(remarkPrism);
}
if (mdxOptions.gfm) { if (mdxOptions.gfm) {
remarkPlugins.push(remarkGfm); remarkPlugins.push(remarkGfm);
} }
@ -144,6 +139,14 @@ export async function getRemarkPlugins(
remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)]; 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 // Apply last in case user plugins resolve relative image paths
remarkPlugins.push(toRemarkContentRelImageError(config)); remarkPlugins.push(toRemarkContentRelImageError(config));