mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Faster implementation of namespace hack
This commit is contained in:
parent
524e0119ed
commit
ade7c9280a
@ -125,11 +125,17 @@ class CaseInsensitiveAttributesTranslator(HTMLTranslator):
|
||||
(id_selector.id.lower()))
|
||||
|
||||
ci_css_to_xpath = CaseInsensitiveAttributesTranslator().css_to_xpath
|
||||
NULL_NAMESPACE_REGEX = re.compile(ur'''name\(\) = ['"]h:''')
|
||||
|
||||
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
|
||||
'''
|
||||
cssselect uses name() = 'h:p' to select tags for some CSS selectors (e.g.
|
||||
h|p+h|p).
|
||||
However, since for us the XHTML namespace is the default namespace (with no
|
||||
prefix), name() is the same as local-name(). So this is a hack to
|
||||
workaround the problem.
|
||||
'''
|
||||
return NULL_NAMESPACE_REGEX.sub(ur'\1', raw)
|
||||
|
||||
class CSSSelector(object):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user