@@ -21,10 +21,15 @@ such).
21
21
* [ API] ( #api )
22
22
* [ ` directiveFromMarkdown ` ] ( #directivefrommarkdown )
23
23
* [ ` directiveToMarkdown ` ] ( #directivetomarkdown )
24
+ * [ ` ContainerDirective ` ] ( #containerdirective )
25
+ * [ ` Directive ` ] ( #directive )
26
+ * [ ` LeafDirective ` ] ( #leafdirective )
27
+ * [ ` TextDirective ` ] ( #textdirective )
28
+ * [ HTML] ( #html )
29
+ * [ Syntax] ( #syntax )
24
30
* [ Syntax tree] ( #syntax-tree )
25
31
* [ Nodes] ( #nodes )
26
32
* [ Mixin] ( #mixin )
27
- * [ ` Directive ` ] ( #directive )
28
33
* [ Types] ( #types )
29
34
* [ Compatibility] ( #compatibility )
30
35
* [ Related] ( #related )
@@ -33,23 +38,18 @@ such).
33
38
34
39
## What is this?
35
40
36
- This package contains extensions that add support for generic directives to
37
- [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
38
- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
39
-
40
- This package handles the syntax tree.
41
- You can use this with some more code to match your specific needs, to allow for
42
- anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
43
- [ Traverse the tree] [ traversal ] to change directives to whatever you please.
41
+ This package contains two extensions that add support for directive syntax in
42
+ markdown to [ mdast] [ ] .
43
+ These extensions plug into
44
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] (to support parsing
45
+ directives in markdown into a syntax tree) and
46
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (to support serializing
47
+ directives in syntax trees to markdown).
44
48
45
49
## When to use this
46
50
47
- These tools are all rather low-level.
48
- In most cases, you’d want to use [ ` remark-directive ` ] [ remark-directive ] with
49
- remark instead.
50
-
51
51
Directives are one of the four ways to extend markdown: an arbitrary extension
52
- syntax (see [ Extending markdown] [ extending-mmarkdown ] in micromark’s docs for
52
+ syntax (see [ Extending markdown] [ extending-markdown ] in micromark’s docs for
53
53
the alternatives and more info).
54
54
This mechanism works well when you control the content: who authors it, what
55
55
tools handle it, and where it’s displayed.
@@ -60,17 +60,29 @@ handle it, and where it ends up.
60
60
Example use cases are a docs website for a project or product, or blogging tools
61
61
and static site generators.
62
62
63
- When working with ` mdast-util-from-markdown ` , you must combine this package with
64
- [ ` micromark-extension-directive ` ] [ extension ] .
63
+ You can use these extensions when you are working with
64
+ ` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
65
+
66
+ When working with ` mdast-util-from-markdown ` , you must combine this package
67
+ with [ ` micromark-extension-directive ` ] [ extension ] .
65
68
66
- This utility does not handle how directives are turned to HTML.
67
- You must [ traverse the tree] [ traversal ] to change directives to whatever you
68
- please.
69
+ When you don’t need a syntax tree, you can use [ ` micromark ` ] [ micromark ]
70
+ directly with ` micromark-extension-directive ` .
71
+
72
+ All these packages are used [ ` remark-directive ` ] [ remark-directive ] , which
73
+ focusses on making it easier to transform content by abstracting these
74
+ internals away.
75
+
76
+ This package only handles the syntax tree.
77
+ For example, it does not handle how markdown is turned to HTML.
78
+ You can use this with some more code to match your specific needs, to allow for
79
+ anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
80
+ [ Traverse the tree] [ traversal ] to change directives to whatever you please.
69
81
70
82
## Install
71
83
72
84
This package is [ ESM only] [ esm ] .
73
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
85
+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
74
86
75
87
``` sh
76
88
npm install mdast-util-directive
@@ -150,21 +162,99 @@ A lovely language know as :abbr[HTML]{title="HyperText Markup Language"}.
150
162
151
163
## API
152
164
153
- This package exports the identifiers ` directiveFromMarkdown ` and
154
- ` directiveToMarkdown ` .
165
+ This package exports the identifiers
166
+ [ ` directiveFromMarkdown ` ] [ api-directivefrommarkdown ] and
167
+ [ ` directiveToMarkdown ` ] [ api-directivetomarkdown ] .
155
168
There is no default export.
156
169
157
170
### ` directiveFromMarkdown `
158
171
159
- Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
172
+ Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] to enable
173
+ directives ([ ` FromMarkdownExtension ` ] [ frommarkdownextension ] ).
160
174
161
175
### ` directiveToMarkdown `
162
176
163
- Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
177
+ Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] to enable
178
+ directives ([ ` ToMarkdownExtension ` ] [ tomarkdownextension ] ).
164
179
165
180
There are no options, but passing [ ` options.quote ` ] [ quote ] to
166
181
` mdast-util-to-markdown ` is honored for attributes.
167
182
183
+ ### ` ContainerDirective `
184
+
185
+ Directive in flow content (such as in the root document, or block quotes),
186
+ which contains further flow content (TypeScript type).
187
+
188
+ ###### Type
189
+
190
+ ``` ts
191
+ import type {BlockContent , DefinitionContent , Parent } from ' mdast'
192
+
193
+ interface ContainerDirective extends Parent {
194
+ type: ' containerDirective'
195
+ name: string
196
+ attributes? : Record <string , string | null | undefined > | null | undefined
197
+ children: Array <BlockContent | DefinitionContent >
198
+ }
199
+ ```
200
+
201
+ ### ` Directive `
202
+
203
+ The different directive nodes (TypeScript type).
204
+
205
+ ###### Type
206
+
207
+ ``` ts
208
+ type Directive = ContainerDirective | LeafDirective | TextDirective
209
+ ` ` `
210
+
211
+ ### ` LeafDirective `
212
+
213
+ Directive in flow content (such as in the root document, or block quotes),
214
+ which contains nothing (TypeScript type).
215
+
216
+ ###### Type
217
+
218
+ ` ` ` ts
219
+ import type {PhrasingContent , Parent } from ' mdast'
220
+
221
+ interface LeafDirective extends Parent {
222
+ type: ' leafDirective'
223
+ name: string
224
+ attributes? : Record <string , string | null | undefined > | null | undefined
225
+ children: Array <PhrasingContent >
226
+ }
227
+ ```
228
+
229
+ ### ` TextDirective `
230
+
231
+ Directive in phrasing content (such as in paragraphs, headings) (TypeScript
232
+ type).
233
+
234
+ ###### Type
235
+
236
+ ``` ts
237
+ import type {PhrasingContent , Parent } from ' mdast'
238
+
239
+ interface TextDirective extends Parent {
240
+ type: ' textDirective'
241
+ name: string
242
+ attributes? : Record <string , string | null | undefined > | null | undefined
243
+ children: Array <PhrasingContent >
244
+ }
245
+ ```
246
+
247
+ ## HTML
248
+
249
+ This utility does not handle how markdown is turned to HTML.
250
+ You can use this with some more code to match your specific needs, to allow for
251
+ anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
252
+ [ Traverse the tree] [ traversal ] to change directives to whatever you please.
253
+
254
+ ## Syntax
255
+
256
+ See [ Syntax in ` micromark-extension-directive ` ] [ syntax ] .
257
+
168
258
## Syntax tree
169
259
170
260
The following interfaces are added to ** [ mdast] [ ] ** by this utility.
@@ -287,7 +377,7 @@ Yields:
287
377
288
378
### Mixin
289
379
290
- ### ` Directive `
380
+ #### ` Directive `
291
381
292
382
``` idl
293
383
interface mixin Directive {
@@ -319,8 +409,9 @@ or hast).
319
409
## Types
320
410
321
411
This package is fully typed with [ TypeScript] [ ] .
322
- It exports the additional types ` ContainerDirective ` , ` LeafDirective ` ,
323
- ` TextDirective ` , and ` Directive ` .
412
+ It exports the additional types [ ` ContainerDirective ` ] [ api-containerdirective ] ,
413
+ [ ` Directive ` ] [ api-directive ] , [ ` LeafDirective ` ] [ api-leafdirective ] , and
414
+ [ ` TextDirective ` ] [ api-textdirective ] .
324
415
325
416
It also registers the node types with ` @types/mdast ` .
326
417
If you’re working with the syntax tree, make sure to import this utility
@@ -345,7 +436,7 @@ visit(tree, (node) => {
345
436
346
437
Projects maintained by the unified collective are compatible with all maintained
347
438
versions of Node.js.
348
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
439
+ As of now, that is Node.js 14.14+ and 16.0+.
349
440
Our projects sometimes work with older versions, but this is not guaranteed.
350
441
351
442
This plugin works with ` mdast-util-from-markdown ` version 1+ and
@@ -428,11 +519,15 @@ abide by its terms.
428
519
429
520
[ quote ] : https://github.com/syntax-tree/mdast-util-to-markdown#optionsquote
430
521
522
+ [ micromark ] : https://github.com/micromark/micromark
523
+
431
524
[ extension ] : https://github.com/micromark/micromark-extension-directive
432
525
526
+ [ syntax ] : https://github.com/micromark/micromark-extension-directive#syntax
527
+
433
528
[ remark-directive ] : https://github.com/remarkjs/remark-directive
434
529
435
- [ extending-mmarkdown ] : https://github.com/micromark/micromark#extending-markdown
530
+ [ extending-markdown ] : https://github.com/micromark/micromark#extending-markdown
436
531
437
532
[ prop ] : https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
438
533
@@ -444,4 +539,20 @@ abide by its terms.
444
539
445
540
[ dfn-phrasing-content ] : https://github.com/syntax-tree/mdast#phrasingcontent
446
541
447
- [ dfn-mxn-directive ] : #directive
542
+ [ frommarkdownextension ] : https://github.com/syntax-tree/mdast-util-from-markdown#extension
543
+
544
+ [ tomarkdownextension ] : https://github.com/syntax-tree/mdast-util-to-markdown#options
545
+
546
+ [ api-directivefrommarkdown ] : #directivefrommarkdown
547
+
548
+ [ api-directivetomarkdown ] : #directivetomarkdown
549
+
550
+ [ api-containerdirective ] : #containerdirective
551
+
552
+ [ api-directive ] : #directive
553
+
554
+ [ api-leafdirective ] : #leafdirective
555
+
556
+ [ api-textdirective ] : #textdirective
557
+
558
+ [ dfn-mxn-directive ] : #directive-1
0 commit comments