minimize
Advanced tools
Comparing version 1.7.4 to 1.8.0
@@ -12,11 +12,16 @@ 'use strict'; | ||
var config = { | ||
empty: false, // remove(false) or retain(true) empty attributes | ||
cdata: false, // remove(false) or retain(true) CDATA from scripts | ||
comments: false, // remove(false) or retain(true) comments | ||
conditionals: false, // remove(false) or retain(true) ie conditional comments | ||
ssi: false, // remove(false) or retain(true) server side includes | ||
spare: false, // remove(false) or retain(true) redundant attributes | ||
quotes: false, // remove(false) or retain(true) quotes if not required | ||
loose: false, // remove(false) all or retain(true) one whitespace | ||
whitespace: false // remove(false) or retain(true) whitespace in attributes | ||
empty: false, // remove(false) or retain(true) empty attributes | ||
cdata: false, // remove(false) or retain(true) CDATA from scripts | ||
comments: false, // remove(false) or retain(true) comments | ||
conditionals: false, // remove(false) or retain(true) ie conditional comments | ||
ssi: false, // remove(false) or retain(true) server side includes | ||
spare: false, // remove(false) or retain(true) redundant attributes | ||
quotes: false, // remove(false) or retain(true) quotes if not required | ||
loose: false, // remove(false) all or retain(true) one whitespace | ||
whitespace: false, // remove(false) or retain(true) whitespace in attributes | ||
dom: { // see https://github.com/fb55/htmlparser2 for all options | ||
xmlMode: false, // Disables the special behavior for script/style tags (false by default) | ||
lowerCaseAttributeNames: true, // call .toLowerCase for each attribute name (true if xmlMode is `false`) | ||
lowerCaseTags: true // call .toLowerCase for each tag name (true if xmlMode is `false`) | ||
} | ||
}; | ||
@@ -148,3 +153,3 @@ | ||
if (!value.length) return result; | ||
if (allowed && (bool && (value === key || 'true' === value))) return result; | ||
if (allowed && bool && (value === key || 'true' === value)) return result; | ||
} | ||
@@ -151,0 +156,0 @@ |
@@ -26,2 +26,3 @@ 'use strict'; | ||
options = parser || {}; | ||
options.dom = options.dom || {}; | ||
parser = void 0; | ||
@@ -38,3 +39,3 @@ } | ||
this.htmlparser = parser || new html.Parser( | ||
new html.DomHandler(this.emits('read')) | ||
new html.DomHandler(this.emits('read')), options.dom | ||
); | ||
@@ -41,0 +42,0 @@ |
{ | ||
"name": "minimize", | ||
"version": "1.7.4", | ||
"version": "1.8.0", | ||
"description": "Minimize HTML", | ||
@@ -18,3 +18,3 @@ "main": "./lib/minimize", | ||
"async": "~1.4.2", | ||
"cli-color": "~1.0.0", | ||
"cli-color": "~1.1.0", | ||
"diagnostics": "~1.0.1", | ||
@@ -26,7 +26,7 @@ "emits": "~3.0.0", | ||
"devDependencies": { | ||
"chai": "~3.2.0", | ||
"istanbul": "~0.3.18", | ||
"mocha": "~2.2.5", | ||
"chai": "~3.3.0", | ||
"istanbul": "~0.4.0", | ||
"mocha": "~2.3.3", | ||
"pre-commit": "~1.1.1", | ||
"sinon": "~1.16.1", | ||
"sinon": "~1.17.1", | ||
"sinon-chai": "~2.8.0" | ||
@@ -33,0 +33,0 @@ }, |
@@ -41,10 +41,15 @@ # HTML minifier | ||
, minimize = new Minimize({ | ||
empty: true, // KEEP empty attributes | ||
cdata: true, // KEEP CDATA from scripts | ||
comments: true, // KEEP comments | ||
ssi: true, // KEEP Server Side Includes | ||
conditionals: true, // KEEP conditional internet explorer comments | ||
spare: true, // KEEP redundant attributes | ||
quotes: true, // KEEP arbitrary quotes | ||
loose: true // KEEP one whitespace | ||
empty: true, // KEEP empty attributes | ||
cdata: true, // KEEP CDATA from scripts | ||
comments: true, // KEEP comments | ||
ssi: true, // KEEP Server Side Includes | ||
conditionals: true, // KEEP conditional internet explorer comments | ||
spare: true, // KEEP redundant attributes | ||
quotes: true, // KEEP arbitrary quotes | ||
loose: true, // KEEP one whitespace | ||
dom: { // options of !(htmlparser2)[https://github.com/fb55/htmlparser2] | ||
xmlMode: false, // Disables the special behavior for script/style tags (false by default) | ||
lowerCaseAttributeNames: true, // call .toLowerCase for each attribute name (true if xmlMode is `false`) | ||
lowerCaseTags: true // call .toLowerCase for each tag name (true if xmlMode is `false`) | ||
} | ||
}); | ||
@@ -221,2 +226,18 @@ | ||
**dom** | ||
Minimize use !(htmlparser2)[https://github.com/fb55/htmlparser2] to parse the dom. The `dom` option permit to customize htmlparser2. | ||
```javascript | ||
var Minimize = require('minimize') | ||
, minimize = new Minimize({ dom: { lowerCaseAttributeNames: false }}); | ||
minimize.parse( | ||
'<a *ngIf="bool">link</a>', | ||
function (error, data) { | ||
// data output: <a *ngIf=bool>link</a> ' | ||
} | ||
); | ||
``` | ||
## Plugins | ||
@@ -223,0 +244,0 @@ |
@@ -163,3 +163,6 @@ 'use strict'; | ||
expect(result).to.equal('<h1 class="slide nodejs">a</h1><h2>b</h2><h3 id=lol>c</h3><h4>d</h4><h5 hidden>e</h5><h6 itemscope>f</h6>'); | ||
done(); | ||
empty.parse('<option value>Select something</option>', function (error, result) { | ||
expect(result).to.equal('<option value>Select something</option>'); | ||
done(); | ||
}); | ||
}); | ||
@@ -301,3 +304,3 @@ }); | ||
it('should keep empty attribute values with if empty and spare options are set', function (done) { | ||
it('should keep empty attribute values if empty and spare options are set', function (done) { | ||
var empty = new Minimize({ empty: true, spare: true }); | ||
@@ -370,2 +373,17 @@ empty.parse('<option value="">Select something</option>', function (error, result) { | ||
it('should lower case attributes names', function (done) { | ||
minimize.parse('<a ngIf="bool">test</a>', function (error, result) { | ||
expect(result).to.equal('<a ngif=bool>test</a>'); | ||
done(); | ||
}); | ||
}); | ||
it('should conserve sensitive case of attributes', function (done) { | ||
var lowerCase = new Minimize({ dom: {lowerCaseAttributeNames: false} }); | ||
lowerCase.parse('<a ngIf="bool">test</a>', function (error, result) { | ||
expect(result).to.equal('<a ngIf=bool>test</a>'); | ||
done(); | ||
}); | ||
}); | ||
it('has the ability to use plugins to alter elements', function (done) { | ||
@@ -372,0 +390,0 @@ var pluggable = new Minimize({ plugins: [{ |
Sorry, the diff of this file is not supported yet
85034
1699
304
+ Addedansi-regex@2.1.1(transitive)
+ Addedcli-color@1.1.0(transitive)
- Removedansi-regex@1.1.1(transitive)
- Removedcli-color@1.0.0(transitive)
Updatedcli-color@~1.1.0