File tree Expand file tree Collapse file tree 5 files changed +136
-13
lines changed Expand file tree Collapse file tree 5 files changed +136
-13
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Prism.languages.css.selector = {
22 pattern : Prism . languages . css . selector ,
33 inside : {
44 'pseudo-element' : / : (?: a f t e r | b e f o r e | f i r s t - l e t t e r | f i r s t - l i n e | s e l e c t i o n ) | : : [ - \w ] + / ,
5- 'pseudo-class' : / : [ - \w ] + (?: \( . * \) ) ? / ,
5+ 'pseudo-class' : / : [ - \w ] + / ,
66 'class' : / \. [ - : . \w ] + / ,
77 'id' : / # [ - : . \w ] + / ,
88 'attribute' : {
@@ -35,7 +35,16 @@ Prism.languages.css.selector = {
3535 ] ,
3636 'operator' : / [ | ~ * ^ $ ] ? = /
3737 }
38- }
38+ } ,
39+ 'n-th' : {
40+ pattern : / ( \( \s * ) [ + - ] ? \d * [ \d n ] (?: \s * [ + - ] \s * \d + ) ? (? = \s * \) ) / ,
41+ lookbehind : true ,
42+ inside : {
43+ 'number' : / [ \d n ] + / ,
44+ 'operator' : / [ + - ] /
45+ }
46+ } ,
47+ 'punctuation' : / [ ( ) ] /
3948 }
4049} ;
4150
Original file line number Diff line number Diff line change 11foo:after {
22foo::first-letter {
33
4- foo:nth-child(2n+1) {
5-
64foo.bar {
75
86foo#bar {
97
10- #foo > .bar:not(baz) :after {
8+ #foo > .bar:hover :after {
119
1210----------------------------------------------------
1311
@@ -22,11 +20,6 @@ foo#bar {
2220 ["pseudo-element", "::first-letter"]
2321 ]], ["punctuation", "{"],
2422
25- ["selector", [
26- "foo",
27- ["pseudo-class", ":nth-child(2n+1)"]
28- ]], ["punctuation", "{"],
29-
3023 ["selector", [
3124 "foo",
3225 ["class", ".bar"]
@@ -41,11 +34,11 @@ foo#bar {
4134 ["id", "#foo"],
4235 " > ",
4336 ["class", ".bar"],
44- ["pseudo-class", ":not(baz) "],
37+ ["pseudo-class", ":hover "],
4538 ["pseudo-element", ":after"]
4639 ]], ["punctuation", "{"]
4740]
4841
4942----------------------------------------------------
5043
51- Checks for pseudo-elements, pseudo-classes, classes and ids inside selectors.
44+ Checks for pseudo-elements, pseudo-classes, classes and ids inside selectors.
Original file line number Diff line number Diff line change 1+ :nth-child(2n+1) {}
2+ :nth-child(+2n - 1) {}
3+ :nth-child(2n) {}
4+ :nth-child(+5) {}
5+
6+ ----------------------------------------------------
7+
8+ [
9+ ["selector", [
10+ ["pseudo-class", ":nth-child"],
11+ ["punctuation", "("],
12+ ["n-th", [
13+ ["number", "2n"],
14+ ["operator", "+"],
15+ ["number", "1"]
16+ ]],
17+ ["punctuation", ")"]
18+ ]],
19+ ["punctuation", "{"],
20+ ["punctuation", "}"],
21+
22+ ["selector", [
23+ ["pseudo-class", ":nth-child"],
24+ ["punctuation", "("],
25+ ["n-th", [
26+ ["operator", "+"],
27+ ["number", "2n"],
28+ ["operator", "-"],
29+ ["number", "1"]
30+ ]],
31+ ["punctuation", ")"]
32+ ]],
33+ ["punctuation", "{"],
34+ ["punctuation", "}"],
35+
36+ ["selector", [
37+ ["pseudo-class", ":nth-child"],
38+ ["punctuation", "("],
39+ ["n-th", [
40+ ["number", "2n"]
41+ ]],
42+ ["punctuation", ")"]
43+ ]],
44+ ["punctuation", "{"],
45+ ["punctuation", "}"],
46+
47+ ["selector", [
48+ ["pseudo-class", ":nth-child"],
49+ ["punctuation", "("],
50+ ["n-th", [
51+ ["operator", "+"],
52+ ["number", "5"]
53+ ]],
54+ ["punctuation", ")"]
55+ ]],
56+ ["punctuation", "{"],
57+ ["punctuation", "}"]
58+ ]
59+
60+ ----------------------------------------------------
61+
62+ Checks for n-th expressions.
Original file line number Diff line number Diff line change 1+ foo:hover {}
2+
3+ :lang(en) {}
4+
5+ .bar:not(baz:hover):not(.foo) {}
6+
7+ :where(p:not(.class)) {}
8+
9+ ----------------------------------------------------
10+
11+ [
12+ ["selector", [
13+ "foo",
14+ ["pseudo-class", ":hover"]
15+ ]],
16+ ["punctuation", "{"],
17+ ["punctuation", "}"],
18+
19+ ["selector", [
20+ ["pseudo-class", ":lang"],
21+ ["punctuation", "("],
22+ "en",
23+ ["punctuation", ")"]
24+ ]],
25+ ["punctuation", "{"],
26+ ["punctuation", "}"],
27+
28+ ["selector", [
29+ ["class", ".bar"],
30+ ["pseudo-class", ":not"],
31+ ["punctuation", "("],
32+ "baz",
33+ ["pseudo-class", ":hover"],
34+ ["punctuation", ")"],
35+ ["pseudo-class", ":not"],
36+ ["punctuation", "("],
37+ ["class", ".foo"],
38+ ["punctuation", ")"]
39+ ]],
40+ ["punctuation", "{"],
41+ ["punctuation", "}"],
42+
43+ ["selector", [
44+ ["pseudo-class", ":where"],
45+ ["punctuation", "("],
46+ "p",
47+ ["pseudo-class", ":not"],
48+ ["punctuation", "("],
49+ ["class", ".class"],
50+ ["punctuation", ")"],
51+ ["punctuation", ")"]
52+ ]],
53+ ["punctuation", "{"],
54+ ["punctuation", "}"]
55+ ]
56+
57+ ----------------------------------------------------
58+
59+ Checks for pseudo-classes inside selectors.
You can’t perform that action at this time.
0 commit comments