fix error on book without right TOC

This commit is contained in:
shirshasa
2020-07-21 15:43:41 +03:00
parent 2c014ae36e
commit 89989b66f4

View File

@@ -594,7 +594,6 @@ class Book:
footnotes.append(content) footnotes.append(content)
self.footnotes = footnotes self.footnotes = footnotes
def _process_images(self): def _process_images(self):
@@ -705,6 +704,7 @@ class Book:
headers_info = [] headers_info = []
header_tags = self.body_tag.find_all(re.compile("^h[1-9]$")) header_tags = self.body_tag.find_all(re.compile("^h[1-9]$"))
headers_outline = [int(re.sub(r"^h", "", tag.name)) for tag in header_tags] headers_outline = [int(re.sub(r"^h", "", tag.name)) for tag in header_tags]
if headers_outline:
top_level_outline = min(headers_outline) top_level_outline = min(headers_outline)
top_level_headers = [tag for tag in header_tags top_level_headers = [tag for tag in header_tags
if int(re.sub(r"^h", "", tag.name)) == top_level_outline] if int(re.sub(r"^h", "", tag.name)) == top_level_outline]
@@ -973,6 +973,7 @@ class Book:
# Add is_introduction field to json structure # Add is_introduction field to json structure
# after deleting content before toc, some chapters can be deleted # after deleting content before toc, some chapters can be deleted
if self.top_level_headers:
same_first_titles = self.top_level_headers[0]['title'] == json_strc[0]['title'] same_first_titles = self.top_level_headers[0]['title'] == json_strc[0]['title']
is_first_header_introduction = not self.top_level_headers[0]['should_be_numbered'] is_first_header_introduction = not self.top_level_headers[0]['should_be_numbered']