Skip to content

Commit f316201

Browse files
committed
Add CSS4 color keywords from PR #37 and fix for Issue #21
1 parent 5b85556 commit f316201

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

src/vscode-css/grammars/css.cson

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,17 @@
754754
]
755755
'color-keywords':
756756
'patterns': [
757+
{
758+
# Allow shorthand property in specific contexts (Fix for https://github.com/microsoft/vscode-css/issues/21)
759+
'match': '''(?xi)
760+
(?<=
761+
(transition|transition-property)
762+
\\:[\\w\\s\\-,]*
763+
)
764+
background
765+
'''
766+
'name': 'support.constant.property-value.css'
767+
}
757768
{
758769
# CSS 2.1 colors: http://www.w3.org/TR/CSS21/syndata.html#value-def-color
759770
'match': '(?i)(?<![\\w-])(aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow)(?![\\w-])'
@@ -786,13 +797,21 @@
786797
'match': '(?i)(?<![\\w-])currentColor(?![\\w-])'
787798
'name': 'support.constant.color.current.css'
788799
}
800+
{
801+
# CSS4 color names https://drafts.csswg.org/css-color-4/#css-system-colors
802+
'match': '''(?xi) (?<![\\w-])
803+
(accentcolor|accentcolortext|activetext|buttonborder|buttonface|buttontext|canvas|canvastext|field|fieldtext
804+
|graytext|highlight|highlighttext|linktext|mark|marktext|selecteditem|selecteditemtext|visitedtext)
805+
(?![\\w-])
806+
'''
807+
'name': 'support.constant.color.system.css'
808+
}
789809
{
790810
# These colors are deprecated in CSS3: http://www.w3.org/TR/css3-color/#css2-system
791811
'match': '''(?xi) (?<![\\w-])
792-
(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonFace|ButtonHighlight|ButtonShadow
793-
|ButtonText|CaptionText|GrayText|Highlight|HighlightText|InactiveBorder|InactiveCaption
794-
|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar|ThreeDDarkShadow
795-
|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText)
812+
(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonHighlight|ButtonShadow|CaptionText
813+
|InactiveBorder|InactiveCaption|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar
814+
|ThreeDDarkShadow|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText)
796815
(?![\\w-])
797816
'''
798817
'name': 'invalid.deprecated.color.system.css'

src/vscode-css/spec/css-spec.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14914,6 +14914,50 @@ describe("CSS grammar", function () {
1491414914
});
1491514915
});
1491614916

14917+
it("tokenizes system color keywords", function () {
14918+
var tokens;
14919+
tokens = testGrammar.tokenizeLine("a { color: AccentColor; }").tokens;
14920+
assert.deepStrictEqual(tokens[7], {
14921+
value: "AccentColor",
14922+
scopes: [
14923+
"source.css",
14924+
"meta.property-list.css",
14925+
"meta.property-value.css",
14926+
"support.constant.color.system.css",
14927+
],
14928+
});
14929+
});
14930+
14931+
it("tokenizes deprecated system color keywords", function () {
14932+
var tokens;
14933+
tokens = testGrammar.tokenizeLine("a { color: background; }").tokens;
14934+
assert.deepStrictEqual(tokens[7], {
14935+
value: "background",
14936+
scopes: [
14937+
"source.css",
14938+
"meta.property-list.css",
14939+
"meta.property-value.css",
14940+
"invalid.deprecated.color.system.css",
14941+
],
14942+
});
14943+
});
14944+
14945+
it("does not confuse property names for deprecated color keywords", function () {
14946+
var tokens;
14947+
tokens = testGrammar.tokenizeLine(
14948+
"a { transition-property: background; }"
14949+
).tokens;
14950+
assert.deepStrictEqual(tokens[7], {
14951+
value: "background",
14952+
scopes: [
14953+
"source.css",
14954+
"meta.property-list.css",
14955+
"meta.property-value.css",
14956+
"support.constant.property-value.css",
14957+
],
14958+
});
14959+
});
14960+
1491714961
it("tokenises RGBA values in hex notation", function () {
1491814962
var tokens;
1491914963
tokens = testGrammar.tokenizeLine("p{ color: #f030; }").tokens;

0 commit comments

Comments
 (0)