From 99a26d34c7778f5fe7aff40fb7ffb88c53b863ee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 3 Jul 2015 13:22:27 +0530 Subject: [PATCH] FB2 Output: Fix error when using the sectionize with toc option and the input documents Table of Contents contains multiple items pointing to the same HTML file. Fixes #1471125 [FB2 conversion failure](https://bugs.launchpad.net/calibre/+bug/1471125) --- src/calibre/ebooks/fb2/fb2ml.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index cee5c735e0..7554a4b1a6 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -264,7 +264,7 @@ class FB2MLizer(object): # Start a
if we must sectionize each file or if the TOC references this page page_section_open = False - if self.opts.sectionize == 'files' or self.toc.get(item.href) == 'page': + if self.opts.sectionize == 'files' or None in self.toc.get(item.href, ()): text.append('
') page_section_open = True self.section_level += 1 @@ -322,7 +322,7 @@ class FB2MLizer(object): for item in nodes: href, mid, id = item.href.partition('#') if not id: - self.toc[href] = 'page' + self.toc[href] = {None: 'page'} else: if not self.toc.get(href, None): self.toc[href] = {} @@ -426,12 +426,13 @@ class FB2MLizer(object): # the TOC pointed to a specific element newlevel = 0 toc_entry = self.toc.get(page.href, None) - if toc_entry == 'page': - if tag != 'body' and hasattr(elem_tree, 'text') and elem_tree.text: - newlevel = 1 - self.toc[page.href] = None - elif toc_entry and elem_tree.attrib.get('id', None): - newlevel = toc_entry.get(elem_tree.attrib.get('id', None), None) + if toc_entry is not None: + if None in toc_entry: + if tag != 'body' and hasattr(elem_tree, 'text') and elem_tree.text: + newlevel = 1 + self.toc[page.href] = None + if not newlevel and elem_tree.attrib.get('id', None) is not None: + newlevel = toc_entry.get(elem_tree.attrib.get('id', None), None) # Start a new section if necessary if newlevel: