From 06e856bf617aae6840c6f4293d9b448dd8e7d5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gra=C3=9Fl?= Date: Fri, 8 Oct 2010 15:47:58 +0200 Subject: [PATCH] html head in template --- resources/templates/html_export_default.tmpl | 4 ++-- src/calibre/ebooks/html/output.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/templates/html_export_default.tmpl b/resources/templates/html_export_default.tmpl index 81c36c631a..4fa20d8662 100644 --- a/resources/templates/html_export_default.tmpl +++ b/resources/templates/html_export_default.tmpl @@ -1,8 +1,7 @@ - - +${head_content}$ @@ -10,6 +9,7 @@ Table of contents ${print toc()}$ + ${ebookContent}$ ${if prevLink:}$ diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index ff76570515..b4a2a88e1c 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -83,6 +83,11 @@ class HTMLOutput(OutputFormatPlugin): path = abspath(unquote(item.href)) dir = dirname(path) root = item.data.getroottree() + head = root.xpath('//h:head', namespaces={'h': 'http://www.w3.org/1999/xhtml'})[0] + head_content = etree.tostring(head, pretty_print=True, encoding='utf-8') + head_content = re.sub(r'\<\/?head.*\>', '', head_content) + head_content = re.sub(re.compile(r'\', re.M|re.S), '', head_content) + 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 = re.sub(r'\<\/?body.*\>', '', ebook_content) @@ -98,7 +103,7 @@ class HTMLOutput(OutputFormatPlugin): prevLink = None templite = Templite(P('templates/html_export_default.tmpl', data=True)) toc = lambda: self.generate_html_toc(oeb_book, path, output_dir) - t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, toc=toc) + t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, toc=toc, head_content=head_content) with open(path, 'wb') as f: f.write(t) item.unload_data_from_memory(memory=path)