Skip to content

Commit 5e5a3e0

Browse files
CSS-Extras: Added even & odd keywords to n-th pattern (#1872)
`even` and `odd` are keywords which are also an `n-th` value. This adds it to the pattern which previously only captured values of the form `an+b`.
1 parent 74050c6 commit 5e5a3e0

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

components/prism-css-extras.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ Prism.languages.css.selector = {
3636
'operator': /[|~*^$]?=/
3737
}
3838
},
39-
'n-th': {
40-
pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
41-
lookbehind: true,
42-
inside: {
43-
'number': /[\dn]+/,
44-
'operator': /[+-]/
39+
'n-th': [
40+
{
41+
pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
42+
lookbehind: true,
43+
inside: {
44+
'number': /[\dn]+/,
45+
'operator': /[+-]/
46+
}
47+
},
48+
{
49+
pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i,
50+
lookbehind: true
4551
}
46-
},
52+
],
4753
'punctuation': /[()]/
4854
}
4955
};

components/prism-css-extras.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/css!+css-extras/selector_n-th_feature.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
:nth-child(+2n - 1) {}
33
:nth-child(2n) {}
44
:nth-child(+5) {}
5+
:nth-child(even) {}
6+
:nth-child(odd) {}
57

68
----------------------------------------------------
79

@@ -54,6 +56,24 @@
5456
["punctuation", ")"]
5557
]],
5658
["punctuation", "{"],
59+
["punctuation", "}"],
60+
61+
["selector", [
62+
["pseudo-class", ":nth-child"],
63+
["punctuation", "("],
64+
["n-th", "even"],
65+
["punctuation", ")"]
66+
]],
67+
["punctuation", "{"],
68+
["punctuation", "}"],
69+
70+
["selector", [
71+
["pseudo-class", ":nth-child"],
72+
["punctuation", "("],
73+
["n-th", "odd"],
74+
["punctuation", ")"]
75+
]],
76+
["punctuation", "{"],
5777
["punctuation", "}"]
5878
]
5979

0 commit comments

Comments
 (0)