Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove multiple tags #3

Merged
merged 11 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js
node_js:
- v6
- v5
- v4

after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
language: node_js
node_js:
- v7
- v6
- v5
- v4

after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
environment:
matrix:
- nodejs_version: "7"
- nodejs_version: "6"
- nodejs_version: "5"
- nodejs_version: "4"
Expand Down
18 changes: 18 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
<a name="0.1.0"></a>
# 0.1.0 (2017-05-02)

* 0.1.0 ([0d94b21](https://github.com/GitScrum/posthtml-remove-tags/commit/0d94b21))
* remove multiple tags ([fb82b35](https://github.com/GitScrum/posthtml-remove-tags/commit/fb82b35))
* Update index.js ([f116f4f](https://github.com/GitScrum/posthtml-remove-tags/commit/f116f4f))
* Update readme.md ([7306bc8](https://github.com/GitScrum/posthtml-remove-tags/commit/7306bc8))
* fix: Proxy is not defined ([373fef9](https://github.com/GitScrum/posthtml-remove-tags/commit/373fef9))
* style: fix comma-spacing ([6124b31](https://github.com/GitScrum/posthtml-remove-tags/commit/6124b31))
* style: remove comment ([7795106](https://github.com/GitScrum/posthtml-remove-tags/commit/7795106))
* chore: update depDev ([4ce73e8](https://github.com/GitScrum/posthtml-remove-tags/commit/4ce73e8))
* chore(changelog): Update changelog ([dad8be9](https://github.com/GitScrum/posthtml-remove-tags/commit/dad8be9))
* ci: add node 7 ([68a1923](https://github.com/GitScrum/posthtml-remove-tags/commit/68a1923))
* test: fix test because change options in #1 ([e7f5599](https://github.com/GitScrum/posthtml-remove-tags/commit/e7f5599)), closes [#1](https://github.com/GitScrum/posthtml-remove-tags/issues/1)
* feat: tags with array, close #1 ([95abcb1](https://github.com/GitScrum/posthtml-remove-tags/commit/95abcb1)), closes [#1](https://github.com/GitScrum/posthtml-remove-tags/issues/1)



<a name="0.0.1"></a>
## 0.0.1 (2016-08-09)

Expand Down
46 changes: 20 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"name": "posthtml-remove-tags",
"version": "0.0.1",
"version": "0.1.0",
"description": "A posthtml plugin for removing tags",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/GitScrum/posthtml-remove-tags.git"
},
"homepage": "https://github.com/GitScrum/posthtml-remove-tags#readme",
"bugs": {
"url": "https://github.com/GitScrum/posthtml-remove-tags/issues"
},
"repository": "GitScrum/posthtml-remove-tags",
"homepage": "githum.com/GitScrum/posthtml-remove-tags#readme",
"bugs": "GitScrum/posthtml-remove-tags/issues",
"author": {
"name": "Ivan Demidov",
"email": "Scrum@list.ru",
Expand All @@ -21,17 +16,16 @@
"node": ">=4"
},
"scripts": {
"lintjs": "eslint ./src/*.js ./test/*.js",
"lintjs": "eslint ./{src,test}/*.js",
"lintmd": "eslint --ext md --rule indent: [error, 4] .",
"pretest": "clinton && npm run lintjs && npm run lintmd",
"commitmsg": "conventional-changelog-lint -e",
"postpublish": "conventional-changelog -i CHANGELOG.md -s -r 0 && git commit -am \"chore(changelog): Update changelog\"",
"postpublish": "conventional-changelog -i changelog.md -s -r 0 && git commit -am \"chore(changelog): Update changelog\"",
"patch": "np patch --any-branch",
"minor": "np minor --any-branch",
"major": "np major --any-branch",
"test": "nyc ava",
"clean": "rm -rf lib && mkdir lib",
"build": "npm run clean && babel src/ -d lib/",
"build": "rimraf lib && babel src -d lib",
"prepublish": "npm run build",
"update": "updtr && ava-codemods --force",
"testen": "testen -n -- ava"
Expand All @@ -49,32 +43,33 @@
"dependencies": {},
"devDependencies": {
"ava": "*",
"ava-codemods": "^0.2.1",
"ava-codemods": "^0.3.2",
"babel-cli": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-eslint": "^7.2.3",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-min": "^0.1.15",
"babel-register": "^6.11.6",
"clinton": "^0.7.1",
"clinton": "^0.12.0",
"conventional-changelog-cli": "^1.2.0",
"conventional-changelog-lint": "^1.0.0",
"coveralls": "^2.11.12",
"eslint": "^3.1.1",
"eslint-config-xo": "^0.15.3",
"eslint-formatter-pretty": "^0.2.2",
"eslint-plugin-ava": "^2.5.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-config-xo": "^0.18.1",
"eslint-formatter-pretty": "^1.1.0",
"eslint-plugin-ava": "^4.2.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-markdown": "^1.0.0-beta.2",
"eslint-plugin-require-path-exists": "^1.1.5",
"eslint-plugin-xo": "^0.5.1",
"husky": "^0.11.5",
"eslint-plugin-xo": "^1.0.0",
"husky": "^0.13.3",
"is-promise": "^2.1.0",
"np": "^2.6.0",
"nyc": "^7.1.0",
"nyc": "^10.3.0",
"posthtml": "^0.9.0",
"testen": "^1.8.2",
"updtr": "^0.2.1"
"rimraf": "^2.6.1",
"testen": "^2.2.0",
"updtr": "^1.0.0"
},
"ava": {
"require": [
Expand All @@ -99,7 +94,6 @@
"ava",
"xo",
"babel",
"require-path-exists",
"markdown"
],
"extends": [
Expand Down
7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import removeTags from 'posthtml-remove-tags';
const html = readFileSync('input.html', 'utf8');

posthtml()
.use(removeTags({tags: '<style></style>'}))
.use(removeTags({tags: ['style', 'script']}))
.process(html)
.then(result => {
writeFileSync('output.html', result.html);
Expand All @@ -53,10 +53,9 @@ Returns the html without the tags listed in option
## Options

#### `tags`
Type: `String`
Default: ` `
Type: `Array`
Default: `[]`
Description: *The list of tags to be deleted*
*:warning: currently works only with `string`, `array` is planed*

## LICENSE

Expand Down
36 changes: 15 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
const remove = (tree, {tags}) => tree.match({tag: tags}, node => Object.assign(node, {tag: false, content: []}));

function removeTags(tree, options) {
return Promise.resolve(tree)
.then(tree => remove(tree, options))
.then(tree => tree);
}

export default (options = {}) => {
return tree => new Promise((resolve, reject) => {
if (!Array.isArray(tree)) {
reject(new Error(`tree is not Array`));
}

if (tree.length === 0) {
resolve(tree);
}

resolve(removeTags(tree, Object.assign({}, options)));
});
};
export default options => tree => new Promise((resolve, reject) => {
if (!Array.isArray(tree)) {
reject(new Error(`tree is not Array`));
}

if (tree.length === 0) {
resolve(tree);
}

resolve(tree.match(options.tags.map(tag => ({tag: tag})), node => {
node.tag = false;
node.content = [];
return node;
}));
});
16 changes: 2 additions & 14 deletions test/test-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import {readFile} from 'fs';
import test from 'ava';
import posthtml from 'posthtml';
import isPromise from 'is-promise';
Expand All @@ -10,23 +9,12 @@ function processing(html, settings = {}, plugins = []) {
.process(html);
}

/* function read(pathFile) {
return new Promise((resolve, reject) => {
readFile(pathFile, 'utf8', (err, data) => {
if (err) {
reject(err);
}
return resolve(data);
});
});
} */

test('plugin must be function', t => {
t.true(typeof removeTags === 'function');
});

test('should return reject', async t => {
t.throws(removeTags()());
await t.throws(removeTags()());
});

test('should return promise', t => {
Expand All @@ -36,5 +24,5 @@ test('should return promise', t => {
test('should remove style tags', async t => {
const fixture = '<html><style></style></html>';
const expected = '<html></html>';
t.deepEqual(expected, (await processing(fixture, {tags: 'style'})).html);
t.deepEqual(expected, (await processing(fixture, {tags: ['style']})).html);
});