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
@@ -103,47 +103,19 @@ import rehypeMinifyHtml from 'rehype-minify-html';
103
103
exportdefaultdefineConfig({
104
104
integrations: [
105
105
mdx({
106
-
remarkPlugins: [exampleRemarkPlugin],
107
-
}),
108
-
],
109
-
});
110
-
```
111
-
112
-
…every MDX file will have `customProperty` in its frontmatter! See [our Markdown documentation](https://docs.astro.build/en/guides/markdown-content/#example-injecting-frontmatter) for more usage instructions and a [reading time plugin example](https://docs.astro.build/en/guides/markdown-content/#example-calculate-reading-time).
113
-
114
-
### Layouts
115
-
Layouts can be applied [in the same way as standard Astro Markdown](https://docs.astro.build/en/guides/markdown-content/#frontmatter-layout). You can add a `layout` to [your frontmatter](#frontmatter) like so:
116
-
117
-
```yaml
118
-
---
119
-
layout: '../layouts/BaseLayout.astro'
120
-
title: 'My Blog Post'
121
-
---
122
-
```
123
-
124
-
Then, you can retrieve all other frontmatter properties from your layout via the `frontmatter` property, and render your MDX using the default [`<slot />`](https://docs.astro.build/en/core-concepts/astro-components/#slots). See [layout props](#layout-props) for a complete list of props available.
<!-- Rendered MDX will be passed into the default slot. -->
138
-
<slot />
139
-
</body>
140
-
</html>
106
+
syntaxHighlight:'shiki',
107
+
shikiConfig: { theme:'dracula' },
108
+
remarkPlugins: [remarkToc],
109
+
rehypePlugins: [rehypeMinifyHtml],
110
+
remarkRehype: { footnoteLabel:'Footnotes' },
111
+
gfm:false,
112
+
})
113
+
]
114
+
})
141
115
```
142
116
143
-
You can set a layout’s [`Props` type](/en/guides/typescript/#component-props) with the `MDXLayoutProps` helper.
144
-
145
-
:::note
146
-
`MDXLayoutProps` is the same as the `MarkdownLayoutProps` utility type with `rawContent()` and `compiledContent()` removed (since these are not available for `.mdx` files). Feel free to **use `MarkdownLayoutProps` instead** when sharing a layout across `.md` and `.mdx` files.
117
+
:::caution
118
+
MDX does not support passing remark and rehype plugins as a string. You should install, import, and apply the plugin function instead.
147
119
:::
148
120
149
121
📚 See the [Markdown Options reference](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) for a complete list of options.
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:
159
131
160
-
```html
161
-
<blockquote>
162
-
<p>A blockquote with <em>some</em> emphasis.</p>
163
-
</blockquote>
164
-
```
165
-
166
-
But what if you want to specify your own markup for these blockquotes? In the above example, you could create a custom `<Blockquote />` component (in any language) that either has a `<slot />` component or accepts a `children` prop.
Now, writing the standard Markdown blockquote syntax (`>`) will use your custom `<Blockquote />` component instead. No need to use a component in Markdown, or write a remark/rehype plugin! Visit the [MDX website](https://mdxjs.com/table-of-components/) for a full list of HTML elements that can be overwritten as custom components.
187
-
188
-
#### Custom components with imported `mdx`
189
-
190
-
When rendering imported MDX content, custom components can be passed via the `components` prop.
191
-
192
-
Note: An MDX file's exported components will _not_ be used unless you manually import and pass them via the `components` property. See the example below:
The MDX integration respects [your project's `markdown.syntaxHighlight` configuration](https://docs.astro.build/en/guides/markdown-content/#syntax-highlighting).
206
-
207
-
We will highlight your code blocks with [Shiki](https://github.com/shikijs/shiki) by default. You can customize this highlighter using the `markdown.shikiConfig` option in your `astro.config`. For example, you can apply a different built-in theme like so:
208
-
209
-
__`astro.config.mjs`__
210
-
211
-
```js
212
-
import { defineConfig } from'astro/config';
213
-
importmdxfrom'@astrojs/mdx';
214
-
215
-
exportdefaultdefineConfig({
216
-
markdown: {
217
-
shikiConfig: {
218
-
theme:'dracula',
219
-
},
220
-
},
221
-
integrations: [mdx()],
222
-
});
223
-
```
224
-
225
-
Visit [our Shiki configuration docs](https://docs.astro.build/en/guides/markdown-content/#shiki-configuration) for more on using Shiki with Astro.
226
-
227
-
#### Switch to Prism
228
-
229
-
You can also use the [Prism](https://prismjs.com/) syntax highlighter by setting `markdown.syntaxHighlight` to `'prism'` in your `astro.config` like so:
This applies a minimal Prism renderer with added support for `astro` code blocks. Visit [our "Prism configuration" docs](https://docs.astro.build/en/guides/markdown-content/#prism-configuration) for more on using Prism with Astro.
248
-
249
-
#### Switch to a custom syntax highlighter
250
-
251
-
You may want to apply your own syntax highlighter too. If your highlighter offers a remark or rehype plugin, you can flip off our syntax highlighting by setting `markdown.syntaxHighlight: false` and wiring up your plugin. For example, say you want to apply [Shiki Twoslash's remark plugin](https://www.npmjs.com/package/remark-shiki-twoslash):
[Remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) allow you to extend your Markdown with new capabilities. This includes [auto-generating a table of contents](https://github.com/remarkjs/remark-toc), [applying accessible emoji labels](https://github.com/florianeckerstorfer/remark-a11y-emoji), and more. We encourage you to browse [awesome-remark](https://github.com/remarkjs/awesome-remark) for a full curated list!
277
-
278
-
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](#extendplugins).
279
-
280
-
__`astro.config.mjs`__
146
+
// `syntaxHighlight` inherited from Markdown
281
147
282
-
```js
283
-
import { defineConfig } from'astro/config';
284
-
importmdxfrom'@astrojs/mdx';
285
-
importremarkTocfrom'remark-toc';
286
-
287
-
exportdefaultdefineConfig({
288
-
integrations: [mdx({
289
-
remarkPlugins: [remarkToc],
290
-
})],
291
-
});
292
-
```
293
-
294
-
### rehypePlugins
295
-
296
-
[Rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md) allow you to transform the HTML that your Markdown generates. We encourage you to browse [awesome-rehype](https://github.com/rehypejs/awesome-rehype) for a full curated list of plugins!
297
-
298
-
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).
299
-
300
-
This example applies the [`rehype-minify`](https://github.com/rehypejs/rehype-minify) plugin to `.mdx` files. To customize plugin inheritance from your Markdown config or Astro's defaults, [see the `extendPlugins` option](#extendplugins).
301
-
302
-
__`astro.config.mjs`__
303
-
304
-
```js
305
-
import { defineConfig } from'astro/config';
306
-
importmdxfrom'@astrojs/mdx';
307
-
importrehypeMinifyHtmlfrom'rehype-minify';
308
-
309
-
exportdefaultdefineConfig({
310
-
integrations: [mdx({
311
-
rehypePlugins: [rehypeMinifyHtml],
312
-
})],
313
-
});
314
-
```
315
-
316
-
### extendPlugins
317
-
318
-
**Type:**`'markdown' | 'astroDefaults' | false`
319
-
320
-
**Default:**`'markdown'`
321
-
322
-
#### `markdown` (default)
323
-
324
-
By default, Astro inherits all [remark](#remarkplugins) and [rehype](#rehypeplugins) plugins from [the `markdown` option in your Astro config](https://docs.astro.build/en/guides/markdown-content/#markdown-plugins). This also respects the [`markdown.extendDefaultPlugins`](https://docs.astro.build/en/reference/configuration-reference/#markdownextenddefaultplugins) option to extend Astro's defaults. Any additional plugins you apply in your MDX config will be applied _after_ your configured Markdown plugins.
325
-
326
-
This example applies [`remark-toc`](https://github.com/remarkjs/remark-toc) to Markdown _and_ MDX, and [`rehype-minify`](https://github.com/rehypejs/rehype-minify) to MDX alone:
327
-
328
-
__`astro.config.mjs`__
329
-
330
-
```js
331
-
import { defineConfig } from'astro/config';
332
-
importmdxfrom'@astrojs/mdx';
333
-
importremarkTocfrom'remark-toc';
334
-
importrehypeMinifyfrom'rehype-minify';
335
-
336
-
exportdefaultdefineConfig({
337
-
markdown: {
338
-
// Applied to .md and .mdx files
339
-
remarkPlugins: [remarkToc],
340
-
},
341
-
integrations: [mdx({
342
-
// Applied to .mdx files only
343
-
rehypePlugins: [rehypeMinify],
344
-
})],
148
+
// Markdown `remarkPlugins` ignored,
149
+
// only `remarkPlugin2` applied.
150
+
remarkPlugins: [remarkPlugin2],
151
+
// `gfm` overridden to `false`
152
+
gfm:false,
153
+
})
154
+
]
345
155
});
346
156
```
347
157
348
158
You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:
349
159
350
160
__`astro.config.mjs`__
351
161
352
-
```js "extendPlugins: 'astroDefaults'"
162
+
```js
353
163
import { defineConfig } from'astro/config';
354
164
importmdxfrom'@astrojs/mdx';
355
-
importremarkTocfrom'remark-toc';
356
165
357
166
exportdefaultdefineConfig({
358
167
markdown: {
359
168
remarkPlugins: [remarkPlugin1],
360
169
},
361
-
integrations: [mdx({
362
-
remarkPlugins: [remarkToc],
363
-
// Astro defaults applied
364
-
extendPlugins:'astroDefaults',
365
-
})],
366
-
});
367
-
```
368
-
369
-
#### `false`
370
-
371
-
If you don't want to extend any plugins, set `extendPlugins` to `false`:
372
-
373
-
__`astro.config.mjs`__
374
-
375
-
```js "extendPlugins: false"
376
-
import { defineConfig } from'astro/config';
377
-
importmdxfrom'@astrojs/mdx';
378
-
importremarkTocfrom'remark-toc';
379
-
380
-
exportdefaultdefineConfig({
381
-
integrations: [mdx({
382
-
remarkPlugins: [remarkToc],
383
-
// Astro defaults not applied
384
-
extendPlugins:false,
385
-
})],
170
+
integrations: [
171
+
mdx({
172
+
// Markdown config now ignored
173
+
extendMarkdownConfig:false,
174
+
// No `remarkPlugins` applied
175
+
})
176
+
]
386
177
});
387
178
```
388
179
@@ -392,30 +183,6 @@ These are plugins that modify the output [estree](https://github.com/estree/estr
392
183
393
184
We suggest [using AST Explorer](https://astexplorer.net/) to play with estree outputs, and trying [`estree-util-visit`](https://unifiedjs.com/explore/package/estree-util-visit/) for searching across JavaScript nodes.
394
185
395
-
### remarkRehype
396
-
397
-
Markdown content is transformed into HTML through remark-rehype which has [a number of options](https://github.com/remarkjs/remark-rehype#options).
398
-
399
-
You can use remark-rehype options in your MDX integration config file like so:
400
-
401
-
__`astro.config.mjs`__
402
-
403
-
```js
404
-
import { defineConfig } from'astro/config';
405
-
importmdxfrom'@astrojs/mdx';
406
-
407
-
exportdefaultdefineConfig({
408
-
integrations: [mdx({
409
-
remarkRehype: {
410
-
footnoteLabel:'Catatan kaki',
411
-
footnoteBackLabel:'Kembali ke konten',
412
-
},
413
-
})],
414
-
});
415
-
```
416
-
417
-
This inherits the configuration of `markdown.remarkRehype`. This behavior can be changed by configuring `extendPlugins`.
418
-
419
186
## Examples
420
187
421
188
* The [Astro MDX starter template](https://github.com/withastro/astro/tree/latest/examples/with-mdx) shows how to use MDX files in your Astro project.
0 commit comments