forked from LiveCarta/BookConverter
add anchor link to start page
This commit is contained in:
@@ -284,6 +284,14 @@ class EpubConverter:
|
||||
self.adjacency_list[-1].append(nav_point)
|
||||
self.hrefs_added_to_toc.add(file)
|
||||
|
||||
@staticmethod
|
||||
def create_new_anchor_span_start_page(soup: BeautifulSoup, id_: str) -> Tag:
|
||||
new_anchor_span = soup.new_tag("span")
|
||||
new_anchor_span.attrs["id"] = id_
|
||||
new_anchor_span.attrs["class"] = "link-anchor-start"
|
||||
new_anchor_span.string = "\xa0"
|
||||
return new_anchor_span
|
||||
|
||||
def label_subchapters_with_lc_tag(self):
|
||||
for html_href, soup in self.html_href2html_body_soup.items():
|
||||
for i in self.html_href2subchapters_ids[html_href]:
|
||||
@@ -291,6 +299,12 @@ class EpubConverter:
|
||||
# in order not to lose tags in verification of same level in chapter
|
||||
parent_tags = tag.find_parents(['body', 'p', 'span', 'h1', 'h2', 'h3', 'h4', 'h5'])
|
||||
parent_tag = parent_tags[-1] if parent_tags else tag
|
||||
|
||||
# insert link to page
|
||||
new_unique_id = self.create_unique_id(html_href, '')
|
||||
parent_tag.insert_after(self.create_new_anchor_span_start_page(soup, new_unique_id))
|
||||
self.internal_anchors.add(new_unique_id)
|
||||
|
||||
tmp_tag = soup.new_tag("lc_tmp")
|
||||
tmp_tag.attrs["class"] = "converter-chapter-mark"
|
||||
tmp_tag.attrs["id"] = i
|
||||
@@ -391,8 +405,11 @@ class EpubConverter:
|
||||
for href_from_toc in self.hrefs_added_to_toc:
|
||||
for tag in self.html_href2html_body_soup[href_from_toc].find_all(attrs={"id": re.compile(r".+")}):
|
||||
if tag.attrs.get("class") not in ["converter-chapter-mark", "footnote-element"]:
|
||||
new_unique_id = self.create_unique_id(
|
||||
href_from_toc, tag.attrs["id"])
|
||||
if tag.attrs.get("class") == 'link-anchor-start':
|
||||
new_unique_id = tag.attrs["id"]
|
||||
tag.attrs["class"] = 'link-anchor'
|
||||
else:
|
||||
new_unique_id = self.create_unique_id(href_from_toc, tag.attrs["id"])
|
||||
tag.attrs["id"] = new_unique_id
|
||||
|
||||
def process_file_anchor():
|
||||
|
||||
Reference in New Issue
Block a user