From 2bc344057cfc88cb185563e0f12e00cfa0be63cd Mon Sep 17 00:00:00 2001 From: Ivan Voischev Date: Sat, 3 Oct 2015 22:32:49 +0300 Subject: [PATCH 01/12] Add plugin name --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c8030f6..557853e 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ var fs = require('fs'); var path = require('path'); -module.exports = function(options) { +module.exports = function posthtmlStyleToFile(options) { options = options || { path: './result.css' }; var buf = ''; From 926accaad43bfdf7809227d11f9347c337378880 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Thu, 7 Jul 2016 14:27:46 +0200 Subject: [PATCH 02/12] docs(README): change style, update example --- readme.md | 102 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/readme.md b/readme.md index 9ab89c6..830cc03 100644 --- a/readme.md +++ b/readme.md @@ -1,49 +1,105 @@ -# PostHTML-style-to-file -[![npm version](https://badge.fury.io/js/posthtml-style-to-file.svg)](http://badge.fury.io/js/posthtml-style-to-file) +[![NPM][npm]][npm-url] +[![Deps][deps]][deps-url] +[![Tests][travis]][travis-url] +[![Coverage][cover]][cover-url] -## Usage +
+ + +

Style-to-File Plugin

+

Save DOM styles to CSS file

+
+ +

Install

+ +```bash +npm i -D posthtml-postcss +``` + +

Usage

+ +### Options + +__`path`__ + +Destination path, where the extracted CSS is saved to. + +

Example

```js -var posthtml = require('posthtml'), - html = fs.readFileSync('path/to/html', 'utf-8').toString(); +const posthtml = require('posthtml') +const styleToFile = require('posthtml-style-to-file') -posthtml() - .use(require('posthtml-style-to-file')({ path: './dist/style.css'})) +const html = readFileSync('path/to/html', 'utf8') + +posthtml([ styleToFile({ path: './dist/style.css' }) ]) .process(html) - .then(function(result) { - console.log(result.html); - }) + .then((result) => console.log(result.html)) ``` -### Input html + +__index.html__ ```html Wow -
-
- Text -
+
+
+ Text
+
``` -### Output css +__style.css__ ```css -/* ./dist/style.css */ html{ margin: 0 } -body{background: #fff;} -div.button{border: 1px solid #000;} +body{ background: #fff; } +div.button{ border: 1px solid #000; } ``` -## Options +

LICENSE

+ +> MIT License (MIT) + +> Copyright (c) PostHTML Ivan Voischev + +> Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +> The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +[npm]: https://img.shields.io/npm/v/posthtml-style-to-file.svg +[npm-url]: https://npmjs.com/package/posthtml-style-to-file + +[deps]: https://david-dm.org/posthtml/posthtml-style-to-file.svg +[deps-url]: https://david-dm.org/posthtml/posthtml-style-to-file + +[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg +[style-url]: http://standardjs.com/ + +[travis]: http://img.shields.io/travis/posthtml/posthtml-style-to-file.svg +[travis-url]: https://travis-ci.org/posthtml/posthtml-style-to-file -#### `path` -Dist path +[cover]: https://coveralls.io/repos/github/posthtml/posthtml-style-to-file/badge.svg?branch=master +[cover-url]: https://coveralls.io/github/posthtml/posthtml-style-to-file?branch=master From 4110523ca645e68b46a40bd0017ede3313fa123f Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Thu, 7 Jul 2016 14:28:13 +0200 Subject: [PATCH 03/12] docs(LICENSE): add --- LICENSE | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ae85a0c --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2016 PostHTML Ivan Voischev + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From b7f6def5c00f37c07b0314ab41b82ce21a463303 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Thu, 7 Jul 2016 14:39:12 +0200 Subject: [PATCH 04/12] docs(README): fix typo --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 830cc03..b7d84b9 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@

Install

```bash -npm i -D posthtml-postcss +npm i -D posthtml-style-to-file ```

Usage

From 5fb455eae204b99491fc059b007fe81c4b575256 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Mon, 24 Jun 2019 17:52:34 +0300 Subject: [PATCH 05/12] build: update depDev --- package.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7c7295d..73480a9 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,13 @@ "version": "0.1.1", "description": "posthtml style-to-file plugin", "main": "index.js", - "dependencies": { - }, + "dependencies": {}, "devDependencies": { - "chai": "^3.2.0", - "jscs": "^1.13.1", + "chai": "^4.2.0", + "jscs": "^3.0.7", "jshint": "^2.8.0", - "posthtml": "^0.3.0", - "mocha": "^2.2.5" + "mocha": "^6.1.4", + "posthtml": "^0.11.4" }, "scripts": { "test": "npm run lint && mocha", From 650008538f42348706f0b14103008f30a9ad1a9d Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 11:54:25 +0300 Subject: [PATCH 06/12] test: for feat remove style --- test/test.js | 86 ++++++++++++++++++++++++++++++++------- test/testRemoveAll.html | 15 +++++++ test/testRemoveAttrs.html | 17 ++++++++ test/testRemoveTag.html | 15 +++++++ 4 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 test/testRemoveAll.html create mode 100644 test/testRemoveAttrs.html create mode 100644 test/testRemoveTag.html diff --git a/test/test.js b/test/test.js index ccc6548..618aac9 100644 --- a/test/test.js +++ b/test/test.js @@ -4,30 +4,88 @@ var plugin = require('..'); var expect = require('chai').expect; var fs = require('fs'); -var HTML = fs.readFileSync('./test/test.html', 'utf-8'), - CSS = fs.readFileSync('./test/test.css', 'utf-8'); +var HTML = fs.readFileSync('./test/test.html', 'utf-8'); +var CSS = fs.readFileSync('./test/test.css', 'utf-8'); -function test(html, referenceCss, done) { +function test(html, options, callbackSuccess, callbackError) { posthtml() - .use(plugin({ path: './test/test2.css' })) + .use(plugin(options)) .process(html) - .then(function(/*result*/) { - setTimeout(function() { - expect(referenceCss).to.eql(fs.readFileSync('./test/test2.css', 'utf-8').toString()); - done(); - }, 20); - }).catch(function(error) { - done(error); - }); + .then(callbackSuccess) + .catch(callbackError); } describe('Simple test', function() { it('style to file', function(done) { test( HTML, - CSS, - done + { path: './test/test2.css' }, + function() { + setTimeout(function() { + expect(CSS).to.eql(fs.readFileSync('./test/test2.css', 'utf-8').toString()); + done(); + }, 20); + }, + function(error) { + done(error); + } ); }); + it('remove style attrs', function(done) { + test( + HTML, + { + path: './test/test2.css', + removeStyle: 'attrs' + }, + function(result) { + setTimeout(function() { + expect(result.html).to.eql(fs.readFileSync('./test/testRemoveAttrs.html', 'utf-8').toString()); + done(); + }, 20); + }, + function(error) { + done(error); + } + ); + }); + + it('remove style tag', function(done) { + test( + HTML, + { + path: './test/test2.css', + removeStyle: 'tag' + }, + function(result) { + setTimeout(function() { + expect(result.html).to.eql(fs.readFileSync('./test/testRemoveTag.html', 'utf-8').toString()); + done(); + }, 20); + }, + function(error) { + done(error); + } + ); + }); + + it('remove style all', function(done) { + test( + HTML, + { + path: './test/test2.css', + removeStyle: 'all' + }, + function(result) { + setTimeout(function() { + expect(result.html).to.eql(fs.readFileSync('./test/testRemoveAll.html', 'utf-8').toString()); + done(); + }, 20); + }, + function(error) { + done(error); + } + ); + }); }); diff --git a/test/testRemoveAll.html b/test/testRemoveAll.html new file mode 100644 index 0000000..4711247 --- /dev/null +++ b/test/testRemoveAll.html @@ -0,0 +1,15 @@ + + + Wow + + + +
+
+
+ Text +
+
+
+ + diff --git a/test/testRemoveAttrs.html b/test/testRemoveAttrs.html new file mode 100644 index 0000000..38cb66b --- /dev/null +++ b/test/testRemoveAttrs.html @@ -0,0 +1,17 @@ + + + Wow + + + +
+
+
+ Text +
+
+
+ + diff --git a/test/testRemoveTag.html b/test/testRemoveTag.html new file mode 100644 index 0000000..49d731c --- /dev/null +++ b/test/testRemoveTag.html @@ -0,0 +1,15 @@ + + + Wow + + + +
+
+
+ Text +
+
+
+ + From 4917203485398c1185d661d9a278926a45fa22ef Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 11:54:59 +0300 Subject: [PATCH 07/12] feat: remove style attrs and tag, close #1 --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 557853e..372adb7 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,12 @@ module.exports = function posthtmlStyleToFile(options) { tree.match({ tag: 'style' }, function(node) { buf += node.content[0].trim() || ''; - return node; + + if (options.removeStyle === 'tag' || options.removeStyle === 'all') { + return ''; + } + + return node; }); tree.match({ attrs: { style: true }}, function(node) { @@ -22,6 +27,11 @@ module.exports = function posthtmlStyleToFile(options) { node.tag + (node.attrs.id? ('#' + node.attrs.id ): '') + cls + '{' + node.attrs.style + '}'; + + if (options.removeStyle === 'attrs' || options.removeStyle === 'all') { + delete node.attrs.style; + } + return node; }); From 8d896808e65692adc6700a4ed095bf3e6fadb2ee Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 11:55:27 +0300 Subject: [PATCH 08/12] docs: add description for remove style --- readme.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index b7d84b9..a694fda 100644 --- a/readme.md +++ b/readme.md @@ -18,9 +18,21 @@ npm i -D posthtml-style-to-file

Usage

-### Options +## Options -__`path`__ +#### `path` + +Type: `String` +Default: `./result.css` +Description: *Destination path, where the extracted CSS is saved to.* + +#### `removeStyle` + +Type: `String` +Default: `` +Description: *Removes the specified value `attrs` | `tag` | `all`* + +__`removeStyle`__ Destination path, where the extracted CSS is saved to. From 51f287f1377ba371137d35e57827912e16e6b4f1 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 12:00:29 +0300 Subject: [PATCH 09/12] ci: add travis config --- .travis.yml | 9 +++++++++ package.json | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..156f12b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +sudo: false +language: node_js +node_js: + - "node" + - "lts/*" + - "8" + +after_script: + - npm run coverage diff --git a/package.json b/package.json index 73480a9..1d41e42 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,16 @@ "dependencies": {}, "devDependencies": { "chai": "^4.2.0", + "coveralls": "^3.0.4", "jscs": "^3.0.7", "jshint": "^2.8.0", "mocha": "^6.1.4", + "nyc": "^14.1.1", "posthtml": "^0.11.4" }, "scripts": { - "test": "npm run lint && mocha", + "coverage": "nyc report --reporter=text-lcov | coveralls", + "test": "npm run lint && nyc mocha", "lint": "jshint . && jscs . -v" }, "repository": { From 7d17ab08606adf435cef64a581d1bd270f9b7432 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 12:00:52 +0300 Subject: [PATCH 10/12] build: update config ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46c912c..a84175b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ # NODEJS node_modules npm-debug.log +.nyc_output From 56326c83204627820dcc832500c91265027a2a85 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 14:16:54 +0300 Subject: [PATCH 11/12] 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d41e42..7052e46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthtml-style-to-file", - "version": "0.1.1", + "version": "0.2.0", "description": "posthtml style-to-file plugin", "main": "index.js", "dependencies": {}, From 89dab6134bf19400cac6df2cec525dae04c25aa5 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Tue, 25 Jun 2019 15:10:42 +0300 Subject: [PATCH 12/12] docs: update badges --- readme.md | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/readme.md b/readme.md index a694fda..fdc6cd4 100644 --- a/readme.md +++ b/readme.md @@ -77,30 +77,6 @@ body{ background: #fff; } div.button{ border: 1px solid #000; } ``` -

LICENSE

- -> MIT License (MIT) - -> Copyright (c) PostHTML Ivan Voischev - -> Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -> The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - [npm]: https://img.shields.io/npm/v/posthtml-style-to-file.svg [npm-url]: https://npmjs.com/package/posthtml-style-to-file @@ -113,5 +89,5 @@ SOFTWARE. [travis]: http://img.shields.io/travis/posthtml/posthtml-style-to-file.svg [travis-url]: https://travis-ci.org/posthtml/posthtml-style-to-file -[cover]: https://coveralls.io/repos/github/posthtml/posthtml-style-to-file/badge.svg?branch=master -[cover-url]: https://coveralls.io/github/posthtml/posthtml-style-to-file?branch=master +[cover]: https://coveralls.io/repos/github/posthtml/posthtml-style-to-file/badge.svg +[cover-url]: https://coveralls.io/github/posthtml/posthtml-style-to-file