diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 0a10b79bd3..478fd121d0 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -434,6 +434,7 @@ from calibre.ebooks.rb.output import RBOutput from calibre.ebooks.rtf.output import RTFOutput from calibre.ebooks.tcr.output import TCROutput from calibre.ebooks.txt.output import TXTOutput +from calibre.ebooks.html.output import HTMLOutput from calibre.customize.profiles import input_profiles, output_profiles @@ -510,6 +511,7 @@ plugins += [ RTFOutput, TCROutput, TXTOutput, + HTMLOutput, ] # Order here matters. The first matched device is the one used. plugins += [ @@ -874,4 +876,3 @@ plugins += [LookAndFeel, Behavior, Columns, Toolbar, InputOptions, Email, Server, Plugins, Tweaks, Misc] #}}} - diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index e85098e293..9106fa3ab0 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1644,6 +1644,22 @@ class TOC(object): node.to_ncx(point) return parent + def to_xhtml(self, parent=None): + print parent.__class__ + if parent is None: + parent = etree.Element(XHTML('ul')) + elif len(self.nodes): + parent = element(parent, (XHTML('ul'))) + for node in self.nodes: + point = element(parent, XHTML('li')) + link = element(point, XHTML('a'), href=urlunquote(node.href)) + title = node.title + if title: + title = re.sub(r'\s+', ' ', title) + link.text=title + node.to_xhtml(point) + return parent + def rationalize_play_orders(self): ''' Ensure that all nodes with the same play_order have the same href and @@ -1962,3 +1978,14 @@ class OEBBook(object): spine.attrib['page-map'] = id results[PAGE_MAP_MIME] = (href, self.pages.to_page_map()) return results + + def html_toc(self): + lang = unicode(self.metadata.language[0]) + html = etree.Element(XHTML('html'), + attrib={XML('lang'): lang}, + nsmap={None: XHTML_NS}) + head = etree.SubElement(html, XHTML('head')) + title = etree.SubElement(head, XHTML('title')) + body = etree.SubElement(html, XHTML('body')) + body.append(self.toc.to_xhtml()) + return html diff --git a/src/calibre/ebooks/oeb/output.py b/src/calibre/ebooks/oeb/output.py index b1de3b97a1..585b56c7b6 100644 --- a/src/calibre/ebooks/oeb/output.py +++ b/src/calibre/ebooks/oeb/output.py @@ -49,5 +49,3 @@ class OEBOutput(OutputFormatPlugin): with open(path, 'wb') as f: f.write(str(item)) item.unload_data_from_memory(memory=path) - -