Skip to content

Commit 7259526

Browse files
authored
Merge pull request #53 from darkriszty/feature/npm
Feature/npm
2 parents 307b4b0 + effdf0e commit 7259526

7 files changed

Lines changed: 260 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
## 3.2.2 - 2020-01-11
10+
### Added
11+
- Issue #49: NPM package support.
12+
13+
## 3.2.1 - 2020-01-01
14+
### Fixed
15+
- Issue #50: Dockerfile improvements.
16+
917
## 3.2.0 - 2020-12-14
1018
### Added
1119
- Issue #47: Support for indented tables.

README.md

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,97 @@
1-
# Markdown table prettifier extension for Visual Studio Code
1+
# Markdown table prettifier
22

33
[![Test Status](https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt/workflows/Tests/badge.svg)](https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt/actions)
4+
[![Visual Studio Code extension](https://img.shields.io/visual-studio-marketplace/v/darkriszty.markdown-table-prettify?color=success&label=VSCode)](https://marketplace.visualstudio.com/items?itemName=darkriszty.markdown-table-prettify)
5+
[![Docker image](https://img.shields.io/docker/v/darkriszty/prettify-md?color=success&label=Docker)](https://hub.docker.com/r/darkriszty/prettify-md/tags?page=1&ordering=last_updated)
6+
[![NPM package](https://img.shields.io/npm/v/markdown-table-prettify?color=success)](https://www.npmjs.com/package/markdown-table-prettify)
47

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

7-
## Features
10+
## Feature highlights
811

912
- Remove redundant ending table border if the beginning has no border, so the table _will not end_ with "|".
1013
- Create missing ending table border if the beginning already has a border, so the table _will end_ with "|".
1114
- Save space by not right-padding the last column if the table has no border.
1215
- Support empty columns inside tables.
1316
- 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
1521

1622
![feature X](assets/animation.gif)
1723

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

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).
2130

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
2732

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

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');
3741

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`));
3946

40-
### Formatting with docker
47+
/* Output:
48+
hello | world
49+
------|------
50+
foo | bar
51+
*/
52+
```
4153

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`.
4357

4458
Available features from docker:
4559
- To prettify a file: `docker container run -i darkriszty/prettify-md < input.md`.
4660
- To prettify a file and save the output: `docker container run -i darkriszty/prettify-md < input.md > output.md`.
4761
- 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.
4862

49-
## Extension Settings
63+
## CLI
5064

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`).
5366

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`).
5795

5896
## Known Issues
5997

cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
import { CliPrettify } from "./cliPrettify";
24
import { InputReader } from "./inputReader";
35

gulpfile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
var gulp = require("gulp");
2+
var merge = require("gulp-merge-json");
23

34
gulp.task("copy-systemTest-resources", function() {
45
return gulp
56
.src("test/systemTests/resources/*")
67
.pipe(gulp.dest("out/test/systemTests/resources"));
7-
});
8+
});
9+
10+
gulp.task("merge-packagejson-for-npm-dist", function () {
11+
return gulp.src("package.*json")
12+
.pipe(merge({fileName: "package.json"}))
13+
.pipe(gulp.dest("out"));
14+
});

0 commit comments

Comments
 (0)