1
1
# mdast-util-directive
2
2
3
- [ ![ Build] [ build-badge ]] [ build ]
4
- [ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
- [ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
- [ ![ Size] [ size-badge ]] [ size ]
7
- [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
- [ ![ Backers] [ backers-badge ]] [ collective ]
9
- [ ![ Chat] [ chat-badge ]] [ chat ]
10
-
11
- [ mdast] [ ] extensions to parse and serialize [ generic directives proposal] [ prop ]
3
+ [ ![ Build] [ badge-build-image ]] [ badge-build-url ]
4
+ [ ![ Coverage] [ badge-coverage-image ]] [ badge-coverage-url ]
5
+ [ ![ Downloads] [ badge-downloads-image ]] [ badge-downloads-url ]
6
+ [ ![ Size] [ badge-size-image ]] [ badge-size-url ]
7
+
8
+ [ mdast] [ github-mdast ] extensions to parse and serialize
9
+ [ generic directives proposal] [ commonmark-directive-proposal ]
12
10
(` :cite[smith04] ` , ` ::youtube[Video of a cat in a box]{v=01ab2cd3efg} ` , and
13
11
such).
14
12
@@ -40,18 +38,19 @@ such).
40
38
## What is this?
41
39
42
40
This package contains two extensions that add support for directive syntax in
43
- markdown to [ mdast] [ ] .
41
+ markdown to [ mdast] [ github-mdast ] .
44
42
These extensions plug into
45
- [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] (to support parsing
46
- directives in markdown into a syntax tree) and
47
- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (to support serializing
48
- directives in syntax trees to markdown).
43
+ [ ` mdast-util-from-markdown ` ] [ github-mdast-util-from-markdown ]
44
+ (to support parsing directives in markdown into a syntax tree)
45
+ and
46
+ [ ` mdast-util-to-markdown ` ] [ github-mdast-util-to-markdown ]
47
+ (to support serializing directives in syntax trees to markdown).
49
48
50
49
## When to use this
51
50
52
51
Directives are one of the four ways to extend markdown: an arbitrary extension
53
- syntax (see [ Extending markdown] [ extending-markdown ] in micromark’s docs for
54
- the alternatives and more info).
52
+ syntax (see [ Extending markdown] [ github-micromark-extending ] in micromark’s
53
+ docs for the alternatives and more info).
55
54
This mechanism works well when you control the content: who authors it, what
56
55
tools handle it, and where it’s displayed.
57
56
When authors can read a guide on how to embed a tweet but are not expected to
@@ -65,25 +64,27 @@ You can use these extensions when you are working with
65
64
` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
66
65
67
66
When working with ` mdast-util-from-markdown ` , you must combine this package
68
- with [ ` micromark-extension-directive ` ] [ extension ] .
67
+ with
68
+ [ ` micromark-extension-directive ` ] [ github-micromark-extension-directive ] .
69
69
70
- When you don’t need a syntax tree, you can use [ ` micromark ` ] [ micromark ]
70
+ When you don’t need a syntax tree, you can use [ ` micromark ` ] [ github- micromark]
71
71
directly with ` micromark-extension-directive ` .
72
72
73
- All these packages are used [ ` remark-directive ` ] [ remark-directive ] , which
73
+ All these packages are used [ ` remark-directive ` ] [ github- remark-directive] , which
74
74
focusses on making it easier to transform content by abstracting these
75
75
internals away.
76
76
77
77
This package only handles the syntax tree.
78
78
For example, it does not handle how markdown is turned to HTML.
79
79
You can use this with some more code to match your specific needs, to allow for
80
80
anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
81
- [ Traverse the tree] [ traversal ] to change directives to whatever you please.
81
+ [ Traverse the tree] [ unifiedjs-tree-traversal ] to change directives to whatever
82
+ you please.
82
83
83
84
## Install
84
85
85
- This package is [ ESM only] [ esm ] .
86
- In Node.js (version 16+), install with [ npm] [ ] :
86
+ This package is [ ESM only] [ github-gist- esm] .
87
+ In Node.js (version 16+), install with [ npm] [ npmjs-install ] :
87
88
88
89
``` sh
89
90
npm install mdast-util-directive
@@ -170,17 +171,19 @@ There is no default export.
170
171
171
172
### ` directiveFromMarkdown() `
172
173
173
- Create an extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ]
174
+ Create an extension for
175
+ [ ` mdast-util-from-markdown ` ] [ github-mdast-util-from-markdown ]
174
176
to enable directives in markdown.
175
177
176
178
###### Returns
177
179
178
180
Extension for ` mdast-util-from-markdown ` to enable directives
179
- ([ ` FromMarkdownExtension ` ] [ from-markdown-extension ] ).
181
+ ([ ` FromMarkdownExtension ` ] [ github-mdast- from-markdown-extension] ).
180
182
181
183
### ` directiveToMarkdown(options?) `
182
184
183
- Create an extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ]
185
+ Create an extension for
186
+ [ ` mdast-util-to-markdown ` ] [ github-mdast-util-to-markdown ]
184
187
to enable directives in markdown.
185
188
186
189
###### Parameters
@@ -192,7 +195,7 @@ to enable directives in markdown.
192
195
###### Returns
193
196
194
197
Extension for ` mdast-util-to-markdown ` to enable directives
195
- ([ ` ToMarkdownExtension ` ] [ to-markdown-extension ] ).
198
+ ([ ` ToMarkdownExtension ` ] [ github-mdast- to-markdown-extension] ).
196
199
197
200
### ` ContainerDirective `
198
201
@@ -278,23 +281,26 @@ Configuration.
278
281
— use the other quote if that results in less bytes
279
282
* ` quote `
280
283
(` '"' ` or ` "'" ` ,
281
- default: the [ ` quote ` ] [ quote ] used by ` mdast-util-to-markdown ` for titles)
284
+ default: the [ ` quote ` ] [ github-mdast-util-to-markdown-quote ]
285
+ used by ` mdast-util-to-markdown ` for titles)
282
286
— preferred quote to use around attribute values
283
287
284
288
## HTML
285
289
286
290
This utility does not handle how markdown is turned to HTML.
287
291
You can use this with some more code to match your specific needs, to allow for
288
292
anything from callouts, citations, styled blocks, forms, embeds, spoilers, etc.
289
- [ Traverse the tree] [ traversal ] to change directives to whatever you please.
293
+ [ Traverse the tree] [ unifiedjs-tree-traversal ] to change directives to whatever
294
+ you please.
290
295
291
296
## Syntax
292
297
293
- See [ Syntax in ` micromark-extension-directive ` ] [ syntax ] .
298
+ See [ Syntax in
299
+ ` micromark-extension-directive ` ] [ github-micromark-extension-directive-syntax ] .
294
300
295
301
## Syntax tree
296
302
297
- The following interfaces are added to ** [ mdast] [ ] ** by this utility.
303
+ The following interfaces are added to ** [ mdast] [ github-mdast ] ** by this utility.
298
304
299
305
### Nodes
300
306
@@ -309,10 +315,12 @@ interface TextDirective <: Parent {
309
315
TextDirective includes Directive
310
316
```
311
317
312
- ** TextDirective** (** [ Parent] [ dfn-parent ] ** ) is a directive.
313
- It can be used where ** [ phrasing] [ dfn-phrasing-content ] ** content is expected.
314
- Its content model is also ** [ phrasing] [ dfn-phrasing-content ] ** content.
315
- It includes the mixin ** [ Directive] [ dfn-mxn-directive ] ** .
318
+ ** TextDirective** (** [ Parent] [ github-mdast-parent ] ** ) is a directive.
319
+ It can be used where ** [ phrasing] [ github-mdast-phrasing-content ] ** content is
320
+ expected.
321
+ Its content model is also ** [ phrasing] [ github-mdast-phrasing-content ] **
322
+ content.
323
+ It includes the mixin ** [ Directive] [ syntax-tree-mixin-directive ] ** .
316
324
317
325
For example, the following Markdown:
318
326
@@ -342,10 +350,10 @@ interface LeafDirective <: Parent {
342
350
LeafDirective includes Directive
343
351
```
344
352
345
- ** LeafDirective** (** [ Parent] [ dfn -parent] ** ) is a directive.
346
- It can be used where ** [ flow] [ dfn -flow-content] ** content is expected.
347
- Its content model is ** [ phrasing] [ dfn -phrasing-content] ** content.
348
- It includes the mixin ** [ Directive] [ dfn-mxn -directive] ** .
353
+ ** LeafDirective** (** [ Parent] [ github-mdast -parent] ** ) is a directive.
354
+ It can be used where ** [ flow] [ github-mdast -flow-content] ** content is expected.
355
+ Its content model is ** [ phrasing] [ github-mdast -phrasing-content] ** content.
356
+ It includes the mixin ** [ Directive] [ syntax-tree-mixin -directive] ** .
349
357
350
358
For example, the following Markdown:
351
359
@@ -375,10 +383,10 @@ interface ContainerDirective <: Parent {
375
383
ContainerDirective includes Directive
376
384
```
377
385
378
- ** ContainerDirective** (** [ Parent] [ dfn -parent] ** ) is a directive.
379
- It can be used where ** [ flow] [ dfn -flow-content] ** content is expected.
380
- Its content model is also ** [ flow] [ dfn -flow-content] ** content.
381
- It includes the mixin ** [ Directive] [ dfn-mxn -directive] ** .
386
+ ** ContainerDirective** (** [ Parent] [ github-mdast -parent] ** ) is a directive.
387
+ It can be used where ** [ flow] [ github-mdast -flow-content] ** content is expected.
388
+ Its content model is also ** [ flow] [ github-mdast -flow-content] ** content.
389
+ It includes the mixin ** [ Directive] [ syntax-tree-mixin -directive] ** .
382
390
383
391
The phrasing in the label is, when available, added as a paragraph with a
384
392
` directiveLabel: true ` field, as the head of its content.
@@ -485,117 +493,109 @@ This utility works with `mdast-util-from-markdown` version 2+ and
485
493
486
494
## Related
487
495
488
- * [ ` remarkjs/ remark-directive` ] [ remark-directive ]
496
+ * [ ` remark-directive ` ] [ github- remark-directive]
489
497
— remark plugin to support generic directives
490
- * [ ` micromark/micromark -extension-directive ` ] [ extension ]
498
+ * [ ` micromark-extension-directive ` ] [ github-micromark- extension-directive ]
491
499
— micromark extension to parse directives
492
500
493
501
## Contribute
494
502
495
- See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
496
- ways to get started.
497
- See [ ` support.md ` ] [ support ] for ways to get help.
503
+ See [ ` contributing.md ` ] [ health-contributing ]
504
+ in
505
+ [ ` syntax-tree/.github ` ] [ health ]
506
+ for ways to get started.
507
+ See [ ` support.md ` ] [ health-support ] for ways to get help.
498
508
499
- This project has a [ code of conduct] [ coc ] .
509
+ This project has a [ code of conduct] [ health- coc] .
500
510
By interacting with this repository, organization, or community you agree to
501
511
abide by its terms.
502
512
503
513
## License
504
514
505
- [ MIT] [ license ] © [ Titus Wormer] [ author ]
515
+ [ MIT] [ file- license] © [ Titus Wormer] [ wooorm ]
506
516
507
517
<!-- Definitions -->
508
518
509
- [ build-badge ] : https://github.com/syntax-tree/mdast-util-directive/workflows/main/badge.svg
510
-
511
- [ build ] : https://github.com/syntax-tree/mdast-util-directive/actions
512
-
513
- [ coverage-badge ] : https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-directive.svg
514
-
515
- [ coverage ] : https://codecov.io/github/syntax-tree/mdast-util-directive
516
-
517
- [ downloads-badge ] : https://img.shields.io/npm/dm/mdast-util-directive.svg
518
-
519
- [ downloads ] : https://www.npmjs.com/package/mdast-util-directive
519
+ [ api-container-directive ] : #containerdirective
520
520
521
- [ size-badge ] : https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-directive
521
+ [ api-directive-from-markdown ] : #directivefrommarkdown
522
522
523
- [ size ] : https://bundlejs.com/?q=mdast-util-directive
523
+ [ api-directive-to-markdown ] : #directivetomarkdownoptions
524
524
525
- [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
525
+ [ api-directives ] : #directives
526
526
527
- [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
527
+ [ api-leaf-directive ] : #leafdirective
528
528
529
- [ collective ] : https://opencollective.com/unified
529
+ [ api-text-directive ] : #textdirective
530
530
531
- [ chat-badge ] : https://img.shields.io/badge/chat-discussions-success.svg
531
+ [ api-to-markdown-options ] : #tomarkdownoptions
532
532
533
- [ chat ] : https://github.com/syntax-tree/unist/discussions
533
+ [ badge-build-image ] : https://github.com/syntax-tree/mdast-util-directive/workflows/main/badge.svg
534
534
535
- [ npm ] : https://docs.npmjs. com/cli/install
535
+ [ badge-build-url ] : https://github. com/syntax-tree/mdast-util-directive/actions
536
536
537
- [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
537
+ [ badge-coverage-image ] : https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-directive.svg
538
538
539
- [ esmsh ] : https://esm.sh
539
+ [ badge-coverage-url ] : https://codecov.io/github/syntax-tree/mdast-util-directive
540
540
541
- [ typescript ] : https://www.typescriptlang.org
541
+ [ badge-downloads-image ] : https://img.shields.io/npm/dm/mdast-util-directive.svg
542
542
543
- [ license ] : license
543
+ [ badge-downloads-url ] : https://www.npmjs.com/package/mdast-util-directive
544
544
545
- [ author ] : https://wooorm.com
545
+ [ badge-size-image ] : https://img.shields.io/bundlejs/size/mdast-util-directive
546
546
547
- [ health ] : https://github .com/syntax-tree/.github
547
+ [ badge-size-url ] : https://bundlejs .com/?q=mdast-util-directive
548
548
549
- [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
549
+ [ commonmark-directive-proposal ] : https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
550
550
551
- [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
551
+ [ esmsh ] : https://esm.sh
552
552
553
- [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
553
+ [ file-license ] : license
554
554
555
- [ mdast ] : https://github.com/syntax-tree/mdast
555
+ [ github-gist-esm ] : https://gist. github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
556
556
557
- [ mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
557
+ [ github-mdast ] : https://github.com/syntax-tree/mdast
558
558
559
- [ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
559
+ [ github- mdast-flow-content ] : https://github.com/syntax-tree/mdast#flowcontent
560
560
561
- [ quote ] : https://github.com/syntax-tree/mdast-util-to -markdown#optionsquote
561
+ [ github-mdast-from-markdown-extension ] : https://github.com/syntax-tree/mdast-util-from -markdown#extension
562
562
563
- [ micromark ] : https://github.com/micromark/micromark
563
+ [ github-mdast-parent ] : https://github.com/syntax-tree/mdast#parent
564
564
565
- [ extension ] : https://github.com/micromark/micromark-extension-directive
565
+ [ github-mdast-phrasing-content ] : https://github.com/syntax-tree/mdast#phrasingcontent
566
566
567
- [ syntax ] : https://github.com/micromark/micromark-extension-directive#syntax
567
+ [ github-mdast-to-markdown-extension ] : https://github.com/syntax-tree/mdast-util-to-markdown#options
568
568
569
- [ remark-directive ] : https://github.com/remarkjs/remark-directive
569
+ [ github-mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
570
570
571
- [ extending- markdown] : https://github.com/micromark/micromark#extending -markdown
571
+ [ github-mdast-util-to- markdown] : https://github.com/syntax-tree/mdast-util-to -markdown
572
572
573
- [ prop ] : https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
573
+ [ github-mdast-util-to-markdown-quote ] : https://github.com/syntax-tree/mdast-util-to-markdown#optionsquote
574
574
575
- [ traversal ] : https://unifiedjs .com/learn/recipe/tree-traversal/
575
+ [ github-micromark ] : https://github .com/micromark/micromark
576
576
577
- [ dfn-parent ] : https://github.com/syntax-tree/mdast#parent
577
+ [ github-micromark-extending ] : https://github.com/micromark/micromark#extending-markdown
578
578
579
- [ dfn-flow-content ] : https://github.com/syntax-tree/mdast#flowcontent
579
+ [ github-micromark-extension-directive ] : https://github.com/micromark/micromark-extension-directive
580
580
581
- [ dfn-phrasing-content ] : https://github.com/syntax-tree/mdast#phrasingcontent
581
+ [ github-micromark-extension-directive-syntax ] : https://github.com/micromark/micromark-extension-directive#syntax
582
582
583
- [ from-markdown-extension ] : https://github.com/syntax-tree/mdast-util-from-markdown#extension
583
+ [ github-remark-directive ] : https://github.com/remarkjs/remark-directive
584
584
585
- [ to-markdown-extension ] : https://github.com/syntax-tree/mdast-util-to-markdown#options
585
+ [ health ] : https://github.com/syntax-tree/.github
586
586
587
- [ api-directive-from-markdown ] : #directivefrommarkdown
587
+ [ health-coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
588
588
589
- [ api-directive-to-markdown ] : #directivetomarkdownoptions
589
+ [ health-contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
590
590
591
- [ api-to-markdown-options ] : #tomarkdownoptions
591
+ [ health-support ] : https://github.com/syntax-tree/.github/blob/main/support.md
592
592
593
- [ api-container-directive ] : #containerdirective
593
+ [ npmjs-install ] : https://docs.npmjs.com/cli/install
594
594
595
- [ api-directives ] : #directives
595
+ [ syntax-tree-mixin-directive ] : #directive
596
596
597
- [ api-leaf-directive ] : #leafdirective
597
+ [ typescript ] : https://www.typescriptlang.org
598
598
599
- [ api-text-directive ] : #textdirective
599
+ [ unifiedjs-tree-traversal ] : https://unifiedjs.com/learn/recipe/tree-traversal/
600
600
601
- [ dfn-mxn-directive ] : #directive
601
+ [ wooorm ] : https://wooorm.com
0 commit comments