From c31de00dcdb285d021af76ce761cdffea5a04427 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 Sep 2014 11:50:04 +0530 Subject: [PATCH] Conversion: Do not allow default (user-agent) style rules to ever override style rules defined in the input document, regardless of CSS selector specificity. Fixes #1369753 [conversion ignores "*" css selector](https://bugs.launchpad.net/calibre/+bug/1369753) --- src/calibre/ebooks/oeb/stylizer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index eb4b6ac915..ec3f4e87ba 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -257,7 +257,7 @@ class Stylizer(object): index = 0 self.stylesheets = set() self.page_rule = {} - for stylesheet in stylesheets: + for sheet_index, stylesheet in enumerate(stylesheets): href = stylesheet.href self.stylesheets.add(href) for rule in stylesheet.cssRules: @@ -267,10 +267,10 @@ class Stylizer(object): if not media.intersection({'all', 'screen', 'amzn-kf8'}): continue for subrule in rule.cssRules: - rules.extend(self.flatten_rule(subrule, href, index)) + rules.extend(self.flatten_rule(subrule, href, index, is_user_agent_sheet=sheet_index==0)) index += 1 else: - rules.extend(self.flatten_rule(rule, href, index)) + rules.extend(self.flatten_rule(rule, href, index, is_user_agent_sheet=sheet_index==0)) index = index + 1 rules.sort() self.rules = rules @@ -351,12 +351,13 @@ class Stylizer(object): data = item.data.cssText return ('utf-8', data) - def flatten_rule(self, rule, href, index): + def flatten_rule(self, rule, href, index, is_user_agent_sheet=False): results = [] + sheet_index = 0 if is_user_agent_sheet else 1 if isinstance(rule, CSSStyleRule): style = self.flatten_style(rule.style) for selector in rule.selectorList: - specificity = selector.specificity + (index,) + specificity = (sheet_index,) + selector.specificity + (index,) text = selector.selectorText selector = list(selector.seq) results.append((specificity, selector, style, text, href))