diff --git a/cssutils/profiles.py b/cssutils/profiles.py index 1175f3a5..b121dc57 100644 --- a/cssutils/profiles.py +++ b/cssutils/profiles.py @@ -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""" @@ -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 diff --git a/newsfragments/19.bugfix.rst b/newsfragments/19.bugfix.rst new file mode 100644 index 00000000..db9603a4 --- /dev/null +++ b/newsfragments/19.bugfix.rst @@ -0,0 +1 @@ +Accept the CSS-wide keywords (initial, inherit, unset and revert) as the value of any property. diff --git a/tests/test_cssfontfacerule.py b/tests/test_cssfontfacerule.py index 665093a7..2c9bebd9 100644 --- a/tests/test_cssfontfacerule.py +++ b/tests/test_cssfontfacerule.py @@ -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', ), } diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 82045c30..bd0a8310 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -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 = { @@ -431,6 +437,9 @@ def test_validate(self): 'color', ( 'inherit', + 'initial', + 'unset', + 'revert', 'black', '#000', '#000000',