From 39d01773a1c8497ba104f2467dbf96ac891c8adf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Dec 2016 17:20:43 +0530 Subject: [PATCH] CSS Transforms: Fix is/is not rules not matching currentColor. Fixes #1650930 [Transform styles border colors and currentColor keyword](https://bugs.launchpad.net/calibre/+bug/1650930) --- src/calibre/ebooks/css_transform_rules.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/css_transform_rules.py b/src/calibre/ebooks/css_transform_rules.py index 577bee9cb0..55e3680835 100644 --- a/src/calibre/ebooks/css_transform_rules.py +++ b/src/calibre/ebooks/css_transform_rules.py @@ -97,6 +97,7 @@ class StyleDeclaration(object): def __str__(self): return force_unicode(self.css_declaration.cssText, 'utf-8') + operator_map = {'==':'eq', '!=': 'ne', '<=':'le', '<':'lt', '>=':'ge', '>':'gt', '-':'sub', '+': 'add', '*':'mul', '/':'truediv'} @@ -171,9 +172,9 @@ class Rule(object): elif self.action in '+-/*': self.action_operator = partial(transform_number, float(self.action_data), getattr(operator, operator_map[self.action])) if match_type == 'is': - self.property_matches = lambda x: x.lower() == query + self.property_matches = lambda x: x.lower() == query.lower() elif match_type == 'is_not': - self.property_matches = lambda x: x.lower() != query + self.property_matches = lambda x: x.lower() != query.lower() elif match_type == '*': self.property_matches = lambda x: True elif 'matches' in match_type: @@ -207,6 +208,7 @@ class Rule(object): declaration.changed = oval or changed return changed + ACTION_MAP = OrderedDict(( ('remove', _('Remove the property')), ('append', _('Add extra properties')), @@ -383,7 +385,7 @@ def test(return_tests=False): # {{{ def test_matching(self): def m(match_type='*', query=''): - self.ae(ecss, apply_rule(css, property=prop, match_type=match_type, query=query)) + self.ae(apply_rule(css, property=prop, match_type=match_type, query=query), ecss) prop = 'color' css, ecss = 'color: red; margin: 0', 'margin: 0' @@ -394,6 +396,8 @@ def test(return_tests=False): # {{{ m('not_matches', 'blue') ecss = css.replace('; ', ';\n') m('is', 'blue') + css, ecss = 'color: currentColor; line-height: 0', 'line-height: 0' + m('is', 'currentColor') prop = 'margin-top' css, ecss = 'color: red; margin-top: 10', 'color: red' @@ -451,6 +455,7 @@ def test(return_tests=False): # {{{ return tests unittest.TextTestRunner(verbosity=4).run(tests) + if __name__ == '__main__': test() # }}}