forked from LiveCarta/BookConverter
LAW-6562 | Change process of adding chapter marks
This commit is contained in:
@@ -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:
|
||||
<p> <span id="123", class="converter-chapter-mark"> </span> </p>
|
||||
Otherwise, it's wrapped with some tags. Like:
|
||||
<p> <lc_tmp id="123", class="converter-chapter-mark"> </lc_tmp> </p>
|
||||
|
||||
"""
|
||||
for html_href in self.html_href2html_body_soup:
|
||||
@@ -304,7 +304,7 @@ class EpubConverter:
|
||||
# fix marks to be on 1 level
|
||||
for mark in marks:
|
||||
while mark.parent != chapter_tag:
|
||||
# todo warning! could reflect on formatting/internal links in some cases
|
||||
# todo warning! could reflect on formatting/internal links in some cases (it removes tags using unwrap)
|
||||
mark.parent.unwrap()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user