diff --git a/index.js b/index.js index 3ed278f..b7b4124 100644 --- a/index.js +++ b/index.js @@ -33,10 +33,10 @@ module.exports = function(css){ var node; var rules = []; whitespace(); - comments(); + comments(rules); while (css[0] != '}' && (node = atrule() || rule())) { - comments(); rules.push(node); + comments(rules); } return rules; } @@ -64,8 +64,11 @@ module.exports = function(css){ * Parse comments; */ - function comments() { - while (comment()) ; + function comments(rules) { + rules = rules || []; + var c; + while (c = comment()) rules.push(c); + return rules; } /** @@ -77,9 +80,10 @@ module.exports = function(css){ var i = 2; while ('*' != css[i] || '/' != css[i + 1]) ++i; i += 2; + var comment = css.slice(2, i - 2); css = css.slice(i); whitespace(); - return true; + return {comment: comment}; } } diff --git a/test/cases/charset.json b/test/cases/charset.json index e4fb6d4..bf8fe58 100644 --- a/test/cases/charset.json +++ b/test/cases/charset.json @@ -4,8 +4,14 @@ { "charset": "\"UTF-8\"" }, + { + "comment": " Set the encoding of the style sheet to Unicode UTF-8" + }, { "charset": "'iso-8859-15'" + }, + { + "comment": " Set the encoding of the style sheet to Latin-9 (Western European languages, with euro sign) " } ] } diff --git a/test/cases/comment.json b/test/cases/comment.json index a8c0c4e..26bd743 100644 --- a/test/cases/comment.json +++ b/test/cases/comment.json @@ -1,6 +1,15 @@ { "stylesheet": { "rules": [ + { + "comment": " foo " + }, + { + "comment": " bar " + }, + { + "comment": " baz\n\nasdfasdfasdf\nasdfasdfasdf\nasdfasdfasdf\nasdfasdfasdf\n\n" + }, { "selectors": [ "foo" diff --git a/test/cases/comment.url.json b/test/cases/comment.url.json index a8c0c4e..2efc0a8 100644 --- a/test/cases/comment.url.json +++ b/test/cases/comment.url.json @@ -1,6 +1,9 @@ { "stylesheet": { "rules": [ + { + "comment": " http://foo.com/bar/baz.html " + }, { "selectors": [ "foo"