@@ -13,8 +13,12 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
13
13
When parsing (` from-markdown ` ), must be combined with
14
14
[ ` micromark-extension-math ` ] [ extension ] .
15
15
16
- You probably shouldn’t use this package directly, but instead use
17
- [ ` remark-math ` ] [ remark-math ] with ** [ remark] [ ] ** .
16
+ ## When to use this
17
+
18
+ Use this if you’re dealing with the AST manually.
19
+ It might be better to use [ ` remark-math ` ] [ remark-math ] with ** [ remark] [ ] ** ,
20
+ which includes this but provides a nicer interface and makes it easier to
21
+ combine with hundreds of plugins.
18
22
19
23
## Install
20
24
42
46
And our script, ` example.js ` , looks as follows:
43
47
44
48
``` js
45
- var fs = require ( ' fs' )
46
- var fromMarkdown = require ( ' mdast-util-from-markdown' )
47
- var toMarkdown = require ( ' mdast-util-to-markdown' )
48
- var syntax = require ( ' micromark-extension-math' )
49
- var math = require ( ' mdast-util-math' )
49
+ import fs from ' fs'
50
+ import { fromMarkdown } from ' mdast-util-from-markdown'
51
+ import { toMarkdown } from ' mdast-util-to-markdown'
52
+ import { math } from ' micromark-extension-math'
53
+ import { mathFromMarkdown , mathToMarkdown } from ' mdast-util-math'
50
54
51
- var doc = fs .readFileSync (' example.md' )
55
+ const doc = fs .readFileSync (' example.md' )
52
56
53
- var tree = fromMarkdown (doc, {
54
- extensions: [syntax ],
55
- mdastExtensions: [math . fromMarkdown ]
57
+ const tree = fromMarkdown (doc, {
58
+ extensions: [math ],
59
+ mdastExtensions: [mathFromMarkdown ]
56
60
})
57
61
58
62
console .log (tree)
59
63
60
- var out = toMarkdown (tree, {extensions: [math . toMarkdown ]})
64
+ const out = toMarkdown (tree, {extensions: [mathToMarkdown ]})
61
65
62
66
console .log (out)
63
67
```
0 commit comments