mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Refactor method to make it more widely useable
This commit is contained in:
parent
16870db206
commit
60c1948130
@ -205,3 +205,14 @@ def apply_func_to_html_text(match, func=icu_upper, handle_entities=handle_entiti
|
||||
parts = (x if x.startswith('<') else f(x) for x in parts)
|
||||
return ''.join(parts)
|
||||
|
||||
def extract(elem):
|
||||
''' Remove an element from the tree, keeping elem.tail '''
|
||||
p = elem.getparent()
|
||||
if p is not None:
|
||||
idx = p.index(elem)
|
||||
p.remove(elem)
|
||||
if elem.tail:
|
||||
if idx > 0:
|
||||
p[idx-1].tail = (p[idx-1].tail or '') + elem.tail
|
||||
else:
|
||||
p.text = (p.text or '') + elem.tail
|
||||
|
@ -24,6 +24,7 @@ from calibre.ebooks.oeb.iterator.book import extract_book
|
||||
from calibre.ebooks.oeb.polish.container import Container as ContainerBase
|
||||
from calibre.ebooks.oeb.polish.cover import set_epub_cover, find_cover_image
|
||||
from calibre.ebooks.oeb.polish.css import transform_css
|
||||
from calibre.ebooks.oeb.polish.utils import extract
|
||||
from calibre.ebooks.css_transform_rules import StyleDeclaration
|
||||
from calibre.ebooks.oeb.polish.toc import get_toc
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
@ -96,17 +97,6 @@ def check_for_maths(root):
|
||||
return True
|
||||
return False
|
||||
|
||||
def extract(elem):
|
||||
p = elem.getparent()
|
||||
if p is not None:
|
||||
idx = p.index(elem)
|
||||
p.remove(elem)
|
||||
if elem.tail:
|
||||
if idx > 0:
|
||||
p[idx-1].tail = (p[idx-1].tail or '') + elem.tail
|
||||
else:
|
||||
p.text = (p.text or '') + elem.tail
|
||||
|
||||
def has_ancestor(elem, q):
|
||||
while elem is not None:
|
||||
elem = elem.getparent()
|
||||
|
Loading…
x
Reference in New Issue
Block a user