From 3d4e7660513d85a8db74983e974560710058844c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Sep 2009 18:06:53 -0600 Subject: [PATCH] Fix #3375 (--max-toc-links option does not seem to work) --- src/calibre/ebooks/oeb/transforms/structure.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/ebooks/oeb/transforms/structure.py b/src/calibre/ebooks/oeb/transforms/structure.py index b84222d82c..2f52fde371 100644 --- a/src/calibre/ebooks/oeb/transforms/structure.py +++ b/src/calibre/ebooks/oeb/transforms/structure.py @@ -106,6 +106,7 @@ class DetectStructure(object): counter += 1 def create_toc_from_links(self): + num = 0 for item in self.oeb.spine: for a in XPath('//h:a[@href]')(item.data): href = a.get('href') @@ -120,8 +121,13 @@ class DetectStructure(object): a.xpath('descendant::text()')]) text = text[:100].strip() if not self.oeb.toc.has_text(text): + num += 1 self.oeb.toc.add(text, href, play_order=self.oeb.toc.next_play_order()) + if self.opts.max_toc_links > 0 and \ + num >= self.opts.max_toc_links: + self.log('Maximum TOC links reached, stopping.') + return