diff --git a/resources/templates/html_export_default.css b/resources/templates/html_export_default.css new file mode 100644 index 0000000000..0eec4f3e6b --- /dev/null +++ b/resources/templates/html_export_default.css @@ -0,0 +1,60 @@ +body{ + padding:0px; + margin:0px; + background-color:#F6F3E9; + font-size:12px; + font-family:Arial, Helvetica, sans-serif; +} + +.calibreMeta{ + background-color:#39322B; + color:white; + padding:10px; +} + +.calibreMeta a, .calibreEbNav a, .calibreEbNavTop a, .calibreToc a{ + color:white; +} + +.calibreMeta h1{ + margin:0px; + font-size:18px; + background-color:#39322B; +} + +.calibreEbookContent{ + padding:20px; +} + +.calibreEbNav, .calibreEbNavTop{ + clear:both; + background-color:#39322B; + color:white; + padding:10px; + text-align:center; +} + +.calibreEbNavTop{ + margin-bottom:20px; +} + +.calibreEbNav a, .calibreEbNavTop a{ + padding:0px 5px; +} + +.calibreTocIndex{ + line-height:18px; +} + +.calibreToc{ + float:left; + margin:20px; + width:300px; + background-color:#39322B; + color:white; + padding:10px; +} +.calibreEbookContent{ + width:600px; + float:left; +} diff --git a/resources/templates/html_export_default.tmpl b/resources/templates/html_export_default.tmpl index f15858e37a..c3ed921255 100644 --- a/resources/templates/html_export_default.tmpl +++ b/resources/templates/html_export_default.tmpl @@ -2,49 +2,73 @@ ${head_content}$ + + + -
-
+
+
${pos1=1}$ ${for title in meta.titles():}$ ${if pos1:}$ -

${print title}$

+

+ ${print title}$ +

${:else:}$ -
${print title}$
+
${print title}$
${:endif}$ ${pos1=0}$ ${:endfor}$
-
+
${print ', '.join(meta.creators())}$
-
-

${print _('Table of contents'),}$

- ${print toc()}$ -
+
-
+
+ ${if prevLink or nextLink:}$ +
+ ${if prevLink:}$ + ${print _('previous page'),}$ + ${:else:}$ + ${print _('previous page'),}$ + ${:endif}$ - ${ebookContent}$ - -
- ${if prevLink:}$ - ${print _('previous page'),}$ + ${if nextLink:}$ + ${print _('next page'),}$ + ${:endif}$ +
${:endif}$ + ${ebookContent}$ +
+ + ${if has_toc:}$ +
+

${print _('Table of contents'),}$

+ ${print toc()}$ +
+ ${:endif}$ + +
+ ${if prevLink:}$ + ${print _('previous page'),}$ + ${:else:}$ + ${print _('previous page'),}$ + ${:endif}$ + + ${print _('start'),}$ + ${if nextLink:}$ - ${print _('next page'),}$ + ${print _('next page'),}$ ${:endif}$
- - - diff --git a/resources/templates/html_export_default_index.tmpl b/resources/templates/html_export_default_index.tmpl index 6af97e1035..4a9e8ab6f3 100644 --- a/resources/templates/html_export_default_index.tmpl +++ b/resources/templates/html_export_default_index.tmpl @@ -6,37 +6,55 @@ - +${print ', '.join(meta.creators()),}$ - ${print meta.titles().next(); meta.titles().close()}$ + ${for item in meta:}$ ${:endfor}$ + -
-
+
+
${pos1=1}$ ${for title in meta.titles():}$ ${if pos1:}$ -

${print title}$

+

+ ${print title}$ +

${:else:}$ -
${print title}$
+
${print title}$
${:endif}$ ${pos1=0}$ ${:endfor}$
-
+
${print ', '.join(meta.creators()),}$
-

${print _('Table of contents'),}$

+
+
-
+ ${if has_toc:}$ +
+

${print _('Table of contents'),}$

+ ${toc}$ +
+ ${:else:}$ +

${print _('No table of contents present'),}$

+ + ${:endif}$ - ${toc}$ +
+
+ ${if nextLink:}$ + ${print _('next page'),}$ + ${:endif}$ +
diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index d76056ce14..287f4e6eb8 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -56,11 +56,6 @@ class HTMLOutput(OutputFormatPlugin): return etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=False) def convert(self, oeb_book, output_path, input_plugin, opts, log): - if oeb_book.toc.count() == 0: - if len(oeb_book.spine) > 1: - pass - else: - pass self.log = log self.opts = opts output_file = output_path @@ -69,12 +64,18 @@ class HTMLOutput(OutputFormatPlugin): if not exists(output_dir): os.makedirs(output_dir) + css_path = output_dir+os.sep+'calibreHtmlOutBasicCss.css' + with open(css_path, 'wb') as f: + f.write(P('templates/html_export_default.css', data=True)) + with open(output_file, 'wb') as f: link_prefix=basename(output_dir)+'/' html_toc = self.generate_html_toc(oeb_book, output_file, output_dir) templite = Templite(P('templates/html_export_default_index.tmpl', data=True)) - print oeb_book.metadata.items - t = templite.render(toc=html_toc, meta=meta) + nextLink = oeb_book.spine[0].href + nextLink = relpath(output_dir+os.sep+nextLink, dirname(output_file)) + cssLink = relpath(abspath(css_path), dirname(output_file)) + t = templite.render(has_toc=bool(oeb_book.toc.count()), toc=html_toc, meta=meta, nextLink=nextLink, tocUrl=output_file, cssLink=cssLink) f.write(t) with CurrentDir(output_dir): @@ -121,10 +122,12 @@ class HTMLOutput(OutputFormatPlugin): else: prevLink = None + cssLink = relpath(abspath(css_path), dir) + # render template 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, head_content=head_content, meta=meta) + t = templite.render(ebookContent=ebook_content, prevLink=prevLink, nextLink=nextLink, has_toc=bool(oeb_book.toc.count()), toc=toc, tocUrl=output_file, head_content=head_content, meta=meta, cssLink=cssLink) # write html to file with open(path, 'wb') as f: