Skip to content

Commit 9507d71

Browse files
committed
add support for CSS4 system colors
1 parent 5b5edcf commit 9507d71

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

grammars/css.cson

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,20 @@
674674
'match': '(?i)(?<![\\w-])currentColor(?![\\w-])'
675675
'name': 'support.constant.color.current.css'
676676
}
677+
{
678+
# CSS4 color names https://drafts.csswg.org/css-color-4/#css-system-colors
679+
'match': '''(?xi) (?<![\\w-])
680+
(accentcolor|accentcolortext|activetext|buttonborder|buttonface|buttontext|canvas|canvastext|field|fieldtext
681+
|graytext|highlight|highlighttext|linktext|mark|marktext|selecteditem|selecteditemtext|visitedtext)
682+
(?![\\w-])
683+
'''
684+
'name': 'support.constant.color.system.css'
685+
}
677686
{
678687
# These colours are deprecated in CSS3: http://www.w3.org/TR/css3-color/#css2-system
679688
'match': '''(?xi) (?<![\\w-])
680-
(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonFace|ButtonHighlight|ButtonShadow
681-
|ButtonText|CaptionText|GrayText|Highlight|HighlightText|InactiveBorder|InactiveCaption
689+
(ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonHighlight|ButtonShadow
690+
|CaptionText|InactiveBorder|InactiveCaption
682691
|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar|ThreeDDarkShadow
683692
|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText)
684693
(?![\\w-])

spec/css-spec.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7315,6 +7315,7 @@ describe('CSS grammar', function () {
73157315
scopes: ['source.css', 'meta.property-list.css', 'meta.property-name.css', 'support.type.property-name.css']
73167316
});
73177317
});
7318+
73187319
describe('values', function () {
73197320
it('tokenizes color keywords', function () {
73207321
var tokens;
@@ -7325,6 +7326,34 @@ describe('CSS grammar', function () {
73257326
});
73267327
});
73277328

7329+
it('tokenizes system color keywords', function () {
7330+
var tokens;
7331+
tokens = testGrammar.tokenizeLine('a { color: AccentColor; }').tokens;
7332+
assert.deepStrictEqual(tokens[7], {
7333+
value: 'AccentColor',
7334+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'support.constant.color.system.css']
7335+
});
7336+
});
7337+
7338+
it('tokenizes deprecated system color keywords', function () {
7339+
var tokens;
7340+
tokens = testGrammar.tokenizeLine('a { color: background; }').tokens;
7341+
assert.deepStrictEqual(tokens[7], {
7342+
value: 'background',
7343+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'invalid.deprecated.color.system.css']
7344+
});
7345+
});
7346+
7347+
// https://github.com/microsoft/vscode-css/issues/21
7348+
it.skip('does not confuse property names for deprecated color keywords', function () {
7349+
var tokens;
7350+
tokens = testGrammar.tokenizeLine('a { transition-property: background; }').tokens;
7351+
assert.deepStrictEqual(tokens[7], {
7352+
value: 'background',
7353+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'support.constant.property-value.css']
7354+
});
7355+
});
7356+
73287357
it('tokenises RGBA values in hex notation', function () {
73297358
var tokens;
73307359
tokens = testGrammar.tokenizeLine('p{ color: #f030; }').tokens;

0 commit comments

Comments
 (0)