mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-29 05:06:22 +01:00
Fix regression that broke certain CSS selectors. Fixes #1068937 (Regression: CSS not interpreted correctly)
This commit is contained in:
parent
950a288d9a
commit
524e0119ed
2 changed files with 9 additions and 3 deletions
|
|
@ -125,6 +125,11 @@ def xpath_hash(self, id_selector):
|
|||
(id_selector.id.lower()))
|
||||
|
||||
ci_css_to_xpath = CaseInsensitiveAttributesTranslator().css_to_xpath
|
||||
NULL_NAMESPACE_REGEX = re.compile(ur'''name\(\) = ['"]h:''')
|
||||
def fix_namespace(raw):
|
||||
ans = NULL_NAMESPACE_REGEX.sub(lambda
|
||||
m:m.group().replace(u'h:', u''), raw)
|
||||
return ans
|
||||
|
||||
class CSSSelector(object):
|
||||
|
||||
|
|
@ -136,7 +141,7 @@ def __init__(self, css, log=None, namespaces=XPNSMAP):
|
|||
|
||||
def build_selector(self, css, log, func=css_to_xpath):
|
||||
try:
|
||||
return etree.XPath(func(css), namespaces=self.namespaces)
|
||||
return etree.XPath(fix_namespace(func(css)), namespaces=self.namespaces)
|
||||
except:
|
||||
if log is not None:
|
||||
log.exception('Failed to parse CSS selector: %r'%css)
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ def split_item(self, item):
|
|||
|
||||
def find_page_breaks(self, item):
|
||||
if self.page_break_selectors is None:
|
||||
from calibre.ebooks.oeb.stylizer import fix_namespace
|
||||
css_to_xpath = HTMLTranslator().css_to_xpath
|
||||
self.page_break_selectors = set([])
|
||||
stylesheets = [x.data for x in self.oeb.manifest if x.media_type in
|
||||
|
|
@ -84,7 +85,7 @@ def find_page_breaks(self, item):
|
|||
'page-break-after'), 'cssText', '').strip().lower()
|
||||
try:
|
||||
if before and before not in {'avoid', 'auto', 'inherit'}:
|
||||
self.page_break_selectors.add((XPath(css_to_xpath(rule.selectorText)),
|
||||
self.page_break_selectors.add((XPath(fix_namespace(css_to_xpath(rule.selectorText))),
|
||||
True))
|
||||
if self.remove_css_pagebreaks:
|
||||
rule.style.removeProperty('page-break-before')
|
||||
|
|
@ -92,7 +93,7 @@ def find_page_breaks(self, item):
|
|||
pass
|
||||
try:
|
||||
if after and after not in {'avoid', 'auto', 'inherit'}:
|
||||
self.page_break_selectors.add((XPath(css_to_xpath(rule.selectorText)),
|
||||
self.page_break_selectors.add((XPath(fix_namespace(css_to_xpath(rule.selectorText))),
|
||||
False))
|
||||
if self.remove_css_pagebreaks:
|
||||
rule.style.removeProperty('page-break-after')
|
||||
|
|
|
|||
Loading…
Reference in a new issue