html head in template

This commit is contained in:
Fabian Graßl 2010-10-08 15:47:58 +02:00
parent e90af71b77
commit 06e856bf61
2 changed files with 8 additions and 3 deletions

View File

@ -1,8 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> ${head_content}$
<title></title>
</head> </head>
<body> <body>
@ -10,6 +9,7 @@
Table of contents Table of contents
${print toc()}$ ${print toc()}$
</div> </div>
${ebookContent}$ ${ebookContent}$
${if prevLink:}$ ${if prevLink:}$

View File

@ -83,6 +83,11 @@ class HTMLOutput(OutputFormatPlugin):
path = abspath(unquote(item.href)) path = abspath(unquote(item.href))
dir = dirname(path) dir = dirname(path)
root = item.data.getroottree() 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'\<style.*\/style\>', re.M|re.S), '', head_content)
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)
@ -98,7 +103,7 @@ class HTMLOutput(OutputFormatPlugin):
prevLink = None prevLink = None
templite = Templite(P('templates/html_export_default.tmpl', data=True)) templite = Templite(P('templates/html_export_default.tmpl', data=True))
toc = lambda: self.generate_html_toc(oeb_book, path, output_dir) 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: 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)