Skip to content

Commit 2d6a196

Browse files
committed
Deals with old / new syntax
1 parent a3be4b4 commit 2d6a196

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

tinycss2/color5.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,31 @@ def parse_color(input, color_schemes=None):
3535
token for token in token.arguments
3636
if token.type not in ('whitespace', 'comment')]
3737
name = token.lower_name
38+
alpha = []
3839

3940
if name == 'color':
4041
space, *tokens = tokens
4142

4243
length = len(tokens)
4344

44-
if length in (7, 9) and all(token == ',' for token in tokens[1::2]):
45-
old_syntax = True
45+
old_syntax = all(token == ',' for token in tokens[1::2])
46+
if old_syntax:
4647
tokens = tokens[::2]
47-
elif length in (3, 4):
48-
old_syntax = False
49-
elif length == 6 and tokens[4] == '/':
50-
tokens.pop(4)
51-
old_syntax = False
5248
else:
53-
return
54-
args, alpha = tokens[:4], color4._parse_alpha(tokens[4:])
49+
for index, token in enumerate(tokens):
50+
if token == '/':
51+
alpha = tokens[index + 1:]
52+
tokens = tokens[:index]
53+
break
5554

5655
if name == 'device-cmyk':
57-
return _parse_device_cmyk(args, alpha, old_syntax)
56+
return _parse_device_cmyk(tokens, color4._parse_alpha(alpha), old_syntax)
57+
elif name == 'color':
58+
return _parse_color(space, tokens, color4._parse_alpha(alpha))
5859
elif name == 'light-dark':
59-
return _parse_light_dark(args, color_scheme)
60-
elif name == 'color' and not old_syntax:
61-
return _parse_color(space, args, alpha)
60+
return _parse_light_dark(tokens, color_scheme)
61+
else:
62+
return
6263

6364

6465
def _parse_device_cmyk(args, alpha, old_syntax):
@@ -74,7 +75,7 @@ def _parse_device_cmyk(args, alpha, old_syntax):
7475
if color4._types(args) != {'number'}:
7576
return
7677
else:
77-
if not color4._types(args) <= {'numbers', 'percentage'}:
78+
if not color4._types(args) <= {'number', 'percentage'}:
7879
return
7980
cmyk = [
8081
arg.value if arg.type == 'number' else

0 commit comments

Comments
 (0)