1919* [ API] ( #api )
2020 * [ ` frontmatterFromMarkdown(options?) ` ] ( #frontmatterfrommarkdownoptions )
2121 * [ ` frontmatterToMarkdown(options?) ` ] ( #frontmattertomarkdownoptions )
22+ * [ ` Info ` ] ( #info )
23+ * [ ` Matter ` ] ( #matter )
24+ * [ ` Options ` ] ( #options )
25+ * [ Syntax] ( #syntax )
2226* [ Syntax tree] ( #syntax-tree )
2327 * [ Nodes] ( #nodes )
2428 * [ Content model] ( #content-model )
3034
3135## What is this?
3236
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).
3744
38- Frontmatter is a metadata format in front of content.
45+ Frontmatter is a metadata format in front of the content.
3946It’s typically written in YAML and is often used with markdown.
4047Frontmatter does not work everywhere so it makes markdown less portable.
4148
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+
4253## When to use this
4354
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 ] .
4760
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.
5068
5169## Install
5270
5371This 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] [ ] :
5573
5674``` sh
5775npm install mdast-util-frontmatter
@@ -132,29 +150,64 @@ title = "New Website"
132150
133151## API
134152
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 ] .
137156There is no default export.
138157
139158### ` frontmatterFromMarkdown(options?) `
140159
141- Function that can be called to get an extension for
160+ Create an extension for
142161[ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
143162
144- ###### ` options `
163+ ###### Parameters
164+
165+ * ` options ` ([ ` Options ` ] [ api-options ] , optional)
166+ — configuration
145167
146- Configuration (optional).
147- Same as [ ` micromark-extension-frontmatter ` ] [ options ] .
168+ ###### Returns
169+
170+ Extension for ` mdast-util-from-markdown `
171+ ([ ` FromMarkdownExtension ` ] [ frommarkdownextension ] ).
148172
149173### ` frontmatterToMarkdown(options?) `
150174
151- Function that can be called to get an extension for
175+ Create an extension for
152176[ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
153177
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 `
155203
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 ] .
158211
159212## Syntax tree
160213
@@ -173,11 +226,11 @@ interface YAML <: Literal {
173226}
174227```
175228
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.
178231
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.
181234Its content is represented by its ` value ` field.
182235
183236For example, the following markdown:
@@ -205,7 +258,7 @@ type FrontmatterContent = YAML
205258** Frontmatter** content represent out-of-band information about the document.
206259
207260If 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 ] * .
209262
210263#### ` FlowContent ` (frontmatter)
211264
@@ -216,7 +269,8 @@ type FlowContentFrontmatter = FrontmatterContent | FlowContent
216269## Types
217270
218271This 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 ] .
220274
221275The YAML node type is supported in ` @types/mdast ` by default.
222276To 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
225279``` ts
226280import type {Literal } from ' mdast'
227281
228- interface TOML extends Literal {
282+ interface Toml extends Literal {
229283 type: ' toml'
230284}
231285
232286declare module ' mdast' {
233287 interface FrontmatterContentMap {
234288 // Allow using TOML nodes defined by `mdast-util-frontmatter`.
235- toml: TOML
289+ toml: Toml
236290 }
237291}
238292```
@@ -241,17 +295,17 @@ declare module 'mdast' {
241295
242296Projects maintained by the unified collective are compatible with all maintained
243297versions 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+.
245299Our projects sometimes work with older versions, but this is not guaranteed.
246300
247- This plugin works with ` mdast-util-from-markdown ` version 1+ and
301+ These extensions works with ` mdast-util-from-markdown ` version 1+ and
248302` mdast-util-to-markdown ` version 1+.
249303
250304## Related
251305
252- * [ ` remarkjs/ remark-frontmatter` ] [ remark-frontmatter ]
306+ * [ ` remark-frontmatter ` ] [ remark-frontmatter ]
253307 — remark plugin to support frontmatter
254- * [ ` micromark/micromark -extension-frontmatter ` ] [ extension ]
308+ * [ ` micromark-extension-frontmatter ` ] [ micromark- extension-frontmatter ]
255309 — micromark extension to parse frontmatter
256310
257311## Contribute
@@ -324,14 +378,34 @@ abide by its terms.
324378
325379[ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
326380
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
328384
329385[ options ] : https://github.com/micromark/micromark-extension-frontmatter#options
330386
331- [ dfn-literal ] : https://github.com/syntax-tree/mdast#literal
387+ [ matter ] : https://github.com/micromark/micromark-extension-frontmatter#matter
332388
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
334392
335393[ term-tree ] : https://github.com/syntax-tree/unist#tree
336394
337395[ 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