Skip to content

Commit ea123f0

Browse files
committed
Add improved docs
1 parent 233dcd5 commit ea123f0

File tree

3 files changed

+113
-39
lines changed

3 files changed

+113
-39
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('./lib/index.js').Info} Info
3-
* @typedef {import('./lib/index.js').Matter} Matter
42
* @typedef {import('./lib/index.js').Options} Options
3+
* @typedef {import('./lib/index.js').Matter} Matter
4+
* @typedef {import('./lib/index.js').Info} Info
55
*/
66

77
export {frontmatterFromMarkdown, frontmatterToMarkdown} from './lib/index.js'

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
66
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
77
*
8-
* @typedef {import('micromark-extension-frontmatter/matters.js').Options} Options
8+
* @typedef {import('micromark-extension-frontmatter').Options} Options
99
* @typedef {import('micromark-extension-frontmatter/matters.js').Matter} Matter
1010
* @typedef {import('micromark-extension-frontmatter/matters.js').Info} Info
1111
*/

readme.md

Lines changed: 110 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
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)
@@ -30,28 +34,42 @@
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.
3946
It’s typically written in YAML and is often used with markdown.
4047
Frontmatter 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

5371
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][]:
5573

5674
```sh
5775
npm 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].
137156
There 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.
181234
Its content is represented by its `value` field.
182235

183236
For example, the following markdown:
@@ -205,7 +258,7 @@ type FrontmatterContent = YAML
205258
**Frontmatter** content represent out-of-band information about the document.
206259

207260
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]*.
209262

210263
#### `FlowContent` (frontmatter)
211264

@@ -216,7 +269,8 @@ type FlowContentFrontmatter = FrontmatterContent | FlowContent
216269
## Types
217270

218271
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].
220274

221275
The YAML node type is supported in `@types/mdast` by default.
222276
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
225279
```ts
226280
import type {Literal} from 'mdast'
227281

228-
interface TOML extends Literal {
282+
interface Toml extends Literal {
229283
type: 'toml'
230284
}
231285

232286
declare 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

242296
Projects maintained by the unified collective are compatible with all maintained
243297
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+.
245299
Our 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

Comments
 (0)