@astrojs/mdx 0.13.0 → 0.15.0-beta.0

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 72ab36e70338807d
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.13.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 a2df0a02dde16921
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.15.0-beta.0 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,147 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.15.0-beta.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
9
+ 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:
10
+
11
+ ```ts
12
+ export function remarkInjectSocialImagePlugin() {
13
+ return function (tree, file) {
14
+ const { frontmatter } = file.data.astro;
15
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
16
+ };
17
+ }
18
+ ```
19
+
20
+ #### Content Collections - new `remarkPluginFrontmatter` property
21
+
22
+ 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.
23
+
24
+ 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.
25
+
26
+ #### Migration instructions
27
+
28
+ Plugin authors should now **check for user frontmatter when applying defaults.**
29
+
30
+ 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:
31
+
32
+ ```diff
33
+ export function remarkInjectTitlePlugin() {
34
+ return function (tree, file) {
35
+ const { frontmatter } = file.data.astro;
36
+ + if (!frontmatter.title) {
37
+ frontmatter.title = 'Default title';
38
+ + }
39
+ }
40
+ }
41
+ ```
42
+
43
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
44
+
45
+ - [#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.
46
+
47
+ #### Markdown
48
+
49
+ - **Remove `remark-smartypants`** from Astro's default Markdown plugins.
50
+ - **Replace the `extendDefaultPlugins` option** with a simplified `gfm` boolean. This is enabled by default, and can be disabled to remove GitHub-Flavored Markdown.
51
+ - 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.
52
+
53
+ #### MDX
54
+
55
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
56
+ - 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.
57
+
58
+ #### Migration
59
+
60
+ To preserve your existing Markdown and MDX setup, you may need some configuration changes:
61
+
62
+ ##### Smartypants manual installation
63
+
64
+ [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.*`:
65
+
66
+ ```diff
67
+ // astro.config.mjs
68
+ import { defineConfig } from 'astro/config';
69
+ + import smartypants from 'remark-smartypants';
70
+
71
+ export default defineConfig({
72
+ markdown: {
73
+ + remarkPlugins: [smartypants],
74
+ }
75
+ });
76
+ ```
77
+
78
+ ##### Migrate `extendDefaultPlugins` to `gfm`
79
+
80
+ 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`.
81
+
82
+ ```diff
83
+ // astro.config.mjs
84
+ import { defineConfig } from 'astro/config';
85
+
86
+ export default defineConfig({
87
+ markdown: {
88
+ - extendDefaultPlugins: false,
89
+ + gfm: false,
90
+ }
91
+ });
92
+ ```
93
+
94
+ Additionally, applying remark and rehype plugins **no longer disables** `gfm`. You will need to opt-out manually by setting `gfm` to `false`.
95
+
96
+ ##### Migrate MDX's `extendPlugins` to `extendMarkdownConfig`
97
+
98
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 2 flags:
99
+
100
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
101
+ - `gfm` (`true` by default) to toggle GitHub-Flavored Markdown in MDX. This replaces the `extendPlugins: 'defaults'` option.
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [[`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d)]:
106
+ - @astrojs/markdown-remark@2.0.0-beta.0
107
+
108
+ ## 0.14.0
109
+
110
+ ### Minor Changes
111
+
112
+ - [#5654](https://github.com/withastro/astro/pull/5654) [`2c65b433b`](https://github.com/withastro/astro/commit/2c65b433bf840a1bb93b0a1947df5949e33512ff) Thanks [@delucis](https://github.com/delucis)! - Run heading ID injection after user plugins
113
+
114
+ ⚠️ BREAKING CHANGE ⚠️
115
+
116
+ If you are using a rehype plugin that depends on heading IDs injected by Astro, the IDs will no longer be available when your plugin runs by default.
117
+
118
+ To inject IDs before your plugins run, import and add the `rehypeHeadingIds` plugin to your `rehypePlugins` config:
119
+
120
+ ```diff
121
+ // astro.config.mjs
122
+ + import { rehypeHeadingIds } from '@astrojs/markdown-remark';
123
+ import mdx from '@astrojs/mdx';
124
+
125
+ export default {
126
+ integrations: [mdx()],
127
+ markdown: {
128
+ rehypePlugins: [
129
+ + rehypeHeadingIds,
130
+ otherPluginThatReliesOnHeadingIDs,
131
+ ],
132
+ },
133
+ }
134
+ ```
135
+
136
+ ### Patch Changes
137
+
138
+ - [#5667](https://github.com/withastro/astro/pull/5667) [`a5ba4af79`](https://github.com/withastro/astro/commit/a5ba4af79930145f4edf66d45cd40ddad045cc86) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Chore: remove verbose "Now interiting Markdown plugins..." logs
139
+
140
+ - [#5648](https://github.com/withastro/astro/pull/5648) [`853081d1c`](https://github.com/withastro/astro/commit/853081d1c857d8ad8a9634c37ed8fd123d32d241) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Prevent relative image paths in `src/content/`
141
+
142
+ - Updated dependencies [[`853081d1c`](https://github.com/withastro/astro/commit/853081d1c857d8ad8a9634c37ed8fd123d32d241), [`2c65b433b`](https://github.com/withastro/astro/commit/2c65b433bf840a1bb93b0a1947df5949e33512ff)]:
143
+ - @astrojs/markdown-remark@1.2.0
144
+
3
145
  ## 0.13.0
4
146
 
5
147
  ### Minor Changes
package/README.md CHANGED
@@ -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`
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,55 +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
- import { blue, bold } from "kleur/colors";
5
6
  import fs from "node:fs/promises";
6
7
  import { VFile } from "vfile";
7
- import {
8
- getRehypePlugins,
9
- getRemarkPlugins,
10
- recmaInjectImportMetaEnvPlugin,
11
- rehypeApplyFrontmatterExport
12
- } from "./plugins.js";
13
- import { getFileInfo, handleExtendsNotSupported, parseFrontmatter } from "./utils.js";
8
+ import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
9
+ import { getFileInfo, parseFrontmatter } from "./utils.js";
14
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";
15
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";
16
- function mdx(mdxOptions = {}) {
12
+ function mdx(partialMdxOptions = {}) {
17
13
  return {
18
14
  name: "@astrojs/mdx",
19
15
  hooks: {
20
16
  "astro:config:setup": async ({ updateConfig, config, addPageExtension, command }) => {
21
- var _a, _b;
22
17
  addPageExtension(".mdx");
23
- mdxOptions.extendPlugins ?? (mdxOptions.extendPlugins = "markdown");
24
- handleExtendsNotSupported(mdxOptions.remarkPlugins);
25
- handleExtendsNotSupported(mdxOptions.rehypePlugins);
26
- if (mdxOptions.extendPlugins === "markdown" && (((_a = config.markdown.rehypePlugins) == null ? void 0 : _a.length) || ((_b = config.markdown.remarkPlugins) == null ? void 0 : _b.length))) {
27
- console.info(
28
- blue(`[MDX] Now inheriting remark and rehype plugins from "markdown" config.`)
29
- );
30
- console.info(
31
- `If you applied a plugin to both your Markdown and MDX configs, we suggest ${bold(
32
- "removing the duplicate MDX entry."
33
- )}`
34
- );
35
- console.info(`See "extendPlugins" option to configure this behavior.`);
36
- }
37
- let remarkRehypeOptions = mdxOptions.remarkRehype;
38
- if (mdxOptions.extendPlugins === "markdown") {
39
- remarkRehypeOptions = {
40
- ...config.markdown.remarkRehype,
41
- ...remarkRehypeOptions
42
- };
43
- }
18
+ const extendMarkdownConfig = partialMdxOptions.extendMarkdownConfig ?? defaultOptions.extendMarkdownConfig;
19
+ const mdxOptions = applyDefaultOptions({
20
+ options: partialMdxOptions,
21
+ defaults: extendMarkdownConfig ? config.markdown : defaultOptions
22
+ });
44
23
  const mdxPluginOpts = {
45
24
  remarkPlugins: await getRemarkPlugins(mdxOptions, config),
46
- rehypePlugins: getRehypePlugins(mdxOptions, config),
25
+ rehypePlugins: getRehypePlugins(mdxOptions),
47
26
  recmaPlugins: mdxOptions.recmaPlugins,
27
+ remarkRehypeOptions: mdxOptions.remarkRehype,
48
28
  jsx: true,
49
29
  jsxImportSource: "astro",
50
30
  format: "mdx",
51
- mdExtensions: [],
52
- remarkRehypeOptions
31
+ mdExtensions: []
53
32
  };
54
33
  let importMetaEnv = {
55
34
  SITE: config.site
@@ -71,9 +50,9 @@ function mdx(mdxOptions = {}) {
71
50
  const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
72
51
  const compiled = await mdxCompile(new VFile({ value: pageContent, path: id }), {
73
52
  ...mdxPluginOpts,
74
- rehypePlugins: [
75
- ...mdxPluginOpts.rehypePlugins ?? [],
76
- () => rehypeApplyFrontmatterExport(frontmatter)
53
+ remarkPlugins: [
54
+ toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
55
+ ...mdxPluginOpts.remarkPlugins ?? []
77
56
  ],
78
57
  recmaPlugins: [
79
58
  ...mdxPluginOpts.recmaPlugins ?? [],
@@ -147,6 +126,29 @@ if (import.meta.hot) {
147
126
  }
148
127
  };
149
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
+ remarkPlugins: options.remarkPlugins ?? defaults.remarkPlugins,
148
+ rehypePlugins: options.rehypePlugins ?? defaults.rehypePlugins,
149
+ shikiConfig: options.shikiConfig ?? defaults.shikiConfig
150
+ };
151
+ }
150
152
  function escapeViteEnvReferences(code) {
151
153
  return code.replace(/import\.meta\.env/g, "import\\u002Emeta.env");
152
154
  }
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'];