@astrojs/mdx 0.14.0 → 0.15.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- @astrojs/mdx:build: cache hit, replaying output 93db87e92a57f3ab
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.14.0 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
1
+ @astrojs/mdx:build: cache hit, replaying output 60f6ddcdbc2ddb72
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.15.0-beta.1 build /home/runner/work/astro/astro/packages/integrations/mdx
4
+ @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,151 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.15.0-beta.1
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5769](https://github.com/withastro/astro/pull/5769) [`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce a `smartypants` flag to opt-out of Astro's default SmartyPants plugin.
8
+
9
+ ```js
10
+ {
11
+ markdown: {
12
+ smartypants: false,
13
+ }
14
+ }
15
+ ```
16
+
17
+ #### Migration
18
+
19
+ You may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the `extendDefaultPlugins` option. This has now been split into 2 flags to disable each plugin individually:
20
+
21
+ - `markdown.gfm` to disable GitHub-Flavored Markdown
22
+ - `markdown.smartypants` to disable SmartyPants
23
+
24
+ ```diff
25
+ // astro.config.mjs
26
+ import { defineConfig } from 'astro/config';
27
+
28
+ export default defineConfig({
29
+ markdown: {
30
+ - extendDefaultPlugins: false,
31
+ + smartypants: false,
32
+ + gfm: false,
33
+ }
34
+ });
35
+ ```
36
+
37
+ ### Patch Changes
38
+
39
+ - [#5741](https://github.com/withastro/astro/pull/5741) [`000d3e694`](https://github.com/withastro/astro/commit/000d3e6940839c2aebba1984e6fb3b133cec6749) Thanks [@delucis](https://github.com/delucis)! - Fix broken links in README
40
+
41
+ - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b)]:
42
+ - @astrojs/markdown-remark@2.0.0-beta.1
43
+
44
+ ## 0.15.0-beta.0
45
+
46
+ ### Minor Changes
47
+
48
+ - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
49
+
50
+ This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an `imageSrc` slug in your document frontmatter:
51
+
52
+ ```ts
53
+ export function remarkInjectSocialImagePlugin() {
54
+ return function (tree, file) {
55
+ const { frontmatter } = file.data.astro;
56
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
57
+ };
58
+ }
59
+ ```
60
+
61
+ #### Content Collections - new `remarkPluginFrontmatter` property
62
+
63
+ We have changed _inject_ frontmatter to _modify_ frontmatter in our docs to improve discoverability. This is based on support forum feedback, where "injection" is rarely the term used.
64
+
65
+ To reflect this, the `injectedFrontmatter` property has been renamed to `remarkPluginFrontmatter`. This should clarify this plugin is still separate from the `data` export Content Collections expose today.
66
+
67
+ #### Migration instructions
68
+
69
+ Plugin authors should now **check for user frontmatter when applying defaults.**
70
+
71
+ For example, say a remark plugin wants to apply a default `title` if none is present. Add a conditional to check if the property is present, and update if none exists:
72
+
73
+ ```diff
74
+ export function remarkInjectTitlePlugin() {
75
+ return function (tree, file) {
76
+ const { frontmatter } = file.data.astro;
77
+ + if (!frontmatter.title) {
78
+ frontmatter.title = 'Default title';
79
+ + }
80
+ }
81
+ }
82
+ ```
83
+
84
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
85
+
86
+ - [#5684](https://github.com/withastro/astro/pull/5684) [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Refine Markdown and MDX configuration options for ease-of-use.
87
+
88
+ #### Markdown
89
+
90
+ - **Remove `remark-smartypants`** from Astro's default Markdown plugins.
91
+ - **Replace the `extendDefaultPlugins` option** with a simplified `gfm` boolean. This is enabled by default, and can be disabled to remove GitHub-Flavored Markdown.
92
+ - Ensure GitHub-Flavored Markdown is applied whether or not custom `remarkPlugins` or `rehypePlugins` are configured. If you want to apply custom plugins _and_ remove GFM, manually set `gfm: false` in your config.
93
+
94
+ #### MDX
95
+
96
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
97
+ - Simplify `extendDefaults` to an `extendMarkdownConfig` option. MDX options will default to their equivalent in your Markdown config. By setting `extendMarkdownConfig` to false, you can "eject" to set your own syntax highlighting, plugins, and more.
98
+
99
+ #### Migration
100
+
101
+ To preserve your existing Markdown and MDX setup, you may need some configuration changes:
102
+
103
+ ##### Smartypants manual installation
104
+
105
+ [Smartypants](https://github.com/silvenon/remark-smartypants) has been removed from Astro's default setup. If you rely on this plugin, [install `remark-smartypants`](https://github.com/silvenon/remark-smartypants#installing) and apply to your `astro.config.*`:
106
+
107
+ ```diff
108
+ // astro.config.mjs
109
+ import { defineConfig } from 'astro/config';
110
+ + import smartypants from 'remark-smartypants';
111
+
112
+ export default defineConfig({
113
+ markdown: {
114
+ + remarkPlugins: [smartypants],
115
+ }
116
+ });
117
+ ```
118
+
119
+ ##### Migrate `extendDefaultPlugins` to `gfm`
120
+
121
+ You may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the `extendDefaultPlugins` option. Since Smartypants has been removed, this has been renamed to `gfm`.
122
+
123
+ ```diff
124
+ // astro.config.mjs
125
+ import { defineConfig } from 'astro/config';
126
+
127
+ export default defineConfig({
128
+ markdown: {
129
+ - extendDefaultPlugins: false,
130
+ + gfm: false,
131
+ }
132
+ });
133
+ ```
134
+
135
+ Additionally, applying remark and rehype plugins **no longer disables** `gfm`. You will need to opt-out manually by setting `gfm` to `false`.
136
+
137
+ ##### Migrate MDX's `extendPlugins` to `extendMarkdownConfig`
138
+
139
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 2 flags:
140
+
141
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
142
+ - `gfm` (`true` by default) to toggle GitHub-Flavored Markdown in MDX. This replaces the `extendPlugins: 'defaults'` option.
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d)]:
147
+ - @astrojs/markdown-remark@2.0.0-beta.0
148
+
3
149
  ## 0.14.0
4
150
 
5
151
  ### Minor Changes
package/README.md CHANGED
@@ -66,7 +66,7 @@ export default defineConfig({
66
66
 
67
67
  ## Usage
68
68
 
69
- With the Astro MDX integration, you can [add MDX pages to your project](/en/guides/markdown-content/#markdown-and-mdx-pages) by adding `.mdx` files within your `src/pages/` directory. You can also [import `.mdx` files](https://docs.astro.build/en/guides/markdown-content/#importing-markdown) into `.astro` files.
69
+ With the Astro MDX integration, you can [add MDX pages to your project](https://docs.astro.build/en/guides/markdown-content/#markdown-and-mdx-pages) by adding `.mdx` files within your `src/pages/` directory. You can also [import `.mdx` files](https://docs.astro.build/en/guides/markdown-content/#importing-markdown) into `.astro` files.
70
70
 
71
71
  Astro's MDX integration adds extra features to standard MDX, including Markdown-style frontmatter. This allows you to use most of Astro's built-in Markdown features like a [special frontmatter `layout` property](https://docs.astro.build/en/guides/markdown-content/#frontmatter-layout) and a [property for marking a page as a draft](https://docs.astro.build/en/guides/markdown-content/#draft-pages).
72
72
 
@@ -78,116 +78,100 @@ Visit the [MDX docs](https://mdxjs.com/docs/what-is-mdx/) to learn about using s
78
78
 
79
79
  Once the MDX integration is installed, no configuration is necessary to use `.mdx` files in your Astro project.
80
80
 
81
- You can extend how your MDX is rendered by adding remark, rehype and recma plugins.
81
+ You can configure how your MDX is rendered with the following options:
82
82
 
83
- - [`extendPlugins`](#extendplugins)
84
- - [`remarkRehype`](#remarkrehype)
85
- - [`remarkPlugins`](#remarkplugins)
86
- - [`rehypePlugins`](#rehypeplugins)
83
+ - [Options inherited from Markdown config](#options-inherited-from-markdown-config)
84
+ - [`extendMarkdownConfig`](#extendmarkdownconfig)
87
85
  - [`recmaPlugins`](#recmaplugins)
88
86
 
89
- ### `extendPlugins`
87
+ ### Options inherited from Markdown config
90
88
 
91
- You can customize how MDX files inherit your project’s existing Markdown configuration using the `extendPlugins` option.
89
+ All [`markdown` configuration options](https://docs.astro.build/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](#extendmarkdownconfig) to modify this).
92
90
 
93
- #### `markdown` (default)
91
+ :::note
92
+ There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.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.
93
+ :::
94
94
 
95
- Astro's MDX files will inherit all [`markdown` options](https://docs.astro.build/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.
96
-
97
- Any additional plugins you apply in your MDX config will be applied *after* your configured Markdown plugins.
98
-
99
- #### `astroDefaults`
100
-
101
- Astro's MDX files will apply only [Astro's default plugins](/en/reference/configuration-reference/#markdownextenddefaultplugins), without inheriting the rest of your Markdown config.
102
-
103
- 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:
104
-
105
- ```js "extendPlugins: 'astroDefaults'"
95
+ ```ts
106
96
  // astro.config.mjs
97
+ import { defineConfig } from 'astro/config';
98
+ import mdx from '@astrojs/mdx';
107
99
  import remarkToc from 'remark-toc';
100
+ import rehypeMinifyHtml from 'rehype-minify-html';
108
101
 
109
- export default {
110
- markdown: {
111
- remarkPlugins: [/** ignored */]
112
- },
113
- integrations: [mdx({
114
- remarkPlugins: [remarkToc],
115
- // Astro defaults applied
116
- extendPlugins: 'astroDefaults',
117
- })],
118
- }
102
+ export default defineConfig({
103
+ integrations: [
104
+ mdx({
105
+ syntaxHighlight: 'shiki',
106
+ shikiConfig: { theme: 'dracula' },
107
+ remarkPlugins: [remarkToc],
108
+ rehypePlugins: [rehypeMinifyHtml],
109
+ remarkRehype: { footnoteLabel: 'Footnotes' },
110
+ gfm: false,
111
+ })
112
+ ]
113
+ })
119
114
  ```
120
115
 
121
- #### `false`
116
+ :::caution
117
+ MDX does not support passing remark and rehype plugins as a string. You should install, import, and apply the plugin function instead.
118
+ :::
122
119
 
123
- Astro's MDX files will not inherit any [`markdown` options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options), nor will any Astro Markdown defaults be applied:
120
+ 📚 See the [Markdown Options reference](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) for a complete list of options.
124
121
 
125
- ```js "extendPlugins: false"
126
- // astro.config.mjs
127
- import remarkToc from 'remark-toc';
128
-
129
- export default {
130
- integrations: [mdx({
131
- remarkPlugins: [remarkToc],
132
- // Astro defaults not applied
133
- extendPlugins: false,
134
- })],
135
- }
136
- ```
122
+ ### `extendMarkdownConfig`
137
123
 
138
- ### `remarkRehype`
124
+ - **Type:** `boolean`
125
+ - **Default:** `true`
139
126
 
140
- Markdown content is transformed into HTML through remark-rehype which has [a number of options](https://github.com/remarkjs/remark-rehype#options).
127
+ MDX will extend [your project's existing Markdown configuration](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) by default. To override individual options, you can specify their equivalent in your MDX configuration.
141
128
 
142
- You can set remark-rehype options in your config file:
129
+ 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:
143
130
 
144
- ```js
131
+ ```ts
145
132
  // astro.config.mjs
146
- export default {
147
- integrations: [mdx({
148
- remarkRehype: {
149
- footnoteLabel: 'Catatan kaki',
150
- footnoteBackLabel: 'Kembali ke konten',
151
- },
152
- })],
153
- };
154
- ```
155
- This inherits the configuration of [`markdown.remarkRehype`](https://docs.astro.build/en/reference/configuration-reference/#markdownremarkrehype). This behavior can be changed by configuring `extendPlugins`.
156
-
157
- ### `remarkPlugins`
158
-
159
- 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.
160
-
161
- 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).
162
-
163
- ```js
164
- // astro.config.mjs
165
- import remarkToc from 'remark-toc';
133
+ import { defineConfig } from 'astro/config';
134
+ import mdx from '@astrojs/mdx';
166
135
 
167
- export default {
168
- integrations: [mdx({
169
- remarkPlugins: [remarkToc],
170
- })],
171
- }
136
+ export default defineConfig({
137
+ markdown: {
138
+ syntaxHighlight: 'prism',
139
+ remarkPlugins: [remarkPlugin1],
140
+ gfm: true,
141
+ },
142
+ integrations: [
143
+ mdx({
144
+ // `syntaxHighlight` inherited from Markdown
145
+
146
+ // Markdown `remarkPlugins` ignored,
147
+ // only `remarkPlugin2` applied.
148
+ remarkPlugins: [remarkPlugin2],
149
+ // `gfm` overridden to `false`
150
+ gfm: false,
151
+ })
152
+ ]
153
+ });
172
154
  ```
173
155
 
174
- ### `rehypePlugins`
175
-
176
- 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.
156
+ You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:
177
157
 
178
- 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).
179
-
180
- 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](#extendplugins).
181
-
182
- ```js
158
+ ```ts
183
159
  // astro.config.mjs
184
- import rehypeAccessibleEmojis from 'rehype-accessible-emojis';
160
+ import { defineConfig } from 'astro/config';
161
+ import mdx from '@astrojs/mdx';
185
162
 
186
- export default {
187
- integrations: [mdx({
188
- rehypePlugins: [rehypeAccessibleEmojis],
189
- })],
190
- }
163
+ export default defineConfig({
164
+ markdown: {
165
+ remarkPlugins: [remarkPlugin1],
166
+ },
167
+ integrations: [
168
+ mdx({
169
+ // Markdown config now ignored
170
+ extendMarkdownConfig: false,
171
+ // No `remarkPlugins` applied
172
+ })
173
+ ]
174
+ });
191
175
  ```
192
176
 
193
177
  ### `recmaPlugins`
@@ -214,6 +198,6 @@ This package is maintained by Astro's Core team. You're welcome to submit an iss
214
198
 
215
199
  See [CHANGELOG.md](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/CHANGELOG.md) for a history of changes to this integration.
216
200
 
217
- [astro-integration]: /en/guides/integrations-guide/
201
+ [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
218
202
 
219
- [astro-ui-frameworks]: /en/core-concepts/framework-components/#using-framework-components
203
+ [astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
package/dist/index.d.ts CHANGED
@@ -1,18 +1,12 @@
1
+ import { markdownConfigDefaults } from '@astrojs/markdown-remark';
1
2
  import { PluggableList } from '@mdx-js/mdx/lib/core.js';
2
3
  import type { AstroIntegration } from 'astro';
3
4
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
4
- export declare type MdxOptions = {
5
- remarkPlugins?: PluggableList;
6
- rehypePlugins?: PluggableList;
7
- recmaPlugins?: PluggableList;
8
- /**
9
- * Choose which remark and rehype plugins to inherit, if any.
10
- *
11
- * - "markdown" (default) - inherit your project’s markdown plugin config ([see Markdown docs](https://docs.astro.build/en/guides/markdown-content/#configuring-markdown))
12
- * - "astroDefaults" - inherit Astro’s default plugins only ([see defaults](https://docs.astro.build/en/reference/configuration-reference/#markdownextenddefaultplugins))
13
- * - false - do not inherit any plugins
14
- */
15
- extendPlugins?: 'markdown' | 'astroDefaults' | false;
16
- remarkRehype?: RemarkRehypeOptions;
5
+ export declare type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
6
+ extendMarkdownConfig: boolean;
7
+ recmaPlugins: PluggableList;
8
+ remarkPlugins: PluggableList;
9
+ rehypePlugins: PluggableList;
10
+ remarkRehype: RemarkRehypeOptions;
17
11
  };
18
- export default function mdx(mdxOptions?: MdxOptions): AstroIntegration;
12
+ export default function mdx(partialMdxOptions?: Partial<MdxOptions>): AstroIntegration;
package/dist/index.js CHANGED
@@ -1,37 +1,34 @@
1
+ import { markdownConfigDefaults } from "@astrojs/markdown-remark";
2
+ import { toRemarkInitializeAstroData } from "@astrojs/markdown-remark/dist/internal.js";
1
3
  import { compile as mdxCompile } from "@mdx-js/mdx";
2
4
  import mdxPlugin from "@mdx-js/rollup";
3
5
  import { parse as parseESM } from "es-module-lexer";
4
6
  import fs from "node:fs/promises";
5
7
  import { VFile } from "vfile";
6
- import {
7
- getRehypePlugins,
8
- getRemarkPlugins,
9
- recmaInjectImportMetaEnvPlugin,
10
- rehypeApplyFrontmatterExport
11
- } from "./plugins.js";
8
+ import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
12
9
  import { getFileInfo, parseFrontmatter } from "./utils.js";
13
10
  const RAW_CONTENT_ERROR = "MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins";
14
11
  const COMPILED_CONTENT_ERROR = "MDX does not support compiledContent()! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins";
15
- function mdx(mdxOptions = {}) {
12
+ function mdx(partialMdxOptions = {}) {
16
13
  return {
17
14
  name: "@astrojs/mdx",
18
15
  hooks: {
19
16
  "astro:config:setup": async ({ updateConfig, config, addPageExtension, command }) => {
20
17
  addPageExtension(".mdx");
21
- mdxOptions.extendPlugins ?? (mdxOptions.extendPlugins = "markdown");
22
- const remarkRehypeOptions = {
23
- ...mdxOptions.extendPlugins === "markdown" ? config.markdown.remarkRehype : {},
24
- ...mdxOptions.remarkRehype
25
- };
18
+ const extendMarkdownConfig = partialMdxOptions.extendMarkdownConfig ?? defaultOptions.extendMarkdownConfig;
19
+ const mdxOptions = applyDefaultOptions({
20
+ options: partialMdxOptions,
21
+ defaults: extendMarkdownConfig ? config.markdown : defaultOptions
22
+ });
26
23
  const mdxPluginOpts = {
27
24
  remarkPlugins: await getRemarkPlugins(mdxOptions, config),
28
- rehypePlugins: getRehypePlugins(mdxOptions, config),
25
+ rehypePlugins: getRehypePlugins(mdxOptions),
29
26
  recmaPlugins: mdxOptions.recmaPlugins,
27
+ remarkRehypeOptions: mdxOptions.remarkRehype,
30
28
  jsx: true,
31
29
  jsxImportSource: "astro",
32
30
  format: "mdx",
33
- mdExtensions: [],
34
- remarkRehypeOptions
31
+ mdExtensions: []
35
32
  };
36
33
  let importMetaEnv = {
37
34
  SITE: config.site
@@ -53,9 +50,9 @@ function mdx(mdxOptions = {}) {
53
50
  const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
54
51
  const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), {
55
52
  ...mdxPluginOpts,
56
- rehypePlugins: [
57
- ...mdxPluginOpts.rehypePlugins ?? [],
58
- () => rehypeApplyFrontmatterExport(frontmatter)
53
+ remarkPlugins: [
54
+ toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
55
+ ...mdxPluginOpts.remarkPlugins ?? []
59
56
  ],
60
57
  recmaPlugins: [
61
58
  ...mdxPluginOpts.recmaPlugins ?? [],
@@ -129,6 +126,30 @@ if (import.meta.hot) {
129
126
  }
130
127
  };
131
128
  }
129
+ const defaultOptions = {
130
+ ...markdownConfigDefaults,
131
+ extendMarkdownConfig: true,
132
+ recmaPlugins: [],
133
+ remarkPlugins: [],
134
+ rehypePlugins: [],
135
+ remarkRehype: {}
136
+ };
137
+ function applyDefaultOptions({
138
+ options,
139
+ defaults
140
+ }) {
141
+ return {
142
+ syntaxHighlight: options.syntaxHighlight ?? defaults.syntaxHighlight,
143
+ extendMarkdownConfig: options.extendMarkdownConfig ?? defaults.extendMarkdownConfig,
144
+ recmaPlugins: options.recmaPlugins ?? defaults.recmaPlugins,
145
+ remarkRehype: options.remarkRehype ?? defaults.remarkRehype,
146
+ gfm: options.gfm ?? defaults.gfm,
147
+ smartypants: options.smartypants ?? defaults.smartypants,
148
+ remarkPlugins: options.remarkPlugins ?? defaults.remarkPlugins,
149
+ rehypePlugins: options.rehypePlugins ?? defaults.rehypePlugins,
150
+ shikiConfig: options.shikiConfig ?? defaults.shikiConfig
151
+ };
152
+ }
132
153
  function escapeViteEnvReferences(code) {
133
154
  return code.replace(/import\.meta\.env/g, "import\\u002Emeta.env");
134
155
  }
package/dist/plugins.d.ts CHANGED
@@ -5,7 +5,6 @@ import { MdxOptions } from './index.js';
5
5
  export declare function recmaInjectImportMetaEnvPlugin({ importMetaEnv, }: {
6
6
  importMetaEnv: Record<string, any>;
7
7
  }): (tree: any) => void;
8
- export declare function remarkInitializeAstroData(): (tree: any, vfile: VFile) => void;
9
- export declare function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any>): (tree: any, vfile: VFile) => void;
8
+ export declare function rehypeApplyFrontmatterExport(): (tree: any, vfile: VFile) => void;
10
9
  export declare function getRemarkPlugins(mdxOptions: MdxOptions, config: AstroConfig): Promise<MdxRollupPluginOptions['remarkPlugins']>;
11
- export declare function getRehypePlugins(mdxOptions: MdxOptions, config: AstroConfig): MdxRollupPluginOptions['rehypePlugins'];
10
+ export declare function getRehypePlugins(mdxOptions: MdxOptions): MdxRollupPluginOptions['rehypePlugins'];