@@ -21,10 +21,15 @@ such).
2121* [ API] ( #api )
2222 * [ ` directiveFromMarkdown ` ] ( #directivefrommarkdown )
2323 * [ ` directiveToMarkdown ` ] ( #directivetomarkdown )
24+ * [ ` ContainerDirective ` ] ( #containerdirective )
25+ * [ ` Directive ` ] ( #directive )
26+ * [ ` LeafDirective ` ] ( #leafdirective )
27+ * [ ` TextDirective ` ] ( #textdirective )
28+ * [ HTML] ( #html )
29+ * [ Syntax] ( #syntax )
2430* [ Syntax tree] ( #syntax-tree )
2531 * [ Nodes] ( #nodes )
2632 * [ Mixin] ( #mixin )
27- * [ ` Directive ` ] ( #directive )
2833* [ Types] ( #types )
2934* [ Compatibility] ( #compatibility )
3035* [ Related] ( #related )
@@ -33,23 +38,18 @@ such).
3338
3439## What is this?
3540
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).
4448
4549## When to use this
4650
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-
5151Directives 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
5353the alternatives and more info).
5454This mechanism works well when you control the content: who authors it, what
5555tools handle it, and where it’s displayed.
@@ -60,17 +60,29 @@ handle it, and where it ends up.
6060Example use cases are a docs website for a project or product, or blogging tools
6161and static site generators.
6262
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 ] .
6568
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.
6981
7082## Install
7183
7284This 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] [ ] :
7486
7587``` sh
7688npm install mdast-util-directive
@@ -150,21 +162,99 @@ A lovely language know as :abbr[HTML]{title="HyperText Markup Language"}.
150162
151163## API
152164
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 ] .
155168There is no default export.
156169
157170### ` directiveFromMarkdown `
158171
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 ] ).
160174
161175### ` directiveToMarkdown `
162176
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 ] ).
164179
165180There are no options, but passing [ ` options.quote ` ] [ quote ] to
166181` mdast-util-to-markdown ` is honored for attributes.
167182
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+
168258## Syntax tree
169259
170260The following interfaces are added to ** [ mdast] [ ] ** by this utility.
@@ -287,7 +377,7 @@ Yields:
287377
288378### Mixin
289379
290- ### ` Directive `
380+ #### ` Directive `
291381
292382``` idl
293383interface mixin Directive {
@@ -319,8 +409,9 @@ or hast).
319409## Types
320410
321411This 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 ] .
324415
325416It also registers the node types with ` @types/mdast ` .
326417If you’re working with the syntax tree, make sure to import this utility
@@ -345,7 +436,7 @@ visit(tree, (node) => {
345436
346437Projects maintained by the unified collective are compatible with all maintained
347438versions 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+.
349440Our projects sometimes work with older versions, but this is not guaranteed.
350441
351442This plugin works with ` mdast-util-from-markdown ` version 1+ and
@@ -428,11 +519,15 @@ abide by its terms.
428519
429520[ quote ] : https://github.com/syntax-tree/mdast-util-to-markdown#optionsquote
430521
522+ [ micromark ] : https://github.com/micromark/micromark
523+
431524[ extension ] : https://github.com/micromark/micromark-extension-directive
432525
526+ [ syntax ] : https://github.com/micromark/micromark-extension-directive#syntax
527+
433528[ remark-directive ] : https://github.com/remarkjs/remark-directive
434529
435- [ extending-mmarkdown ] : https://github.com/micromark/micromark#extending-markdown
530+ [ extending-markdown ] : https://github.com/micromark/micromark#extending-markdown
436531
437532[ prop ] : https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
438533
@@ -444,4 +539,20 @@ abide by its terms.
444539
445540[ dfn-phrasing-content ] : https://github.com/syntax-tree/mdast#phrasingcontent
446541
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