diff --git a/src/epub_converter/epub_converter.py b/src/epub_converter/epub_converter.py index 9eec34e..6e83e74 100644 --- a/src/epub_converter/epub_converter.py +++ b/src/epub_converter/epub_converter.py @@ -99,7 +99,7 @@ class EpubConverter: self.process_internal_links() self.book_logger.log( f"Check if converter-chapter-marks are on the same level.") - self.chapter_marks_are_same_level() + self.chapter_marks_are_first_level() self.book_logger.log(f"Define chapters content.") self.define_chapters_with_content() self.book_logger.log(f"Converting html_nodes to LiveCarta chapter items.") @@ -276,23 +276,23 @@ class EpubConverter: self.hrefs_added_to_toc.add(file) def label_subchapters_with_lc_tag(self): - for html_href in self.html_href2html_body_soup: - ids, soup = self.html_href2subchapters_ids[html_href], \ - self.html_href2html_body_soup[html_href] - for i in ids: + for html_href, soup in self.html_href2html_body_soup.items(): + for i in self.html_href2subchapters_ids[html_href]: tag = soup.find(id=i) + # in order not to lose tags in verification of same level of chapter + parent_tag = tag.find_parents(['p', 'span', 'div', 'h1', 'h2', 'h3', 'h4', 'h5'])[-1] tmp_tag = soup.new_tag("lc_tmp") tmp_tag.attrs["class"] = "converter-chapter-mark" tmp_tag.attrs["id"] = i - tag.insert_before(tmp_tag) + parent_tag.insert_before(tmp_tag) - def chapter_marks_are_same_level(self): + def chapter_marks_are_first_level(self): """ - Function checks that marks for pointing a start of a chapter are placed on one level in html tree. + Function checks that marks for pointing a start of a chapter are placed on 1st level in html tree. Mark is tag with "class": "converter-chapter-mark". Added while TOC was parsed. This tag must have a chapter_tag as a parent. - Otherwise, it is wrapped with some tags. Like: -
+ Otherwise, it's wrapped with some tags. Like: +