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

Commit 4c32163

Browse files
authoredNov 19, 2017
Merge pull request #88 from hail2u/issue87
Support in-casesensitivity flag in attr selector
2 parents faba5ed + 27e72ab commit 4c32163

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed
 

‎index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function wringValue(prop, value) {
181181
}
182182

183183
// Unquote attribute selector if possible
184-
function unquoteAttributeSelector(m, att, con, val) {
184+
function unquoteAttributeSelector(m, att, con, val, oq, flag) {
185185
if (!con || !val) {
186186
return `[${att}]`;
187187
}
@@ -193,7 +193,15 @@ function unquoteAttributeSelector(m, att, con, val) {
193193
val = `${quote}${val}${quote}`;
194194
}
195195

196-
return `[${att}${con}${val}]`;
196+
if (!flag) {
197+
flag = "";
198+
}
199+
200+
if (flag && !val.startsWith(quote)) {
201+
flag = ` ${flag}`;
202+
}
203+
204+
return `[${att}${con}${val}${flag}]`;
197205
}
198206

199207
// Remove white spaces from string

‎lib/regexp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ re.propertyMultipleValues = /^(margin|padding|border-(color|radius|spacing|style
5151
re.quotedString = /("|')?(.*)\1/;
5252

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

5656
// p > a, p + a, p ~ a
5757
re.selectorCombinators = /\s+((\\?)[>+~])\s+/g;

‎test/expected/issue87.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[class=foo i]{display:block}[class="bar baz"i]{display:block}

‎test/fixtures/issue87.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[class = "foo" i] {
2+
display: block;
3+
}
4+
5+
[class = "bar baz"
6+
i] {
7+
display: block;
8+
}

0 commit comments

Comments
 (0)
This repository has been archived.