mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
a01e96d678
commit
abe30ca2fb
@ -162,6 +162,22 @@ def get_sheet_rules(sheet):
|
|||||||
return sheet.cssRules
|
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):
|
def process_rules(node, rules, address, sheet, sheet_index, all_properties, node_style, is_ancestor, ans):
|
||||||
for rule_index in range(rules.length):
|
for rule_index in range(rules.length):
|
||||||
rule = rules[rule_index]
|
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:
|
if rule.type is not CSSRule.STYLE_RULE:
|
||||||
continue
|
continue
|
||||||
st = rule.selectorText
|
st = rule.selectorText
|
||||||
if not node.matches(st):
|
if not selector_matches(node, st):
|
||||||
continue
|
continue
|
||||||
type = 'sheet'
|
type = 'sheet'
|
||||||
href = sheet.href
|
href = sheet.href
|
||||||
@ -184,7 +200,7 @@ def process_rules(node, rules, address, sheet, sheet_index, all_properties, node
|
|||||||
parts = st.split(',')
|
parts = st.split(',')
|
||||||
if parts.length > 1:
|
if parts.length > 1:
|
||||||
for q in parts:
|
for q in parts:
|
||||||
if node.matches(q):
|
if selector_matches(node, q):
|
||||||
st = q
|
st = q
|
||||||
break
|
break
|
||||||
properties = get_style_properties(rule.style, all_properties, node_style, is_ancestor)
|
properties = get_style_properties(rule.style, all_properties, node_style, is_ancestor)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user