mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
html head in template
This commit is contained in:
parent
e90af71b77
commit
06e856bf61
@ -1,8 +1,7 @@
|
||||
<!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">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title></title>
|
||||
${head_content}$
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -10,6 +9,7 @@
|
||||
Table of contents
|
||||
${print toc()}$
|
||||
</div>
|
||||
|
||||
${ebookContent}$
|
||||
|
||||
${if prevLink:}$
|
||||
|
@ -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'\<style.*\/style\>', 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user