Skip to content

Commit 9b91f3d

Browse files
committed
Merge pull request #64 from bem/move-to-htmlparser2
Move to htmlparser2
2 parents 106f180 + ec27713 commit 9b91f3d

9 files changed

Lines changed: 24 additions & 75 deletions

File tree

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ var html1 = fs.readFileSync('1.html', 'utf-8'),
8484
var options = {
8585
ignoreHtmlAttrs: [],
8686
compareHtmlAttrsAsJSON: [],
87-
verbose: true,
8887
ignoreWhitespace: true,
8988
bem: false
9089
}
@@ -106,9 +105,7 @@ where ```options``` is the ```Object```:
106105

107106
* ```compareHtmlAttrsAsJSON: [ Array ]``` - sets what respective attributes' content will be compared as ```JSONs```, not as ```Strings```
108107

109-
* ```verbose: Boolean``` - see [here](https://github.com/tautologistics/node-htmlparser#option-verbose)
110-
111-
* ```ignoreWhitespace: Boolean``` - see [here](https://github.com/tautologistics/node-htmlparser#option-ignorewhitespace)
108+
* ```ignoreWhitespace: Boolean``` - if is set ```true```, ```html-differ``` will consider all groups of ```spaces```, ```new lines```, ```tabs``` as one ```space```
112109

113110
* ```bem: Boolean``` - predefined options for BEM
114111

@@ -119,10 +116,6 @@ Options for BEM are predefined:
119116

120117
* ```compareHtmlAttrsAsJSON: ['data-bem', 'onclick', 'ondblclick']```
121118

122-
* ```verbose: true```
123-
124-
* ```ignoreWhitespace: true```
125-
126119
* ```charsAroundDiff: 40```
127120

128121

@@ -139,7 +132,7 @@ Options:
139132
-h, --help : Help
140133
-v, --version : Shows the version number
141134
--config=CONFIG : Path to configuration JSON-file
142-
--chars-around-diff=CHARSAROUNDDIFF : The number of characters around the diff
135+
--chars-around-diff=CHARSAROUNDDIFF : The number of characters around the diff (default: 40)
143136

144137
Arguments:
145138
PATH1 : Path to the 1-st html-file (required)
@@ -162,7 +155,6 @@ Study the following ```config.json```:
162155
{
163156
"ignoreHtmlAttrs": [],
164157
"compareHtmlAttrsAsJSON": [],
165-
"verbose": true,
166158
"ignoreWhitespace": true,
167159
"bem": false
168160
}

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var utils = require('./utils'),
22

33
diff = require('diff'),
4-
htmlParser = require('htmlparser'),
4+
htmlParser = require('htmlparser2'),
55
AST2Html = require('htmlparser-to-html'),
66
_ = require('lodash');
77

@@ -15,7 +15,7 @@ function htmlToAST(HTMLDoc, options) {
1515
var parser,
1616
parserHandler;
1717

18-
parserHandler = new htmlParser.DefaultHandler(function(err) {
18+
parserHandler = new htmlParser.DomHandler(function(err) {
1919
if (err) console.log(err);
2020
}, options);
2121

lib/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ exports.defaults = function(options) {
5858
ignoreHtmlAttrs: [],
5959
compareHtmlAttrsAsJSON: [],
6060

61-
verbose: true,
6261
ignoreWhitespace: true,
6362

6463
bem: false

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"dependencies": {
3131
"vow": "0.4.3",
3232
"vow-fs": "0.3.1",
33-
"htmlparser": "1.7.7",
3433
"htmlparser-to-html": "0.0.5",
3534
"coa": "0.4.0",
3635
"diff": "1.0.8",
3736
"colors": "0.6.2",
3837
"lodash": "2.4.1",
39-
"istanbul": "0.3.0"
38+
"istanbul": "0.3.0",
39+
"htmlparser2": "3.7.3"
4040
},
4141
"devDependencies": {
4242
"mocha": "1.18.2",

test/diffHtml.js

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,13 @@ function readFiles(f1, f2) {
1212

1313
describe('\'diffHtml\'', function () {
1414

15-
it('must not be diffs', function () {
16-
var htmlDiffer = new HtmlDiffer(),
17-
18-
files = readFiles('1.html', '_1.html'),
19-
20-
res = [ {
21-
value: '<!DOCTYPE html>\n<html>\n<head lang="en">\n <meta charset="UTF-8">\n <title></title>\n</head>\n<body>\nText\n</body>\n</html>\n'
22-
} ];
23-
24-
htmlDiffer.diffHtml(files.html1, files.html2).must.be.eql(res);
25-
});
26-
27-
it('must be diffs', function () {
28-
var htmlDiffer = new HtmlDiffer(),
29-
30-
files = readFiles('2.html', '_2.html'),
31-
32-
res = [ {
33-
value: '<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title></title></head><body>\n',
34-
added: undefined,
35-
removed: undefined
36-
}, {
37-
value: '!',
38-
added: true,
39-
removed: undefined
40-
}, {
41-
value: 'Text',
42-
added: undefined,
43-
removed: undefined
44-
}, {
45-
value: '!',
46-
added: true,
47-
removed: undefined
48-
}, {
49-
value: '\n</body></html>',
50-
added: undefined,
51-
removed: undefined
52-
} ];
53-
54-
htmlDiffer.diffHtml(files.html1, files.html2).must.be.eql(res);
55-
});
56-
5715
it('must set options', function () {
58-
var htmlDiffer = new HtmlDiffer({ ignoreHtmlAttrs: ['id', 'for'] }),
16+
var htmlDiffer = new HtmlDiffer({ ignoreHtmlAttrs: ['id', 'for'], ignoreWhitespace: true }),
5917

6018
files = readFiles('3.html', '_3.html'),
6119

6220
res = [ {
63-
value: '<html><head><title>Test</title></head><body><label for="">label for input</label><input id=""></body></html>',
21+
value: '<html> <head> <title>Test</title> </head> <body> <label for="">label for input</label> <input id=""> </body> </html> ',
6422
added: undefined,
6523
removed: undefined
6624
} ];

test/fixtures/9.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<title></title>
66
</head>
77
<body>
8-
<label for="random">label for input</label>
9-
<input id="random">
10-
<div onclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}" ondblclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}"></div>
11-
<div data-bem="{&quot;a&quot;:{&quot;a&quot;:{&quot;x&quot;:&quot;xx&quot;,&quot;y&quot;:&quot;yy&quot;},&quot;b&quot;:&quot;bb&quot;,&quot;c&quot;:&quot;cc&quot;},&quot;b&quot;:&quot;bb&quot;}">
8+
<label for="random">label for input</label>
9+
<input id="random">
10+
<div onclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}" ondblclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}"></div>
11+
<div data-bem="{&quot;a&quot;:{&quot;a&quot;:{&quot;x&quot;:&quot;xx&quot;,&quot;y&quot;:&quot;yy&quot;},&quot;b&quot;:&quot;bb&quot;,&quot;c&quot;:&quot;cc&quot;},&quot;b&quot;:&quot;bb&quot;}">
1212
</body>
1313
</html>

test/fixtures/_9.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head lang="en">
4-
<meta charset="UTF-8">
5-
<title></title>
4+
<meta charset="UTF-8">
5+
<title></title>
66
</head>
77
<body>
8-
<label for="sfsdfksdf">label for input</label>
9-
<input id="sfsdfksdf">
10-
<div onclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}" ondblclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}"></div>
11-
<div data-bem="{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:{&quot;c&quot;:&quot;cc&quot;,&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:{&quot;y&quot;:&quot;yy&quot;,&quot;x&quot;:&quot;xx&quot;}}}">
8+
<label for="sfsdfksdf">label for input</label>
9+
<input id="sfsdfksdf">
10+
<div onclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}" ondblclick="return {&quot;a&quot;:{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:&quot;function() { return true; }&quot;}}"></div>
11+
<div data-bem="{&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:{&quot;c&quot;:&quot;cc&quot;,&quot;b&quot;:&quot;bb&quot;,&quot;a&quot;:{&quot;y&quot;:&quot;yy&quot;,&quot;x&quot;:&quot;xx&quot;}}}">
1212
</body>
1313
</html>

test/getDiffText.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('\'diffHtml\'', function () {
1212
removed: undefined
1313
} ];
1414

15-
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.equal('');
15+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 }).must.be.equal('');
1616
});
1717

1818
it('must return a diff string', function () {
@@ -41,7 +41,7 @@ describe('\'diffHtml\'', function () {
4141

4242
out = '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'Text'.grey + '!'.inverse.green + 'texttexttexttext'.grey;
4343

44-
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
44+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 }).must.be.eql(out);
4545
});
4646

4747
it('must consider negative value of \'charsAroundDiff\' option', function () {
@@ -51,7 +51,7 @@ describe('\'diffHtml\'', function () {
5151
removed: undefined
5252
} ];
5353

54-
diffLoger.getDiffText(inp, { charsAroundDiff: -5 } ).must.be.equal('');
54+
diffLoger.getDiffText(inp, { charsAroundDiff: -5 }).must.be.equal('');
5555
});
5656

5757

@@ -70,7 +70,7 @@ describe('\'diffHtml\'', function () {
7070

7171
out = '\n' + 'texttexttexttexttexttexttexttexttexttexttext'.inverse.green + 'ololoololoololoololoololoololoololoololoolol'.inverse.red;
7272

73-
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
73+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 }).must.be.eql(out);
7474
});
7575

7676
it('must return a diff on the beginning of the input', function () {
@@ -128,7 +128,7 @@ describe('\'diffHtml\'', function () {
128128

129129
out = '\n...\n' + 'texttexttexttexttext'.grey + 'text'.inverse.red + 'texttexttexttexttext'.grey + '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'text'.grey + '!'.inverse.green + 'texttexttexttexttext'.grey;
130130

131-
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
131+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 }).must.be.eql(out);
132132
});
133133

134134
});

test/isEqual.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('\'isEqual\'', function () {
6161
});
6262

6363
it('must ignore space characters', function () {
64-
var htmlDiffer = new HtmlDiffer({ ignoreWhitespaces: true }),
64+
var htmlDiffer = new HtmlDiffer({ ignoreWhitespace: true }),
6565

6666
files = readFiles('7.html', '_7.html');
6767

0 commit comments

Comments
 (0)