Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
Support in-casesensitivity flag in attr selector
Browse files Browse the repository at this point in the history
This type of selector already is supported by Firefox 47+, Chrome 49+,
and Safari 9.

This fixes #87.
  • Loading branch information
hail2u committed Nov 18, 2017
1 parent faba5ed commit 172805b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function wringValue(prop, value) {
}

// Unquote attribute selector if possible
function unquoteAttributeSelector(m, att, con, val) {
function unquoteAttributeSelector(m, att, con, val, oq, flag) {
if (!con || !val) {
return `[${att}]`;
}
Expand All @@ -193,6 +193,10 @@ function unquoteAttributeSelector(m, att, con, val) {
val = `${quote}${val}${quote}`;
}

if (flag === "i") {
val = `${val} i`;
}

return `[${att}${con}${val}]`;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ re.propertyMultipleValues = /^(margin|padding|border-(color|radius|spacing|style
re.quotedString = /("|')?(.*)\1/;

// [class = "foo"], [class ~= "foo"], [class |= "foo"], [class ^= "foo"], [class $= "foo"], [class *= "foo"]
re.selectorAtt = /\[\s*(.*?)(?:\s*([~|^$*]?=)\s*(("|').*\4|.*?[^\\]))?\s*\]/g;
re.selectorAtt = /\[\s*(.*?)(?:\s*([~|^$*]?=)\s*(("|').*\4|.*?[^\\]))?\s*(i)?\]/g;

// p > a, p + a, p ~ a
re.selectorCombinators = /\s+((\\?)[>+~])\s+/g;
Expand Down
1 change: 1 addition & 0 deletions test/expected/issue87.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[class=foo i]{display:block}[class="bar baz" i]{display:block}
8 changes: 8 additions & 0 deletions test/fixtures/issue87.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[class = "foo" i] {
display: block;
}

[class = "bar baz"
i] {
display: block;
}

0 comments on commit 172805b

Please sign in to comment.