Skip to content

Commit

Permalink
Normalize plugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eush77 committed Aug 12, 2015
1 parent b0e7b50 commit 6ec5508
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Remove empty paragraphs left from other [mdast] transformations.

Paragraph is considered empty if it is composed from whitespace characters.

This module provides both AST transformation and a plugin.

[mdast]: https://github.com/wooorm/mdast

[travis]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs
Expand All @@ -20,7 +18,7 @@ This module provides both AST transformation and a plugin.
## Example

```js
> mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs/plugin')
> mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs')

> mdast.use(mdastStripBadges)
.process('![](http://img.shields.io/)\n\ntext')
Expand All @@ -34,13 +32,19 @@ This module provides both AST transformation and a plugin.

## API

#### `mdastSqueezeParagraphs(ast)`
```js
var mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs');

mdast.use(mdastSqueezeParagraphs)
```

Remove empty paragraphs from the AST. Return the reference to the AST for convenience.
Modifies AST in-place.

#### `mdast.use(require('mdast-squeeze-paragraphs/plugin'))`
## CLI

Use this transformation as a plugin.
```
mdast -u mdast-squeeze-paragraphs
```

## Install

Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';


module.exports = function (ast) {
ast.children = ast.children.filter(function (node) {
return node.type != 'paragraph' || node.children.some(function (node) {
return node.type != 'text' || !/^\s*$/.test(node.value);
module.exports = function () {
return function (ast) {
ast.children = ast.children.filter(function (node) {
return node.type != 'paragraph' || node.children.some(function (node) {
return node.type != 'text' || !/^\s*$/.test(node.value);
});
});
});

return ast;
return ast;
};
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"test": "tape test/*.js"
},
"files": [
"index.js",
"plugin.js"
"index.js"
],
"homepage": "https://github.com/eush77/mdast-squeeze-paragraphs",
"repository": "eush77/mdast-squeeze-paragraphs",
Expand Down
8 changes: 0 additions & 8 deletions plugin.js

This file was deleted.

8 changes: 2 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var mdastSqueezeParagraphs = require('..'),
mdastSqueezeParagraphsPlugin = require('../plugin');
var mdastSqueezeParagraphs = require('..');

var test = require('tape'),
mdast = require('mdast'),
Expand All @@ -12,9 +11,6 @@ test(function (t) {
var input = require('./input');
var output = require('./output');

t.deepEqual(mdastSqueezeParagraphs(clone(input)), output,
'Works as an AST transformation');
t.deepEqual(mdast.use(mdastSqueezeParagraphsPlugin).run(input), output,
'Works as a plugin');
t.deepEqual(mdast.use(mdastSqueezeParagraphs).run(input), output);
t.end();
});

0 comments on commit 6ec5508

Please sign in to comment.