Force pretty printing of output when outputting to OEB or EPUB. Fix #2777 (ToC incorrect in MS Reader to ePub)

This commit is contained in:
Kovid Goyal 2009-07-07 12:01:20 -06:00
parent d57e1d98c3
commit e0d515874b
4 changed files with 28 additions and 3 deletions

View File

@ -80,6 +80,8 @@ class EPUBOutput(OutputFormatPlugin):
])
recommendations = set([('pretty_print', True, OptionRecommendation.HIGH)])
TITLEPAGE_COVER = '''\
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

View File

@ -367,7 +367,7 @@ class MetaInformation(object):
if self.pubdate is not None:
ans += [(_('Published'), unicode(self.pubdate.isoformat(' ')))]
if self.rights is not None:
ans += [(_('Rights'), unicode(self.rights.isoformat(' ')))]
ans += [(_('Rights'), unicode(self.rights))]
for i, x in enumerate(ans):
ans[i] = u'<tr><td><b>%s</b></td><td>%s</td></tr>'%x
return u'<table>%s</table>'%u'\n'.join(ans)

View File

@ -9,6 +9,8 @@ from lxml import etree
from calibre.customize.conversion import OutputFormatPlugin
from calibre import CurrentDir
from calibre.customize.conversion import OptionRecommendation
from urllib import unquote
class OEBOutput(OutputFormatPlugin):
@ -17,6 +19,9 @@ class OEBOutput(OutputFormatPlugin):
author = 'Kovid Goyal'
file_type = 'oeb'
recommendations = set([('pretty_print', True, OptionRecommendation.HIGH)])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
self.log, self.opts = log, opts
if not os.path.exists(output_path):

View File

@ -16,7 +16,7 @@ from lxml import etree
from lxml.cssselect import CSSSelector
from calibre.ebooks.oeb.base import OEB_STYLES, XPNSMAP as NAMESPACES, \
urldefrag, rewrite_links, urlunquote, barename
urldefrag, rewrite_links, urlunquote, barename, XHTML
from calibre.ebooks.epub import rules
XPath = functools.partial(_XPath, namespaces=NAMESPACES)
@ -216,7 +216,25 @@ class FlowSplitter(object):
self.trees.append(before)
tree = after
self.trees.append(tree)
self.trees = [t for t in self.trees if not self.is_page_empty(t.getroot())]
trees, ids = [], set([])
for tree in self.trees:
root = tree.getroot()
if self.is_page_empty(root):
discarded_ids = root.xpath('//*[@id]')
for x in discarded_ids:
x = x.get('id')
if not x.startswith('calibre_'):
ids.add(x)
else:
if ids:
body = self.get_body(root)
if body is not None:
for x in ids:
body.insert(0, body.makeelement(XHTML('div'),
id=x, style='height:0pt'))
ids = set([])
trees.append(tree)
self.trees = trees
def get_body(self, root):
body = root.xpath('//h:body', namespaces=NAMESPACES)