Skip to content

Commit e1436a7

Browse files
committed
Merge pull request #10 from shvaikalesh/master
Minor improvements
2 parents cf3927e + fcfc1e9 commit e1436a7

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

index.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/*jshint -W082 */
1+
'use strict';
2+
23
var htmlparser = require('htmlparser2');
34

45
/**
@@ -16,7 +17,9 @@ module.exports = function postHTMLParser(html) {
1617

1718
var parser = new htmlparser.Parser({
1819
onprocessinginstruction: function(name, data) {
19-
name.toLowerCase() === '!doctype' && results.push('<' + data + '>');
20+
if (name.toLowerCase() === '!doctype') {
21+
results.push('<' + data + '>');
22+
}
2023
},
2124
oncomment: function(data) {
2225
var comment = '<!--' + data + '-->',
@@ -31,26 +34,27 @@ module.exports = function postHTMLParser(html) {
3134
last.content.push(comment);
3235
},
3336
onopentag: function(tag, attrs) {
34-
var buf = {};
37+
var buf = { tag: tag };
3538

36-
buf.tag = tag;
37-
38-
if (!isEmpty(attrs)) buf.attrs = attrs;
39+
if (Object.keys(attrs).length) {
40+
buf.attrs = attrs;
41+
}
3942

4043
bufArray.push(buf);
4144
},
4245
onclosetag: function() {
4346
var buf = bufArray.pop();
4447

45-
if (bufArray.length === 0) {
48+
if (!bufArray.length) {
4649
results.push(buf);
4750
return;
4851
}
4952

5053
var last = bufArray.last();
51-
if (!(last.content instanceof Array)) {
54+
if (!Array.isArray(last.content)) {
5255
last.content = [];
5356
}
57+
5458
last.content.push(buf);
5559
},
5660
ontext: function(text) {
@@ -70,12 +74,3 @@ module.exports = function postHTMLParser(html) {
7074

7175
return results;
7276
};
73-
74-
function isEmpty(obj) {
75-
for (var key in obj) {
76-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
77-
return false;
78-
}
79-
}
80-
return true;
81-
}

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"preversion": "npm test",
1818
"postversion": "git push && git push --tags && rm -rf coverage"
1919
},
20-
"repository": {
21-
"type": "git",
22-
"url": "git+https://github.com/posthtml/posthtml-parser.git"
23-
},
20+
"repository": "posthtml/posthtml-parser",
2421
"author": "Ivan Voischev <voischev.ivan@ya.ru>",
2522
"license": "MIT",
2623
"bugs": {

0 commit comments

Comments
 (0)