1
- /*jshint -W082 */
1
+ 'use strict' ;
2
+
2
3
var htmlparser = require ( 'htmlparser2' ) ;
3
4
4
5
/**
@@ -16,7 +17,9 @@ module.exports = function postHTMLParser(html) {
16
17
17
18
var parser = new htmlparser . Parser ( {
18
19
onprocessinginstruction : function ( name , data ) {
19
- name . toLowerCase ( ) === '!doctype' && results . push ( '<' + data + '>' ) ;
20
+ if ( name . toLowerCase ( ) === '!doctype' ) {
21
+ results . push ( '<' + data + '>' ) ;
22
+ }
20
23
} ,
21
24
oncomment : function ( data ) {
22
25
var comment = '<!--' + data + '-->' ,
@@ -31,26 +34,27 @@ module.exports = function postHTMLParser(html) {
31
34
last . content . push ( comment ) ;
32
35
} ,
33
36
onopentag : function ( tag , attrs ) {
34
- var buf = { } ;
37
+ var buf = { tag : tag } ;
35
38
36
- buf . tag = tag ;
37
-
38
- if ( ! isEmpty ( attrs ) ) buf . attrs = attrs ;
39
+ if ( Object . keys ( attrs ) . length ) {
40
+ buf . attrs = attrs ;
41
+ }
39
42
40
43
bufArray . push ( buf ) ;
41
44
} ,
42
45
onclosetag : function ( ) {
43
46
var buf = bufArray . pop ( ) ;
44
47
45
- if ( bufArray . length === 0 ) {
48
+ if ( ! bufArray . length ) {
46
49
results . push ( buf ) ;
47
50
return ;
48
51
}
49
52
50
53
var last = bufArray . last ( ) ;
51
- if ( ! ( last . content instanceof Array ) ) {
54
+ if ( ! Array . isArray ( last . content ) ) {
52
55
last . content = [ ] ;
53
56
}
57
+
54
58
last . content . push ( buf ) ;
55
59
} ,
56
60
ontext : function ( text ) {
@@ -70,12 +74,3 @@ module.exports = function postHTMLParser(html) {
70
74
71
75
return results ;
72
76
} ;
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
- }
0 commit comments