diff --git a/src/calibre/ebooks/lrf/__init__.py b/src/calibre/ebooks/lrf/__init__.py index 16983fb0cd..91330b44aa 100644 --- a/src/calibre/ebooks/lrf/__init__.py +++ b/src/calibre/ebooks/lrf/__init__.py @@ -163,6 +163,9 @@ def option_parser(usage, gui_mode=False): link.add_option('--link-exclude', dest='link_exclude', default='@', help=_('''A regular expression. 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.''')) diff --git a/src/calibre/ebooks/lrf/html/convert_from.py b/src/calibre/ebooks/lrf/html/convert_from.py index f41e2276b2..adfa7b37eb 100644 --- a/src/calibre/ebooks/lrf/html/convert_from.py +++ b/src/calibre/ebooks/lrf/html/convert_from.py @@ -547,7 +547,8 @@ class HTMLConverter(object, LoggingInterface): 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 @@ class HTMLConverter(object, LoggingInterface): 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) diff --git a/src/calibre/gui2/dialogs/lrf_single.ui b/src/calibre/gui2/dialogs/lrf_single.ui index ba7fe27123..0a8d6b6669 100644 --- a/src/calibre/gui2/dialogs/lrf_single.ui +++ b/src/calibre/gui2/dialogs/lrf_single.ui @@ -132,6 +132,7 @@ + categoryList @@ -473,8 +474,8 @@ 0 0 - 100 - 30 + 622 + 454 @@ -739,8 +740,8 @@ 0 0 - 100 - 30 + 622 + 454 @@ -863,8 +864,8 @@ 0 0 - 100 - 30 + 622 + 454 @@ -873,8 +874,8 @@ Title based detection - - + + &Disable chapter detection @@ -894,6 +895,20 @@ + + + + Add &chapters to table of contents + + + + + + + Don't add &links to the table of contents + + + @@ -1066,8 +1081,8 @@ p, li { white-space: pre-wrap; } reject() - 584 - 661 + 794 + 660 286 @@ -1082,8 +1097,8 @@ p, li { white-space: pre-wrap; } setCurrentIndex(int) - 245 - 199 + 191 + 236 368 @@ -1098,12 +1113,12 @@ p, li { white-space: pre-wrap; } setDisabled(bool) - 439 - 97 + 428 + 89 - 539 - 149 + 788 + 140 @@ -1114,12 +1129,28 @@ p, li { white-space: pre-wrap; } setEnabled(bool) - 398 - 177 + 348 + 340 - 476 - 211 + 823 + 372 + + + + + gui_disable_chapter_detection + toggled(bool) + gui_add_chapters_to_toc + setDisabled(bool) + + + 321 + 78 + + + 322 + 172