MOBI Output: Recognize type=text in addition to type=start guide elements

This commit is contained in:
Kovid Goyal 2012-03-28 10:40:21 +05:30
parent 962209439f
commit 164a116098
2 changed files with 11 additions and 7 deletions

View File

@ -161,8 +161,8 @@ class Serializer(object):
self.serialize_text(ref.title, quot=True) self.serialize_text(ref.title, quot=True)
buf.write(b'" ') buf.write(b'" ')
if (ref.title.lower() == 'start' or if (ref.title.lower() == 'start' or
(ref.type and ref.type.lower() in ('start', (ref.type and ref.type.lower() in {'start',
'other.start'))): 'other.start', 'text'})):
self._start_href = ref.href self._start_href = ref.href
self.serialize_href(ref.href) self.serialize_href(ref.href)
# Space required or won't work, I kid you not # Space required or won't work, I kid you not

View File

@ -8,10 +8,9 @@ __docformat__ = 'restructuredtext en'
class Clean(object): class Clean(object):
'''Clean up guide, leaving only a pointer to the cover''' '''Clean up guide, leaving only known values '''
def __call__(self, oeb, opts): def __call__(self, oeb, opts):
from calibre.ebooks.oeb.base import urldefrag
self.oeb, self.log, self.opts = oeb, oeb.log, opts self.oeb, self.log, self.opts = oeb, oeb.log, opts
if 'cover' not in self.oeb.guide: if 'cover' not in self.oeb.guide:
@ -32,10 +31,15 @@ class Clean(object):
ref.type = 'cover' ref.type = 'cover'
self.oeb.guide.refs['cover'] = ref self.oeb.guide.refs['cover'] = ref
if ('start' in self.oeb.guide and 'text' not in self.oeb.guide):
# Prefer text to start as per the OPF 2.0 spec
x = self.oeb.guide['start']
self.oeb.guide.add('text', x.title, x.href)
self.oeb.guide.remove('start')
for x in list(self.oeb.guide): for x in list(self.oeb.guide):
href = urldefrag(self.oeb.guide[x].href)[0] if x.lower() not in {'cover', 'titlepage', 'masthead', 'toc',
if x.lower() not in ('cover', 'titlepage', 'masthead', 'toc', 'title-page', 'copyright-page', 'text'}:
'title-page', 'copyright-page', 'start'):
item = self.oeb.guide[x] item = self.oeb.guide[x]
if item.title and item.title.lower() == 'start': if item.title and item.title.lower() == 'start':
continue continue