Skip to content

Commit

Permalink
separate remark plugin from mdast transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
eush77 committed Jan 4, 2016
1 parent 532073e commit f907fb8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Eugene Sharygin
Copyright (c) 2015, 2016 Eugene Sharygin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
[![npm](https://nodei.co/npm/mdast-squeeze-paragraphs.png)](https://npmjs.com/package/mdast-squeeze-paragraphs)
[![npm](https://nodei.co/npm/remark-squeeze-paragraphs.png)](https://npmjs.com/package/remark-squeeze-paragraphs)

# mdast-squeeze-paragraphs
# remark-squeeze-paragraphs

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

Remove empty paragraphs left from other [mdast] transformations.
[Remark] plugin for removing empty paragraphs.

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

[remark]: https://github.com/wooorm/remark
[mdast]: https://github.com/wooorm/mdast
[mdast-squeeze-paragraphs]: https://github.com/eush77/mdast-squeeze-paragraphs

[travis]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs
[travis-badge]: https://travis-ci.org/eush77/mdast-squeeze-paragraphs.svg
[david]: https://david-dm.org/eush77/mdast-squeeze-paragraphs
[david-badge]: https://david-dm.org/eush77/mdast-squeeze-paragraphs.png
[travis]: https://travis-ci.org/eush77/remark-squeeze-paragraphs
[travis-badge]: https://travis-ci.org/eush77/remark-squeeze-paragraphs.svg
[david]: https://david-dm.org/eush77/remark-squeeze-paragraphs
[david-badge]: https://david-dm.org/eush77/remark-squeeze-paragraphs.png

## Example

```js
> mdastSqueezeParagraphs = require('mdast-squeeze-paragraphs')
var squeezeParagraphs = require('remark-squeeze-paragraphs');

> mdast.use(mdastStripBadges)
.process('![](http://img.shields.io/)\n\ntext')
'\n\ntext\n'
remark.use(stripBadges)
.process('![](http://img.shields.io/)\n\ntext')
//=> "\n\ntext\n"

> mdast.use(mdastStripBadges)
.use(mdastSqueezeParagraphs)
.process('![](http://img.shields.io/)\n\ntext')
'text\n'
remark.use(stripBadges)
.use(squeezeParagraphs)
.process('![](http://img.shields.io/)\n\ntext')
//=> "text\n"
```

## API

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

mdast.use(mdastSqueezeParagraphs)
remark.use(squeezeParagraphs)
```

Modifies AST in-place.

## CLI

```
mdast -u mdast-squeeze-paragraphs
remark -u remark-squeeze-paragraphs
```

## Related

- [mdast-squeeze-paragraphs][mdast] transformation utility that is in the core of this plugin.

## Install

```
npm install mdast-squeeze-paragraphs
npm install remark-squeeze-paragraphs
```

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

var squeezeParagraphs = require('mdast-squeeze-paragraphs');

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;
};
module.exports = function () {
return squeezeParagraphs;
};
35 changes: 16 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mdast-squeeze-paragraphs",
"name": "remark-squeeze-paragraphs",
"version": "1.1.0",
"description": "Remove empty paragraphs left from other mdast transformations",
"description": "Remark plugin for removing empty paragraphs",
"author": "Eugene Sharygin <eush77@gmail.com>",
"license": "MIT",
"scripts": {
Expand All @@ -10,30 +10,27 @@
"files": [
"index.js"
],
"homepage": "https://github.com/eush77/mdast-squeeze-paragraphs",
"repository": "eush77/mdast-squeeze-paragraphs",
"homepage": "https://github.com/eush77/remark-squeeze-paragraphs",
"repository": "eush77/remark-squeeze-paragraphs",
"bugs": {
"url": "https://github.com/eush77/mdast-squeeze-paragraphs/issues"
"url": "https://github.com/eush77/remark-squeeze-paragraphs/issues"
},
"keywords": [
"mdast",
"plugin",
"markdown",
"squeeze",
"remove",
"clean",
"empty",
"markdown",
"paragraph",
"whitespace",
"ast",
"transform",
"transformation",
"util",
"clean"
"plugin",
"remark",
"remove",
"squeeze",
"whitespace"
],
"dependencies": {},
"dependencies": {
"mdast-squeeze-paragraphs": "^3.0.0"
},
"devDependencies": {
"clone": "^1.0.2",
"mdast": "^0.26.2",
"remark": "^3.1.3",
"tape": "^4.0.0"
}
}
7 changes: 3 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';

var mdastSqueezeParagraphs = require('..');
var squeezeParagraphs = require('..');

var test = require('tape'),
mdast = require('mdast'),
clone = require('clone');
remark = require('remark');


test(function (t) {
var input = require('./input');
var output = require('./output');

t.deepEqual(mdast.use(mdastSqueezeParagraphs).run(input), output);
t.deepEqual(remark.use(squeezeParagraphs).run(input), output);
t.end();
});

0 comments on commit f907fb8

Please sign in to comment.