Skip to content

Commit

Permalink
fix(mdx): fix issue in mdx rehype plugin ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Feb 22, 2024
1 parent 4e46157 commit e2aa2f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/create-astro/test/fixtures/not-empty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"dev": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview"
},
"dependencies": {
"@astrojs/check": "^0.5.5",
"typescript": "^5.3.3"
}
}
}
9 changes: 6 additions & 3 deletions packages/integrations/mdx/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ function getRehypePlugins(mdxOptions: MdxOptions): PluggableList {
rehypeMetaString,
// rehypeRaw allows custom syntax highlighters to work without added config
[rehypeRaw, { passThrough: nodeTypes }],
...mdxOptions.rehypePlugins,
];

if (!isPerformanceBenchmark) {
// getHeadings() is guaranteed by TS, so this must be included.
// We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins.
rehypePlugins.push(rehypeHeadingIds, rehypeInjectHeadingsExport);
}

// computed from `astro.data.frontmatter` in VFile data
rehypePlugins.push(rehypeApplyFrontmatterExport);

if (!isPerformanceBenchmark) {
// Apply syntax highlighters after user plugins to match `markdown/remark` behavior
if (mdxOptions.syntaxHighlight === 'shiki') {
rehypePlugins.push([rehypeShiki, mdxOptions.shikiConfig]);
Expand All @@ -80,9 +86,6 @@ function getRehypePlugins(mdxOptions: MdxOptions): PluggableList {
}
}

// computed from `astro.data.frontmatter` in VFile data
rehypePlugins.push(...mdxOptions.rehypePlugins, rehypeApplyFrontmatterExport);

if (mdxOptions.optimize) {
// Convert user `optimize` option to compatible `rehypeOptimizeStatic` option
const options = mdxOptions.optimize === true ? undefined : mdxOptions.optimize;
Expand Down

0 comments on commit e2aa2f9

Please sign in to comment.