Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

markdown-table-prettify

darkriszty60.3kMIT3.6.0

Transforms markdown tables to be more readable.

markdown, table, formatter

readme

Markdown table prettifier

Test Status Visual Studio Code extension OVSX Docker image NPM package

Makes tables more readable for humans. Compatible with the Markdown writer plugin's table formatter feature in Atom.

Feature highlights

  • Remove redundant ending table border if the beginning has no border, so the table will not end with "|".
  • Create missing ending table border if the beginning already has a border, so the table will end with "|".
  • Save space by not right-padding the last column if the table has no border.
  • Support empty columns inside tables.
  • Support column alignment options with ":".
  • Find and format multiple tables.
  • Support `code blocks` and ignore blocks with <!-- markdown-table-prettify-ignore-start --> and <!-- markdown-table-prettify-ignore-end -->.
  • Support indented tables.

Visual Studio Code

feature X

The extension is available for markdown language mode. It can either prettify a selection (Format Selection) or the entire document (Format Document). A VSCode command called Prettify markdown tables is also available to format the currently opened document.

Configurable settings:

  • The maximum texth length of a selection/entire document to consider for formatting. Default: 1M chars (limit does not apply from CLI or NPM).
  • Additional languages to support formatting for besides markdown. See possible configurable values here. Default: [ ].
  • Column padding to make the columns more spaced out from each other. Default: 0 (no extra spacing/padding).
  • Keyboard shortcut to prettify the currently opened markdown document. Default: <kbd>CTRL</kbd>+<kbd>ALT</kbd>+<kbd>M</kbd> (<kbd>CMD</kbd>+<kbd>ALT</kbd>+<kbd>M</kbd> on Mac).

NPM

The core formatting logic is available as an NPM package: npm install --save markdown-table-prettify. The Typescript code is compiled down to ES5 and shipped inside the package.

It currently exposes the entry point also used by the CLI. It can be used from regular NodeJS or web apps:

import { CliPrettify } from 'markdown-table-prettify';
// or
const { CliPrettify } = require('markdown-table-prettify');

console.log(CliPrettify.prettify(
`hello|world
-|-
foo|bar`));
/* Output:
hello | world
------|------
foo   | bar
*/

// specifying a column padding
console.log(CliPrettify.prettify(
`hello|world
-|-
foo|bar`, { columnPadding: 1 }));
/* Output:
 hello  |  world
 ------ | ------
 foo    |  bar
*/

Docker & CLI

The core formatting logic is available as a node docker image: docker pull darkriszty/prettify-md or as a stand alone CLI tool.

Formatting files or checking if they're already formatted is also possible from the command line without docker. This requires node and npm (optionally also npx).

Feature Docker CLI
Prettify a file docker container run -i darkriszty/prettify-md < input.md npm run --silent prettify-md < input.md
Prettify a file and save the output docker container run -i darkriszty/prettify-md < input.md > output.md npm run --silent prettify-md < input.md > output.md
Check whether a file is pretty or not docker container run -i darkriszty/prettify-md --check < input.md npm run --silent check-md < input.md
Use 1 as column padding docker container run -i darkriszty/prettify-md --columnPadding=1 < input.md npm run --silent prettify-md -- --columnPadding=1 < input.md

Notes:

  • The prettify check (--check or check-md) will fail with an exception and return code 1 if the file is not prettyfied.
  • The --silent switch sets the NPM log level to silent, which is useful to hide the executed file name and concentrate on the actual output.
  • The -- after the npm run script part is needed for npm to forward the arguments (for instance --columnPadding=1) to the actual prettyfier script.
  • Optionally, use npx to prettify files: npx markdown-table-prettify < input.md instead of npm run --silent prettify-md < input.md.

Installation

To access the CLI, the extension can either be used from the Github sources, from the already installed VSCode extension or from NPM.

Compiling from the source code

  • Clone or download the source code.
  • Run npm install.
  • Run npm run compile.

Using the already installed VSCode extension

Locate the installed extension path. The typical location of the installed extension:

  • Windows: %USERPROFILE%\.vscode\extensions\darkriszty.markdown-table-prettify-{version}
  • macOS: ~/.vscode/extensions/darkriszty.markdown-table-prettify-{version}
  • Linux: ~/.vscode/extensions/darkriszty.markdown-table-prettify-{version}

Getting it from NPM

Install the NPM package npm install -g markdown-table-prettify.

Known Issues

  • Tables with mixed character widths (eg: CJK) are not always properly formatted (issue #4).

changelog

Change Log

All notable changes will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

3.5.0 - 2021-08-20

Added

  • Issue #60: Ignore whitespaces around alignment markers.

3.4.0 - 2021-04-04

Added

  • Issue #56: Support ignoring parts of documents with an ignore directive.

3.3.0 - 2021-03-25

Added

  • Issue #54: Config to support more languages in VSCode formatting.

3.2.2 - 2021-01-11

Added

  • Issue #49: NPM package support.

3.2.1 - 2021-01-01

Fixed

  • Issue #50: Dockerfile improvements.

3.2.0 - 2020-12-14

Added

  • Issue #47: Support for indented tables.

3.1.0 - 2020-11-04

Fixed

  • Issue #42: Don't alter selection for invalid range formatting attempt (does not impact CLI).
  • Issue #43: Handle Format Selection with multiple tables (does not impact CLI).

3.0.0 - 2020-10-06

Added

  • Issue #32: Major refactoring to support CLI. Support npm run prettify-md and npm run check-md.
  • Issue #40: Provide command to run alongside prettier (shortcut CTRL+ALT+M).

2.5.0 - 2020-07-04

Added

  • Issue #30: Add configurable text limit for table formatting

2.4.0 - 2019-05-11

Added

  • Issue #28: Add the possibility to disable window messages from the extension

2.3.0 - 2018-12-16

Added

  • Issue #7: Support formatting all tables in the document.

2.2.0 - 2018-09-26

Added

  • Issue #22: Allow formatting without a filename

2.1.0 - 2018-09-15

Added

  • Issue #15: Support alignment options

2.0.0 - 2018-02-09

Added

  • Issue #12: Full rewrite for refactoring.
  • Issue #11: Support escaping of separators with backslash.
  • Issue #16: Ignore separators that are in code blocks.

1.1.1 - 2017-05-27

Fixed

  • Issue #10: Don't show format failure messages when using the Format Document from VsCode.

1.1.0 - 2017-05-09

Added

  • Issue #6: Formatting when there's only a single table in the entire file.
  • Issue #4: Add support for CJK characters.

1.0.1 - 2017-04-08

Fixed

  • Fixed issue #1 by improving the detection of header separator to avoid unintended table formatting failures.

1.0.0 - 2017-04-03

Added

  • Support to format individual tables with right click -> Format Selection.