mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
prev / next link working
This commit is contained in:
parent
4e61fb7c1f
commit
c23d7a1123
@ -42,21 +42,41 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
dir = os.path.dirname(path)
|
dir = os.path.dirname(path)
|
||||||
if not os.path.exists(dir):
|
if not os.path.exists(dir):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
if isinstance(item.data, etree._Element):
|
if item.spine_position is not None:
|
||||||
|
with open(path, 'wb') as f:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
with open(path, 'wb') as f:
|
||||||
|
f.write(str(item))
|
||||||
|
item.unload_data_from_memory(memory=path)
|
||||||
|
|
||||||
|
for item in oeb_book.spine:
|
||||||
|
path = os.path.abspath(unquote(item.href))
|
||||||
|
dir = os.path.dirname(path)
|
||||||
root = item.data.getroottree()
|
root = item.data.getroottree()
|
||||||
body = root.xpath('//h:body', namespaces={'h': 'http://www.w3.org/1999/xhtml'})[0]
|
body = root.xpath('//h:body', namespaces={'h': 'http://www.w3.org/1999/xhtml'})[0]
|
||||||
ebook_content = etree.tostring(body, pretty_print=True, encoding='utf-8')
|
ebook_content = etree.tostring(body, pretty_print=True, encoding='utf-8')
|
||||||
ebook_content = re.sub(r'\<\/?body.*\>', '', ebook_content)
|
ebook_content = re.sub(r'\<\/?body.*\>', '', ebook_content)
|
||||||
|
if item.spine_position+1 < len(oeb_book.spine):
|
||||||
|
nextLink = oeb_book.spine[item.spine_position+1].href
|
||||||
|
nextLink = os.path.abspath((nextLink))
|
||||||
|
nextLink = os.path.relpath(nextLink, dir)
|
||||||
|
else:
|
||||||
|
nextLink = None
|
||||||
|
if item.spine_position > 0:
|
||||||
|
prevLink = oeb_book.spine[item.spine_position-1].href
|
||||||
|
prevLink = os.path.abspath((prevLink))
|
||||||
|
prevLink = os.path.relpath(prevLink, dir)
|
||||||
|
else:
|
||||||
|
prevLink = None
|
||||||
vars = {
|
vars = {
|
||||||
'ebookContent': ebook_content,
|
'ebookContent': ebook_content,
|
||||||
'prevLink': None,
|
'prevLink': prevLink,
|
||||||
'nextLink': None
|
'nextLink': nextLink
|
||||||
}
|
}
|
||||||
template_file = os.path.dirname(__file__)+'/outputtemplates/default.tmpl'
|
template_file = os.path.dirname(__file__)+'/outputtemplates/default.tmpl'
|
||||||
t = Template(file=template_file, searchList=[ vars ]) # compilerSettings={'useStackFrames': False}
|
t = Template(file=template_file, searchList=[ vars ]) # compilerSettings={'useStackFrames': False}
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(str(t))
|
f.write(str(t))
|
||||||
else:
|
|
||||||
with open(path, 'wb') as f:
|
|
||||||
f.write(str(item))
|
|
||||||
item.unload_data_from_memory(memory=path)
|
item.unload_data_from_memory(memory=path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user