implement better serialization of class names
RTWYSIWYG-27 : poorly formed yet valid HTML caused hyperjson to produce element
selectors which hyperscript could not parse.
This commit is contained in:
parent
fbe6225681
commit
0ff4906f0e
@ -17,7 +17,7 @@ define([], function () {
|
|||||||
|
|
||||||
var callOnHyperJSON = function (hj, cb) {
|
var callOnHyperJSON = function (hj, cb) {
|
||||||
var children;
|
var children;
|
||||||
|
|
||||||
if (hj && hj[2]) {
|
if (hj && hj[2]) {
|
||||||
children = hj[2].map(function (child) {
|
children = hj[2].map(function (child) {
|
||||||
if (isArray(child)) {
|
if (isArray(child)) {
|
||||||
@ -39,6 +39,14 @@ define([], function () {
|
|||||||
return cb(hj[0], hj[1], children);
|
return cb(hj[0], hj[1], children);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var prependDot = function (token) {
|
||||||
|
return '.' + token;
|
||||||
|
};
|
||||||
|
|
||||||
|
var isTruthy = function (x) {
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
|
||||||
var DOM2HyperJSON = function(el){
|
var DOM2HyperJSON = function(el){
|
||||||
if(!el.tagName && el.nodeType === Node.TEXT_NODE){
|
if(!el.tagName && el.nodeType === Node.TEXT_NODE){
|
||||||
return el.textContent;
|
return el.textContent;
|
||||||
@ -73,7 +81,14 @@ define([], function () {
|
|||||||
delete attributes.id;
|
delete attributes.id;
|
||||||
}
|
}
|
||||||
if(attributes.class){
|
if(attributes.class){
|
||||||
sel = sel +'.'+ attributes.class.replace(/ /g,".");
|
/* TODO this can be done with RegExps alone, and it will be faster
|
||||||
|
but this works and is a little less error prone, albeit slower
|
||||||
|
come back and speed it up when it comes time to optimize */
|
||||||
|
sel = sel +'.'+ attributes.class
|
||||||
|
.split(/\s+/)
|
||||||
|
.split(isTruthy)
|
||||||
|
.map(prependDot)
|
||||||
|
.join('');
|
||||||
delete attributes.class;
|
delete attributes.class;
|
||||||
}
|
}
|
||||||
result.push(sel);
|
result.push(sel);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user