Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/prism-css-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Prism.languages.css.selector = {
pattern: Prism.languages.css.selector,
inside: {
'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,
'pseudo-class': /:[-\w]+(?:\(.*\))?/,
'pseudo-class': /:[-\w]+/,
'class': /\.[-:.\w]+/,
'id': /#[-:.\w]+/,
'attribute': {
Expand Down Expand Up @@ -35,7 +35,16 @@ Prism.languages.css.selector = {
],
'operator': /[|~*^$]?=/
}
}
},
'n-th': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n-th is a class in our themes already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it's a necessary wrapper for the number and operator tokens.

pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
lookbehind: true,
inside: {
'number': /[\dn]+/,
'operator': /[+-]/
}
},
'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.

13 changes: 3 additions & 10 deletions tests/languages/css!+css-extras/selector_feature.test
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
foo:after {
foo::first-letter {

foo:nth-child(2n+1) {

foo.bar {

foo#bar {

#foo > .bar:not(baz):after {
#foo > .bar:hover:after {

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

Expand All @@ -22,11 +20,6 @@ foo#bar {
["pseudo-element", "::first-letter"]
]], ["punctuation", "{"],

["selector", [
"foo",
["pseudo-class", ":nth-child(2n+1)"]
]], ["punctuation", "{"],

["selector", [
"foo",
["class", ".bar"]
Expand All @@ -41,11 +34,11 @@ foo#bar {
["id", "#foo"],
" > ",
["class", ".bar"],
["pseudo-class", ":not(baz)"],
["pseudo-class", ":hover"],
["pseudo-element", ":after"]
]], ["punctuation", "{"]
]

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

Checks for pseudo-elements, pseudo-classes, classes and ids inside selectors.
Checks for pseudo-elements, pseudo-classes, classes and ids inside selectors.
62 changes: 62 additions & 0 deletions tests/languages/css!+css-extras/selector_n-th_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
:nth-child(2n+1) {}
:nth-child(+2n - 1) {}
:nth-child(2n) {}
:nth-child(+5) {}

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

[
["selector", [
["pseudo-class", ":nth-child"],
["punctuation", "("],
["n-th", [
["number", "2n"],
["operator", "+"],
["number", "1"]
]],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["pseudo-class", ":nth-child"],
["punctuation", "("],
["n-th", [
["operator", "+"],
["number", "2n"],
["operator", "-"],
["number", "1"]
]],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

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

["selector", [
["pseudo-class", ":nth-child"],
["punctuation", "("],
["n-th", [
["operator", "+"],
["number", "5"]
]],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"]
]

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

Checks for n-th expressions.
59 changes: 59 additions & 0 deletions tests/languages/css!+css-extras/selector_pseudo-class_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
foo:hover {}

:lang(en) {}

.bar:not(baz:hover):not(.foo) {}

:where(p:not(.class)) {}

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

[
["selector", [
"foo",
["pseudo-class", ":hover"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["pseudo-class", ":lang"],
["punctuation", "("],
"en",
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["class", ".bar"],
["pseudo-class", ":not"],
["punctuation", "("],
"baz",
["pseudo-class", ":hover"],
["punctuation", ")"],
["pseudo-class", ":not"],
["punctuation", "("],
["class", ".foo"],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"],

["selector", [
["pseudo-class", ":where"],
["punctuation", "("],
"p",
["pseudo-class", ":not"],
["punctuation", "("],
["class", ".class"],
["punctuation", ")"],
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"]
]

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

Checks for pseudo-classes inside selectors.