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

Commit

Permalink
Merge pull request #88 from hail2u/issue87
Browse files Browse the repository at this point in the history
Support in-casesensitivity flag in attr selector
  • Loading branch information
hail2u committed Nov 19, 2017
2 parents faba5ed + 27e72ab commit 4c32163
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
12 changes: 10 additions & 2 deletions index.js
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,7 +193,15 @@ function unquoteAttributeSelector(m, att, con, val) {
val = `${quote}${val}${quote}`;
}

return `[${att}${con}${val}]`;
if (!flag) {
flag = "";
}

if (flag && !val.startsWith(quote)) {
flag = ` ${flag}`;
}

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

// Remove white spaces from string
Expand Down
2 changes: 1 addition & 1 deletion lib/regexp.js
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
@@ -0,0 +1 @@
[class=foo i]{display:block}[class="bar baz"i]{display:block}
8 changes: 8 additions & 0 deletions test/fixtures/issue87.css
@@ -0,0 +1,8 @@
[class = "foo" i] {
display: block;
}

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

0 comments on commit 4c32163

Please sign in to comment.