mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion pipeline: Add option to control if duplicate entries are allowed when generating the Table of Contents from links. Fixes #806095 ([Enhancement] Preserve duplicate chapter names in TOC)
This commit is contained in:
parent
6f73a2982b
commit
1acc8f0c73
@ -176,7 +176,7 @@ def add_pipeline_options(parser, plumber):
|
|||||||
[
|
[
|
||||||
'level1_toc', 'level2_toc', 'level3_toc',
|
'level1_toc', 'level2_toc', 'level3_toc',
|
||||||
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
|
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
|
||||||
'use_auto_toc', 'toc_filter',
|
'use_auto_toc', 'toc_filter', 'duplicate_links_in_toc',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -265,6 +265,14 @@ OptionRecommendation(name='toc_filter',
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
OptionRecommendation(name='duplicate_links_in_toc',
|
||||||
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
|
help=_('When creating a TOC from links in the input document, '
|
||||||
|
'allow duplicate entries, i.e. allow more than one entry '
|
||||||
|
'with the same text, provided that they point to a '
|
||||||
|
'different location.')
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
OptionRecommendation(name='chapter',
|
OptionRecommendation(name='chapter',
|
||||||
recommended_value="//*[((name()='h1' or name()='h2') and "
|
recommended_value="//*[((name()='h1' or name()='h2') and "
|
||||||
|
@ -121,7 +121,9 @@ class DetectStructure(object):
|
|||||||
if not self.oeb.toc.has_href(href):
|
if not self.oeb.toc.has_href(href):
|
||||||
text = xml2text(a)
|
text = xml2text(a)
|
||||||
text = text[:100].strip()
|
text = text[:100].strip()
|
||||||
if not self.oeb.toc.has_text(text):
|
if (not self.opts.duplicate_links_in_toc and
|
||||||
|
self.oeb.toc.has_text(text)):
|
||||||
|
continue
|
||||||
num += 1
|
num += 1
|
||||||
self.oeb.toc.add(text, href,
|
self.oeb.toc.add(text, href,
|
||||||
play_order=self.oeb.toc.next_play_order())
|
play_order=self.oeb.toc.next_play_order())
|
||||||
|
@ -22,7 +22,7 @@ class TOCWidget(Widget, Ui_Form):
|
|||||||
Widget.__init__(self, parent,
|
Widget.__init__(self, parent,
|
||||||
['level1_toc', 'level2_toc', 'level3_toc',
|
['level1_toc', 'level2_toc', 'level3_toc',
|
||||||
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
|
'toc_threshold', 'max_toc_links', 'no_chapters_in_toc',
|
||||||
'use_auto_toc', 'toc_filter',
|
'use_auto_toc', 'toc_filter', 'duplicate_links_in_toc',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_10">
|
<widget class="QLabel" name="label_10">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Number of &links to add to Table of Contents</string>
|
<string>Number of &links to add to Table of Contents</string>
|
||||||
@ -31,14 +31,14 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QSpinBox" name="opt_max_toc_links">
|
<widget class="QSpinBox" name="opt_max_toc_links">
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>10000</number>
|
<number>10000</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="label_16">
|
<widget class="QLabel" name="label_16">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Chapter &threshold</string>
|
<string>Chapter &threshold</string>
|
||||||
@ -48,7 +48,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QSpinBox" name="opt_toc_threshold"/>
|
<widget class="QSpinBox" name="opt_toc_threshold"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
@ -58,7 +58,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>TOC &Filter:</string>
|
<string>TOC &Filter:</string>
|
||||||
@ -68,19 +68,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QLineEdit" name="opt_toc_filter"/>
|
<widget class="QLineEdit" name="opt_toc_filter"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0" colspan="2">
|
<item row="6" column="0" colspan="2">
|
||||||
<widget class="XPathEdit" name="opt_level1_toc" native="true"/>
|
<widget class="XPathEdit" name="opt_level1_toc" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="7" column="0" colspan="2">
|
||||||
<widget class="XPathEdit" name="opt_level2_toc" native="true"/>
|
<widget class="XPathEdit" name="opt_level2_toc" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0" colspan="2">
|
<item row="8" column="0" colspan="2">
|
||||||
<widget class="XPathEdit" name="opt_level3_toc" native="true"/>
|
<widget class="XPathEdit" name="opt_level3_toc" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="9" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -93,6 +93,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="opt_duplicate_links_in_toc">
|
||||||
|
<property name="text">
|
||||||
|
<string>Allow &duplicate links when creating the Table of Contents</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user