You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Options inherited from Markdown config](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/#options-inherited-from-markdown-config)
You can customize how MDX files inherit your project’s existing Markdown configuration using the `extendPlugins` option.
101
+
All [`markdown` configuration options](/en/reference/configuration-reference/#markdown-options) except `drafts`can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config ([see the `extendMarkdownConfig` option](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/#extendmarkdownconfig) to modify this).
104
102
105
-
#### `markdown` (default)
103
+
:::note
104
+
There is no separate MDX configuration for [including pages marked as draft in the build](/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be overriden for MDX files specifically.
105
+
:::
106
106
107
-
Astro's MDX files will inherit all [`markdown` options](/en/reference/configuration-reference/#markdown-options) in your Astro configuration file, which includes the [GitHub-Flavored Markdown](https://github.com/remarkjs/remark-gfm) and [Smartypants](https://github.com/silvenon/remark-smartypants) plugins by default.
108
-
109
-
Any additional plugins you apply in your MDX config will be applied *after* your configured Markdown plugins.
110
-
111
-
#### `astroDefaults`
112
-
113
-
Astro's MDX files will apply only [Astro's default plugins](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/en/reference/configuration-reference/#markdownextenddefaultplugins), without inheriting the rest of your Markdown config.
114
-
115
-
This example will apply the default [GitHub-Flavored Markdown](https://github.com/remarkjs/remark-gfm) and [Smartypants](https://github.com/silvenon/remark-smartypants) plugins alongside [`remark-toc`](https://github.com/remarkjs/remark-toc) to your MDX files, while ignoring any `markdown.remarkPlugins` configuration:
116
-
117
-
```js "extendPlugins: 'astroDefaults'"
118
-
// astro.config.mjs
119
-
importremarkTocfrom'remark-toc';
120
-
121
-
exportdefault {
122
-
markdown: {
123
-
remarkPlugins: [/** ignored */]
124
-
},
125
-
integrations: [mdx({
126
-
remarkPlugins: [remarkToc],
127
-
// Astro defaults applied
128
-
extendPlugins:'astroDefaults',
129
-
})],
130
-
}
131
-
```
132
-
133
-
#### `false`
134
-
135
-
Astro's MDX files will not inherit any [`markdown` options](/en/reference/configuration-reference/#markdown-options), nor will any Astro Markdown defaults be applied:
136
-
137
-
```js "extendPlugins: false"
107
+
```ts
138
108
// astro.config.mjs
109
+
import { defineConfig } from'astro/config';
110
+
importmdxfrom'@astrojs/mdx';
139
111
importremarkTocfrom'remark-toc';
112
+
importrehypeMinifyHtmlfrom'rehype-minify-html';
140
113
141
-
exportdefault {
142
-
integrations: [mdx({
143
-
remarkPlugins: [remarkToc],
144
-
// Astro defaults not applied
145
-
extendPlugins:false,
146
-
})],
147
-
}
114
+
exportdefaultdefineConfig({
115
+
integrations: [
116
+
mdx({
117
+
syntaxHighlight: 'shiki',
118
+
shikiConfig: { theme: 'dracula' },
119
+
remarkPlugins: [remarkToc],
120
+
rehypePlugins: [rehypeMinifyHtml],
121
+
remarkRehype: { footnoteLabel: 'Footnotes' },
122
+
gfm: false,
123
+
})
124
+
]
125
+
})
148
126
```
149
127
150
-
### `remarkRehype`
151
-
152
-
Markdown content is transformed into HTML through remark-rehype which has [a number of options](https://github.com/remarkjs/remark-rehype#options).
128
+
:::caution
129
+
MDX does not support passing remark and rehype plugins as a string. You should install, import, and apply the plugin function instead.
130
+
:::
153
131
154
-
You can set remark-rehype options in your config file:
155
-
156
-
```js
157
-
// astro.config.mjs
158
-
exportdefault {
159
-
integrations: [mdx({
160
-
remarkRehype: {
161
-
footnoteLabel:'Catatan kaki',
162
-
footnoteBackLabel:'Kembali ke konten',
163
-
},
164
-
})],
165
-
};
166
-
```
132
+
📚 See the [Markdown Options reference](/en/reference/configuration-reference/#markdown-options) for a complete list of options.
167
133
168
-
This inherits the configuration of [`markdown.remarkRehype`](/en/reference/configuration-reference/#markdownremarkrehype). This behavior can be changed by configuring `extendPlugins`.
134
+
### `extendMarkdownConfig`
169
135
170
-
### `remarkPlugins`
136
+
***Type:**`boolean`
137
+
***Default:**`true`
171
138
172
-
Browse [awesome-remark](https://github.com/remarkjs/awesome-remark) for a full curated list of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) to extend your Markdown's capabilities.
139
+
MDX will extend [your project's existing Markdown configuration](/en/reference/configuration-reference/#markdown-options) by default. To override individual options, you can specify their equivalent in your MDX configuration.
173
140
174
-
This example applies the [`remark-toc`](https://github.com/remarkjs/remark-toc) plugin to `.mdx` files. To customize plugin inheritance from your Markdown config or Astro's defaults, [see the `extendPlugins` option](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/#extendplugins).
141
+
For example, say you need to disable GitHub-Flavored Markdown and apply a different set of remark plugins for MDX files. You can apply these options like so, with `extendMarkdownConfig` enabled by default:
175
142
176
-
```js
143
+
```ts
177
144
// astro.config.mjs
178
-
importremarkTocfrom'remark-toc';
145
+
import { defineConfig } from'astro/config';
146
+
importmdxfrom'@astrojs/mdx';
179
147
180
-
exportdefault {
181
-
integrations: [mdx({
182
-
remarkPlugins: [remarkToc],
183
-
})],
184
-
}
148
+
exportdefaultdefineConfig({
149
+
markdown: {
150
+
syntaxHighlight: 'prism',
151
+
remarkPlugins: [remarkPlugin1],
152
+
gfm: true,
153
+
},
154
+
integrations: [
155
+
mdx({
156
+
// `syntaxHighlight` inherited from Markdown
157
+
158
+
// Markdown `remarkPlugins` ignored,
159
+
// only `remarkPlugin2` applied.
160
+
remarkPlugins: [remarkPlugin2],
161
+
// `gfm` overridden to `false`
162
+
gfm: false,
163
+
})
164
+
]
165
+
});
185
166
```
186
167
187
-
### `rehypePlugins`
168
+
You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:
188
169
189
-
Browse [awesome-rehype](https://github.com/rehypejs/awesome-rehype) for a full curated list of [Rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md) to transform the HTML that your Markdown generates.
190
-
191
-
We apply our own (non-removable) [`collect-headings`](https://github.com/withastro/astro/blob/main/packages/integrations/mdx/src/rehype-collect-headings.ts) plugin. This applies IDs to all headings (i.e. `h1 -> h6`) in your MDX files to [link to headings via anchor tags](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#linking_to_an_element_on_the_same_page).
192
-
193
-
This example applies the [`rehype-accessible-emojis`](https://www.npmjs.com/package/rehype-accessible-emojis) plugin to `.mdx` files. To customize plugin inheritance from your Markdown config or Astro's defaults, [see the `extendPlugins` option](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/#extendplugins).
Copy file name to clipboardExpand all lines: src/pages/en/guides/markdown-content.mdx
+55-17Lines changed: 55 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -422,7 +422,7 @@ Custom components defined and exported in an MDX file must be imported and then
422
422
423
423
Markdown support in Astro is powered by [remark](https://remark.js.org/), a powerful parsing and processing tool with an active ecosystem. Other Markdown parsers like Pandoc and markdown-it are not currently supported.
424
424
425
-
Astro applies the [GitHub-flavored Markdown](https://github.com/remarkjs/remark-gfm)and [Smartypants](https://github.com/silvenon/remark-smartypants) plugins by default. This brings some niceties like generating clickable links from text and formatting quotes for readability.
425
+
Astro applies the [GitHub-flavored Markdown](https://github.com/remarkjs/remark-gfm)plugin by default. This brings some niceties like generating clickable links from text.
426
426
427
427
You can customize how remark parses your Markdown in `astro.config.mjs`. See the full list of [Markdown configuration options](/en/reference/configuration-reference/#markdown-options).
428
428
@@ -432,15 +432,7 @@ Astro supports adding third-party [remark](https://github.com/remarkjs/remark) a
432
432
433
433
We encourage you to browse [awesome-remark](https://github.com/remarkjs/awesome-remark) and [awesome-rehype](https://github.com/rehypejs/awesome-rehype) for popular plugins! See each plugin's own README for specific installation instructions.
434
434
435
-
:::tip
436
-
When adding your own plugins, Astro's default plugins are removed. You can preserve these defaults with the [`markdown.extendDefaultPlugins` flag](/en/reference/configuration-reference/#markdownextenddefaultplugins).
437
-
:::
438
-
439
-
By default, Astro's MDX integration inherits all remark and rehype plugins from your Astro config `markdown` options. To change this behavior, configure [`extendPlugins`](/en/guides/integrations-guide/mdx/#extendplugins) in your `mdx` integration.
440
-
441
-
Any additional plugins you apply in your MDX config will be applied *after* your configured Markdown plugins, and will apply only to `.mdx` files.
442
-
443
-
This example applies [`remark-toc`](https://github.com/remarkjs/remark-toc) to Markdown *and* MDX, and [`rehype-accessible-emojis`](https://www.npmjs.com/package/rehype-accessible-emojis) to MDX only, while preserving Astro's default plugins:
435
+
This example applies [`remark-toc`](https://github.com/remarkjs/remark-toc) and [`rehype-accessible-emojis`](https://www.npmjs.com/package/rehype-accessible-emojis) to both Markdown and MDX files:
444
436
445
437
```js title="astro.config.mjs"
446
438
import { defineConfig } from'astro/config';
@@ -450,14 +442,8 @@ import { rehypeAccessibleEmojis } from 'rehype-accessible-emojis';
Astro's MDX integration will extend [your project's existing Markdown configuration](/en/reference/configuration-reference/#markdown-options) by default. To override individual options, you can specify their equivalent in your MDX configuration.
582
+
583
+
The following example disables GitHub-Flavored Markdown and applies a different set of remark plugins for MDX files:
584
+
585
+
```ts
586
+
// astro.config.mjs
587
+
import { defineConfig } froAm'astro/config';
588
+
importmdxfrom'@astrojs/mdx';
589
+
590
+
exportdefaultdefineConfig({
591
+
markdown: {
592
+
syntaxHighlight: 'prism',
593
+
remarkPlugins: [remarkPlugin1],
594
+
gfm: true,
595
+
},
596
+
integrations: [
597
+
mdx({
598
+
// `syntaxHighlight` inherited from Markdown
599
+
600
+
// Markdown `remarkPlugins` ignored,
601
+
// only `remarkPlugin2` applied.
602
+
remarkPlugins: [remarkPlugin2],
603
+
// `gfm` overridden to `false`
604
+
gfm: false,
605
+
})
606
+
]
607
+
});
608
+
```
609
+
610
+
To avoid extending your Markdown config from MDX, set [the `extendMarkdownConfig` option](/en/guides/integrations-guide/mdx/#extendmarkdownconfig) (enabled by default) to `false`:
611
+
612
+
```ts
613
+
// astro.config.mjs
614
+
import { defineConfig } from'astro/config';
615
+
importmdxfrom'@astrojs/mdx';
616
+
617
+
exportdefaultdefineConfig({
618
+
markdown: {
619
+
remarkPlugins: [remarkPlugin],
620
+
},
621
+
integrations: [
622
+
mdx({
623
+
// Markdown config now ignored
624
+
extendMarkdownConfig: false,
625
+
// No `remarkPlugins` applied
626
+
})
627
+
]
628
+
});
629
+
```
630
+
593
631
### Syntax Highlighting
594
632
595
633
Astro comes with built-in support for [Shiki](https://shiki.matsu.io/) and [Prism](https://prismjs.com/). This provides syntax highlighting for:
0 commit comments