CSSJSON
CSSJSON copied to clipboard
Issue converting from JSON (ordered) to CSS
Basically I can convert the css to JSON ordered but not back to css. Here are the fixes I would recommend to allow for that to happen correctly:
In CSSJSON.js -> base.toJSON function
replace
} else if (!isEmpty(match[capEnd])) {
// Node has finished
return node;
}
with
} else if (!isEmpty(match[capEnd])) {
// Node has finished
if (args.ordered) node.length=count;
return node;
}
replace
return node;
with
if (args.ordered) node.length=count;
return node;
In CSSJSON.js -> base.toCSS function
replace
return cssString;
with
if ( typeof node.length === "number" ) {
for (var j = 0; j < node.length; j++) {
cssString += base.toCSS(node[j], depth);
}
}
else if ( typeof node.value === "object" ) {
cssString += strNode(node.name, node.value, depth);
}
else if ( typeof node.value != undefined ) {
cssString += strAttr(node.name, node.value, depth);
}
return cssString;
In CSSJSON.js -> strNode function
replace
var strNode = function (name, value, depth) {
var cssString = '\t'.repeat(depth) + name + ' {\n';
cssString += base.toCSS(value, depth + 1);
cssString += '\t'.repeat(depth) + '}\n';
return cssString;
};
with
var strNode = function (name, value, depth) {
var cssIndent = '\t'.repeat(depth),
cssString = cssIndent + name.split(/\s*,\s*/gi).join( ',\n' + cssIndent ) + ' {\n';
cssString += base.toCSS(value, depth + 1);
cssString += cssIndent + '}\n';
return cssString;
};
@svarlitskiy Hi, can you make a PR please ?
@svarlitskiy I tried but it doesn't work!