Gathering detailed insights and metrics for mdast-util-gfm-table
Gathering detailed insights and metrics for mdast-util-gfm-table
Gathering detailed insights and metrics for mdast-util-gfm-table
Gathering detailed insights and metrics for mdast-util-gfm-table
mdast-util-gfm-task-list-item
mdast extension to parse and serialize GFM task list items
mdast-util-gfm-strikethrough
mdast extension to parse and serialize GFM strikethrough
mdast-util-gfm
mdast extension to parse and serialize GFM (GitHub Flavored Markdown)
mdast-util-gfm-autolink-literal
mdast extension to parse and serialize GFM autolink literals
mdast extension to parse and serialize GFM tables
npm install mdast-util-gfm-table
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
13 Stars
78 Commits
7 Forks
9 Watching
1 Branches
12 Contributors
Updated on 15 Oct 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
0.3%
805,896
Compared to previous day
Last week
6.2%
4,242,174
Compared to previous week
Last month
18.2%
17,283,947
Compared to previous month
Last year
98.7%
161,511,864
Compared to previous year
mdast extensions to parse and serialize GFM tables.
This package contains two extensions that add support for GFM table syntax in
markdown to mdast.
These extensions plug into
mdast-util-from-markdown
(to support parsing
tables in markdown into a syntax tree) and
mdast-util-to-markdown
(to support serializing
tables in syntax trees to markdown).
You can use these extensions when you are working with
mdast-util-from-markdown
and mdast-util-to-markdown
already.
When working with mdast-util-from-markdown
, you must combine this package
with micromark-extension-gfm-table
.
When you don’t need a syntax tree, you can use micromark
directly with micromark-extension-gfm-table
.
When you are working with syntax trees and want all of GFM, use
mdast-util-gfm
instead.
All these packages are used remark-gfm
, which
focusses on making it easier to transform content by abstracting these
internals away.
This utility does not handle how markdown is turned to HTML.
That’s done by mdast-util-to-hast
.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install mdast-util-gfm-table
In Deno with esm.sh
:
1import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'https://esm.sh/mdast-util-gfm-table@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'https://esm.sh/mdast-util-gfm-table@2?bundle' 3</script>
Say our document example.md
contains:
1| a | b | c | d | 2| - | :- | -: | :-: | 3| e | f | 4| g | h | i | j | k |
…and our module example.js
looks as follows:
1import fs from 'node:fs/promises' 2import {gfmTable} from 'micromark-extension-gfm-table' 3import {fromMarkdown} from 'mdast-util-from-markdown' 4import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' 5import {toMarkdown} from 'mdast-util-to-markdown' 6 7const doc = await fs.readFile('example.md') 8 9const tree = fromMarkdown(doc, { 10 extensions: [gfmTable()], 11 mdastExtensions: [gfmTableFromMarkdown()] 12}) 13 14console.log(tree) 15 16const out = toMarkdown(tree, {extensions: [gfmTableToMarkdown()]}) 17 18console.log(out)
…now running node example.js
yields (positional info removed for brevity):
1{ 2 type: 'root', 3 children: [ 4 { 5 type: 'table', 6 align: [null, 'left', 'right', 'center'], 7 children: [ 8 { 9 type: 'tableRow', 10 children: [ 11 {type: 'tableCell', children: [{type: 'text', value: 'a'}]}, 12 {type: 'tableCell', children: [{type: 'text', value: 'b'}]}, 13 {type: 'tableCell', children: [{type: 'text', value: 'c'}]}, 14 {type: 'tableCell', children: [{type: 'text', value: 'd'}]} 15 ] 16 }, 17 { 18 type: 'tableRow', 19 children: [ 20 {type: 'tableCell', children: [{type: 'text', value: 'e'}]}, 21 {type: 'tableCell', children: [{type: 'text', value: 'f'}]} 22 ] 23 }, 24 { 25 type: 'tableRow', 26 children: [ 27 {type: 'tableCell', children: [{type: 'text', value: 'g'}]}, 28 {type: 'tableCell', children: [{type: 'text', value: 'h'}]}, 29 {type: 'tableCell', children: [{type: 'text', value: 'i'}]}, 30 {type: 'tableCell', children: [{type: 'text', value: 'j'}]}, 31 {type: 'tableCell', children: [{type: 'text', value: 'k'}]} 32 ] 33 } 34 ] 35 } 36 ] 37}
1| a | b | c | d | | 2| - | :- | -: | :-: | - | 3| e | f | | | | 4| g | h | i | j | k |
This package exports the identifiers
gfmTableFromMarkdown
and
gfmTableToMarkdown
.
There is no default export.
gfmTableFromMarkdown
Create an extension for mdast-util-from-markdown
to enable GFM tables in markdown.
Extension for mdast-util-from-markdown
to enable GFM tables
(FromMarkdownExtension
).
gfmTableToMarkdown(options?)
Create an extension for mdast-util-to-markdown
to
enable GFM tables in markdown.
options
(Options
, optional)
— configurationExtension for mdast-util-to-markdown
to enable GFM tables
(ToMarkdownExtension
).
Options
Configuration (TypeScript type).
tableCellPadding
(boolean
, default: true
)
— whether to add a space of padding between delimiters and cellstablePipeAlign
(boolean
, default: true
)
— whether to align the delimitersstringLength
(((value: string) => number)
, default: s => s.length
)
— function to detect the length of table cell content, used when aligning
the delimiters between cellsstringLength
It’s possible to align tables based on the visual width of cells. First, let’s show the problem:
1import {gfmTable} from 'micromark-extension-gfm-table' 2import {fromMarkdown} from 'mdast-util-from-markdown' 3import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' 4import {toMarkdown} from 'mdast-util-to-markdown' 5 6const doc = `| Alpha | Bravo | 7| - | - | 8| 中文 | Charlie | 9| 👩❤️👩 | Delta |` 10 11const tree = fromMarkdown(doc, { 12 extensions: [gfmTable], 13 mdastExtensions: [gfmTableFromMarkdown] 14}) 15 16console.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]}))
The above code shows how these utilities can be used to format markdown. The output is as follows:
1| Alpha | Bravo | 2| -------- | ------- | 3| 中文 | Charlie | 4| 👩❤️👩 | Delta |
To improve the alignment of these full-width characters and emoji, pass a
stringLength
function that calculates the visual width of cells.
One such algorithm is string-width
.
It can be used like so:
1@@ -2,6 +2,7 @@ import {gfmTable} from 'micromark-extension-gfm-table' 2 import {fromMarkdown} from 'mdast-util-from-markdown' 3 import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' 4 import {toMarkdown} from 'mdast-util-to-markdown' 5+import stringWidth from 'string-width' 6 7 const doc = `| Alpha | Bravo | 8 | - | - | 9@@ -13,4 +14,8 @@ const tree = fromMarkdown(doc, { 10 mdastExtensions: [gfmTableFromMarkdown()] 11 }) 12 13-console.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]})) 14+console.log( 15+ toMarkdown(tree, { 16+ extensions: [gfmTableToMarkdown({stringLength: stringWidth})] 17+ }) 18+)
The output of our code with these changes is as follows:
1| Alpha | Bravo | 2| ----- | ------- | 3| 中文 | Charlie | 4| 👩❤️👩 | Delta |
This utility does not handle how markdown is turned to HTML.
That’s done by mdast-util-to-hast
.
See Syntax in micromark-extension-gfm-table
.
The following interfaces are added to mdast by this utility.
Table
1interface Table <: Parent { 2 type: 'table' 3 align: [alignType]? 4 children: [TableContent] 5}
Table (Parent) represents two-dimensional data.
Table can be used where flow content is expected. Its content model is table content.
The head of the node represents the labels of the columns.
An align
field can be present.
If present, it must be a list of alignTypes.
It represents how cells in columns are aligned.
For example, the following markdown:
1| foo | bar | 2| :-- | :-: | 3| baz | qux |
Yields:
1{ 2 type: 'table', 3 align: ['left', 'center'], 4 children: [ 5 { 6 type: 'tableRow', 7 children: [ 8 { 9 type: 'tableCell', 10 children: [{type: 'text', value: 'foo'}] 11 }, 12 { 13 type: 'tableCell', 14 children: [{type: 'text', value: 'bar'}] 15 } 16 ] 17 }, 18 { 19 type: 'tableRow', 20 children: [ 21 { 22 type: 'tableCell', 23 children: [{type: 'text', value: 'baz'}] 24 }, 25 { 26 type: 'tableCell', 27 children: [{type: 'text', value: 'qux'}] 28 } 29 ] 30 } 31 ] 32}
TableRow
1interface TableRow <: Parent { 2 type: "tableRow" 3 children: [RowContent] 4}
TableRow (Parent) represents a row of cells in a table.
TableRow can be used where table content is expected. Its content model is row content.
If the node is a head, it represents the labels of the columns for its parent Table.
For an example, see Table.
TableCell
1interface TableCell <: Parent { 2 type: "tableCell" 3 children: [PhrasingContent] 4}
TableCell (Parent) represents a header cell in a Table, if its parent is a head, or a data cell otherwise.
TableCell can be used where row content is expected. Its content model is phrasing content excluding Break nodes.
For an example, see Table.
alignType
1enum alignType { 2 'center' | 'left' | 'right' | null 3}
alignType represents how phrasing content is aligned ([CSSTEXT]).
'left'
: See the left
value of the text-align
CSS
property'right'
: See the right
value of the text-align
CSS property'center'
: See the center
value of the text-align
CSS propertynull
: phrasing content is aligned as defined by the host environmentFlowContent
(GFM table)1type FlowContentGfm = Table | FlowContent
TableContent
1type TableContent = TableRow
Table content represent the rows in a table.
RowContent
1type RowContent = TableCell
Row content represent the cells in a row.
This package is fully typed with TypeScript.
It exports the additional type Options
.
The Table
, TableRow
, and TableCell
types of the mdast nodes are exposed
from @types/mdast
.
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, mdast-util-gfm-table@^2
,
compatible with Node.js 16.
This utility works with mdast-util-from-markdown
version 2+ and
mdast-util-to-markdown
version 2+.
remarkjs/remark-gfm
— remark plugin to support GFMsyntax-tree/mdast-util-gfm
— same but all of GFM (autolink literals, footnotes, strikethrough, tables,
tasklists)micromark/micromark-extension-gfm-table
— micromark extension to parse GFM tablesSee contributing.md
in syntax-tree/.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.
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
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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