From 2faac51cebf54662c4a1cde746990a9ecca6615b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 4 Sep 2014 10:46:11 +0530 Subject: [PATCH] Make the template used to create empty EPUB files customizable by the user --- resources/templates/new_book.html | 12 ++++++++++++ src/calibre/ebooks/oeb/polish/create.py | 21 ++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 resources/templates/new_book.html diff --git a/resources/templates/new_book.html b/resources/templates/new_book.html new file mode 100644 index 0000000000..bb765addea --- /dev/null +++ b/resources/templates/new_book.html @@ -0,0 +1,12 @@ + + + + + _TITLE_ + + + +

_TITLE_

+ + + diff --git a/src/calibre/ebooks/oeb/polish/create.py b/src/calibre/ebooks/oeb/polish/create.py index 81993c7940..f6b01edd40 100644 --- a/src/calibre/ebooks/oeb/polish/create.py +++ b/src/calibre/ebooks/oeb/polish/create.py @@ -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. '''.format(prepare_string_for_xml(opf_name, True)).encode('utf-8') - HTML = '''\ - - - - - {0} - - - -

{0}

- - - '''.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')