Make the template used to create empty EPUB files customizable by the user

This commit is contained in:
Kovid Goyal 2014-09-04 10:46:11 +05:30
parent d724fbcffb
commit 2faac51ceb
2 changed files with 20 additions and 13 deletions

View File

@ -0,0 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<html lang="_LANGUAGE_" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>_TITLE_</title>
</head>
<body>
<h1>_TITLE_</h1>
</body>
</html>

View File

@ -13,6 +13,7 @@ from lxml import etree
from calibre import prepare_string_for_xml, CurrentDir
from calibre.ptempfile import TemporaryDirectory
from calibre.ebooks.oeb.base import serialize
from calibre.ebooks.metadata import authors_to_string
from calibre.ebooks.metadata.opf2 import metadata_to_opf
from calibre.ebooks.oeb.polish.parsing import parse
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES, opf_to_azw3, Container
@ -63,19 +64,13 @@ def create_book(mi, path, fmt='epub', opf_name='metadata.opf', html_name='start.
</rootfiles>
</container>
'''.format(prepare_string_for_xml(opf_name, True)).encode('utf-8')
HTML = '''\
<?xml version='1.0' encoding='utf-8'?>
<html lang="{1}" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{0}</title>
</head>
<body>
<h1>{0}</h1>
</body>
</html>
'''.format(prepare_string_for_xml(mi.title), lang).encode('utf-8')
HTML = P('templates/new_book.html', data=True).decode('utf-8').replace(
'_LANGUAGE_', prepare_string_for_xml(lang, True)
).replace(
'_TITLE_', prepare_string_for_xml(mi.title)
).replace(
'_AUTHORS_', prepare_string_for_xml(authors_to_string(mi.authors))
).encode('utf-8')
h = parse(HTML)
pretty_html_tree(None, h)
HTML = serialize(h, 'text/html')