@@ -10,7 +10,7 @@ import type {
1010} from 'astro' ;
1111import type { Options as RemarkRehypeOptions } from 'remark-rehype' ;
1212import type { PluggableList } from 'unified' ;
13- import type { OptimizeOptions } from './rehype-optimize-static .js' ;
13+ import type { MdastPluginDefinition , HastPluginDefinition } from './satteri-plugins .js' ;
1414import { ignoreStringPlugins , safeParseFrontmatter } from './utils.js' ;
1515import { type VitePluginMdxOptions , vitePluginMdx } from './vite-plugin-mdx.js' ;
1616import { vitePluginMdxPostprocess } from './vite-plugin-mdx-postprocess.js' ;
@@ -23,7 +23,10 @@ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | '
2323 remarkPlugins : PluggableList ;
2424 rehypePlugins : PluggableList ;
2525 remarkRehype : RemarkRehypeOptions ;
26- optimize : boolean | OptimizeOptions ;
26+ optimize : boolean | { ignoreElementNames ?: string [ ] } ;
27+ mdastPlugins : MdastPluginDefinition [ ] ;
28+ hastPlugins : HastPluginDefinition [ ] ;
29+ features ?: import ( 'satteri' ) . Features ;
2730} ;
2831
2932type SetupHookParams = HookParameters < 'astro:config:setup' > & {
@@ -97,10 +100,32 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
97100 ) ,
98101 } ) ;
99102
103+ const nativeMd = config . experimental . nativeMarkdown ;
104+
105+ // When nativeMarkdown is enabled, merge mdastPlugins/hastPlugins/features from the experimental config
106+ if ( nativeMd && extendMarkdownConfig ) {
107+ const nativeOpts = typeof nativeMd === 'object' ? nativeMd : undefined ;
108+ resolvedMdxOptions . mdastPlugins = [
109+ ...( nativeOpts ?. mdastPlugins ?? [ ] ) ,
110+ ...resolvedMdxOptions . mdastPlugins ,
111+ ] ;
112+ resolvedMdxOptions . hastPlugins = [
113+ ...( nativeOpts ?. hastPlugins ?? [ ] ) ,
114+ ...resolvedMdxOptions . hastPlugins ,
115+ ] ;
116+ if ( nativeOpts ?. features || resolvedMdxOptions . features ) {
117+ resolvedMdxOptions . features = {
118+ ...nativeOpts ?. features ,
119+ ...resolvedMdxOptions . features ,
120+ } ;
121+ }
122+ }
123+
100124 // Mutate `mdxOptions` so that `vitePluginMdx` can reference the actual options
101125 Object . assign ( vitePluginMdxOptions , {
102126 mdxOptions : resolvedMdxOptions ,
103127 srcDir : config . srcDir ,
128+ nativeMarkdown : nativeMd ,
104129 } ) ;
105130 // @ts -expect-error After we assign, we don't need to reference `mdxOptions` in this context anymore.
106131 // Re-assign it so that the garbage can be collected later.
@@ -114,6 +139,8 @@ const defaultMdxOptions = {
114139 extendMarkdownConfig : true ,
115140 recmaPlugins : [ ] ,
116141 optimize : false ,
142+ mdastPlugins : [ ] ,
143+ hastPlugins : [ ] ,
117144} satisfies Partial < MdxOptions > ;
118145
119146function markdownConfigToMdxOptions (
@@ -147,5 +174,8 @@ function applyDefaultOptions({
147174 rehypePlugins : options . rehypePlugins ?? defaults . rehypePlugins ,
148175 shikiConfig : options . shikiConfig ?? defaults . shikiConfig ,
149176 optimize : options . optimize ?? defaults . optimize ,
177+ mdastPlugins : options . mdastPlugins ?? defaults . mdastPlugins ,
178+ hastPlugins : options . hastPlugins ?? defaults . hastPlugins ,
179+ features : options . features ?? defaults . features ,
150180 } ;
151181}
0 commit comments