Skip to content

Commit

Permalink
Fixed CSS extra variable (#1649)
Browse files Browse the repository at this point in the history
Details are described [here](#1450 (comment)).

I decided to go with the property variant, highlighting custom property declarations as `variable`.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Dec 3, 2018
1 parent 5fcee96 commit 9de47d3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 6 additions & 3 deletions components/prism-css-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ Prism.languages.css.selector = {
}
};

Prism.languages.insertBefore('css', 'function', {
Prism.languages.insertBefore('css', 'property', {
'variable': {
pattern: /(var\()[^)]+(?=\))/,
pattern: /(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,
lookbehind: true
},
}
});

Prism.languages.insertBefore('css', 'function', {
'operator': {
pattern: /(\s)[+\-*\/](?=\s)/,
lookbehind: true
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/variable_feature.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
element {
--foo: green;
}

var(--color-primary)
var(--level-3)
var(--foo, red)
calc(100% - var(--margin-size) * 2)

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

[
["selector", ["element"]],
["punctuation", "{"],
["variable", "--foo"],
["punctuation", ":"],
" green",
["punctuation", ";"],
["punctuation", "}"],

["function", "var"],
["punctuation", "("],
["variable", "--color-primary"],
Expand All @@ -15,6 +28,13 @@ calc(100% - var(--margin-size) * 2)
["variable", "--level-3"],
["punctuation", ")"],

["function", "var"],
["punctuation", "("],
["variable", "--foo"],
["punctuation", ","],
" red",
["punctuation", ")"],

["function", "calc"],
["punctuation", "("],
["number", "100"],
Expand Down

0 comments on commit 9de47d3

Please sign in to comment.