aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-13 21:07:32 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-13 21:07:32 +0000
commit6554612c305bfd75116b00ed89d0f3b104b1a3ca (patch)
treee428a0713d79c7fa53fcc9b8024031966ced560c
parenta50b0bf683fa87fc8927c66a9f0f2ccea3290067 (diff)
Read CSS classes with escaped colon
-rw-r--r--lib/style-reader.js12
-rw-r--r--test/style-reader.tests.js7
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/style-reader.js b/lib/style-reader.js
index db3bdbc..95fe81d 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -199,10 +199,12 @@ function htmlPathRule() {
var identifierRule = lop.rules.tokenOfType("identifier");
var integerRule = lop.rules.tokenOfType("integer");
-var classRule = lop.rules.sequence(
- lop.rules.tokenOfType("dot"),
- lop.rules.sequence.capture(identifierRule)
-).head();
+var classRule = lop.rules.then(
+ lop.rules.tokenOfType("cssClassName"),
+ function(text) {
+ return text.substring(1).replace(/\\(.)/g, "$1");
+ }
+);
function parseString(rule, string) {
var tokens = tokenise(string);
@@ -228,7 +230,7 @@ function describeError(error) {
function tokenise(string) {
var tokeniser = new RegexTokeniser([
{name: "identifier", regex: /([a-zA-Z][a-zA-Z0-9\-]*)/},
- {name: "dot", regex: /\./},
+ {name: "cssClassName", regex: /(\.(?:[a-zA-Z0-9\-]|\\.)+)/},
{name: "colon", regex: /:/},
{name: "gt", regex: />/},
{name: "whitespace", regex: /\s+/},
diff --git a/test/style-reader.tests.js b/test/style-reader.tests.js
index ec17e3a..46c2ace 100644
--- a/test/style-reader.tests.js
+++ b/test/style-reader.tests.js
@@ -40,6 +40,13 @@ test('styleReader.readHtmlPath', {
assertHtmlPath("p.tip", expected);
},
+ 'reads class with escaped colon': function() {
+ var expected = htmlPaths.elements([
+ htmlPaths.element("p", {"class": "a:b"})
+ ]);
+ assertHtmlPath("p.a\\:b", expected);
+ },
+
'reads multiple classes on element': function() {
var expected = htmlPaths.elements([
htmlPaths.element("p", {"class": "tip help"})