micromark extension to support GFM tables
Installations
npm install micromark-extension-gfm-table
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
23.1.0
NPM Version
11.0.0
Score
99.2
Supply Chain
99.6
Quality
82.6
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
326,257,180
Last Day
851,307
Last Week
3,921,657
Last Month
16,791,896
Last Year
175,428,637
GitHub Statistics
7 Stars
103 Commits
7 Forks
7 Watching
1 Branches
13 Contributors
Bundle Size
7.83 kB
Minified
2.56 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
2.1.1
Package Id
micromark-extension-gfm-table@2.1.1
Unpacked Size
89.92 kB
Size
17.31 kB
File Count
31
NPM Version
11.0.0
Node Version
23.1.0
Publised On
20 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
326,257,180
Last day
-3.3%
851,307
Compared to previous day
Last week
-11.1%
3,921,657
Compared to previous week
Last month
10.7%
16,791,896
Compared to previous month
Last year
89.2%
175,428,637
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
micromark-extension-gfm-table
micromark extensions to support GFM tables.
Contents
- What is this?
- When to use this
- Install
- Use
- API
- Bugs
- Authoring
- HTML
- CSS
- Syntax
- Types
- Compatibility
- Security
- Related
- Contribute
- License
What is this?
This package contains extensions that add support for the table syntax enabled
by GFM to micromark
.
These extensions match github.com.
When to use this
This project is useful when you want to support tables in markdown.
You can use these extensions when you are working with micromark
.
To support all GFM features, use
micromark-extension-gfm
instead.
When you need a syntax tree, combine this package with
mdast-util-gfm-table
.
All these packages are used in remark-gfm
, which focusses on
making it easier to transform content by abstracting these internals away.
Install
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install micromark-extension-gfm-table
In Deno with esm.sh
:
1import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2?bundle' 3</script>
Use
1import {micromark} from 'micromark' 2import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table' 3 4const output = micromark('| a |\n| - |', { 5 extensions: [gfmTable()], 6 htmlExtensions: [gfmTableHtml()] 7}) 8 9console.log(output)
Yields:
1<table> 2<thead> 3<tr> 4<th>a</th> 5</tr> 6</thead> 7</table>
API
This package exports the identifiers gfmTable
and
gfmTableHtml
.
There is no default export.
The export map supports the development
condition.
Run node --conditions development module.js
to get instrumented dev code.
Without this condition, production code is loaded.
gfmTable()
Create an HTML extension for micromark
to support GitHub tables syntax.
Returns
Extension for micromark
that can be passed in extensions
to enable GFM
table syntax (Extension
).
gfmTableHtml()
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 support
GFM tables when serializing to HTML
(HtmlExtension
).
Bugs
GitHub’s own algorithm to parse tables contains a bug. This bug is not present in this project. The issue relating to tables is:
Authoring
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:
1| Alpha bravo charlie | delta | 2| ------------------- | -----------------: | 3| Echo | Foxtrot golf hotel |
Instead, use single spaces (and single filler dashes):
1| Alpha bravo charlie | delta | 2| - | -: | 3| Echo | Foxtrot golf hotel |
HTML
GFM tables relate to several HTML elements: <table>
, <tbody>
, <td>
,
<th>
, <thead>
, and <tr>
.
See
§ 4.9.1 The table
element,
§ 4.9.5 The tbody
element,
§ 4.9.9 The td
element,
§ 4.9.10 The th
element,
§ 4.9.6 The thead
element, and
§ 4.9.8 The tr
element
in the HTML spec for more info.
If the alignment of a column is left, right, or center, a deprecated
align
attribute is added to each <th>
and <td>
element belonging to
that column.
That attribute is interpreted by browsers as if a CSS text-align
property
was included, with its value set to that same keyword.
CSS
The following CSS is needed to make tables look a bit like GitHub.
For the complete actual CSS see
sindresorhus/github-markdown-css
1/* Light theme. */ 2:root { 3 --color-canvas-default: #ffffff; 4 --color-canvas-subtle: #f6f8fa; 5 --color-border-default: #d0d7de; 6 --color-border-muted: hsla(210, 18%, 87%, 1); 7} 8 9/* Dark theme. */ 10@media (prefers-color-scheme: dark) { 11 :root { 12 --color-canvas-default: #0d1117; 13 --color-canvas-subtle: #161b22; 14 --color-border-default: #30363d; 15 --color-border-muted: #21262d; 16 } 17} 18 19table { 20 border-spacing: 0; 21 border-collapse: collapse; 22 display: block; 23 margin-top: 0; 24 margin-bottom: 16px; 25 width: max-content; 26 max-width: 100%; 27 overflow: auto; 28} 29 30tr { 31 background-color: var(--color-canvas-default); 32 border-top: 1px solid var(--color-border-muted); 33} 34 35tr:nth-child(2n) { 36 background-color: var(--color-canvas-subtle); 37} 38 39td, 40th { 41 padding: 6px 13px; 42 border: 1px solid var(--color-border-default); 43} 44 45th { 46 font-weight: 600; 47} 48 49table img { 50 background-color: transparent; 51}
Syntax
Tables form with the following BNF:
1gfmTable ::= gfmTableHead 0*(eol gfmTableBodyRow) 2 3; Restriction: both rows must have the same number of cells. 4gfmTableHead ::= gfmTableRow eol gfmTableDelimiterRow 5 6gfmTableRow ::= ["|"] gfmTableCell 0*("|" gfmTableCell) ["|"] *spaceOrTab 7gfmTableCell ::= *spaceOrTab gfmTableText *spaceOrTab 8gfmTableText ::= 0*(line - "\\" - "|" / "\\" ["\\" / "|"]) 9 10gfmTableDelimiterRow ::= ["|"] gfmTableDelimiterCell 0*("|" gfmTableDelimiterCell) ["|"] *spaceOrTab 11gfmTableDelimiterCell ::= *spaceOrTab gfmTableDelimiterValue *spaceOrTab 12gfmTableDelimiterValue ::= [":"] 1*"-" [":"]
As this construct occurs in flow, like all flow constructs, it must be followed by an eol (line ending) or eof (end of file).
The above grammar shows that basically anything can be a cell or a row. The main thing that makes something a row, is that it occurs directly before or after a delimiter row, or after another row.
It is not required for a table to have a body: it can end right after the delimiter row.
Each column can be marked with an alignment.
The alignment marker is a colon (:
) used before and/or after delimiter row
filler.
To illustrate:
1| none | left | right | center | 2| ---- | :--- | ----: | :----: |
The number of cells in the delimiter row, is the number of columns of the table. Only the head row is required to have the same number of cells. Body rows are not required to have a certain number of cells. For body rows that have less cells than the number of columns of the table, empty cells are injected. When a row has more cells than the number of columns of the table, the superfluous cells are dropped. To illustrate:
1| a | b | 2| - | - | 3| c | 4| d | e | f |
Yields:
1<table> 2<thead> 3<tr> 4<th>a</th> 5<th>b</th> 6</tr> 7</thead> 8<tbody> 9<tr> 10<td>c</td> 11<td></td> 12</tr> 13<tr> 14<td>d</td> 15<td>e</td> 16</tr> 17</tbody> 18</table>
Each cell’s text is interpreted as the text content type. That means that it can include constructs such as attention (emphasis, strong).
The grammar for cells prohibits the use of |
in them.
To use pipes in cells, encode them as a character reference or character
escape: |
(or |
, |
, |
, |
) or
\|
.
Escapes will typically work, but they are not supported in code (text) (and the math (text) extension). To work around this, GitHub came up with a rather weird “trick”. When inside a table cell and inside code, escaped pipes are decoded. To illustrate:
1| Name | Character |
2| - | - |
3| Left curly brace | `{` |
4| Pipe | `\|` |
5| Right curly brace | `}` |
Yields:
1<table> 2<thead> 3<tr> 4<th>Name</th> 5<th>Character</th> 6</tr> 7</thead> 8<tbody> 9<tr> 10<td>Left curly brace</td> 11<td><code>{</code></td> 12</tr> 13<tr> 14<td>Pipe</td> 15<td><code>|</code></td> 16</tr> 17<tr> 18<td>Right curly brace</td> 19<td><code>}</code></td> 20</tr> 21</tbody> 22</table>
👉 Note: no other character can be escaped like this. Escaping pipes in code does not work when not inside a table, either.
Types
This package is fully typed with TypeScript. It exports no additional types.
Compatibility
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
micromark-extension-gfm-table@^2
, compatible with Node.js 16.
This package works with micromark
version 3
and later.
Security
This package is safe.
Related
micromark-extension-gfm
— support all of GFMmdast-util-gfm-table
— support all of GFM in mdastmdast-util-gfm
— support all of GFM in mdastremark-gfm
— support all of GFM in remark
Contribute
See contributing.md
in micromark/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/micromark/.github/security.md:1
- Info: Found linked content: github.com/micromark/.github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/micromark/.github/security.md:1
- Info: Found text in security policy: github.com/micromark/.github/security.md:1
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/bb.yml:1
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:5: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-gfm-table/bb.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:6: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-gfm-table/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-gfm-table/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/micromark/micromark-extension-gfm-table/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:11
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
4.9
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More