Comparing version 0.7.5 to 0.7.6
@@ -191,11 +191,13 @@ 'use strict'; | ||
// | ||
content = content.replace(/^\s+/, prev && this.isInline(prev) ? ' ' : ''); | ||
content = content.replace(/\s+$/, next && this.isInline(next) ? ' ' : ''); | ||
if (!ancestors) { | ||
content = content.replace( | ||
ancestors ? /^[^\S\n]+/ : /^\s+/, | ||
prev && this.isInline(prev) ? ' ' : '' | ||
).replace( | ||
ancestors ? /[^\S\n]+$/ : /\s+$/, | ||
next && this.isInline(next) ? ' ' : '' | ||
).replace(/\n/g, ' ').replace(/\s+/g, ' '); | ||
} | ||
// | ||
// If we have ancestors stored do not remove structure. | ||
// | ||
if (!ancestors) content = content.replace(/\n/g, ' ').replace(/\s+/g, ' '); | ||
// | ||
// Remove CDATA from scripts. | ||
@@ -202,0 +204,0 @@ // |
@@ -6,3 +6,3 @@ 'use strict'; | ||
// | ||
var parser = require('htmlparser2') | ||
var html = require('htmlparser2') | ||
, EventEmitter = require('events').EventEmitter | ||
@@ -26,4 +26,4 @@ , Helpers = require('./helpers'); | ||
// | ||
this.htmlparser = new parser.Parser( | ||
new parser.DefaultHandler(this.minifier.bind(this)) | ||
this.htmlparser = new html.Parser( | ||
new html.DomHandler(this.minifier.bind(this)) | ||
); | ||
@@ -30,0 +30,0 @@ } |
{ | ||
"name": "minimize", | ||
"version": "0.7.5", | ||
"version": "0.7.6", | ||
"description": "Minimize HTML", | ||
@@ -15,8 +15,8 @@ "main": "./lib/minimize", | ||
"devDependencies": { | ||
"coveralls": "~2.8.0", | ||
"mocha": "~1.18.0", | ||
"coveralls": "~2.11.1", | ||
"mocha": "~1.20.1", | ||
"mocha-lcov-reporter": "~0.0.1", | ||
"chai": "~1.9.0", | ||
"istanbul": "~0.2.6", | ||
"sinon": "~1.9.0", | ||
"istanbul": "~0.3.0", | ||
"sinon": "~1.10.3", | ||
"sinon-chai": "~2.5.0", | ||
@@ -23,0 +23,0 @@ "pre-commit": "~0.0.4" |
@@ -38,9 +38,9 @@ # HTML minifier [![Build Status][status]](https://travis-ci.org/Moveo/minimize) [![NPM version][npmimgurl]](http://npmjs.org/package/minimize) [![Coverage Status][coverage]](http://coveralls.io/r/Moveo/minimize?branch=master) | ||
, minimize = new Minimize({ | ||
empty: true, // DO NOT remove empty attributes | ||
cdata: true, // DO NOT strip CDATA from scripts | ||
comments: true, // DO NOT remove comments | ||
ssi: true, // DO NOT remove Server Side Includes (i.e. <!--#include virtual="../quote.txt" -->) | ||
conditionals: true, // DO NOT remove conditional internet explorer comments | ||
spare: true, // DO NOT remove redundant attributes | ||
quotes: true // DO NOT remove arbitrary quotes | ||
empty: true, // KEEP empty attributes | ||
cdata: true, // KEEP CDATA from scripts | ||
comments: true, // KEEP comments | ||
ssi: true, // KEEP Server Side Includes (i.e. <!--#include virtual="../quote.txt" -->) | ||
conditionals: true, // KEEP conditional internet explorer comments | ||
spare: true, // KEEP redundant attributes | ||
quotes: true // KEEP arbitrary quotes | ||
}); | ||
@@ -147,3 +147,3 @@ | ||
**Qoutes** | ||
**Quotes** | ||
@@ -192,3 +192,3 @@ Quotes are always added around attributes that have spaces or an equal sign in | ||
[kangax]: https://github.com/kangax/html-minifier/ | ||
[fb55]: https://github.com/fb55/node-htmlparser/ | ||
[fb55]: https://github.com/fb55/htmlparser2 | ||
[nodejitsu]: http://www.nodejitsu.com/ |
@@ -19,2 +19,3 @@ { | ||
"br": "<p class=\"slide\">\n <span>\n <em>Does your organization have security or licensing restrictions?</em>\n </span>\n\n <br/><br/>\n <span>\n Your private npm registry makes managing them simple by giving you the power\n to work with a blacklist and a whitelist of public npm packages.\n </span>\n </p>", | ||
"pre": "<pre><code class=\"lang-bash\">git clone https://github.com/cjdelisle/cjdns.git cjdns\n <span class=\"hljs-built_in\">cd</span> cjdns\n ./<span class=\"hljs-keyword\">do</span>\n</code></pre>", | ||
"doctype": { | ||
@@ -21,0 +22,0 @@ "data": "!doctype html", |
@@ -325,7 +325,10 @@ /*global beforeEach, afterEach*/ | ||
beforeEach(function () { | ||
helpers.ancestor = []; | ||
html.text.data = text; | ||
}); | ||
afterEach(function () { | ||
delete html.text.next; | ||
delete html.text.prev; | ||
html.text.data = text; | ||
helpers.ancestor = []; | ||
}); | ||
@@ -410,3 +413,3 @@ | ||
describe('structural collection', function () { | ||
it('matches pre or textarea', function () { | ||
it('matches pre, textarea or code', function () { | ||
expect(!!~list.structural.indexOf('pre')).to.be.true; | ||
@@ -413,0 +416,0 @@ expect(!!~list.structural.indexOf('textarea')).to.be.true; |
@@ -135,3 +135,3 @@ 'use strict'; | ||
minimize.parse(html.code, function (error, result) { | ||
expect(result).to.equal("<code class=copy><span>var http = require('http');\nhttp.createServer(function (req, res) {\n res.writeHead(200, {'Content-Type': 'text/plain'});\n res.end('hello, i know nodejitsu');\n})listen(8080);</span><a href=#><s class=ss-layers role=presentation></s> copy</a></code>"); | ||
expect(result).to.equal("<code class=copy>\n<span>var http = require('http');\nhttp.createServer(function (req, res) {\n res.writeHead(200, {'Content-Type': 'text/plain'});\n res.end('hello, i know nodejitsu');\n})listen(8080);</span><a href=#><s class=ss-layers role=presentation></s> copy</a></code>"); | ||
done(); | ||
@@ -143,3 +143,3 @@ }); | ||
minimize.parse(html.styles, function (error, result) { | ||
expect(result).to.equal("<style>.test { color: #FFF }</style><style>.test { color: black }</style>"); | ||
expect(result).to.equal("<style> .test { color: #FFF }</style><style>.test { color: black }</style>"); | ||
done(); | ||
@@ -207,3 +207,3 @@ }); | ||
minimize.parse(html.cdata, function (error, result) { | ||
expect(result).to.equal("<script type=text/javascript>\n...code...\n</script>"); | ||
expect(result).to.equal("<script type=text/javascript>\n\n...code...\n\n</script>"); | ||
done(); | ||
@@ -216,3 +216,3 @@ }); | ||
cdata.parse(html.cdata, function (error, result) { | ||
expect(result).to.equal("<script type=text/javascript>//<![CDATA[\n...code...\n//]]></script>"); | ||
expect(result).to.equal("<script type=text/javascript>\n//<![CDATA[\n...code...\n//]]>\n</script>"); | ||
done(); | ||
@@ -231,4 +231,3 @@ }); | ||
it('should clobber space around <br> elements', function (done) { | ||
var quote = new Minimize; | ||
quote.parse(html.br, function (error, result) { | ||
minimize.parse(html.br, function (error, result) { | ||
expect(result).to.equal("<p class=slide><span><em>Does your organization have security or licensing restrictions?</em></span><br><br><span>Your private npm registry makes managing them simple by giving you the power to work with a blacklist and a whitelist of public npm packages.</span></p>"); | ||
@@ -238,2 +237,9 @@ done(); | ||
}); | ||
it('should maintain flow in pre elements', function (done) { | ||
minimize.parse(html.pre, function (error, result) { | ||
expect(result).to.equal('<pre><code class=lang-bash>git clone https://github.com/cjdelisle/cjdns.git cjdns\n <span class=hljs-built_in>cd</span> cjdns\n ./<span class=hljs-keyword>do</span>\n</code></pre>'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -240,0 +246,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51888
1082