@@ -13,8 +13,12 @@ Extension for [`mdast-util-from-markdown`][from-markdown] and/or
1313When parsing (` from-markdown ` ), must be combined with
1414[ ` micromark-extension-math ` ] [ extension ] .
1515
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.
1822
1923## Install
2024
4246And our script, ` example.js ` , looks as follows:
4347
4448``` 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'
5054
51- var doc = fs .readFileSync (' example.md' )
55+ const doc = fs .readFileSync (' example.md' )
5256
53- var tree = fromMarkdown (doc, {
54- extensions: [syntax ],
55- mdastExtensions: [math . fromMarkdown ]
57+ const tree = fromMarkdown (doc, {
58+ extensions: [math ],
59+ mdastExtensions: [mathFromMarkdown ]
5660})
5761
5862console .log (tree)
5963
60- var out = toMarkdown (tree, {extensions: [math . toMarkdown ]})
64+ const out = toMarkdown (tree, {extensions: [mathToMarkdown ]})
6165
6266console .log (out)
6367```
0 commit comments