Skip to content

Commit

Permalink
CSS Extras: Renamed attr-{name,value} tokens and added tokens for c…
Browse files Browse the repository at this point in the history
…ombinators and selector lists (#2373)
  • Loading branch information
dev-itsheng committed May 8, 2020
1 parent 8a72830 commit e523f5d
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 181 deletions.
12 changes: 9 additions & 3 deletions components/prism-css-extras.js
Expand Up @@ -27,11 +27,11 @@
'punctuation': /\|$/
}
},
'attribute': {
'attr-name': {
pattern: /^(\s*)[-\w\xA0-\uFFFF]+/,
lookbehind: true
},
'value': [
'attr-value': [
string,
{
pattern: /(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,
Expand All @@ -55,7 +55,13 @@
lookbehind: true
}
],
'punctuation': /[()]/
'combinator': />|\+|~|\|\|/,

// the `tag` token has been existed and removed.
// because we can't find a perfect tokenize to match it.
// if you want to add it, please read https://github.com/PrismJS/prism/pull/2373 first.

'punctuation': /[(),]/,
}
};

Expand Down
2 changes: 1 addition & 1 deletion components/prism-css-extras.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 35 additions & 35 deletions tests/languages/css!+css-extras/selector_attribute_feature.test
Expand Up @@ -28,7 +28,7 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["punctuation", "]"]
]]
]],
Expand All @@ -38,9 +38,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -50,9 +50,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "\"val\""],
["attr-value", "\"val\""],
["punctuation", "]"]
]]
]],
Expand All @@ -62,9 +62,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "'val'"],
["attr-value", "'val'"],
["punctuation", "]"]
]]
]],
Expand All @@ -74,9 +74,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "|="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -86,9 +86,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "~="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -98,9 +98,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "|="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -110,9 +110,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "^="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -122,9 +122,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "$="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -134,9 +134,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "*="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -150,7 +150,7 @@
"foo",
["punctuation", "|"]
]],
["attribute", "attr"],
["attr-name", "attr"],
["punctuation", "]"]
]],
["attribute", [
Expand All @@ -159,15 +159,15 @@
"*",
["punctuation", "|"]
]],
["attribute", "attr"],
["attr-name", "attr"],
["punctuation", "]"]
]],
["attribute", [
["punctuation", "["],
["namespace", [
["punctuation", "|"]
]],
["attribute", "attr"],
["attr-name", "attr"],
["punctuation", "]"]
]]
]],
Expand All @@ -181,9 +181,9 @@
"foo",
["punctuation", "|"]
]],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "|="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -193,9 +193,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "val"],
["attr-value", "val"],
["case-sensitivity", "i"],
["punctuation", "]"]
]]
Expand All @@ -206,9 +206,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "\"val\""],
["attr-value", "\"val\""],
["case-sensitivity", "S"],
["punctuation", "]"]
]]
Expand All @@ -219,7 +219,7 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["punctuation", "]"]
]]
]],
Expand All @@ -229,9 +229,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "val"],
["attr-value", "val"],
["punctuation", "]"]
]]
]],
Expand All @@ -241,9 +241,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "val"],
["attr-value", "val"],
["case-sensitivity", "i"],
["punctuation", "]"]
]]
Expand All @@ -254,9 +254,9 @@
["selector", [
["attribute", [
["punctuation", "["],
["attribute", "attr"],
["attr-name", "attr"],
["operator", "="],
["value", "\"i#m :not(a.class)\""],
["attr-value", "\"i#m :not(a.class)\""],
["punctuation", "]"]
]]
]],
Expand Down
34 changes: 33 additions & 1 deletion tests/languages/css!+css-extras/selector_feature.test
Expand Up @@ -7,6 +7,14 @@ foo#bar {

#foo > .bar:hover:after {

span,
div {

div > p,
.css-li ~ .css-li,
.previous-selector + .selector,
.selected || td {

----------------------------------------------------

[
Expand All @@ -32,10 +40,34 @@ foo#bar {

["selector", [
["id", "#foo"],
" > ",
["combinator", ">"],
["class", ".bar"],
["pseudo-class", ":hover"],
["pseudo-element", ":after"]
]], ["punctuation", "{"],

["selector", [
"span",
["punctuation", ","],
"\r\ndiv"
]], ["punctuation", "{"],

["selector", [
"div ",
["combinator", ">"],
" p",
["punctuation", ","],
["class", ".css-li"],
["combinator", "~"],
["class", ".css-li"],
["punctuation", ","],
["class", ".previous-selector"],
["combinator", "+"],
["class", ".selector"],
["punctuation", ","],
["class", ".selected"],
["combinator", "||"],
" td"
]], ["punctuation", "{"]
]

Expand Down

0 comments on commit e523f5d

Please sign in to comment.