getting combinators to output properly. some little hacks, but it beats having a white-space sensitive grammar

This commit is contained in:
cloudhead
2010-03-05 11:39:39 -05:00
parent 06acb92d20
commit 476581f77a
3 changed files with 11 additions and 4 deletions

View File

@@ -10,16 +10,21 @@ tree.Element.prototype.toCSS = function () {
};
tree.Combinator = function Combinator(value) {
this.value = value ? value.trim() : "";
if (value === ' ') {
this.value = ' ';
} else {
this.value = value ? value.trim() : "";
}
};
tree.Combinator.prototype.toCSS = function () {
switch (this.value) {
case '' : return '';
case ' ' : return ' ';
case '&' : return '';
case ':' : return ' :';
case '::': return '::';
case '+' : return ' + ';
case '~' : return ' ~ ';
case '>' : return ' > ';
default : return ' ' + this.value;
}
};

View File

@@ -86,7 +86,9 @@ tree.Ruleset.prototype = {
} else {
if (rules.length > 0) {
selector = paths.map(function (p) {
return new(tree.Selector)(p).toCSS().trim();
return p.map(function (s) {
return s.toCSS();
}).join('').trim();
}).join(paths.length > 3 ? ',\n' : ', ');
css.push(selector, " {\n " + rules.join('\n ') + "\n}\n");
}

View File

@@ -341,7 +341,7 @@ less.parser = {
if (match = $(/[+>~]/g) || $('&') || $(/::/g)) {
return new(tree.Combinator)(match);
} else {
return new(tree.Combinator);
return new(tree.Combinator)(input[i - 1] === " " ? " " : null);
}
},
selector: function () {