|
1 | | -# Markdown table prettifier extension for Visual Studio Code |
| 1 | +# Markdown table prettifier |
2 | 2 |
|
3 | 3 | [](https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt/actions) |
| 4 | +[](https://marketplace.visualstudio.com/items?itemName=darkriszty.markdown-table-prettify) |
| 5 | +[](https://hub.docker.com/r/darkriszty/prettify-md/tags?page=1&ordering=last_updated) |
| 6 | +[](https://www.npmjs.com/package/markdown-table-prettify) |
4 | 7 |
|
5 | 8 | Makes tables more readable for humans. Compatible with the Markdown writer plugin's table formatter feature in Atom. |
6 | 9 |
|
7 | | -## Features |
| 10 | +## Feature highlights |
8 | 11 |
|
9 | 12 | - Remove redundant ending table border if the beginning has no border, so the table _will not end_ with "|". |
10 | 13 | - Create missing ending table border if the beginning already has a border, so the table _will end_ with "|". |
11 | 14 | - Save space by not right-padding the last column if the table has no border. |
12 | 15 | - Support empty columns inside tables. |
13 | 16 | - Support column alignment options with ":". |
14 | | -- CLI and docker support to prettify files. |
| 17 | +- Find and format multiple tables. |
| 18 | +- Support indented tables. |
| 19 | + |
| 20 | +## Visual Studio Code |
15 | 21 |
|
16 | 22 |  |
17 | 23 |
|
18 | | -### CLI formatting |
| 24 | +The extension is available for markdown language mode. It can either prettify a selection (`Format Selection`) or the entire document (`Format Document`). |
| 25 | +A VSCode command called `Prettify markdown tables` is also available to format the currently opened document. |
19 | 26 |
|
20 | | -Formatting files or checking if they're already formatted is possible from the command line. This requires `node` and `npm`. |
| 27 | +Configurable settings: |
| 28 | +- The maximum texth length of a selection/entire document to consider for formatting. Defaults to 1M chars. (limit does not apply from CLI or NPM). |
| 29 | +- Keyboard shortcut to prettify the currently opened markdown document. Default: CTRL+ALT+M (CMD+ALT+M on Mac). |
21 | 30 |
|
22 | | -The extension has to be downloaded and compiled: |
23 | | -- Locate the installed extension path or download the extension from Github. |
24 | | -- Go to the extension directory. |
25 | | -- Run `npm install`. |
26 | | -- Run `npm run compile`. |
| 31 | +## NPM |
27 | 32 |
|
28 | | -The typical location of the installed extension (your actual version might differ): |
29 | | -- Windows: `%USERPROFILE%\.vscode\extensions\darkriszty.markdown-table-prettify-3.0.0` |
30 | | -- macOS: `~/.vscode/extensions/darkriszty.markdown-table-prettify-3.0.0` |
31 | | -- Linux: `~/.vscode/extensions/darkriszty.markdown-table-prettify-3.0.0` |
| 33 | +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. |
32 | 34 |
|
33 | | -Available features from the command line: |
34 | | -- To prettify a file: `npm run --silent prettify-md < input.md`. |
35 | | -- To prettify a file and save the output: `npm run --silent prettify-md < input.md > output.md`. |
36 | | -- To check whether a file is prettyfied or not: `npm run --silent check-md < input.md`. This will fail with an exception and return code `1` if the file is not prettyfied. |
| 35 | +It currently exposes the entry point also used by the _CLI_. It can be used from regular NodeJS or web apps: |
| 36 | + |
| 37 | +```JS |
| 38 | +import { CliPrettify } from 'markdown-table-prettify'; |
| 39 | +// or |
| 40 | +const { CliPrettify } = require('markdown-table-prettify'); |
37 | 41 |
|
38 | | -> Note: 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. |
| 42 | +console.log(CliPrettify.prettify( |
| 43 | +`hello|world |
| 44 | +-|- |
| 45 | +foo|bar`)); |
39 | 46 |
|
40 | | -### Formatting with docker |
| 47 | +/* Output: |
| 48 | +hello | world |
| 49 | +------|------ |
| 50 | +foo | bar |
| 51 | +*/ |
| 52 | +``` |
41 | 53 |
|
42 | | -The core formatting logic of the extension is also available as a node docker image: `docker pull darkriszty/prettify-md`. |
| 54 | +## Docker |
| 55 | + |
| 56 | +The core formatting logic is available as a node docker image: `docker pull darkriszty/prettify-md`. |
43 | 57 |
|
44 | 58 | Available features from docker: |
45 | 59 | - To prettify a file: `docker container run -i darkriszty/prettify-md < input.md`. |
46 | 60 | - To prettify a file and save the output: `docker container run -i darkriszty/prettify-md < input.md > output.md`. |
47 | 61 | - To check whether a file is prettyfied or not: `docker container run -i darkriszty/prettify-md --check < input.md`. This will fail with an exception and return code `1` if the file is not prettyfied. |
48 | 62 |
|
49 | | -## Extension Settings |
| 63 | +## CLI |
50 | 64 |
|
51 | | -The extension is available for markdown language mode. It can either prettify a selection (`Format Selection`) or the entire document (`Format Document`). |
52 | | -A VSCode command called `Prettify markdown tables` is also available to format the currently opened document. |
| 65 | +Formatting files or checking if they're already formatted is possible from the command line. This requires `node` and `npm` (optionally also `npx`). |
53 | 66 |
|
54 | | -Configurable settings: |
55 | | -- The maximum texth length of a selection/entire document to consider for formatting. Defaults to 1M chars. There is no limit when running from the command line. |
56 | | -- Keyboard shortcut to prettify the currently opened markdown document. Default: CTRL+ALT+M (CMD+ALT+M on Mac). |
| 67 | +### Available features from the command line: |
| 68 | +- To prettify a file: `npm run --silent prettify-md < input.md`. |
| 69 | +- To prettify a file and save the output: `npm run --silent prettify-md < input.md > output.md`. |
| 70 | +- To check whether a file is prettyfied or not: `npm run --silent check-md < input.md`. This will fail with an exception and return code `1` if the file is not prettyfied. |
| 71 | + |
| 72 | +> Note: 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. |
| 73 | +
|
| 74 | +### Installation |
| 75 | + |
| 76 | +To access the CLI, the extension can either be used from the Github sources, from the already instaledl VSCode extension or from NPM. |
| 77 | + |
| 78 | +#### Compiling from the source code |
| 79 | + |
| 80 | +- Download the source code. |
| 81 | +- Go to the extension directory. |
| 82 | +- Run `npm install`. |
| 83 | +- Run `npm run compile`. |
| 84 | + |
| 85 | +#### Using the already installed VSCode extension |
| 86 | + |
| 87 | +Locate the installed extension path. The typical location of the installed extension: |
| 88 | +- Windows: `%USERPROFILE%\.vscode\extensions\darkriszty.markdown-table-prettify-{version}` |
| 89 | +- macOS: `~/.vscode/extensions/darkriszty.markdown-table-prettify-{version}` |
| 90 | +- Linux: `~/.vscode/extensions/darkriszty.markdown-table-prettify-{version}` |
| 91 | + |
| 92 | +#### Getting it from NPM |
| 93 | + |
| 94 | +Install the NPM package `npm install -g markdown-table-prettify`. Optionally, use `npx` to prettify files: `npx markdown-table-prettify < input.md` (instead of `npm run --silent prettify-md < input.md`). |
57 | 95 |
|
58 | 96 | ## Known Issues |
59 | 97 |
|
|
0 commit comments