Skip to content

Commit 3f488e0

Browse files
committed
Add improved docs
1 parent 7179d76 commit 3f488e0

File tree

1 file changed

+89
-52
lines changed

1 file changed

+89
-52
lines changed

readme.md

Lines changed: 89 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
* [API](#api)
2020
* [`gfmTableFromMarkdown`](#gfmtablefrommarkdown)
2121
* [`gfmTableToMarkdown(options?)`](#gfmtabletomarkdownoptions)
22+
* [`Options`](#options)
2223
* [Examples](#examples)
2324
* [Example: `stringLength`](#example-stringlength)
25+
* [HTML](#html)
26+
* [Syntax](#syntax)
2427
* [Syntax tree](#syntax-tree)
2528
* [Nodes](#nodes)
2629
* [Enumeration](#enumeration)
@@ -33,29 +36,39 @@
3336

3437
## What is this?
3538

36-
This package contains extensions that add support for the table syntax enabled
37-
by GFM to [`mdast-util-from-markdown`][mdast-util-from-markdown] and
38-
[`mdast-util-to-markdown`][mdast-util-to-markdown].
39+
This package contains two extensions that add support for GFM table syntax in
40+
markdown to [mdast][].
41+
These extensions plug into
42+
[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing
43+
tables in markdown into a syntax tree) and
44+
[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing
45+
tables in syntax trees to markdown).
3946

4047
## When to use this
4148

42-
These tools are all rather low-level.
43-
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-table`][extension].
54+
55+
When you don’t need a syntax tree, you can use [`micromark`][micromark]
56+
directly with `micromark-extension-gfm-table`.
4457

4558
When you are working with syntax trees and want all of GFM, use
4659
[`mdast-util-gfm`][mdast-util-gfm] instead.
4760

48-
When working with `mdast-util-from-markdown`, you must combine this package with
49-
[`micromark-extension-gfm-table`][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.
5064

5165
This utility does not handle how markdown is turned to HTML.
5266
That’s done by [`mdast-util-to-hast`][mdast-util-to-hast].
53-
If your content is not in English, you should configure that utility.
5467

5568
## Install
5669

5770
This package is [ESM only][esm].
58-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
71+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
5972

6073
```sh
6174
npm install mdast-util-gfm-table
@@ -160,43 +173,44 @@ console.log(out)
160173

161174
## API
162175

163-
This package exports the identifiers `gfmTableFromMarkdown` and
164-
`gfmTableToMarkdown`.
176+
This package exports the identifiers
177+
[`gfmTableFromMarkdown`][api-gfmtablefrommarkdown] and
178+
[`gfmTableToMarkdown`][api-gfmtabletomarkdown].
165179
There is no default export.
166180

167181
### `gfmTableFromMarkdown`
168182

169-
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown].
183+
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable
184+
GFM tables ([`FromMarkdownExtension`][frommarkdownextension]).
170185

171186
### `gfmTableToMarkdown(options?)`
172187

173-
Function that can be called to get an extension for
174-
[`mdast-util-to-markdown`][mdast-util-to-markdown].
188+
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to
189+
enable GFM tables in markdown.
175190

176-
##### `options`
191+
###### Parameters
177192

178-
Configuration (optional).
193+
* `options` ([`Options`][api-options], optional)
194+
— configuration
179195

180-
###### `options.tableCellPadding`
196+
###### Returns
181197

182-
Serialize tables with a space between delimiters (`|`) and cell content
183-
(`boolean`, default: `true`).
198+
Extension for `mdast-util-to-markdown` to enable GFM tables
199+
([`ToMarkdownExtension`][tomarkdownextension]).
184200

185-
###### `options.tablePipeAlign`
201+
### `Options`
186202

187-
Serialize by aligning the delimiters (`|`) between table cells so that they all
188-
align nicely and form a grid (`boolean`, default: `true`).
203+
Configuration (TypeScript type).
189204

190-
###### `options.stringLength`
205+
###### Fields
191206

192-
Function to detect the length of table cell content (`Function`, default:
193-
`s => s.length`).
194-
This is used when aligning the delimiters (`|`) between table cells.
195-
Full-width characters and emoji mess up delimiter alignment when viewing the
196-
markdown source.
197-
To fix this, you can pass this function, which receives the cell content and
198-
returns its “visible” size.
199-
Note that what is and isn’t visible depends on where the text is displayed.
207+
* `tableCellPadding` (`boolean`, default: `true`)
208+
— whether to add a space of padding between delimiters and cells
209+
* `tablePipeAlign` (`boolean`, default: `true`)
210+
— whether to align the delimiters
211+
* `stringLength` (`((value: string) => number)`, default: `s => s.length`)
212+
— function to detect the length of table cell content, used when aligning
213+
the delimiters between cells
200214

201215
## Examples
202216

@@ -269,6 +283,15 @@ The output of our code with these changes is as follows:
269283
| 👩‍❤️‍👩 | Delta |
270284
```
271285

286+
## HTML
287+
288+
This utility does not handle how markdown is turned to HTML.
289+
That’s done by [`mdast-util-to-hast`][mdast-util-to-hast].
290+
291+
## Syntax
292+
293+
See [Syntax in `micromark-extension-gfm-table`][syntax].
294+
272295
## Syntax tree
273296

274297
The following interfaces are added to **[mdast][]** by this utility.
@@ -285,15 +308,15 @@ interface Table <: Parent {
285308
}
286309
```
287310

288-
**Table** ([**Parent**][dfn-parent]) represents two-dimensional data.
311+
**Table** (**[Parent][dfn-parent]**) represents two-dimensional data.
289312

290-
**Table** can be used where [**flow**][dfn-flow-content] content is expected.
291-
Its content model is [**table**][dfn-table-content] content.
313+
**Table** can be used where **[flow][dfn-flow-content]** content is expected.
314+
Its content model is **[table][dfn-table-content]** content.
292315

293-
The [*head*][term-head] of the node represents the labels of the columns.
316+
The *[head][term-head]* of the node represents the labels of the columns.
294317

295318
An `align` field can be present.
296-
If present, it must be a list of [**alignType**s][dfn-enum-align-type].
319+
If present, it must be a list of **[alignTypes][dfn-enum-align-type]**.
297320
It represents how cells in columns are aligned.
298321

299322
For example, the following markdown:
@@ -350,16 +373,16 @@ interface TableRow <: Parent {
350373
}
351374
```
352375

353-
**TableRow** ([**Parent**][dfn-parent]) represents a row of cells in a table.
376+
**TableRow** (**[Parent][dfn-parent]**) represents a row of cells in a table.
354377

355-
**TableRow** can be used where [**table**][dfn-table-content] content is
378+
**TableRow** can be used where **[table][dfn-table-content]** content is
356379
expected.
357-
Its content model is [**row**][dfn-row-content] content.
380+
Its content model is **[row][dfn-row-content]** content.
358381

359-
If the node is a [*head*][term-head], it represents the labels of the columns
360-
for its parent [**Table**][dfn-table].
382+
If the node is a *[head][term-head]*, it represents the labels of the columns
383+
for its parent **[Table][dfn-table]**.
361384

362-
For an example, see [**Table**][dfn-table].
385+
For an example, see **[Table][dfn-table]**.
363386

364387
#### `TableCell`
365388

@@ -370,15 +393,15 @@ interface TableCell <: Parent {
370393
}
371394
```
372395

373-
**TableCell** ([**Parent**][dfn-parent]) represents a header cell in a
374-
[**Table**][dfn-table], if its parent is a [*head*][term-head], or a data
396+
**TableCell** (**[Parent][dfn-parent]**) represents a header cell in a
397+
**[Table][dfn-table]**, if its parent is a *[head][term-head]*, or a data
375398
cell otherwise.
376399

377-
**TableCell** can be used where [**row**][dfn-row-content] content is expected.
378-
Its content model is [**phrasing**][dfn-phrasing-content] content excluding
379-
[**Break**][dfn-break] nodes.
400+
**TableCell** can be used where **[row][dfn-row-content]** content is expected.
401+
Its content model is **[phrasing][dfn-phrasing-content]** content excluding
402+
**[Break][dfn-break]** nodes.
380403

381-
For an example, see [**Table**][dfn-table].
404+
For an example, see **[Table][dfn-table]**.
382405

383406
### Enumeration
384407

@@ -428,16 +451,16 @@ type RowContent = TableCell
428451
## Types
429452

430453
This package is fully typed with [TypeScript][].
431-
It exports the additional type `Options`.
454+
It exports the additional type [`Options`][api-options].
432455

433-
The `Table`, `TableRow`, and `TableCell` node types are supported in
434-
`@types/mdast` by default.
456+
The `Table`, `TableRow`, and `TableCell` types of the mdast nodes are exposed
457+
from `@types/mdast`.
435458

436459
## Compatibility
437460

438461
Projects maintained by the unified collective are compatible with all maintained
439462
versions of Node.js.
440-
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
463+
As of now, that is Node.js 14.14+ and 16.0+.
441464
Our projects sometimes work with older versions, but this is not guaranteed.
442465

443466
This plugin works with `mdast-util-from-markdown` version 1+ and
@@ -527,8 +550,12 @@ abide by its terms.
527550

528551
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
529552

553+
[micromark]: https://github.com/micromark/micromark
554+
530555
[extension]: https://github.com/micromark/micromark-extension-gfm-table
531556

557+
[syntax]: https://github.com/micromark/micromark-extension-gfm-table#syntax
558+
532559
[gfm]: https://github.github.com/gfm/
533560

534561
[string-width]: https://github.com/sindresorhus/string-width
@@ -549,6 +576,16 @@ abide by its terms.
549576

550577
[dfn-break]: https://github.com/syntax-tree/mdast#break
551578

579+
[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
580+
581+
[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
582+
583+
[api-gfmtablefrommarkdown]: #gfmtablefrommarkdown
584+
585+
[api-gfmtabletomarkdown]: #gfmtabletomarkdownoptions
586+
587+
[api-options]: #options
588+
552589
[dfn-flow-content]: #flowcontent-gfm-table
553590

554591
[dfn-table-content]: #tablecontent

0 commit comments

Comments
 (0)