mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MOBI Output: Make generating the navpoints for chapter to chapter skipping more robust. Also geenrate navpoints for every item in the TOC, not just the items at the deepest level.
This commit is contained in:
parent
7c3aaf5864
commit
d72b9ff142
@ -50,6 +50,13 @@ class MOBIOutput(OutputFormatPlugin):
|
||||
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
||||
'book instead of the end. Not recommended.')
|
||||
),
|
||||
OptionRecommendation(name='mobi_navpoints_only_deepest',
|
||||
recommended_value=False,
|
||||
help=_('When adding navpoints for the chapter-to-chapter'
|
||||
' navigation on the kindle, use only the lowest level '
|
||||
'of items in the TOC, instead of items at every level.')
|
||||
),
|
||||
|
||||
OptionRecommendation(name='kindlegen',
|
||||
recommended_value=False,
|
||||
help=('Use kindlegen (must be in your PATH) to generate the'
|
||||
|
@ -1231,6 +1231,9 @@ class MobiWriter(object):
|
||||
self._oeb.logger.info(' Compressing markup content...')
|
||||
data, overlap = self._read_text_record(text)
|
||||
|
||||
if not self.opts.mobi_periodical:
|
||||
self._flatten_toc()
|
||||
|
||||
# Evaluate toc for conformance
|
||||
if self.opts.mobi_periodical :
|
||||
self._oeb.logger.info(' MOBI periodical specified, evaluating TOC for periodical conformance ...')
|
||||
@ -1697,6 +1700,32 @@ class MobiWriter(object):
|
||||
|
||||
# Index {{{
|
||||
|
||||
def _flatten_toc(self):
|
||||
'''
|
||||
Flatten and re-order entries in TOC so that chapter to chapter jumping
|
||||
never fails on the Kindle.
|
||||
'''
|
||||
from calibre.ebooks.oeb.base import TOC
|
||||
items = list(self._oeb.toc.iterdescendants())
|
||||
if self.opts.mobi_navpoints_only_deepest:
|
||||
items = [i for i in items if i.depth == 1]
|
||||
offsets = {i:self._id_offsets.get(i.href, -1) for i in items if i.href}
|
||||
items = [i for i in items if offsets[i] > -1]
|
||||
items.sort(key=lambda i:offsets[i])
|
||||
filt = []
|
||||
seen = set()
|
||||
for i in items:
|
||||
off = offsets[i]
|
||||
if off in seen: continue
|
||||
seen.add(off)
|
||||
filt.append(i)
|
||||
items = filt
|
||||
newtoc = TOC()
|
||||
for c, i in enumerate(items):
|
||||
newtoc.add(i.title, i.href, play_order=c+1, id=str(c),
|
||||
klass='chapter')
|
||||
self._oeb.toc = newtoc
|
||||
|
||||
def _generate_index(self):
|
||||
self._oeb.log('Generating INDX ...')
|
||||
self._primary_index_record = None
|
||||
|
@ -25,7 +25,8 @@ class PluginWidget(Widget, Ui_Form):
|
||||
Widget.__init__(self, parent,
|
||||
['prefer_author_sort', 'rescale_images', 'toc_title',
|
||||
'mobi_ignore_margins', 'mobi_toc_at_start',
|
||||
'dont_compress', 'no_inline_toc', 'masthead_font','personal_doc']
|
||||
'dont_compress', 'no_inline_toc',
|
||||
'masthead_font','personal_doc', 'mobi_navpoints_only_deepest']
|
||||
)
|
||||
from calibre.utils.fonts import fontconfig
|
||||
self.db, self.book_id = db, book_id
|
||||
|
@ -55,7 +55,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<item row="9" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Kindle options</string>
|
||||
@ -101,7 +101,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<item row="10" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -128,6 +128,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_mobi_navpoints_only_deepest">
|
||||
<property name="text">
|
||||
<string>Use only &lowest level of items in the TOC for chapter-to-chapter navigation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user