@@ -14,10 +14,10 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
14
14
When parsing (` from-markdown ` ), must be combined with either
15
15
[ ` micromark-extension-mdx ` ] [ mdx ] or [ ` micromark-extension-mdxjs ` ] [ mdxjs ] .
16
16
17
- You might instead want to use this package through [ ` remark-mdx ` ] [ remark-mdx ]
18
- with ** [ remark] [ ] ** .
17
+ ## When to use this
19
18
20
- Alternatively, the extensions can be used separately:
19
+ Use this if you’re dealing with the AST manually and want to support all of MDX.
20
+ You can also use the extensions separately:
21
21
22
22
* [ ` mdast-util-mdx-expression ` ] ( https://github.com/syntax-tree/mdast-util-mdx-expression )
23
23
— support MDX (or MDX.js) expressions
@@ -62,22 +62,22 @@ Which you can also put inline: {1+1}.
62
62
And our script, ` example.js ` , looks as follows:
63
63
64
64
``` js
65
- var fs = require ( ' fs' )
66
- var fromMarkdown = require ( ' mdast-util-from-markdown' )
67
- var toMarkdown = require ( ' mdast-util-to-markdown' )
68
- var syntax = require ( ' micromark-extension-mdxjs' )
69
- var mdx = require ( ' mdast-util-mdx' )
65
+ import fs from ' node: fs'
66
+ import { fromMarkdown } from ' mdast-util-from-markdown'
67
+ import { toMarkdown } from ' mdast-util-to-markdown'
68
+ import { mdxjs } from ' micromark-extension-mdxjs'
69
+ import { mdxFromMarkdown , mdxToMarkdown } from ' mdast-util-mdx'
70
70
71
- var doc = fs .readFileSync (' example.mdx' )
71
+ const doc = fs .readFileSync (' example.mdx' )
72
72
73
- var tree = fromMarkdown (doc, {
74
- extensions: [syntax ()],
75
- mdastExtensions: [mdx . fromMarkdown ]
73
+ const tree = fromMarkdown (doc, {
74
+ extensions: [mdxjs ()],
75
+ mdastExtensions: [mdxFromMarkdown ]
76
76
})
77
77
78
78
console .log (tree)
79
79
80
- var out = toMarkdown (tree, {extensions: [mdx . toMarkdown ]})
80
+ const out = toMarkdown (tree, {extensions: [mdxToMarkdown ]})
81
81
82
82
console .log (out)
83
83
```
0 commit comments