@@ -19,8 +19,12 @@ See [`micromark-extension-directive`][extension] for how the syntax works.
1919This utility handles parsing and serializing.
2020[ Traverse the tree] [ traversal ] to change them to whatever you please.
2121
22- You probably shouldn’t use this package directly, but instead use
23- [ ` remark-directive ` ] [ plugin ] with ** [ remark] [ ] **
22+ ## When to use this
23+
24+ Use this if you’re dealing with the AST manually.
25+ It might be better to use [ ` remark-directive ` ] [ plugin ] with ** [ remark] [ ] ** ,
26+ which includes this but provides a nicer interface and makes it easier to
27+ combine with hundreds of plugins.
2428
2529## Install
2630
@@ -35,24 +39,24 @@ npm install mdast-util-directive
3539
3640## Use
3741
38- Say our script , ` example.js ` , looks as follows:
42+ Say our module , ` example.js ` , looks as follows:
3943
4044``` js
41- var fromMarkdown = require ( ' mdast-util-from-markdown' )
42- var toMarkdown = require ( ' mdast-util-to-markdown' )
43- var syntax = require ( ' micromark-extension-directive' )
44- var directive = require ( ' mdast-util-directive' )
45+ import { fromMarkdown } from ' mdast-util-from-markdown'
46+ import { toMarkdown } from ' mdast-util-to-markdown'
47+ import { directive } from ' micromark-extension-directive'
48+ import { directiveFromMarkdown , directiveToMarkdown } from ' mdast-util-directive'
4549
46- var doc = ' A lovely language know as :abbr[HTML]{title="HyperText Markup Language"}.'
50+ const doc = ' A lovely language know as :abbr[HTML]{title="HyperText Markup Language"}.'
4751
48- var tree = fromMarkdown (doc, {
49- extensions: [syntax ()],
50- mdastExtensions: [directive . fromMarkdown ]
52+ const tree = fromMarkdown (doc, {
53+ extensions: [directive ()],
54+ mdastExtensions: [directiveFromMarkdown ]
5155})
5256
5357console .log (tree)
5458
55- var out = toMarkdown (tree, {extensions: [directive . toMarkdown ]})
59+ const out = toMarkdown (tree, {extensions: [directiveToMarkdown ]})
5660
5761console .log (out)
5862```
@@ -111,7 +115,7 @@ The following interfaces are added to **[mdast][]** by this utility.
111115
112116``` idl
113117interface TextDirective <: Parent {
114- type: " textDirective"
118+ type: ' textDirective'
115119 children: [PhrasingContent]
116120}
117121
@@ -144,7 +148,7 @@ Yields:
144148
145149``` idl
146150interface LeafDirective <: Parent {
147- type: " leafDirective"
151+ type: ' leafDirective'
148152 children: [PhrasingContent]
149153}
150154
@@ -177,7 +181,7 @@ Yields:
177181
178182``` idl
179183interface ContainerDirective <: Parent {
180- type: " containerDirective"
184+ type: ' containerDirective'
181185 children: [FlowContent]
182186}
183187
0 commit comments