mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-29 23:53:08 +02:00
Add support for auto generating the TOC based on detected chapters
This commit is contained in:
commit
82c02981e2
3 changed files with 63 additions and 21 deletions
|
|
@ -163,6 +163,9 @@ def option_parser(usage, gui_mode=False):
|
|||
link.add_option('--link-exclude', dest='link_exclude', default='@',
|
||||
help=_('''A regular expression. <a> tags whoose href '''
|
||||
'''matches will be ignored. Defaults to %default'''))
|
||||
link.add_option('--no-links-in-toc', action='store_true', default=False,
|
||||
dest='no_links_in_toc',
|
||||
help=_('''Don't add links to the table of contents.'''))
|
||||
chapter = parser.add_option_group('CHAPTER OPTIONS')
|
||||
chapter.add_option('--disable-chapter-detection', action='store_true',
|
||||
default=False, dest='disable_chapter_detection',
|
||||
|
|
@ -186,6 +189,9 @@ def option_parser(usage, gui_mode=False):
|
|||
default='$', help=_('Force a page break before tags whoose names match this regular expression.'))
|
||||
chapter.add_option('--force-page-break-before-attr', dest='force_page_break_attr',
|
||||
default='$,,$', help=_('Force a page break before an element having the specified attribute. The format for this option is tagname regexp,attribute name,attribute value regexp. For example to match all heading tags that have the attribute class="chapter" you would use "h\d,class,chapter". Default is %default'''))
|
||||
chapter.add_option('--add-chapters-to-toc', action='store_true',
|
||||
default=False, dest='add_chapters_to_toc',
|
||||
help=_('''Add detected chapters to the table of contents.'''))
|
||||
prepro = parser.add_option_group('PREPROCESSING OPTIONS')
|
||||
prepro.add_option('--baen', action='store_true', default=False, dest='baen',
|
||||
help=_('''Preprocess Baen HTML files to improve generated LRF.'''))
|
||||
|
|
|
|||
|
|
@ -547,7 +547,8 @@ def create_link(self, children, tag):
|
|||
|
||||
path, fragment = munge_paths(self.target_prefix, tag['href'])
|
||||
return {'para':para, 'text':text, 'path':os.path.abspath(path),
|
||||
'fragment':fragment, 'in toc': (self.link_level == 0 and not self.use_spine)}
|
||||
'fragment':fragment, 'in toc': (self.link_level == 0 and
|
||||
not self.use_spine and not self.options.no_links_in_toc)}
|
||||
|
||||
|
||||
def get_text(self, tag, limit=None):
|
||||
|
|
@ -1620,6 +1621,10 @@ def parse_tag(self, tag, parent_css):
|
|||
self.log_debug('Detected chapter %s', src)
|
||||
self.end_page()
|
||||
self.page_break_found = True
|
||||
|
||||
if self.options.add_chapters_to_toc:
|
||||
self.extra_toc_entries.append((self.get_text(tag,
|
||||
limit=1000), self.current_block))
|
||||
|
||||
if self.current_para.has_text():
|
||||
self.current_para.append_to(self.current_block)
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>categoryList</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
@ -473,8 +474,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>100</width>
|
||||
<height>30</height>
|
||||
<width>622</width>
|
||||
<height>454</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
|
|
@ -739,8 +740,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>100</width>
|
||||
<height>30</height>
|
||||
<width>622</width>
|
||||
<height>454</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
|
|
@ -863,8 +864,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>100</width>
|
||||
<height>30</height>
|
||||
<width>622</width>
|
||||
<height>454</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
|
|
@ -873,8 +874,8 @@
|
|||
<property name="title" >
|
||||
<string>Title based detection</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<layout class="QGridLayout" name="gridLayout" >
|
||||
<item row="0" column="0" colspan="2" >
|
||||
<widget class="QCheckBox" name="gui_disable_chapter_detection" >
|
||||
<property name="text" >
|
||||
<string>&Disable chapter detection</string>
|
||||
|
|
@ -894,6 +895,20 @@
|
|||
<item row="1" column="1" >
|
||||
<widget class="QLineEdit" name="gui_chapter_regex" />
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2" >
|
||||
<widget class="QCheckBox" name="gui_add_chapters_to_toc" >
|
||||
<property name="text" >
|
||||
<string>Add &chapters to table of contents</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2" >
|
||||
<widget class="QCheckBox" name="gui_no_links_in_toc" >
|
||||
<property name="text" >
|
||||
<string>Don't add &links to the table of contents</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -1066,8 +1081,8 @@ p, li { white-space: pre-wrap; }
|
|||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>584</x>
|
||||
<y>661</y>
|
||||
<x>794</x>
|
||||
<y>660</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>286</x>
|
||||
|
|
@ -1082,8 +1097,8 @@ p, li { white-space: pre-wrap; }
|
|||
<slot>setCurrentIndex(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>245</x>
|
||||
<y>199</y>
|
||||
<x>191</x>
|
||||
<y>236</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>368</x>
|
||||
|
|
@ -1098,12 +1113,12 @@ p, li { white-space: pre-wrap; }
|
|||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>439</x>
|
||||
<y>97</y>
|
||||
<x>428</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>539</x>
|
||||
<y>149</y>
|
||||
<x>788</x>
|
||||
<y>140</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
|
@ -1114,12 +1129,28 @@ p, li { white-space: pre-wrap; }
|
|||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>398</x>
|
||||
<y>177</y>
|
||||
<x>348</x>
|
||||
<y>340</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>476</x>
|
||||
<y>211</y>
|
||||
<x>823</x>
|
||||
<y>372</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gui_disable_chapter_detection</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>gui_add_chapters_to_toc</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>321</x>
|
||||
<y>78</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>322</x>
|
||||
<y>172</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
|
|
|||
Loading…
Reference in a new issue