Skip to content

Commit 94ddfdd

Browse files
committed
Add improved docs
1 parent fe25136 commit 94ddfdd

File tree

2 files changed

+86
-39
lines changed

2 files changed

+86
-39
lines changed

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ footnoteReference.peek = footnoteReferencePeek
2222
// utilities on `state`.
2323

2424
/**
25-
* Create an extension for `mdast-util-from-markdown` to enable footnotes
26-
* in markdown like in GFM.
25+
* Create an extension for `mdast-util-from-markdown` to enable GFM footnotes
26+
* in markdown.
2727
*
2828
* @returns {FromMarkdownExtension}
2929
* Extension for `mdast-util-from-markdown`.
@@ -46,8 +46,8 @@ export function gfmFootnoteFromMarkdown() {
4646
}
4747

4848
/**
49-
* Create an extension for `mdast-util-to-markdown` to enable footnotes
50-
* in markdown like in GFM.
49+
* Create an extension for `mdast-util-to-markdown` to enable GFM footnotes
50+
* in markdown.
5151
*
5252
* @returns {ToMarkdownExtension}
5353
* Extension for `mdast-util-to-markdown`.

readme.md

Lines changed: 82 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* [API](#api)
2020
* [`gfmFootnoteFromMarkdown()`](#gfmfootnotefrommarkdown)
2121
* [`gfmFootnoteToMarkdown()`](#gfmfootnotetomarkdown)
22+
* [HTML](#html)
23+
* [Syntax](#syntax)
2224
* [Syntax tree](#syntax-tree)
2325
* [Nodes](#nodes)
2426
* [Content model](#content-model)
@@ -30,24 +32,35 @@
3032

3133
## What is this?
3234

33-
This package contains extensions that add support for the footnote syntax
34-
enabled by GFM to [`mdast-util-from-markdown`][mdast-util-from-markdown] and
35-
[`mdast-util-to-markdown`][mdast-util-to-markdown].
35+
This package contains two extensions that add support for GFM footnote syntax
36+
in markdown to [mdast][].
37+
These extensions plug into
38+
[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing
39+
footnotes in markdown into a syntax tree) and
40+
[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing
41+
footnotes in syntax trees to markdown).
3642

3743
GFM footnotes were [announced September 30, 2021][post] but are not specified.
3844
Their implementation on github.com is currently buggy.
3945
The bugs have been reported on [`cmark-gfm`][cmark-gfm].
4046

4147
## When to use this
4248

43-
These tools are all rather low-level.
44-
In most cases, you’d want to use [`remark-gfm`][remark-gfm] with remark instead.
49+
You can use these extensions when you are working with
50+
`mdast-util-from-markdown` and `mdast-util-to-markdown` already.
51+
52+
When working with `mdast-util-from-markdown`, you must combine this package
53+
with [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote].
54+
55+
When you don’t need a syntax tree, you can use [`micromark`][micromark]
56+
directly with `micromark-extension-gfm-footnote`.
4557

4658
When you are working with syntax trees and want all of GFM, use
4759
[`mdast-util-gfm`][mdast-util-gfm] instead.
4860

49-
When working with `mdast-util-from-markdown`, you must combine this package with
50-
[`micromark-extension-gfm-footnote`][extension].
61+
All these packages are used [`remark-gfm`][remark-gfm], which
62+
focusses on making it easier to transform content by abstracting these
63+
internals away.
5164

5265
This utility does not handle how markdown is turned to HTML.
5366
That’s done by [`mdast-util-to-hast`][mdast-util-to-hast].
@@ -56,7 +69,7 @@ If your content is not in English, you should configure that utility.
5669
## Install
5770

5871
This package is [ESM only][esm].
59-
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][]:
6073

6174
```sh
6275
npm install mdast-util-gfm-footnote
@@ -142,19 +155,42 @@ Hi\![^1]
142155

143156
## API
144157

145-
This package exports the identifiers `gfmFootnoteFromMarkdown` and
146-
`gfmFootnoteToMarkdown`.
158+
This package exports the identifiers
159+
[`gfmFootnoteFromMarkdown`][api-gfmfootnotefrommarkdown] and
160+
[`gfmFootnoteToMarkdown`][api-gfmfootnotetomarkdown].
147161
There is no default export.
148162

149163
### `gfmFootnoteFromMarkdown()`
150164

151-
Function that can be called to get an extension for
152-
[`mdast-util-from-markdown`][mdast-util-from-markdown].
165+
Create an extension for
166+
[`mdast-util-from-markdown`][mdast-util-from-markdown]
167+
to enable GFM footnotes in markdown.
168+
169+
###### Returns
170+
171+
Extension for `mdast-util-from-markdown`
172+
([`FromMarkdownExtension`][frommarkdownextension]).
153173

154174
### `gfmFootnoteToMarkdown()`
155175

156-
Function that can be called to get an extension for
157-
[`mdast-util-to-markdown`][mdast-util-to-markdown].
176+
Create an extension for
177+
[`mdast-util-to-markdown`][mdast-util-to-markdown]
178+
to enable GFM footnotes in markdown.
179+
180+
###### Returns
181+
182+
Extension for `mdast-util-to-markdown`
183+
([`ToMarkdownExtension`][tomarkdownextension]).
184+
185+
## HTML
186+
187+
This utility does not handle how markdown is turned to HTML.
188+
That’s done by [`mdast-util-to-hast`][mdast-util-to-hast].
189+
If your content is not in English, you should configure that utility.
190+
191+
## Syntax
192+
193+
See [Syntax in `micromark-extension-frontmatter`][syntax].
158194

159195
## Syntax tree
160196

@@ -166,25 +202,25 @@ The following interfaces are added to **[mdast][]** by this utility.
166202

167203
```idl
168204
interface FootnoteDefinition <: Parent {
169-
type: "footnoteDefinition"
205+
type: 'footnoteDefinition'
170206
children: [FlowContent]
171207
}
172208
173209
FootnoteDefinition includes Association
174210
```
175211

176-
**FootnoteDefinition** ([**Parent**][dfn-parent]) represents content relating
212+
**FootnoteDefinition** (**[Parent][dfn-parent]**) represents content relating
177213
to the document that is outside its flow.
178214

179-
**FootnoteDefinition** can be used where [**flow**][dfn-flow-content] content is
180-
expected.
181-
Its content model is also [**flow**][dfn-flow-content] content.
215+
**FootnoteDefinition** can be used where **[flow][dfn-flow-content]** content
216+
is expected.
217+
Its content model is also **[flow][dfn-flow-content]** content.
182218

183219
**FootnoteDefinition** includes the mixin
184-
[**Association**][dfn-mxn-association].
220+
**[Association][dfn-mxn-association]**.
185221

186222
**FootnoteDefinition** should be associated with
187-
[**FootnoteReferences**][dfn-footnote-reference].
223+
**[FootnoteReferences][dfn-footnote-reference]**.
188224

189225
For example, the following markdown:
190226

@@ -210,23 +246,23 @@ Yields:
210246

211247
```idl
212248
interface FootnoteReference <: Node {
213-
type: "footnoteReference"
249+
type: 'footnoteReference'
214250
}
215251
216252
FootnoteReference includes Association
217253
```
218254

219-
**FootnoteReference** ([**Node**][dfn-node]) represents a marker through
255+
**FootnoteReference** (**[Node][dfn-node]**) represents a marker through
220256
association.
221257

222258
**FootnoteReference** can be used where
223-
[**static phrasing**][dfn-static-phrasing-content] content is expected.
259+
**[static phrasing][dfn-static-phrasing-content]** content is expected.
224260
It has no content model.
225261

226-
**FootnoteReference** includes the mixin [**Association**][dfn-mxn-association].
262+
**FootnoteReference** includes the mixin **[Association][dfn-mxn-association]**.
227263

228264
**FootnoteReference** should be associated with a
229-
[**FootnoteDefinition**][dfn-footnote-definition].
265+
**[FootnoteDefinition][dfn-footnote-definition]**.
230266

231267
For example, the following markdown:
232268

@@ -255,36 +291,35 @@ type FlowContentGfm = FootnoteDefinition | FlowContent
255291
#### `StaticPhrasingContent` (GFM footnotes)
256292

257293
```idl
258-
type StaticPhrasingContentGfm =
259-
FootnoteReference | StaticPhrasingContent
294+
type StaticPhrasingContentGfm = FootnoteReference | StaticPhrasingContent
260295
```
261296

262297
## Types
263298

264299
This package is fully typed with [TypeScript][].
265300
It does not export additional types.
266301

267-
The `FootnoteDefinition` and `FootnoteReference` node types are supported in
268-
`@types/mdast` by default.
302+
The `FootnoteDefinition` and `FootnoteReference` types of the mdast nodes are
303+
exposed from `@types/mdast`.
269304

270305
## Compatibility
271306

272307
Projects maintained by the unified collective are compatible with all maintained
273308
versions of Node.js.
274-
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
309+
As of now, that is Node.js 14.14+ and 16.0+.
275310
Our projects sometimes work with older versions, but this is not guaranteed.
276311

277312
This plugin works with `mdast-util-from-markdown` version 1+ and
278313
`mdast-util-to-markdown` version 1+.
279314

280315
## Related
281316

282-
* [`remarkjs/remark-gfm`][remark-gfm]
317+
* [`remark-gfm`][remark-gfm]
283318
— remark plugin to support GFM
284-
* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm]
319+
* [`mdast-util-gfm`][mdast-util-gfm]
285320
— same but all of GFM (autolink literals, footnotes, strikethrough, tables,
286321
tasklists)
287-
* [`micromark/micromark-extension-gfm-footnote`][extension]
322+
* [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote]
288323
— micromark extension to parse GFM footnotes
289324

290325
## Contribute
@@ -355,7 +390,11 @@ abide by its terms.
355390

356391
[remark-gfm]: https://github.com/remarkjs/remark-gfm
357392

358-
[extension]: https://github.com/micromark/micromark-extension-gfm-footnote
393+
[micromark]: https://github.com/micromark/micromark
394+
395+
[micromark-extension-gfm-footnote]: https://github.com/micromark/micromark-extension-gfm-footnote
396+
397+
[syntax]: https://github.com/micromark/micromark-extension-gfm-footnote#syntax
359398

360399
[gfm]: https://github.github.com/gfm/
361400

@@ -375,10 +414,18 @@ abide by its terms.
375414

376415
[dfn-node]: https://github.com/syntax-tree/unist#node
377416

417+
[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
418+
419+
[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
420+
378421
[dfn-flow-content]: #flowcontent-gfm-footnotes
379422

380423
[dfn-static-phrasing-content]: #staticphrasingcontent-gfm-footnotes
381424

382425
[dfn-footnote-reference]: #footnotereference
383426

384427
[dfn-footnote-definition]: #footnotedefinition
428+
429+
[api-gfmfootnotefrommarkdown]: #gfmfootnotefrommarkdown
430+
431+
[api-gfmfootnotetomarkdown]: #gfmfootnotetomarkdown

0 commit comments

Comments
 (0)