|
1 |
| -[](https://npmjs.com/package/mdast-squeeze-paragraphs) |
| 1 | +# mdast-squeeze-paragraphs [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] |
2 | 2 |
|
3 |
| -# mdast-squeeze-paragraphs |
| 3 | +Remove empty paragraphs from [**mdast**][mdast] syntax trees. |
4 | 4 |
|
5 |
| -[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david] |
| 5 | +Paragraphs are considered empty if they do not contain non-whitespace |
| 6 | +characters. |
6 | 7 |
|
7 |
| -> :warning: |
8 |
| -> |
9 |
| -> This is an AST transformer for [mdast][] syntax trees. A [remark][] plugin has been split up into [a different project][remark-squeeze-paragraphs]. |
| 8 | +## Installation |
10 | 9 |
|
11 |
| -Remove empty paragraphs from [mdast][] tree. |
| 10 | +[npm][]: |
12 | 11 |
|
13 |
| -Paragraph is considered empty if it is composed of whitespace characters only. |
| 12 | +```bash |
| 13 | +npm install mdast-squeeze-paragraphs |
| 14 | +``` |
14 | 15 |
|
15 |
| -[mdast]: https://github.com/syntax-tree/mdast |
16 |
| -[remark]: https://github.com/wooorm/remark |
17 |
| -[remark-squeeze-paragraphs]: https://github.com/eush77/remark-squeeze-paragraphs |
| 16 | +## Usage |
18 | 17 |
|
19 |
| -[travis]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs |
20 |
| -[travis-badge]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs.svg |
21 |
| -[david]: https://david-dm.org/eush77/mdast-squeeze-paragraphs |
22 |
| -[david-badge]: https://david-dm.org/eush77/mdast-squeeze-paragraphs.png |
| 18 | +```js |
| 19 | +var u = require('unist-builder') |
| 20 | +var squeezeParagraphs = require('mdast-squeeze-paragraphs') |
23 | 21 |
|
24 |
| -## Example |
| 22 | +var tree = u('root', [ |
| 23 | + u('paragraph', []), |
| 24 | + u('paragraph', [u('text', 'Alpha')]), |
| 25 | + u('paragraph', [u('text', ' ')]) |
| 26 | +]) |
| 27 | + |
| 28 | +squeezeParagraphs(tree) |
| 29 | + |
| 30 | +console.dir(tree, {depth: null}) |
| 31 | +``` |
| 32 | + |
| 33 | +Yields: |
25 | 34 |
|
26 | 35 | ```js
|
27 |
| -var squeezeParagraphs = require('mdast-squeeze-paragraphs'); |
28 |
| - |
29 |
| -ast |
30 |
| -//=> { |
31 |
| -// "type": "root", |
32 |
| -// "children": [ |
33 |
| -// { |
34 |
| -// "type": "paragraph", |
35 |
| -// "children": [] |
36 |
| -// }, |
37 |
| -// { |
38 |
| -// "type": "paragraph", |
39 |
| -// "children": [ |
40 |
| -// { |
41 |
| -// "type": "text", |
42 |
| -// "value": "foo" |
43 |
| -// } |
44 |
| -// ] |
45 |
| -// } |
46 |
| -// ] |
47 |
| -// } |
48 |
| - |
49 |
| -squeezeParagraphs(ast) |
50 |
| -//=> { |
51 |
| -// "type": "root", |
52 |
| -// "children": [ |
53 |
| -// { |
54 |
| -// "type": "paragraph", |
55 |
| -// "children": [ |
56 |
| -// { |
57 |
| -// "type": "text", |
58 |
| -// "value": "foo" |
59 |
| -// } |
60 |
| -// ] |
61 |
| -// } |
62 |
| -// ] |
63 |
| -// } |
| 36 | +{ type: 'root', |
| 37 | + children: |
| 38 | + [ { type: 'paragraph', |
| 39 | + children: [ { type: 'text', value: 'Alpha' } ] } ] } |
64 | 40 | ```
|
65 | 41 |
|
66 | 42 | ## API
|
67 | 43 |
|
68 |
| -#### `squeezeParagraphs(ast)` |
| 44 | +### `squeezeParagraphs(tree)` |
69 | 45 |
|
70 |
| -Modifies AST in-place. Returns `ast`. |
| 46 | +Modifies tree in-place. Returns `tree`. |
71 | 47 |
|
72 | 48 | ## Related
|
73 | 49 |
|
74 |
| -- [remark-squeeze-paragraphs][] — [remark][] plugin wrapper. |
| 50 | +* [`remark-squeeze-paragraphs`][squeeze-paragraphs] |
| 51 | + — [**remark**][remark] plugin wrapper |
75 | 52 |
|
76 |
| -## Install |
| 53 | +## Contribute |
77 | 54 |
|
78 |
| -``` |
79 |
| -npm install mdast-squeeze-paragraphs |
80 |
| -``` |
| 55 | +See [`contributing.md` in `syntax-tree/mdast`][contributing] for ways to get |
| 56 | +started. |
| 57 | + |
| 58 | +This organisation has a [Code of Conduct][coc]. By interacting with this |
| 59 | +repository, organisation, or community you agree to abide by its terms. |
81 | 60 |
|
82 | 61 | ## License
|
83 | 62 |
|
84 |
| -MIT |
| 63 | +[MIT][license] © Eugene Sharygin |
| 64 | + |
| 65 | +<!-- Definitions --> |
| 66 | + |
| 67 | +[travis-badge]: https://img.shields.io/travis/syntax-tree/mdast-squeeze-paragraphs.svg |
| 68 | + |
| 69 | +[travis]: https://travis-ci.org/syntax-tree/mdast-squeeze-paragraphs |
| 70 | + |
| 71 | +[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-squeeze-paragraphs.svg |
| 72 | + |
| 73 | +[codecov]: https://codecov.io/github/syntax-tree/mdast-squeeze-paragraphs |
| 74 | + |
| 75 | +[npm]: https://docs.npmjs.com/cli/install |
| 76 | + |
| 77 | +[license]: license |
| 78 | + |
| 79 | +[contributing]: https://github.com/syntax-tree/mdast/blob/master/contributing.md |
| 80 | + |
| 81 | +[coc]: https://github.com/syntax-tree/mdast/blob/master/code-of-conduct.md |
| 82 | + |
| 83 | +[mdast]: https://github.com/syntax-tree/mdast |
| 84 | + |
| 85 | +[remark]: https://github.com/remarkjs/remark |
| 86 | + |
| 87 | +[squeeze-paragraphs]: https://github.com/remarkjs/remark-squeeze-paragraphs |
0 commit comments