@astrojs/mdx 2.0.2 → 2.0.3

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.
Files changed (2) hide show
  1. package/README.md +21 -241
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -2,257 +2,37 @@
2
2
 
3
3
  This **[Astro integration][astro-integration]** enables the usage of [MDX](https://mdxjs.com/) components and allows you to create pages as `.mdx` files.
4
4
 
5
- - <strong>[Why MDX?](#why-mdx)</strong>
6
- - <strong>[Installation](#installation)</strong>
7
- - <strong>[Usage](#usage)</strong>
8
- - <strong>[Configuration](#configuration)</strong>
9
- - <strong>[Examples](#examples)</strong>
10
- - <strong>[Troubleshooting](#troubleshooting)</strong>
11
- - <strong>[Contributing](#contributing)</strong>
12
- - <strong>[Changelog](#changelog)</strong>
5
+ ## Documentation
13
6
 
14
- ## Why MDX?
7
+ Read the [`@astrojs/mdx` docs][docs]
15
8
 
16
- MDX allows you to [use variables, JSX expressions and components within Markdown content](https://docs.astro.build/en/guides/markdown-content/#mdx-only-features) in Astro. If you have existing content authored in MDX, this integration allows you to bring those files to your Astro project.
9
+ ## Support
17
10
 
18
- ## Installation
11
+ - Get help in the [Astro Discord][discord]. Post questions in our `#support` forum, or visit our dedicated `#dev` channel to discuss current development and more!
19
12
 
20
- ### Quick Install
13
+ - Check our [Astro Integration Documentation][astro-integration] for more on integrations.
21
14
 
22
- The `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one.
15
+ - Submit bug reports and feature requests as [GitHub issues][issues].
23
16
 
24
- ```sh
25
- # Using NPM
26
- npx astro add mdx
27
- # Using Yarn
28
- yarn astro add mdx
29
- # Using PNPM
30
- pnpm astro add mdx
31
- ```
32
-
33
- If you run into any issues, [feel free to report them to us on GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below.
34
-
35
- ### Manual Install
36
-
37
- First, install the `@astrojs/mdx` package using your package manager. If you're using npm or aren't sure, run this in the terminal:
38
-
39
- ```sh
40
- npm install @astrojs/mdx
41
- ```
42
-
43
- Then, apply this integration to your `astro.config.*` file using the `integrations` property:
44
-
45
- ```diff lang="js" "mdx()"
46
- // astro.config.mjs
47
- import { defineConfig } from 'astro/config';
48
- + import mdx from '@astrojs/mdx';
49
-
50
- export default defineConfig({
51
- // ...
52
- integrations: [mdx()],
53
- // ^^^^^
54
- });
55
- ```
56
-
57
- ### Editor Integration
58
-
59
- For editor support in [VS Code](https://code.visualstudio.com/), install the [official MDX extension](https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx).
60
-
61
- For other editors, use the [MDX language server](https://github.com/mdx-js/mdx-analyzer/tree/main/packages/language-server).
62
-
63
- ## Usage
64
-
65
- 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.
66
-
67
- 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).
68
-
69
- See how MDX works in Astro with examples in our [Markdown & MDX guide](https://docs.astro.build/en/guides/markdown-content/).
70
-
71
- Visit the [MDX docs](https://mdxjs.com/docs/what-is-mdx/) to learn about using standard MDX features.
72
-
73
- ## Configuration
74
-
75
- Once the MDX integration is installed, no configuration is necessary to use `.mdx` files in your Astro project.
76
-
77
- You can configure how your MDX is rendered with the following options:
78
-
79
- - [Options inherited from Markdown config](#options-inherited-from-markdown-config)
80
- - [`extendMarkdownConfig`](#extendmarkdownconfig)
81
- - [`recmaPlugins`](#recmaplugins)
82
- - [`optimize`](#optimize)
83
-
84
- ### Options inherited from Markdown config
85
-
86
- All [`markdown` configuration options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) 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).
87
-
88
- ```js
89
- // astro.config.mjs
90
- import { defineConfig } from 'astro/config';
91
- import mdx from '@astrojs/mdx';
92
- import remarkToc from 'remark-toc';
93
- import rehypeMinifyHtml from 'rehype-minify-html';
94
-
95
- export default defineConfig({
96
- integrations: [
97
- mdx({
98
- syntaxHighlight: 'shiki',
99
- shikiConfig: { theme: 'dracula' },
100
- remarkPlugins: [remarkToc],
101
- rehypePlugins: [rehypeMinifyHtml],
102
- remarkRehype: { footnoteLabel: 'Footnotes' },
103
- gfm: false,
104
- }),
105
- ],
106
- });
107
- ```
108
-
109
- :::caution
110
- MDX does not support passing remark and rehype plugins as a string. You should install, import, and apply the plugin function instead.
111
- :::
112
-
113
- 📚 See the [Markdown Options reference](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) for a complete list of options.
114
-
115
- ### `extendMarkdownConfig`
116
-
117
- - **Type:** `boolean`
118
- - **Default:** `true`
119
-
120
- 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.
121
-
122
- 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:
123
-
124
- ```js
125
- // astro.config.mjs
126
- import { defineConfig } from 'astro/config';
127
- import mdx from '@astrojs/mdx';
128
-
129
- export default defineConfig({
130
- markdown: {
131
- syntaxHighlight: 'prism',
132
- remarkPlugins: [remarkPlugin1],
133
- gfm: true,
134
- },
135
- integrations: [
136
- mdx({
137
- // `syntaxHighlight` inherited from Markdown
138
-
139
- // Markdown `remarkPlugins` ignored,
140
- // only `remarkPlugin2` applied.
141
- remarkPlugins: [remarkPlugin2],
142
- // `gfm` overridden to `false`
143
- gfm: false,
144
- }),
145
- ],
146
- });
147
- ```
148
-
149
- You may also need to disable `markdown` config extension in MDX. For this, set `extendMarkdownConfig` to `false`:
150
-
151
- ```js
152
- // astro.config.mjs
153
- import { defineConfig } from 'astro/config';
154
- import mdx from '@astrojs/mdx';
155
-
156
- export default defineConfig({
157
- markdown: {
158
- remarkPlugins: [remarkPlugin1],
159
- },
160
- integrations: [
161
- mdx({
162
- // Markdown config now ignored
163
- extendMarkdownConfig: false,
164
- // No `remarkPlugins` applied
165
- }),
166
- ],
167
- });
168
- ```
169
-
170
- ### `recmaPlugins`
171
-
172
- These are plugins that modify the output [estree](https://github.com/estree/estree) directly. This is useful for modifying or injecting JavaScript variables in your MDX files.
173
-
174
- 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.
175
-
176
- ### `optimize`
177
-
178
- - **Type:** `boolean | { customComponentNames?: string[] }`
179
-
180
- This is an optional configuration setting to optimize the MDX output for faster builds and rendering via an internal rehype plugin. This may be useful if you have many MDX files and notice slow builds. However, this option may generate some unescaped HTML, so make sure your site's interactive parts still work correctly after enabling it.
181
-
182
- This is disabled by default. To enable MDX optimization, add the following to your MDX integration configuration:
183
-
184
- ```js
185
- // astro.config.mjs
186
- import { defineConfig } from 'astro/config';
187
- import mdx from '@astrojs/mdx';
188
-
189
- export default defineConfig({
190
- integrations: [
191
- mdx({
192
- optimize: true,
193
- }),
194
- ],
195
- });
196
- ```
197
-
198
- #### `customComponentNames`
199
-
200
- - **Type:** `string[]`
201
-
202
- An optional property of `optimize` to prevent the MDX optimizer from handling any [custom components passed to imported MDX content via the components prop](https://docs.astro.build/en/guides/markdown-content/#custom-components-with-imported-mdx).
203
-
204
- You will need to exclude these components from optimization as the optimizer eagerly converts content into a static string, which will break custom components that needs to be dynamically rendered.
205
-
206
- For example, the intended MDX output of the following is `<Heading>...</Heading>` in place of every `"<h1>...</h1>"`:
207
-
208
- ```astro
209
- ---
210
- import { Content, components } from '../content.mdx';
211
- import Heading from '../Heading.astro';
212
- ---
213
-
214
- <Content components={{ ...components, h1: Heading }} />
215
- ```
216
-
217
- To configure optimization for this using the `customComponentNames` property, specify an array of HTML element names that should be treated as custom components:
218
-
219
- ```js
220
- // astro.config.mjs
221
- import { defineConfig } from 'astro/config';
222
- import mdx from '@astrojs/mdx';
223
-
224
- export default defineConfig({
225
- integrations: [
226
- mdx({
227
- optimize: {
228
- // Prevent the optimizer from handling `h1` elements
229
- // These will be treated as custom components
230
- customComponentNames: ['h1'],
231
- },
232
- }),
233
- ],
234
- });
235
- ```
236
-
237
- Note that if your MDX file [configures custom components using `export const components = { ... }`](https://docs.astro.build/en/guides/markdown-content/#assigning-custom-components-to-html-elements), then you do not need to manually configure this option. The optimizer will automatically detect them.
238
-
239
- ## Examples
240
-
241
- - 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.
242
-
243
- ## Troubleshooting
244
-
245
- For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help!
17
+ ## Contributing
246
18
 
247
- You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
19
+ This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! These links will help you get started:
248
20
 
249
- ## Contributing
21
+ - [Contributor Manual][contributing]
22
+ - [Code of Conduct][coc]
23
+ - [Community Guide][community]
250
24
 
251
- This package is maintained by Astro's Core team. You're welcome to submit an issue or PR!
25
+ ## License
252
26
 
253
- ## Changelog
27
+ MIT
254
28
 
255
- See [CHANGELOG.md](https://github.com/withastro/astro/tree/main/packages/integrations/mdx/CHANGELOG.md) for a history of changes to this integration.
29
+ Copyright (c) 2023–present [Astro][astro]
256
30
 
31
+ [astro]: https://astro.build/
32
+ [docs]: https://docs.astro.build/en/guides/integrations-guide/mdx/
33
+ [contributing]: https://github.com/withastro/astro/blob/main/CONTRIBUTING.md
34
+ [coc]: https://github.com/withastro/.github/blob/main/CODE_OF_CONDUCT.md
35
+ [community]: https://github.com/withastro/.github/blob/main/COMMUNITY_GUIDE.md
36
+ [discord]: https://astro.build/chat/
37
+ [issues]: https://github.com/withastro/astro/issues
257
38
  [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
258
- [astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/mdx",
3
3
  "description": "Add support for MDX pages in your Astro site",
4
- "version": "2.0.2",
4
+ "version": "2.0.3",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -67,7 +67,7 @@
67
67
  "remark-toc": "^9.0.0",
68
68
  "unified": "^11.0.4",
69
69
  "vite": "^5.0.10",
70
- "astro": "4.0.7",
70
+ "astro": "4.0.8",
71
71
  "astro-scripts": "0.0.14"
72
72
  },
73
73
  "engines": {