Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
return '"' + v + '"';
}

function camelCase( str ) {
return str.replace( /-([a-z])/g, function( all, i ){
return i.toUpperCase();
} )
}

function removeDOCTYPE(html) {
return html
.replace(/<\?xml.*\?>\n/, '')
Expand Down Expand Up @@ -39,9 +45,20 @@

// has multi attibutes
// make it array of attribute
if (value.match(/ /)) {
if (name === 'style') {
var arr = value.split(';');
if (!arr.length) return;
value = {};
arr.map(item => {
var attr = item.split(':');
if (attr && attr.length > 1) {
var camelCaseAttr = camelCase(attr[0]).trim();
value[camelCaseAttr] = attr[1].trim();
}
})
} else if (value.match(/ /)) {
value = value.split(' ');
}
}

// if attr already exists
// merge it
Expand Down