Skip to content

Commit

Permalink
Merge df73606 into 128c6af
Browse files Browse the repository at this point in the history
  • Loading branch information
manland committed Jan 9, 2016
2 parents 128c6af + df73606 commit 885c3fe
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
node_modules/
.idea/
lib-cov
*.seed
*.log
Expand Down
37 changes: 29 additions & 8 deletions README.md
Expand Up @@ -38,14 +38,19 @@ object can be provided. All options are listed below and `false` per default.
```javascript
var Minimize = require('minimize')
, 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`)
}
});

minimize.parse(content, function (error, data) {
Expand Down Expand Up @@ -217,6 +222,22 @@ minimize.parse(
);
```
**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
Register a set of plugins that will be ran on each iterated element. Plugins
Expand Down
23 changes: 14 additions & 9 deletions lib/helpers.js
Expand Up @@ -9,15 +9,20 @@ var list = require('./list');
// Predefined parsing options.
//
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`)
}
};

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/minimize.js
Expand Up @@ -23,6 +23,7 @@ var debug = require('diagnostics')('minimize')
function Minimize(parser, options) {
if ('object' !== typeof options) {
options = parser || {};
options.dom = options.dom || {};
parser = void 0;
}

Expand All @@ -34,7 +35,7 @@ function Minimize(parser, options) {
// Prepare the parser.
//
this.htmlparser = parser || new html.Parser(
new html.DomHandler(this.emits('read'))
new html.DomHandler(this.emits('read')), options.dom
);

//
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "minimize",
"version": "1.7.4",
"version": "1.8.0",
"description": "Minimize HTML",
"main": "./lib/minimize",
"bin": {
Expand Down
15 changes: 15 additions & 0 deletions test/minimize-test.js
Expand Up @@ -368,6 +368,21 @@ describe('Minimize', function () {
});
});

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) {
var pluggable = new Minimize({ plugins: [{
id: 'test',
Expand Down

0 comments on commit 885c3fe

Please sign in to comment.