markdown-table

WebJar for markdown-table

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

markdown-table
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

markdown-table
WebJar for markdown-table
Project URL

Project URL

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

Source Code Management

https://github.com/wooorm/markdown-table

Download markdown-table

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : repeat-string jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

markdown-table

Build Coverage Downloads Size

Generate fancy Markdown tables.

Install

npm:

npm install markdown-table

Use

Typical usage (defaults to align left):

var table = require('markdown-table')

table([
  ['Branch', 'Commit'],
  ['main', '0123456789abcdef'],
  ['staging', 'fedcba9876543210']
])

Yields:

| Branch  | Commit           |
| ------- | ---------------- |
| main    | 0123456789abcdef |
| staging | fedcba9876543210 |

With align:

table(
  [
    ['Beep', 'No.', 'Boop'],
    ['beep', '1024', 'xyz'],
    ['boop', '3388450', 'tuv'],
    ['foo', '10106', 'qrstuv'],
    ['bar', '45', 'lmno']
  ],
  {align: ['l', 'c', 'r']}
)

Yields:

| Beep |   No.   |   Boop |
| :--- | :-----: | -----: |
| beep |   1024  |    xyz |
| boop | 3388450 |    tuv |
| foo  |  10106  | qrstuv |
| bar  |    45   |   lmno |

API

markdownTable(table[, options])

Turns a given matrix of strings (an array of arrays of strings) into a table.

options
options.align

One style for all columns, or styles for their respective columns (string or Array.<string>). Each style is either 'l' (left), 'r' (right), or 'c' (center). Other values are treated as '', which doesn’t place the colon in the alignment row but does align left. Only the lowercased first character is used, so Right is fine.

options.padding

Whether to add a space of padding between delimiters and cells (boolean, default: true).

When true, there is padding:

| Alpha | B     |
| ----- | ----- |
| C     | Delta |

When false, there is no padding:

|Alpha|B    |
|-----|-----|
|C    |Delta|
options.delimiterStart

Whether to begin each row with the delimiter (boolean, default: true).

Note: please don’t use this: it could create fragile structures that aren’t understandable to some Markdown parsers.

When true, there are starting delimiters:

| Alpha | B     |
| ----- | ----- |
| C     | Delta |

When false, there are no starting delimiters:

Alpha | B     |
----- | ----- |
C     | Delta |
options.delimiterEnd

Whether to end each row with the delimiter (boolean, default: true).

Note: please don’t use this: it could create fragile structures that aren’t understandable to some Markdown parsers.

When true, there are ending delimiters:

| Alpha | B     |
| ----- | ----- |
| C     | Delta |

When false, there are no ending delimiters:

| Alpha | B
| ----- | -----
| C     | Delta
options.alignDelimiters

Whether to align the delimiters (boolean, default: true). By default, they are aligned:

| Alpha | B     |
| ----- | ----- |
| C     | Delta |

Pass false to make them staggered:

| Alpha | B |
| - | - |
| C | Delta |
options.stringLength

Method to detect the length of a cell (Function, default: s => s.length).

Full-width characters and ANSI-sequences all mess up delimiter alignment when viewing the Markdown source. To fix this, you have to pass in a stringLength option to detect the “visible” length of a cell (note that what is and isn’t visible depends on your editor).

Without such a function, the following:

table([
  ['Alpha', 'Bravo'],
  ['中文', 'Charlie'],
  ['👩‍❤️‍👩', 'Delta']
])

Yields:

| Alpha | Bravo |
| - | - |
| 中文 | Charlie |
| 👩‍❤️‍👩 | Delta |

With string-width:

var width = require('string-width')

table(
  [
    ['Alpha', 'Bravo'],
    ['中文', 'Charlie'],
    ['👩‍❤️‍👩', 'Delta']
  ],
  {stringLength: width}
)

Yields:

| Alpha | Bravo   |
| ----- | ------- |
| 中文  | Charlie |
| 👩‍❤️‍👩    | Delta   |

Inspiration

The original idea and basic implementation was inspired by James Halliday’s text-table library.

License

MIT © Titus Wormer

Versions

Version
2.0.0
1.1.3
1.1.2