mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
* install eslint-plugin-markdown * add doc/.eslintrc.yaml * add `<!-- eslint-disable rule -->` or `<!-- eslint-disable -->` for the rest of problematic code * .js files in doc folder added to .eslintignore * update Makefile and vcbuild.bat PR-URL: https://github.com/nodejs/node/pull/12563 Refs: https://github.com/nodejs/node/pull/12557#issuecomment-296015032 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
markdown-table

Generate fancy Markdown/ASCII tables.
Installation
npm:
$ npm install markdown-table
$ component install wooorm/markdown-table
$ bower install markdown-table
Duo:
var table = require('wooorm/markdown-table');
Usage
var table = require('markdown-table');
/**
* Normal usage (defaults to left-alignment):
*/
table([
['Branch', 'Commit'],
['master', '0123456789abcdef'],
['staging', 'fedcba9876543210']
]);
/*
* | Branch | Commit |
* | ------- | ---------------- |
* | master | 0123456789abcdef |
* | staging | fedcba9876543210 |
*/
/**
* With alignment:
*/
table([
['Beep', 'No.', 'Boop'],
['beep', '1024', 'xyz'],
['boop', '3388450', 'tuv'],
['foo', '10106', 'qrstuv'],
['bar', '45', 'lmno']
], {
'align': ['l', 'c', 'r']
});
/*
* | Beep | No. | Boop |
* | :--- | :-----: | -----: |
* | beep | 1024 | xyz |
* | boop | 3388450 | tuv |
* | foo | 10106 | qrstuv |
* | bar | 45 | lmno |
*/
/**
* Alignment on dots:
*/
table([
['No.'],
['0.1.2'],
['11.22.33'],
['5.6.'],
['1.22222'],
], {
'align': '.'
});
/*
* | No. |
* | :---------: |
* | 0.1.2 |
* | 11.22.33 |
* | 5.6. |
* | 1.22222 |
*/
API
markdownTable(table, options?)
Turns a given matrix of strings (an array of arrays of strings) into a table.
The following options are available:
options.align— String or array of strings, the strings being either"l"(left),"r"(right),c(center), or.(dot). Other values are treated as"", which doesn’t place the colon but does left align. Only the lowercased first character is used, soRightis fine;options.delimiter— Value to insert between cells. Carefull, non-pipe values will break GitHub Flavored Markdown;options.start— Value to insert at the beginning of every row.options.end— Value to insert at the end of every row.options.rule— Whether to display a rule between the header and the body of the table. Carefull, will break GitHub Flavored Markdown whenfalse;options.stringLength— The method to detect the length of a cell (see below).
options.stringLength(cell)
ANSI-sequences mess up tables on terminals. To fix this, you have to pass in a stringLength option to detect the “visible” length of a cell.
var chalk = require('chalk');
function stringLength(cell) {
return chalk.stripColor(cell).length;
}
See the tests for an example.
Inspiration
The original idea and basic implementation was inspired by James Halliday's text-table library.