Skip to content

Commit e38be0b

Browse files
committed
separate remark plugin from mdast transformation
1 parent 532073e commit e38be0b

File tree

5 files changed

+60
-41
lines changed

5 files changed

+60
-41
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Eugene Sharygin
3+
Copyright (c) 2015, 2016 Eugene Sharygin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+49-22
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]
66

7-
Remove empty paragraphs left from other [mdast] transformations.
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].
810
9-
Paragraph is considered empty if it is composed from whitespace characters.
11+
Remove empty paragraphs from [mdast] tree.
12+
13+
Paragraph is considered empty if it is composed of whitespace characters only.
1014

1115
[mdast]: https://github.com/wooorm/mdast
16+
[remark]: https://github.com/wooorm/remark
17+
[remark-squeeze-paragraphs]: https://github.com/eush77/remark-squeeze-paragraphs
1218

1319
[travis]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs
1420
[travis-badge]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs.svg
@@ -18,33 +24,54 @@ Paragraph is considered empty if it is composed from whitespace characters.
1824
## Example
1925

2026
```js
21-
> mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs')
22-
23-
> mdast.use(mdastStripBadges)
24-
.process('![](http://img.shields.io/)\n\ntext')
25-
'\n\ntext\n'
26-
27-
> mdast.use(mdastStripBadges)
28-
.use(mdastSqueezeParagraphs)
29-
.process('![](http://img.shields.io/)\n\ntext')
30-
'text\n'
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+
// }
3164
```
3265

3366
## API
3467

35-
```js
36-
var mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs');
37-
38-
mdast.use(mdastSqueezeParagraphs)
39-
```
68+
#### `squeezeParagraphs(ast)`
4069

41-
Modifies AST in-place.
70+
Modifies AST in-place. Returns `ast`.
4271

43-
## CLI
72+
## Related
4473

45-
```
46-
mdast -u mdast-squeeze-paragraphs
47-
```
74+
- [remark-squeeze-paragraphs][remark] plugin wrapper.
4875

4976
## Install
5077

index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33

4-
module.exports = function () {
5-
return function (ast) {
6-
ast.children = ast.children.filter(function (node) {
7-
return node.type != 'paragraph' || node.children.some(function (node) {
8-
return node.type != 'text' || !/^\s*$/.test(node.value);
9-
});
4+
module.exports = function (ast) {
5+
ast.children = ast.children.filter(function (node) {
6+
return node.type != 'paragraph' || node.children.some(function (node) {
7+
return node.type != 'text' || !/^\s*$/.test(node.value);
108
});
9+
});
1110

12-
return ast;
13-
};
11+
return ast;
1412
};

package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mdast-squeeze-paragraphs",
33
"version": "1.1.0",
4-
"description": "Remove empty paragraphs left from other mdast transformations",
4+
"description": "Remove empty paragraphs from mdast tree",
55
"author": "Eugene Sharygin <[email protected]>",
66
"license": "MIT",
77
"scripts": {
@@ -17,8 +17,6 @@
1717
},
1818
"keywords": [
1919
"mdast",
20-
"plugin",
21-
"markdown",
2220
"squeeze",
2321
"remove",
2422
"empty",
@@ -32,8 +30,6 @@
3230
],
3331
"dependencies": {},
3432
"devDependencies": {
35-
"clone": "^1.0.2",
36-
"mdast": "^0.26.2",
3733
"tape": "^4.0.0"
3834
}
3935
}

test/test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
'use strict';
22

3-
var mdastSqueezeParagraphs = require('..');
3+
var squeezeParagraphs = require('..');
44

5-
var test = require('tape'),
6-
mdast = require('mdast'),
7-
clone = require('clone');
5+
var test = require('tape');
86

97

108
test(function (t) {
119
var input = require('./input');
1210
var output = require('./output');
1311

14-
t.deepEqual(mdast.use(mdastSqueezeParagraphs).run(input), output);
12+
t.deepEqual(squeezeParagraphs(input), output);
1513
t.end();
1614
});

0 commit comments

Comments
 (0)