@@ -19,8 +19,12 @@ See [`micromark-extension-directive`][extension] for how the syntax works.
19
19
This utility handles parsing and serializing.
20
20
[ Traverse the tree] [ traversal ] to change them to whatever you please.
21
21
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.
24
28
25
29
## Install
26
30
@@ -35,24 +39,24 @@ npm install mdast-util-directive
35
39
36
40
## Use
37
41
38
- Say our script , ` example.js ` , looks as follows:
42
+ Say our module , ` example.js ` , looks as follows:
39
43
40
44
``` 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'
45
49
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"}.'
47
51
48
- var tree = fromMarkdown (doc, {
49
- extensions: [syntax ()],
50
- mdastExtensions: [directive . fromMarkdown ]
52
+ const tree = fromMarkdown (doc, {
53
+ extensions: [directive ()],
54
+ mdastExtensions: [directiveFromMarkdown ]
51
55
})
52
56
53
57
console .log (tree)
54
58
55
- var out = toMarkdown (tree, {extensions: [directive . toMarkdown ]})
59
+ const out = toMarkdown (tree, {extensions: [directiveToMarkdown ]})
56
60
57
61
console .log (out)
58
62
```
@@ -111,7 +115,7 @@ The following interfaces are added to **[mdast][]** by this utility.
111
115
112
116
``` idl
113
117
interface TextDirective <: Parent {
114
- type: " textDirective"
118
+ type: ' textDirective'
115
119
children: [PhrasingContent]
116
120
}
117
121
@@ -144,7 +148,7 @@ Yields:
144
148
145
149
``` idl
146
150
interface LeafDirective <: Parent {
147
- type: " leafDirective"
151
+ type: ' leafDirective'
148
152
children: [PhrasingContent]
149
153
}
150
154
@@ -177,7 +181,7 @@ Yields:
177
181
178
182
``` idl
179
183
interface ContainerDirective <: Parent {
180
- type: " containerDirective"
184
+ type: ' containerDirective'
181
185
children: [FlowContent]
182
186
}
183
187
0 commit comments