Skip to content

Commit 9de47d3

Browse files
RunDevelopmentmAAdhaTTah
authored andcommitted
Fixed CSS extra variable (#1649)
Details are described [here](#1450 (comment)). I decided to go with the property variant, highlighting custom property declarations as `variable`.
1 parent 5fcee96 commit 9de47d3

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

components/prism-css-extras.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ Prism.languages.css.selector = {
99
}
1010
};
1111

12-
Prism.languages.insertBefore('css', 'function', {
12+
Prism.languages.insertBefore('css', 'property', {
1313
'variable': {
14-
pattern: /(var\()[^)]+(?=\))/,
14+
pattern: /(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,
1515
lookbehind: true
16-
},
16+
}
17+
});
18+
19+
Prism.languages.insertBefore('css', 'function', {
1720
'operator': {
1821
pattern: /(\s)[+\-*\/](?=\s)/,
1922
lookbehind: true

components/prism-css-extras.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/css!+css-extras/variable_feature.test

+20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
element {
2+
--foo: green;
3+
}
4+
15
var(--color-primary)
26
var(--level-3)
7+
var(--foo, red)
38
calc(100% - var(--margin-size) * 2)
49

510
----------------------------------------------------
611

712
[
13+
["selector", ["element"]],
14+
["punctuation", "{"],
15+
["variable", "--foo"],
16+
["punctuation", ":"],
17+
" green",
18+
["punctuation", ";"],
19+
["punctuation", "}"],
20+
821
["function", "var"],
922
["punctuation", "("],
1023
["variable", "--color-primary"],
@@ -15,6 +28,13 @@ calc(100% - var(--margin-size) * 2)
1528
["variable", "--level-3"],
1629
["punctuation", ")"],
1730

31+
["function", "var"],
32+
["punctuation", "("],
33+
["variable", "--foo"],
34+
["punctuation", ","],
35+
" red",
36+
["punctuation", ")"],
37+
1838
["function", "calc"],
1939
["punctuation", "("],
2040
["number", "100"],

0 commit comments

Comments
 (0)