mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
MOBI Output: Add an option to place the automatically generated TOC at the start of the book. It is highly recommended that this option not be used, unless you know what you are doing. See http://manual.calibre-ebook.com/faq.html#what-s-the-deal-with-table-of-contents-in-mobi-files
This commit is contained in:
parent
27a482d329
commit
e43cb7da48
@ -27,7 +27,7 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
),
|
),
|
||||||
OptionRecommendation(name='no_inline_toc',
|
OptionRecommendation(name='no_inline_toc',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Don\'t add Table of Contents to end of book. Useful if '
|
help=_('Don\'t add Table of Contents to the book. Useful if '
|
||||||
'the book has its own table of contents.')),
|
'the book has its own table of contents.')),
|
||||||
OptionRecommendation(name='toc_title', recommended_value=None,
|
OptionRecommendation(name='toc_title', recommended_value=None,
|
||||||
help=_('Title for any generated in-line table of contents.')
|
help=_('Title for any generated in-line table of contents.')
|
||||||
@ -45,6 +45,12 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
'the MOBI output plugin will try to convert margins specified'
|
'the MOBI output plugin will try to convert margins specified'
|
||||||
' in the input document, otherwise it will ignore them.')
|
' in the input document, otherwise it will ignore them.')
|
||||||
),
|
),
|
||||||
|
OptionRecommendation(name='mobi_toc_at_start',
|
||||||
|
recommended_value=False,
|
||||||
|
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
||||||
|
'book instead of the end. Not recommended.')
|
||||||
|
),
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
def check_for_periodical(self):
|
def check_for_periodical(self):
|
||||||
@ -167,7 +173,8 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
from calibre.customize.ui import plugin_for_input_format
|
from calibre.customize.ui import plugin_for_input_format
|
||||||
imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None
|
imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None
|
||||||
if not opts.no_inline_toc:
|
if not opts.no_inline_toc:
|
||||||
tocadder = HTMLTOCAdder(title=opts.toc_title)
|
tocadder = HTMLTOCAdder(title=opts.toc_title, position='start' if
|
||||||
|
opts.mobi_toc_at_start else 'end')
|
||||||
tocadder(oeb, opts)
|
tocadder(oeb, opts)
|
||||||
mangler = CaseMangler()
|
mangler = CaseMangler()
|
||||||
mangler(oeb, opts)
|
mangler(oeb, opts)
|
||||||
|
@ -45,9 +45,10 @@ body > .calibre_toc_block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HTMLTOCAdder(object):
|
class HTMLTOCAdder(object):
|
||||||
def __init__(self, title=None, style='nested'):
|
def __init__(self, title=None, style='nested', position='end'):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.style = style
|
self.style = style
|
||||||
|
self.position = position
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def config(cls, cfg):
|
def config(cls, cfg):
|
||||||
@ -98,7 +99,10 @@ class HTMLTOCAdder(object):
|
|||||||
self.add_toc_level(body, oeb.toc)
|
self.add_toc_level(body, oeb.toc)
|
||||||
id, href = oeb.manifest.generate('contents', 'contents.xhtml')
|
id, href = oeb.manifest.generate('contents', 'contents.xhtml')
|
||||||
item = oeb.manifest.add(id, href, XHTML_MIME, data=contents)
|
item = oeb.manifest.add(id, href, XHTML_MIME, data=contents)
|
||||||
oeb.spine.add(item, linear=False)
|
if self.position == 'end':
|
||||||
|
oeb.spine.add(item, linear=False)
|
||||||
|
else:
|
||||||
|
oeb.spine.insert(0, item, linear=True)
|
||||||
oeb.guide.add('toc', 'Table of Contents', href)
|
oeb.guide.add('toc', 'Table of Contents', href)
|
||||||
|
|
||||||
def add_toc_level(self, elem, toc):
|
def add_toc_level(self, elem, toc):
|
||||||
|
@ -24,7 +24,7 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent,
|
Widget.__init__(self, parent,
|
||||||
['prefer_author_sort', 'rescale_images', 'toc_title',
|
['prefer_author_sort', 'rescale_images', 'toc_title',
|
||||||
'mobi_ignore_margins',
|
'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']
|
||||||
)
|
)
|
||||||
from calibre.utils.fonts import fontconfig
|
from calibre.utils.fonts import fontconfig
|
||||||
|
@ -27,21 +27,21 @@
|
|||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="opt_toc_title"/>
|
<widget class="QLineEdit" name="opt_toc_title"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="4" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_rescale_images">
|
<widget class="QCheckBox" name="opt_rescale_images">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Rescale images for &Palm devices</string>
|
<string>Rescale images for &Palm devices</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="2">
|
<item row="5" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_prefer_author_sort">
|
<widget class="QCheckBox" name="opt_prefer_author_sort">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Use author &sort for author</string>
|
<string>Use author &sort for author</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QCheckBox" name="opt_dont_compress">
|
<widget class="QCheckBox" name="opt_dont_compress">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Disable compression of the file contents</string>
|
<string>Disable compression of the file contents</string>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="8" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Kindle options</string>
|
<string>Kindle options</string>
|
||||||
@ -101,7 +101,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="9" column="0">
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -114,7 +114,14 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="opt_mobi_toc_at_start">
|
||||||
|
<property name="text">
|
||||||
|
<string>Put generated Table of Contents at &start of book instead of end</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
<widget class="QCheckBox" name="opt_mobi_ignore_margins">
|
<widget class="QCheckBox" name="opt_mobi_ignore_margins">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Ignore &margins</string>
|
<string>Ignore &margins</string>
|
||||||
|
@ -61,7 +61,7 @@ In the MOBI format, the situation is a little confused. This is because the MOBI
|
|||||||
|
|
||||||
Now it might well seem to you that the MOBI book has two identical TOCs. Remember that one is semantically a content TOC and the other is a metadata TOC, even though both might have exactly the same entries and look the same. One can be accessed directly from the Kindle's menus, the other cannot.
|
Now it might well seem to you that the MOBI book has two identical TOCs. Remember that one is semantically a content TOC and the other is a metadata TOC, even though both might have exactly the same entries and look the same. One can be accessed directly from the Kindle's menus, the other cannot.
|
||||||
|
|
||||||
When converting to MOBI, calibre detects the *metadata TOC* in the input document and generates an end-of-file TOC in the output MOBI file. You can turn this off by an option in the MOBI Output settings. You cannot control where this generated TOC will go. Remember this TOC is semantically a *metadata TOC*, in any format other than MOBI it *cannot not be part of the text*. The fact that it is part of the text in MOBI is an accident caused by the limitations of MOBI. If you want a TOC at a particular location in your document text, create one by hand.
|
When converting to MOBI, calibre detects the *metadata TOC* in the input document and generates an end-of-file TOC in the output MOBI file. You can turn this off by an option in the MOBI Output settings. You can also tell calibre whether to put it and the start or the end of the book via an option in the MOBI Output settings. Remember this TOC is semantically a *metadata TOC*, in any format other than MOBI it *cannot not be part of the text*. The fact that it is part of the text in MOBI is an accident caused by the limitations of MOBI. If you want a TOC at a particular location in your document text, create one by hand. So we strongly recommend that you leave the default as it is, i.e. with the metadata TOC at the end of the book.
|
||||||
|
|
||||||
If you have a hand edited TOC in the input document, you can use the TOC detection options in calibre to automatically generate the metadata TOC from it. See the conversion section of the User Manual for more details on how to use these options.
|
If you have a hand edited TOC in the input document, you can use the TOC detection options in calibre to automatically generate the metadata TOC from it. See the conversion section of the User Manual for more details on how to use these options.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user