Skip to content

Commit

Permalink
Identify css operators
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Sep 19, 2018
1 parent e1de79a commit 4a60bb1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
6 changes: 5 additions & 1 deletion components/prism-css-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ Prism.languages.insertBefore('css', 'function', {
pattern: /(var\()[^)]+(?=\))/,
lookbehind: true
},
'operator': {
pattern: /(\s)[+\-*\/](?=\s)/,
lookbehind: true
},
'hexcode': /#[\da-f]{3,8}/i,
'entity': /\\[\da-f]{1,8}/i,
'unit': {
pattern: /(\d)(?:%|[a-z]+)/,
lookbehind: true
},
'number': /-?[\d.]+/
});
});
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.

34 changes: 34 additions & 0 deletions tests/languages/css!+css-extras/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
width: calc(100% - 20px);
height: -20px;
content: 'this - is not an operator';

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

[
["property", "width"],
["punctuation", ":"],
["function", "calc"],
["punctuation", "("],
["number", "100"],
["unit", "%"],
["operator", "-"],
["number", "20"],
["unit", "px"],
["punctuation", ")"],
["punctuation", ";"],

["property", "height"],
["punctuation", ":"],
["number", "-20"],
["unit", "px"],
["punctuation", ";"],

["property", "content"],
["punctuation", ":"],
["string", "'this - is not an operator'"],
["punctuation", ";"]
]

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

Checks for operators.
6 changes: 3 additions & 3 deletions tests/languages/css!+css-extras/variable_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ calc(100% - var(--margin-size) * 2)
["punctuation", "("],
["number", "100"],
["unit", "%"],
" - ",
["operator", "-"],
["function", "var"],
["punctuation", "("],
["variable", "--margin-size"],
["punctuation", ")"],
" * ",
["operator", "*"],
["number", "2"],
["punctuation", ")"]
]

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

Checks for variables.
Checks for variables.

0 comments on commit 4a60bb1

Please sign in to comment.