Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions cssutils/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from cssutils import util
import re

# The CSS-wide keywords are valid in place of the value of any property.
# https://drafts.csswg.org/css-values-4/#common-keywords
CSS_WIDE_KEYWORDS = 'inherit|initial|unset|revert'


class NoSuchProfileException(Exception):
"""Raised if no profile with given name is found"""
Expand Down Expand Up @@ -168,10 +172,10 @@ def _compile_regexes(self, dictionary):
for key, value in list(dictionary.items()):
if not hasattr(value, '__call__'):
# Compiling them now will slow down the cssutils import time,
# even if cssutils is not needed. Thus, lazily compile them the
# first time they're needed.
# even if the cssutils is not needed. Thus, lazily compile them
# the first time they're needed.
# https://web.archive.org/web/20200701035537/https://bitbucket.org/cthedot/cssutils/issues/69)
value = util.LazyRegex('^(?:%s)$' % value, re.I)
value = util.LazyRegex('^(?:%s|%s)$' % (value, CSS_WIDE_KEYWORDS), re.I)
dictionary[key] = value

return dictionary
Expand Down
1 change: 1 addition & 0 deletions newsfragments/19.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Accept the CSS-wide keywords (initial, inherit, unset and revert) as the value of any property.
3 changes: 2 additions & 1 deletion tests/test_cssfontfacerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ def test_valid(self):
True: (
N,
N + 'font-style: italic; font-weight: bold',
# a CSS-wide keyword is valid for any property
N + 'font-style: inherit',
),
False: (
'',
'font-family: x, y; src: local(x);',
N + 'font-style: inherit',
N + 'invalid: 1',
),
}
Expand Down
9 changes: 9 additions & 0 deletions tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ def test_csscolorlevel3(self):
# 'color', color
# )

def test_css_wide_keywords(self):
"the CSS-wide keywords are valid for any property"
for name in cssutils.profile.knownNames:
for keyword in ('inherit', 'initial', 'unset', 'revert'):
assert cssutils.profile.validate(name, keyword), (name, keyword)

def test_validate(self):
"Profiles.validate()"
tests = {
Expand Down Expand Up @@ -431,6 +437,9 @@ def test_validate(self):
'color',
(
'inherit',
'initial',
'unset',
'revert',
'black',
'#000',
'#000000',
Expand Down