micromark extension to support GFM tables
npm install micromark-extension-gfm-table[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[micromark][] extensions to support GFM [tables][].
* What is this?
* When to use this
* Install
* Use
* API
* gfmTable()
* gfmTableHtml()
* Bugs
* Authoring
* HTML
* CSS
* Syntax
* Types
* Compatibility
* Security
* Related
* Contribute
* License
This package contains extensions that add support for the table syntax enabled
by GFM to [micromark][micromark].
These extensions match github.com.
This project is useful when you want to support tables in markdown.
You can use these extensions when you are working with [micromark][micromark].
To support all GFM features, use
[micromark-extension-gfm][micromark-extension-gfm] instead.
When you need a syntax tree, combine this package with
[mdast-util-gfm-table][mdast-util-gfm-table].
All these packages are used in [remark-gfm][remark-gfm], which focusses on
making it easier to transform content by abstracting these internals away.
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
``sh`
npm install micromark-extension-gfm-table
In Deno with [esm.sh][esmsh]:
`js`
import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2'
In browsers with [esm.sh][esmsh]:
`html`
`js
import {micromark} from 'micromark'
import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table'
const output = micromark('| a |\n| - |', {
extensions: [gfmTable()],
htmlExtensions: [gfmTableHtml()]
})
console.log(output)
`
Yields:
`html`a
This package exports the identifiers [gfmTable][api-gfm-table] andgfmTableHtml
[][api-gfm-table-html].
There is no default export.
The export map supports the [development condition][development].node --conditions development module.js
Run to get instrumented dev code.
Without this condition, production code is loaded.
Create an HTML extension for micromark to support GitHub tables syntax.
###### Returns
Extension for micromark that can be passed in extensions to enable GFMExtension
table syntax ([][micromark-extension]).
Create an HTML extension for micromark to support GitHub tables when
serializing to HTML.
###### Returns
Extension for micromark that can be passed in htmlExtensions to supportHtmlExtension
GFM tables when serializing to HTML
([][micromark-html-extension]).
GitHub’s own algorithm to parse tables contains a bug.
This bug is not present in this project.
The issue relating to tables is:
* GFM tables: escaped escapes are incorrectly treated as
escapes
When authoring markdown with GFM tables, it’s recommended to always put
pipes around cells.
Without them, it can be hard to infer whether the table will work, how many
columns there are, and which column you are currently editing.
It is recommended to not use many columns, as it results in very long lines,
making it hard to infer which column you are currently editing.
For larger tables, particularly when cells vary in size, it is recommended
not to manually “pad” cell text.
While it can look better, it results in a lot of time spent realigning
everything when a new, longer cell is added or the longest cell removed, as
every row then must be changed.
Other than costing time, it also causes large diffs in Git.
To illustrate, when authoring large tables, it is discouraged to pad cells
like this:
`markdown`
| Alpha bravo charlie | delta |
| ------------------- | -----------------: |
| Echo | Foxtrot golf hotel |
Instead, use single spaces (and single filler dashes):
`markdown`
| Alpha bravo charlie | delta |
| - | -: |
| Echo | Foxtrot golf hotel |
GFM tables relate to several HTML elements:
, | , , and .table element][html-table],tbody element][html-tbody],td element][html-td],th element][html-th],thead element][html-thead], andtr element][html-tr]align attribute is added to each and element belonging totext-align propertysindresorhus/github-markdown-css][github-markdown-css]`css``abnf`:) used before and/or after delimiter row`markdown``markdown``html`| in them.| (or |, |, |, |) or\|.`markdown{ |\| |} |``html`micromark-extension-gfm-table@^2, compatible with Node.js 16.micromark version 3 and later.micromark-extension-gfm][micromark-extension-gfm]mdast-util-gfm-table][mdast-util-gfm-table]mdast-util-gfm][mdast-util-gfm]remark-gfm][remark-gfm]contributing.md in micromark/.github][contributing] for ways to getsupport.md`][support] for ways to get help.This project has a [code of conduct][coc]. License[MIT][license] © [Titus Wormer][author] [build-badge]: https://github.com/micromark/micromark-extension-gfm-table/workflows/main/badge.svg [build]: https://github.com/micromark/micromark-extension-gfm-table/actions [coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-table.svg [coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-table [downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-table.svg [downloads]: https://www.npmjs.com/package/micromark-extension-gfm-table [size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-table [size]: https://bundlejs.com/?q=micromark-extension-gfm-table [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg [backers-badge]: https://opencollective.com/unified/backers/badge.svg [collective]: https://opencollective.com/unified [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg [chat]: https://github.com/micromark/micromark/discussions [npm]: https://docs.npmjs.com/cli/install [esmsh]: https://esm.sh [license]: license [author]: https://wooorm.com [contributing]: https://github.com/micromark/.github/blob/main/contributing.md [support]: https://github.com/micromark/.github/blob/main/support.md [coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c [typescript]: https://www.typescriptlang.org [development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions [micromark]: https://github.com/micromark/micromark [micromark-extension]: https://github.com/micromark/micromark#syntaxextension [micromark-html-extension]: https://github.com/micromark/micromark#htmlextension [micromark-content-type]: https://github.com/micromark/micromark#content-types [micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm [mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm [mdast-util-gfm-table]: https://github.com/syntax-tree/mdast-util-gfm-table [remark-gfm]: https://github.com/remarkjs/remark-gfm [tables]: https://github.github.com/gfm/#tables-extension- [html-table]: https://html.spec.whatwg.org/multipage/tables.html#the-table-element [html-tbody]: https://html.spec.whatwg.org/multipage/tables.html#the-tbody-element [html-thead]: https://html.spec.whatwg.org/multipage/tables.html#the-thead-element [html-tr]: https://html.spec.whatwg.org/multipage/tables.html#the-tr-element [html-td]: https://html.spec.whatwg.org/multipage/tables.html#the-td-element [html-th]: https://html.spec.whatwg.org/multipage/tables.html#the-th-element [github-markdown-css]: https://github.com/sindresorhus/github-markdown-css [api-gfm-table]: #gfmtable [api-gfm-table-html]: #gfmtablehtml |
|---|