ability to insert table of contents in each file

This commit is contained in:
Fabian Graßl 2010-10-08 12:32:25 +02:00
parent 62dae4bfc3
commit 6dafb63202
2 changed files with 11 additions and 3 deletions

View File

@ -6,6 +6,10 @@
</head> </head>
<body> <body>
<div class="toc">
Table of contents
${print toc()}$
</div>
${ebookContent}$ ${ebookContent}$
${if prevLink:}$ ${if prevLink:}$

View File

@ -46,6 +46,10 @@ class HTMLOutput(OutputFormatPlugin):
wrap.append(build_node(oeb_book.toc)) wrap.append(build_node(oeb_book.toc))
return wrap return wrap
def generate_html_toc(self, oeb_book, ref_url, output_dir):
root = self.generate_toc(oeb_book, ref_url, output_dir)
return etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
def convert(self, oeb_book, output_path, input_plugin, opts, log): def convert(self, oeb_book, output_path, input_plugin, opts, log):
self.log = log self.log = log
self.opts = opts self.opts = opts
@ -56,8 +60,7 @@ class HTMLOutput(OutputFormatPlugin):
with open(output_file, 'wb') as f: with open(output_file, 'wb') as f:
link_prefix=basename(output_dir)+'/' link_prefix=basename(output_dir)+'/'
root = self.generate_toc(oeb_book, output_dir, output_dir) html_toc = self.generate_html_toc(oeb_book, output_file, output_dir)
html_toc = etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False)
templite = Templite(P('templates/html_export_default_index.tmpl', data=True)) templite = Templite(P('templates/html_export_default_index.tmpl', data=True))
t = templite.render(toc=html_toc) t = templite.render(toc=html_toc)
f.write(t) f.write(t)
@ -94,7 +97,8 @@ class HTMLOutput(OutputFormatPlugin):
else: else:
prevLink = None prevLink = None
templite = Templite(P('templates/html_export_default.tmpl', data=True)) templite = Templite(P('templates/html_export_default.tmpl', data=True))
t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink) toc = lambda: self.generate_html_toc(oeb_book, path, output_dir)
t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, toc=toc)
with open(path, 'wb') as f: with open(path, 'wb') as f:
f.write(t) f.write(t)
item.unload_data_from_memory(memory=path) item.unload_data_from_memory(memory=path)