19
19
* [ API] ( #api )
20
20
* [ ` frontmatterFromMarkdown(options?) ` ] ( #frontmatterfrommarkdownoptions )
21
21
* [ ` frontmatterToMarkdown(options?) ` ] ( #frontmattertomarkdownoptions )
22
+ * [ ` Info ` ] ( #info )
23
+ * [ ` Matter ` ] ( #matter )
24
+ * [ ` Options ` ] ( #options )
25
+ * [ Syntax] ( #syntax )
22
26
* [ Syntax tree] ( #syntax-tree )
23
27
* [ Nodes] ( #nodes )
24
28
* [ Content model] ( #content-model )
30
34
31
35
## What is this?
32
36
33
- This package contains extensions that add support for the frontmatter syntax
34
- enabled by GitHub and many other places to
35
- [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
36
- [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
37
+ This package contains two extensions that add support for frontmatter syntax
38
+ as often used in markdown to [ mdast] [ ] .
39
+ These extensions plug into
40
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] (to support parsing
41
+ frontmatter in markdown into a syntax tree) and
42
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] (to support serializing
43
+ frontmatter in syntax trees to markdown).
37
44
38
- Frontmatter is a metadata format in front of content.
45
+ Frontmatter is a metadata format in front of the content.
39
46
It’s typically written in YAML and is often used with markdown.
40
47
Frontmatter does not work everywhere so it makes markdown less portable.
41
48
49
+ These extensions follow how GitHub handles frontmatter.
50
+ GitHub only supports YAML frontmatter, but these extensions also support
51
+ different flavors (such as TOML).
52
+
42
53
## When to use this
43
54
44
- These tools are all rather low-level.
45
- In most cases, you’d want to use [ ` remark-frontmatter ` ] [ remark-frontmatter ] with
46
- remark instead.
55
+ You can use these extensions when you are working with
56
+ ` mdast-util-from-markdown ` and ` mdast-util-to-markdown ` already.
57
+
58
+ When working with ` mdast-util-from-markdown ` , you must combine this package
59
+ with [ ` micromark-extension-frontmatter ` ] [ micromark-extension-frontmatter ] .
47
60
48
- When working with ` mdast-util-from-markdown ` , you must combine this package with
49
- [ ` micromark-extension-frontmatter ` ] [ extension ] .
61
+ When you don’t need a syntax tree, you can use [ ` micromark ` ] [ micromark ]
62
+ directly with
63
+ [ ` micromark-extension-frontmatter ` ] [ micromark-extension-frontmatter ] .
64
+
65
+ All these packages are used [ ` remark-frontmatter ` ] [ remark-frontmatter ] , which
66
+ focusses on making it easier to transform content by abstracting these
67
+ internals away.
50
68
51
69
## Install
52
70
53
71
This package is [ ESM only] [ esm ] .
54
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
72
+ In Node.js (version 14.14+ and 16.0+), install with [ npm] [ ] :
55
73
56
74
``` sh
57
75
npm install mdast-util-frontmatter
@@ -132,29 +150,64 @@ title = "New Website"
132
150
133
151
## API
134
152
135
- This package exports the identifiers ` frontmatterFromMarkdown ` and
136
- ` frontmatterToMarkdown ` .
153
+ This package exports the identifiers
154
+ [ ` frontmatterFromMarkdown ` ] [ api-frontmatterfrommarkdown ] and
155
+ [ ` frontmatterToMarkdown ` ] [ api-frontmattertomarkdown ] .
137
156
There is no default export.
138
157
139
158
### ` frontmatterFromMarkdown(options?) `
140
159
141
- Function that can be called to get an extension for
160
+ Create an extension for
142
161
[ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
143
162
144
- ###### ` options `
163
+ ###### Parameters
164
+
165
+ * ` options ` ([ ` Options ` ] [ api-options ] , optional)
166
+ — configuration
145
167
146
- Configuration (optional).
147
- Same as [ ` micromark-extension-frontmatter ` ] [ options ] .
168
+ ###### Returns
169
+
170
+ Extension for ` mdast-util-from-markdown `
171
+ ([ ` FromMarkdownExtension ` ] [ frommarkdownextension ] ).
148
172
149
173
### ` frontmatterToMarkdown(options?) `
150
174
151
- Function that can be called to get an extension for
175
+ Create an extension for
152
176
[ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
153
177
154
- ###### ` options `
178
+ ###### Parameters
179
+
180
+ * ` options ` ([ ` Options ` ] [ api-options ] , optional)
181
+ — configuration
182
+
183
+ ###### Returns
184
+
185
+ Extension for ` mdast-util-to-markdown `
186
+ ([ ` ToMarkdownExtension ` ] [ tomarkdownextension ] ).
187
+
188
+ ### ` Info `
189
+
190
+ Structure of marker or fence (TypeScript type).
191
+
192
+ <!-- To do: fix link when `info` is documented -->
193
+
194
+ Same as [ ` Info ` from ` micromark-extension-frontmatter ` ] [ matter ] .
195
+
196
+ ### ` Matter `
197
+
198
+ Structure of matter (TypeScript type).
199
+
200
+ Same as [ ` Matter ` from ` micromark-extension-frontmatter ` ] [ matter ] .
201
+
202
+ ### ` Options `
155
203
156
- Configuration (optional).
157
- Same as [ ` micromark-extension-frontmatter ` ] [ options ] .
204
+ Configuration (TypeScript type).
205
+
206
+ Same as [ ` Options ` from ` micromark-extension-frontmatter ` ] [ options ] .
207
+
208
+ ## Syntax
209
+
210
+ See [ Syntax in ` micromark-extension-frontmatter ` ] [ syntax ] .
158
211
159
212
## Syntax tree
160
213
@@ -173,11 +226,11 @@ interface YAML <: Literal {
173
226
}
174
227
```
175
228
176
- ** YAML** ([ ** Literal** ] [ dfn-literal ] ) represents a collection of metadata for
177
- the document in the YAML data serialisation language.
229
+ ** YAML** (** [ Literal] [ dfn-literal ] ** ) represents a collection of metadata for
230
+ the document in the YAML data serialization language.
178
231
179
- ** YAML** can be used where [ ** frontmatter** ] [ dfn-frontmatter-content ] content is
180
- expected.
232
+ ** YAML** can be used where ** [ frontmatter] [ dfn-frontmatter-content ] ** content
233
+ is expected.
181
234
Its content is represented by its ` value ` field.
182
235
183
236
For example, the following markdown:
@@ -205,7 +258,7 @@ type FrontmatterContent = YAML
205
258
** Frontmatter** content represent out-of-band information about the document.
206
259
207
260
If frontmatter is present, it must be limited to one node in the
208
- [ * tree* ] [ term-tree ] , and can only exist as a [ * head* ] [ term-head ] .
261
+ * [ tree] [ term-tree ] * , and can only exist as a * [ head] [ term-head ] * .
209
262
210
263
#### ` FlowContent ` (frontmatter)
211
264
@@ -216,7 +269,8 @@ type FlowContentFrontmatter = FrontmatterContent | FlowContent
216
269
## Types
217
270
218
271
This package is fully typed with [ TypeScript] [ ] .
219
- It exports the additional types ` Options ` , ` Matter ` , and ` Info ` .
272
+ It exports the additional types [ ` Info ` ] [ api-info ] , [ ` Matter ` ] [ api-matter ] ,
273
+ and [ ` Options ` ] [ api-options ] .
220
274
221
275
The YAML node type is supported in ` @types/mdast ` by default.
222
276
To add other node types, register them by adding them to
@@ -225,14 +279,14 @@ To add other node types, register them by adding them to
225
279
``` ts
226
280
import type {Literal } from ' mdast'
227
281
228
- interface TOML extends Literal {
282
+ interface Toml extends Literal {
229
283
type: ' toml'
230
284
}
231
285
232
286
declare module ' mdast' {
233
287
interface FrontmatterContentMap {
234
288
// Allow using TOML nodes defined by `mdast-util-frontmatter`.
235
- toml: TOML
289
+ toml: Toml
236
290
}
237
291
}
238
292
```
@@ -241,17 +295,17 @@ declare module 'mdast' {
241
295
242
296
Projects maintained by the unified collective are compatible with all maintained
243
297
versions of Node.js.
244
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
298
+ As of now, that is Node.js 14.14+ and 16.0+.
245
299
Our projects sometimes work with older versions, but this is not guaranteed.
246
300
247
- This plugin works with ` mdast-util-from-markdown ` version 1+ and
301
+ These extensions works with ` mdast-util-from-markdown ` version 1+ and
248
302
` mdast-util-to-markdown ` version 1+.
249
303
250
304
## Related
251
305
252
- * [ ` remarkjs/ remark-frontmatter` ] [ remark-frontmatter ]
306
+ * [ ` remark-frontmatter ` ] [ remark-frontmatter ]
253
307
— remark plugin to support frontmatter
254
- * [ ` micromark/micromark -extension-frontmatter ` ] [ extension ]
308
+ * [ ` micromark-extension-frontmatter ` ] [ micromark- extension-frontmatter ]
255
309
— micromark extension to parse frontmatter
256
310
257
311
## Contribute
@@ -324,14 +378,34 @@ abide by its terms.
324
378
325
379
[ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
326
380
327
- [ extension ] : https://github.com/micromark/micromark-extension-frontmatter
381
+ [ micromark ] : https://github.com/micromark/micromark
382
+
383
+ [ micromark-extension-frontmatter ] : https://github.com/micromark/micromark-extension-frontmatter
328
384
329
385
[ options ] : https://github.com/micromark/micromark-extension-frontmatter#options
330
386
331
- [ dfn-literal ] : https://github.com/syntax-tree/mdast#literal
387
+ [ matter ] : https://github.com/micromark/micromark-extension-frontmatter#matter
332
388
333
- [ dfn-frontmatter-content ] : #frontmattercontent
389
+ [ syntax ] : https://github.com/micromark/micromark-extension-frontmatter#syntax
390
+
391
+ [ dfn-literal ] : https://github.com/syntax-tree/mdast#literal
334
392
335
393
[ term-tree ] : https://github.com/syntax-tree/unist#tree
336
394
337
395
[ term-head ] : https://github.com/syntax-tree/unist#head
396
+
397
+ [ frommarkdownextension ] : https://github.com/syntax-tree/mdast-util-from-markdown#extension
398
+
399
+ [ tomarkdownextension ] : https://github.com/syntax-tree/mdast-util-to-markdown#options
400
+
401
+ [ dfn-frontmatter-content ] : #frontmattercontent
402
+
403
+ [ api-frontmatterfrommarkdown ] : #frontmatterfrommarkdownoptions
404
+
405
+ [ api-frontmattertomarkdown ] : #frontmattertomarkdownoptions
406
+
407
+ [ api-info ] : #info
408
+
409
+ [ api-matter ] : #matter
410
+
411
+ [ api-options ] : #options
0 commit comments