88[ ![ Backers] [ backers-badge ]] [ collective ]
99[ ![ Chat] [ chat-badge ]] [ chat ]
1010
11- [ mdast] [ ] extensions to parse and serialize [ MDX] [ ] ESM import/exports.
11+ [ mdast] [ ] extensions to parse and serialize [ MDX] [ ] ESM ( import/exports) .
1212
1313## Contents
1414
1919* [ API] ( #api )
2020 * [ ` mdxjsEsmFromMarkdown ` ] ( #mdxjsesmfrommarkdown )
2121 * [ ` mdxjsEsmToMarkdown ` ] ( #mdxjsesmtomarkdown )
22+ * [ ` MdxjsEsm ` ] ( #mdxjsesm )
23+ * [ HTML] ( #html )
24+ * [ Syntax] ( #syntax )
2225* [ Syntax tree] ( #syntax-tree )
2326 * [ Nodes] ( #nodes )
2427 * [ Content model] ( #content-model )
3033
3134## What is this?
3235
33- This package contains extensions that add support for the ESM syntax enabled
34- by MDX to [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
35- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
36+ This package contains two extensions that add support for MDX ESM syntax in
37+ markdown to [ mdast] [ ] .
38+ These extensions plug into
39+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] (to support parsing
40+ ESM in markdown into a syntax tree) and
41+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (to support serializing
42+ ESM in syntax trees to markdown).
3643
3744## When to use this
3845
39- These tools are all rather low-level.
40- In most cases, you’d want to use [ ` remark-mdx ` ] [ remark-mdx ] with remark instead.
46+ You can use these extensions when you are working with
47+ ` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
48+
49+ When working with ` mdast-util-from-markdown ` , you must combine this package
50+ with [ ` micromark-extension-mdxjs-esm ` ] [ extension ] .
4151
4252When you are working with syntax trees and want all of MDX, use
4353[ ` mdast-util-mdx ` ] [ mdast-util-mdx ] instead.
4454
45- When working with ` mdast-util-from-markdown ` , you must combine this package with
46- [ ` micromark-extension-mdxjs-esm ` ] [ extension ] .
55+ All these packages are used in [ ` remark-mdx ` ] [ remark-mdx ] , which
56+ focusses on making it easier to transform content by abstracting these
57+ internals away.
4758
4859## Install
4960
5061This package is [ ESM only] [ esm ] .
51- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
62+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
5263
5364``` sh
5465npm install mdast-util-mdxjs-esm
161172
162173## API
163174
164- This package exports the identifiers ` mdxjsEsmFromMarkdown ` and
165- ` mdxjsEsmToMarkdown ` .
175+ This package exports the identifiers
176+ [ ` mdxjsEsmFromMarkdown ` ] [ api-mdxjs-esm-from-markdown ] and
177+ [ ` mdxjsEsmToMarkdown ` ] [ api-mdxjs-esm-to-markdown ] .
166178There is no default export.
167179
168180### ` mdxjsEsmFromMarkdown `
169181
170- Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
182+ Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] to enable
183+ MDX ESM.
171184
172- When using the [ syntax extension with ` addResult ` ] [ extension ] , nodes will have
173- a ` data.estree ` field set to an [ ESTree] [ ] .
185+ When using the [ micromark syntax extension] [ extension ] with ` addResult ` , nodes
186+ will have a ` data.estree ` field set to an ESTree [ ` Program ` ] [ program ] node .
174187
175188### ` mdxjsEsmToMarkdown `
176189
177- Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
190+ Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] to enable MDX
191+ ESM.
192+
193+ ### ` MdxjsEsm `
194+
195+ MDX ESM (import/export) node (TypeScript type).
196+
197+ ###### Type
198+
199+ ``` ts
200+ import type {Literal } from ' mdast'
201+ import type {Program } from ' estree-jsx'
202+
203+ interface MdxjsEsm extends Literal {
204+ type: ' mdxjsEsm'
205+ data? : {estree? : Program | null | undefined }
206+ }
207+ ```
208+
209+ ## HTML
210+
211+ MDX ESM has no representation in HTML.
212+ Though, when you are dealing with MDX, you will likely go * through* hast.
213+ You can enable passing MDX ESM through to hast by configuring
214+ [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ] with ` passThrough: ['mdxjsEsm'] ` .
215+
216+ ## Syntax
217+
218+ See [ Syntax in ` micromark-extension-mdxjs-esm ` ] [ syntax ] .
178219
179220## Syntax tree
180221
181222The following interfaces are added to ** [ mdast] [ ] ** by this utility.
182223
183224### Nodes
184225
185- #### ` MDXJSEsm `
226+ #### ` MdxjsEsm `
186227
187228``` idl
188- interface MDXJSEsm <: Literal {
229+ interface MdxjsEsm <: Literal {
189230 type: "mdxjsEsm"
190231}
191232```
192233
193- ** MDXJSEsm ** (** [ Literal] [ dfn-literal ] ** ) represents ESM import/exports embedded
194- in MDX.
234+ ** MdxjsEsm ** (** [ Literal] [ dfn-literal ] ** ) represents ESM import/exports
235+ embedded in MDX.
195236It can be used where ** [ flow] [ dfn-flow-content ] ** content is expected.
196237Its content is represented by its ` value ` field.
197238
@@ -215,7 +256,7 @@ Yields:
215256#### ` FlowContent ` (MDX.js ESM)
216257
217258``` idl
218- type FlowContentMdxjsEsm = MDXJSEsm | FlowContent
259+ type FlowContentMdxjsEsm = MdxjsEsm | FlowContent
219260```
220261
221262Note that when ESM is present, it can only exist as top-level content: if it has
@@ -224,9 +265,9 @@ a *[parent][dfn-parent]*, that parent must be **[Root][dfn-root]**.
224265## Types
225266
226267This package is fully typed with [ TypeScript] [ ] .
227- It exports the additional type ` MdxjsEsm ` .
268+ It exports the additional type [ ` MdxjsEsm ` ] [ api-mdxjs-esm ] .
228269
229- It also registers the node types with ` @types/mdast ` .
270+ It also registers the node type with ` @types/mdast ` .
230271If you’re working with the syntax tree, make sure to import this utility
231272somewhere in your types, as that registers the new node types in the tree.
232273
@@ -249,7 +290,7 @@ visit(tree, (node) => {
249290
250291Projects maintained by the unified collective are compatible with all maintained
251292versions of Node.js.
252- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
293+ As of now, that is Node.js 14.14+ and 16.0+.
253294Our projects sometimes work with older versions, but this is not guaranteed.
254295
255296This plugin works with ` mdast-util-from-markdown ` version 1+ and
@@ -328,6 +369,8 @@ abide by its terms.
328369
329370[ mdast ] : https://github.com/syntax-tree/mdast
330371
372+ [ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
373+
331374[ mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
332375
333376[ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
@@ -336,7 +379,9 @@ abide by its terms.
336379
337380[ extension ] : https://github.com/micromark/micromark-extension-mdxjs-esm
338381
339- [ estree ] : https://github.com/estree/estree
382+ [ syntax ] : https://github.com/micromark/micromark-extension-mdxjs-esm#syntax
383+
384+ [ program ] : https://github.com/estree/estree/blob/master/es2015.md#programs
340385
341386[ dfn-literal ] : https://github.com/syntax-tree/mdast#literal
342387
@@ -349,3 +394,9 @@ abide by its terms.
349394[ remark-mdx ] : https://mdxjs.com/packages/remark-mdx/
350395
351396[ mdx ] : https://mdxjs.com
397+
398+ [ api-mdxjs-esm-from-markdown ] : #mdxjsesmfrommarkdown
399+
400+ [ api-mdxjs-esm-to-markdown ] : #mdxjsesmtomarkdown
401+
402+ [ api-mdxjs-esm ] : #mdxjsesm
0 commit comments