Editor Live CSS: Dont fail totally if the stylesheet uses namespaced selectors

Fixes #1846538 [Private bug](https://bugs.launchpad.net/calibre/+bug/1846538)
This commit is contained in:
Kovid Goyal 2019-10-04 05:14:26 +05:30
parent a01e96d678
commit abe30ca2fb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -162,6 +162,22 @@ def get_sheet_rules(sheet):
return sheet.cssRules
def selector_matches(node, selector):
try:
return node.matches(selector)
except:
# happens if the selector uses epub|type
if 'epub|' in selector:
sanitized_sel = str.replace(selector, 'epub|', '*|')
try:
# TODO: Actually parse the selector and extract the attribute
# and check it manually
return node.matches(sanitized_sel)
except:
return False
return False
def process_rules(node, rules, address, sheet, sheet_index, all_properties, node_style, is_ancestor, ans):
for rule_index in range(rules.length):
rule = rules[rule_index]
@ -172,7 +188,7 @@ def process_rules(node, rules, address, sheet, sheet_index, all_properties, node
if rule.type is not CSSRule.STYLE_RULE:
continue
st = rule.selectorText
if not node.matches(st):
if not selector_matches(node, st):
continue
type = 'sheet'
href = sheet.href
@ -184,7 +200,7 @@ def process_rules(node, rules, address, sheet, sheet_index, all_properties, node
parts = st.split(',')
if parts.length > 1:
for q in parts:
if node.matches(q):
if selector_matches(node, q):
st = q
break
properties = get_style_properties(rule.style, all_properties, node_style, is_ancestor)