7
7
8
8
[ mdast] [ github-mdast ] extensions to parse and serialize
9
9
[ generic directives proposal] [ commonmark-directive-proposal ]
10
- (` :cite[smith04] ` , ` ::youtube[Video of a cat in a box]{v=01ab2cd3efg} ` , and
11
- such).
10
+ (` :cite[smith04] ` ,
11
+ ` ::youtube[Video of a cat in a box]{v=01ab2cd3efg} ` ,
12
+ and such).
12
13
13
14
## Contents
14
15
48
49
49
50
## When to use this
50
51
51
- Directives are one of the four ways to extend markdown: an arbitrary extension
52
- syntax (see [ Extending markdown] [ github-micromark-extending ] in micromark’s
53
- docs for the alternatives and more info).
54
- This mechanism works well when you control the content: who authors it, what
55
- tools handle it, and where it’s displayed.
52
+ Directives are one of the four ways to extend markdown:
53
+ an arbitrary extension syntax
54
+ (see [ Extending markdown] [ github-micromark-extending ] in micromark’s docs for
55
+ the alternatives and more info).
56
+ This mechanism works well when you control the content:
57
+ who authors it,
58
+ what tools handle it,
59
+ and where it’s displayed.
56
60
When authors can read a guide on how to embed a tweet but are not expected to
57
61
know the ins and outs of HTML or JavaScript.
58
- Directives don’t work well if you don’t know who authors content, what tools
59
- handle it, and where it ends up.
60
- Example use cases are a docs website for a project or product, or blogging tools
61
- and static site generators.
62
+ Directives don’t work well if you don’t know who authors content,
63
+ what tools handle it,
64
+ and where it ends up.
65
+ Example use cases are a docs website for a project or product,
66
+ or blogging tools and static site generators.
62
67
63
68
You can use these extensions when you are working with
64
69
` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
65
70
66
- When working with ` mdast-util-from-markdown ` , you must combine this package
67
- with
71
+ When working with ` mdast-util-from-markdown ` ,
72
+ you must combine this package with
68
73
[ ` micromark-extension-directive ` ] [ github-micromark-extension-directive ] .
69
74
70
- When you don’t need a syntax tree, you can use [ ` micromark ` ] [ github-micromark ]
71
- directly with ` micromark-extension-directive ` .
75
+ When you don’t need a syntax tree,
76
+ you can use [ ` micromark ` ] [ github-micromark ] directly with
77
+ ` micromark-extension-directive ` .
72
78
73
- All these packages are used [ ` remark-directive ` ] [ github-remark-directive ] , which
74
- focusses on making it easier to transform content by abstracting these
79
+ All these packages are used [ ` remark-directive ` ] [ github-remark-directive ] ,
80
+ which focusses on making it easier to transform content by abstracting these
75
81
internals away.
76
82
77
83
This package only handles the syntax tree.
78
- For example, it does not handle how markdown is turned to HTML.
79
- You can use this with some more code to match your specific needs, to allow for
80
- anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
84
+ For example,
85
+ it does not handle how markdown is turned to HTML.
86
+ You can use this with some more code to match your specific needs,
87
+ to allow for anything from callouts,
88
+ citations,
89
+ styled blocks,
90
+ forms,
91
+ embeds,
92
+ spoilers,
93
+ etc.
81
94
[ Traverse the tree] [ unifiedjs-tree-traversal ] to change directives to whatever
82
95
you please.
83
96
84
97
## Install
85
98
86
99
This package is [ ESM only] [ github-gist-esm ] .
87
- In Node.js (version 16+), install with [ npm] [ npmjs-install ] :
100
+ In Node.js (version 16+),
101
+ install with [ npm] [ npmjs-install ] :
88
102
89
103
``` sh
90
104
npm install mdast-util-directive
@@ -199,8 +213,10 @@ Extension for `mdast-util-to-markdown` to enable directives
199
213
200
214
### ` ContainerDirective `
201
215
202
- Directive in flow content (such as in the root document, or block quotes),
203
- which contains further flow content (TypeScript type).
216
+ Directive in flow content
217
+ (such as in the root document or block quotes),
218
+ which contains further flow content
219
+ (TypeScript type).
204
220
205
221
###### Type
206
222
@@ -217,7 +233,8 @@ interface ContainerDirective extends Parent {
217
233
218
234
### ` Directives `
219
235
220
- The different directive nodes (TypeScript type).
236
+ The different directive nodes
237
+ (TypeScript type).
221
238
222
239
###### Type
223
240
@@ -227,8 +244,10 @@ type Directives = ContainerDirective | LeafDirective | TextDirective
227
244
228
245
### ` LeafDirective `
229
246
230
- Directive in flow content (such as in the root document, or block quotes),
231
- which contains nothing (TypeScript type).
247
+ Directive in flow content
248
+ (such as in the root document or block quotes),
249
+ which contains nothing
250
+ (TypeScript type).
232
251
233
252
###### Type
234
253
@@ -245,8 +264,9 @@ interface LeafDirective extends Parent {
245
264
246
265
### ` TextDirective `
247
266
248
- Directive in phrasing content (such as in paragraphs, headings) (TypeScript
249
- type).
267
+ Directive in phrasing content
268
+ (such as in paragraphs and headings)
269
+ (TypeScript type).
250
270
251
271
###### Type
252
272
@@ -288,8 +308,14 @@ Configuration.
288
308
## HTML
289
309
290
310
This utility does not handle how markdown is turned to HTML.
291
- You can use this with some more code to match your specific needs, to allow for
292
- anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
311
+ You can use this with some more code to match your specific needs,
312
+ to allow for anything from callouts,
313
+ citations,
314
+ styled blocks,
315
+ forms,
316
+ embeds,
317
+ spoilers,
318
+ etc.
293
319
[ Traverse the tree] [ unifiedjs-tree-traversal ] to change directives to whatever
294
320
you please.
295
321
@@ -322,7 +348,8 @@ Its content model is also **[phrasing][github-mdast-phrasing-content]**
322
348
content.
323
349
It includes the mixin ** [ Directive] [ syntax-tree-mixin-directive ] ** .
324
350
325
- For example, the following Markdown:
351
+ For example,
352
+ the following Markdown:
326
353
327
354
``` markdown
328
355
:name[Label]{#x.y.z key=value}
@@ -355,7 +382,8 @@ It can be used where **[flow][github-mdast-flow-content]** content is expected.
355
382
Its content model is ** [ phrasing] [ github-mdast-phrasing-content ] ** content.
356
383
It includes the mixin ** [ Directive] [ syntax-tree-mixin-directive ] ** .
357
384
358
- For example, the following Markdown:
385
+ For example,
386
+ the following Markdown:
359
387
360
388
``` markdown
361
389
::youtube[Label]{v=123}
@@ -388,10 +416,13 @@ It can be used where **[flow][github-mdast-flow-content]** content is expected.
388
416
Its content model is also ** [ flow] [ github-mdast-flow-content ] ** content.
389
417
It includes the mixin ** [ Directive] [ syntax-tree-mixin-directive ] ** .
390
418
391
- The phrasing in the label is, when available, added as a paragraph with a
392
- ` directiveLabel: true ` field, as the head of its content.
419
+ The phrasing in the label is,
420
+ when available,
421
+ added as a paragraph with a ` directiveLabel: true ` field,
422
+ as the head of its content.
393
423
394
- For example, the following Markdown:
424
+ For example,
425
+ the following Markdown:
395
426
396
427
``` markdown
397
428
:::spoiler[Open at your own peril]
@@ -442,25 +473,29 @@ The `name` field must be present and represents an identifier of an extension.
442
473
The ` attributes ` field represents information associated with the node.
443
474
The value of the ` attributes ` field implements the ** Attributes** interface.
444
475
445
- In the ** Attributes** interface, every field must be an ` AttributeName ` and
446
- every value an ` AttributeValue ` .
447
- The fields and values can be anything: there are no semantics (such as by HTML
448
- or hast).
476
+ In the ** Attributes** interface,
477
+ every field must be an ` AttributeName ` and every value an ` AttributeValue ` .
478
+ The fields and values can be anything:
479
+ there are no semantics (such as by HTML or hast).
449
480
450
- > In JSON, the value ` null ` must be treated as if the attribute was not
451
- > included.
452
- > In JavaScript, both ` null ` and ` undefined ` must be similarly ignored.
481
+ > In JSON,
482
+ > the value ` null ` must be treated as if the attribute was not included.
483
+ > In JavaScript,
484
+ > both ` null ` and ` undefined ` must be similarly ignored.
453
485
454
486
## Types
455
487
456
488
This package is fully typed with [ TypeScript] [ ] .
457
489
It exports the additional types [ ` ContainerDirective ` ] [ api-container-directive ] ,
458
- [ ` Directives ` ] [ api-directives ] , [ ` LeafDirective ` ] [ api-leaf-directive ] , and
490
+ [ ` Directives ` ] [ api-directives ] ,
491
+ [ ` LeafDirective ` ] [ api-leaf-directive ] ,
492
+ and
459
493
[ ` TextDirective ` ] [ api-text-directive ] .
460
494
461
495
It also registers the node types with ` @types/mdast ` .
462
- If you’re working with the syntax tree, make sure to import this utility
463
- somewhere in your types, as that registers the new node types in the tree.
496
+ If you’re working with the syntax tree,
497
+ make sure to import this utility somewhere in your types,
498
+ as that registers the new node types in the tree.
464
499
465
500
``` js
466
501
/**
@@ -483,9 +518,10 @@ visit(tree, function (node) {
483
518
Projects maintained by the unified collective are compatible with maintained
484
519
versions of Node.js.
485
520
486
- When we cut a new major release, we drop support for unmaintained versions of
487
- Node.
488
- This means we try to keep the current release line, ` mdast-util-directive@^3 ` ,
521
+ When we cut a new major release,
522
+ we drop support for unmaintained versions of Node.
523
+ This means we try to keep the current release line,
524
+ ` mdast-util-directive@3 ` ,
489
525
compatible with Node.js 16.
490
526
491
527
This utility works with ` mdast-util-from-markdown ` version 2+ and
@@ -507,8 +543,9 @@ for ways to get started.
507
543
See [ ` support.md ` ] [ health-support ] for ways to get help.
508
544
509
545
This project has a [ code of conduct] [ health-coc ] .
510
- By interacting with this repository, organization, or community you agree to
511
- abide by its terms.
546
+ By interacting with this repository,
547
+ organization,
548
+ or community you agree to abide by its terms.
512
549
513
550
## License
514
551
0 commit comments