Skip to content

Commit

Permalink
Merge pull request #13 from sdebarros/master
Browse files Browse the repository at this point in the history
Fix issue when parsing style (need to run saucelab again)
  • Loading branch information
bitinn committed Apr 12, 2016
2 parents 61f164c + 8db69df commit f5d70f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 21 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,7 @@ function createProperties(el) {
for (var i = 0; i < el.attributes.length; i++) {
// use built in css style parsing
if(el.attributes[i].name == 'style'){
var style = el.style;
var output = {};
for (var i = 0; i < style.length; ++i) {
var item = style.item(i);
output[item] = style[item];
// hack to workaround browser inconsistency with url()
if (output[item].indexOf('url') > -1) {
output[item] = output[item].replace(/\"/g, '')
}
}
attr = {name: 'style', value: output};
attr = createStyleProperty(el);
}
else if (ns) {
attr = createPropertyNS(el.attributes[i]);
Expand Down Expand Up @@ -239,3 +229,23 @@ function createPropertyNS(attr) {
, ns: namespaceMap[attr.name] || ''
};
}

/**
* Create style property from dom node
*
* @param Object el DOM node
* @return Object Normalized attribute
*/
function createStyleProperty(el) {
var style = el.style;
var output = {};
for (var i = 0; i < style.length; ++i) {
var item = style.item(i);
output[item] = style[item];
// hack to workaround browser inconsistency with url()
if (output[item].indexOf('url') > -1) {
output[item] = output[item].replace(/\"/g, '')
}
}
return { name: 'style', value: output };
}
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@ describe('vdom-parser', function () {
});

it('should parse style attribute on node', function () {
input = '<div style="color: red;">test</div>';
input = '<div style="color: red;" id="abc">test</div>';
output = parser(input);

expect(output.type).to.equal('VirtualNode');
expect(output.tagName).to.equal('DIV');
expect(output.properties.style).to.eql({
color: 'red'
});
expect(output.properties.id).to.equal('abc');
});

it('should parse complex style attribute on node', function () {
Expand Down

0 comments on commit f5d70f6

Please sign in to comment.