Skip to content

Commit ca34e47

Browse files
committed
add support for CSS4 system colors
1 parent 8ec4f90 commit ca34e47

2 files changed

Lines changed: 39 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,34 @@ describe('CSS grammar', function () {
24862486
assert.deepStrictEqual(tokens[8], { scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'support.constant.color.w3c-extended-color-name.css'], value: 'snow' });
24872487
});
24882488

2489+
it('tokenizes system color keywords', function () {
2490+
var tokens;
2491+
tokens = testGrammar.tokenizeLine('a { color: AccentColor; }').tokens;
2492+
assert.deepStrictEqual(tokens[7], {
2493+
value: 'AccentColor',
2494+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'support.constant.color.system.css']
2495+
});
2496+
});
2497+
2498+
it('tokenizes deprecated system color keywords', function () {
2499+
var tokens;
2500+
tokens = testGrammar.tokenizeLine('a { color: background; }').tokens;
2501+
assert.deepStrictEqual(tokens[7], {
2502+
value: 'background',
2503+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'invalid.deprecated.color.system.css']
2504+
});
2505+
});
2506+
2507+
// https://github.com/microsoft/vscode-css/issues/21
2508+
it.skip('does not confuse property names for deprecated color keywords', function () {
2509+
var tokens;
2510+
tokens = testGrammar.tokenizeLine('a { transition-property: background; }').tokens;
2511+
assert.deepStrictEqual(tokens[7], {
2512+
value: 'background',
2513+
scopes: ['source.css', 'meta.property-list.css', 'meta.property-value.css', 'support.constant.property-value.css']
2514+
});
2515+
});
2516+
24892517
it('tokenises RGBA values in hex notation', function () {
24902518
var tokens;
24912519
tokens = testGrammar.tokenizeLine('p{ color: #f030; }').tokens;

0 commit comments

Comments
 (0)