mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
295441d9b2
commit
c31de00dcd
@ -257,7 +257,7 @@ class Stylizer(object):
|
|||||||
index = 0
|
index = 0
|
||||||
self.stylesheets = set()
|
self.stylesheets = set()
|
||||||
self.page_rule = {}
|
self.page_rule = {}
|
||||||
for stylesheet in stylesheets:
|
for sheet_index, stylesheet in enumerate(stylesheets):
|
||||||
href = stylesheet.href
|
href = stylesheet.href
|
||||||
self.stylesheets.add(href)
|
self.stylesheets.add(href)
|
||||||
for rule in stylesheet.cssRules:
|
for rule in stylesheet.cssRules:
|
||||||
@ -267,10 +267,10 @@ class Stylizer(object):
|
|||||||
if not media.intersection({'all', 'screen', 'amzn-kf8'}):
|
if not media.intersection({'all', 'screen', 'amzn-kf8'}):
|
||||||
continue
|
continue
|
||||||
for subrule in rule.cssRules:
|
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
|
index += 1
|
||||||
else:
|
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
|
index = index + 1
|
||||||
rules.sort()
|
rules.sort()
|
||||||
self.rules = rules
|
self.rules = rules
|
||||||
@ -351,12 +351,13 @@ class Stylizer(object):
|
|||||||
data = item.data.cssText
|
data = item.data.cssText
|
||||||
return ('utf-8', data)
|
return ('utf-8', data)
|
||||||
|
|
||||||
def flatten_rule(self, rule, href, index):
|
def flatten_rule(self, rule, href, index, is_user_agent_sheet=False):
|
||||||
results = []
|
results = []
|
||||||
|
sheet_index = 0 if is_user_agent_sheet else 1
|
||||||
if isinstance(rule, CSSStyleRule):
|
if isinstance(rule, CSSStyleRule):
|
||||||
style = self.flatten_style(rule.style)
|
style = self.flatten_style(rule.style)
|
||||||
for selector in rule.selectorList:
|
for selector in rule.selectorList:
|
||||||
specificity = selector.specificity + (index,)
|
specificity = (sheet_index,) + selector.specificity + (index,)
|
||||||
text = selector.selectorText
|
text = selector.selectorText
|
||||||
selector = list(selector.seq)
|
selector = list(selector.seq)
|
||||||
results.append((specificity, selector, style, text, href))
|
results.append((specificity, selector, style, text, href))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user