Skip to content

Commit 7e32484

Browse files
committed
fix(index): parse obj in attrs, close #22
1 parent a44f4fe commit 7e32484

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

index.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var defaultDirectives = [{name: '!doctype', start: '<', end: '>'}];
1818
*/
1919
function postHTMLParser(html, options) {
2020
var bufArray = [],
21+
bufAttributes = {},
2122
results = [];
2223

2324
bufArray.last = function() {
@@ -44,6 +45,15 @@ function postHTMLParser(html, options) {
4445
}
4546
}
4647

48+
function normalizeArributes(attrs) {
49+
var result = {};
50+
Object.keys(attrs).forEach(function(key) {
51+
Object.assign(result, {[key]: attrs[key].replace(/&quot;/g, '"')});
52+
});
53+
54+
return result;
55+
}
56+
4757
var parser = new htmlparser.Parser({
4858
onprocessinginstruction: parserDirective,
4959
oncomment: function(data) {
@@ -61,12 +71,16 @@ function postHTMLParser(html, options) {
6171
onopentag: function(tag, attrs) {
6272
var buf = { tag: tag };
6373

64-
if (Object.keys(attrs).length) {
65-
buf.attrs = attrs;
74+
if (Object.keys(bufAttributes).length) {
75+
buf.attrs = normalizeArributes(bufAttributes);
76+
bufAttributes = {};
6677
}
6778

6879
bufArray.push(buf);
6980
},
81+
onattribute: function(name, value) {
82+
Object.assign(bufAttributes, {[name]: value});
83+
},
7084
onclosetag: function() {
7185
var buf = bufArray.pop();
7286

0 commit comments

Comments
 (0)