html output first version

This commit is contained in:
Fabian Graßl 2010-10-04 15:21:25 +02:00
parent 735b22b934
commit 5451c38d5d
3 changed files with 29 additions and 3 deletions

View File

@ -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]
#}}}

View File

@ -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

View File

@ -49,5 +49,3 @@ class OEBOutput(OutputFormatPlugin):
with open(path, 'wb') as f:
f.write(str(item))
item.unload_data_from_memory(memory=path)