mdast-util-gfm-table

WebJar for mdast-util-gfm-table

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

mdast-util-gfm-table
Last Version

Last Version

0.1.6
Release Date

Release Date

Type

Type

jar
Description

Description

mdast-util-gfm-table
WebJar for mdast-util-gfm-table
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/syntax-tree/mdast-util-gfm-table

Download mdast-util-gfm-table

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-gfm-table/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>mdast-util-gfm-table</artifactId>
    <version>0.1.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-gfm-table/
implementation 'org.webjars.npm:mdast-util-gfm-table:0.1.6'
// https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-gfm-table/
implementation ("org.webjars.npm:mdast-util-gfm-table:0.1.6")
'org.webjars.npm:mdast-util-gfm-table:jar:0.1.6'
<dependency org="org.webjars.npm" name="mdast-util-gfm-table" rev="0.1.6">
  <artifact name="mdast-util-gfm-table" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='mdast-util-gfm-table', version='0.1.6')
)
libraryDependencies += "org.webjars.npm" % "mdast-util-gfm-table" % "0.1.6"
[org.webjars.npm/mdast-util-gfm-table "0.1.6"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : markdown-table jar [2.0.0,3)
org.webjars.npm » mdast-util-to-markdown jar [0.6.0,0.7)

Project Modules

There are no modules declared in this project.

mdast-util-gfm-table

Build Coverage Downloads Size Sponsors Backers Chat

Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support GitHub flavored markdown tables in mdast. When parsing (from-markdown), must be combined with micromark-extension-gfm-table.

You probably shouldn’t use this package directly, but instead use remark-gfm with remark.

Install

npm:

npm install mdast-util-gfm-table

Use

Say we have the following file, example.md:

| a | b | c | d |
| - | :- | -: | :-: |
| e | f |
| g | h | i | j | k |

And our script, example.js, looks as follows:

var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-table')
var table = require('mdast-util-gfm-table')

var doc = fs.readFileSync('example.md')

var tree = fromMarkdown(doc, {
  extensions: [syntax],
  mdastExtensions: [table.fromMarkdown]
})

console.log(tree)

var out = toMarkdown(tree, {extensions: [table.toMarkdown()]})

console.log(out)

Now, running node example yields (positional info removed for the sake of brevity):

{
  type: 'root',
  children: [
    {
      type: 'table',
      align: [null, 'left', 'right', 'center'],
      children: [
        {
          type: 'tableRow',
          children: [
            {type: 'tableCell', children: [{type: 'text', value: 'a'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'b'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'c'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'd'}]}
          ]
        },
        {
          type: 'tableRow',
          children: [
            {type: 'tableCell', children: [{type: 'text', value: 'e'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'f'}]}
          ]
        },
        {
          type: 'tableRow',
          children: [
            {type: 'tableCell', children: [{type: 'text', value: 'g'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'h'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'i'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'j'}]},
            {type: 'tableCell', children: [{type: 'text', value: 'k'}]}
          ]
        }
      ]
    }
  ]
}
| a | b  |  c |  d  |   |
| - | :- | -: | :-: | - |
| e | f  |    |     |   |
| g | h  |  i |  j  | k |

API

table.fromMarkdown

table.toMarkdown(options?)

Note: the separate extensions are also available at mdast-util-gfm-table/from-markdown and mdast-util-gfm-table/to-markdown.

Support tables. The exports of fromMarkdown is an extension for mdast-util-from-markdown. The export of toMarkdown is a function that can be called with options and returns an extension for mdast-util-to-markdown.

options
options.tableCellPadding

Create tables with a space between cell delimiters (|) and content (boolean, default: true).

options.tablePipeAlign

Align the delimiters (|) between table cells so that they all align nicely and form a grid (boolean, default: true).

options.stringLength

Function passed to markdown-table to detect the length of a table cell (Function, default: s => s.length). Used to pad tables.

Related

Contribute

See 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.

License

MIT © Titus Wormer

org.webjars.npm
🌲🌲🌲🌳🌲🌳🌲🌲🌲🌳🌳🌲🌲🌳🌲🌲🎄🌲🌳🌲🌲🌳🐻🌳🌳🌳🌲🌲🌳🌲🎄🌲🌳🌲🌲🌳🌳🌳

Versions

Version
0.1.6