Skip to content

Commit

Permalink
CSS-Extras: Added even & odd keywords to n-th pattern (#1872)
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
RunDevelopment authored May 12, 2019
1 parent 74050c6 commit 5e5a3e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
20 changes: 13 additions & 7 deletions components/prism-css-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ Prism.languages.css.selector = {
'operator': /[|~*^$]?=/
}
},
'n-th': {
pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
lookbehind: true,
inside: {
'number': /[\dn]+/,
'operator': /[+-]/
'n-th': [
{
pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
lookbehind: true,
inside: {
'number': /[\dn]+/,
'operator': /[+-]/
}
},
{
pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i,
lookbehind: true
}
},
],
'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.

20 changes: 20 additions & 0 deletions tests/languages/css!+css-extras/selector_n-th_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
:nth-child(+2n - 1) {}
:nth-child(2n) {}
:nth-child(+5) {}
:nth-child(even) {}
:nth-child(odd) {}

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

Expand Down Expand Up @@ -54,6 +56,24 @@
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["pseudo-class", ":nth-child"],
["punctuation", "("],
["n-th", "even"],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["pseudo-class", ":nth-child"],
["punctuation", "("],
["n-th", "odd"],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"]
]

Expand Down

0 comments on commit 5e5a3e0

Please sign in to comment.