Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CSS Color Module Level 4 #53

Merged
merged 20 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only allow 4- and 8-digit hashes in Color Level 4
liZe committed Jun 18, 2024
commit 29e2e7cfcb7c78b8b7f8e126455a4dead484e357
2 changes: 0 additions & 2 deletions tinycss2/color3.py
Original file line number Diff line number Diff line change
@@ -142,8 +142,6 @@ def _parse_comma_separated(tokens):


_HASH_REGEXPS = (
(2, re.compile('^{}$'.format(4 * '([\\da-f])'), re.I).match),
(1, re.compile('^{}$'.format(4 * '([\\da-f]{2})'), re.I).match),
(2, re.compile('^{}$'.format(3 * '([\\da-f])'), re.I).match),
(1, re.compile('^{}$'.format(3 * '([\\da-f]{2})'), re.I).match),
)
6 changes: 6 additions & 0 deletions tinycss2/color4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from colorsys import hls_to_rgb
from math import tau

@@ -137,6 +138,11 @@ def _parse_hwb(args, alpha):
return RGBA(r, g, b, alpha)


_HASH_REGEXPS += (
(2, re.compile('^{}$'.format(4 * '([\\da-f])'), re.I).match),
(1, re.compile('^{}$'.format(4 * '([\\da-f]{2})'), re.I).match),
)

# (r, g, b) in 0..255
_EXTENDED_COLOR_KEYWORDS = _EXTENDED_COLOR_KEYWORDS.copy()
_EXTENDED_COLOR_KEYWORDS.append(('rebeccapurple', (102, 51, 153)))