forked from docs/doc-exports
fix duplicated anchor
Reviewed-by: gtema <artem.goncharov@gmail.com> Co-authored-by: argoncha Goncharov, Artem <artem.goncharov@t-systems.com> Co-committed-by: argoncha Goncharov, Artem <artem.goncharov@t-systems.com>
This commit is contained in:
parent
2ef676d3aa
commit
4c07c197d8
@ -76,6 +76,7 @@ class OTCDocConvertor:
|
||||
def streamline_html(self, soup, file_name):
|
||||
# Drop eventual header duplicated anchors
|
||||
fname = file_name.replace(".html", "").lower()
|
||||
page_anchors = set()
|
||||
met_page_anchors = dict()
|
||||
for lnk in soup.body.find_all("a"):
|
||||
name = None
|
||||
@ -138,6 +139,7 @@ class OTCDocConvertor:
|
||||
sec_id = i.get("id").lower()
|
||||
if self.is_element_referred(sec_id, file_name):
|
||||
logging.debug('Add section label')
|
||||
page_anchors.add(sec_id)
|
||||
i.insert_before(self.make_label(soup, sec_id))
|
||||
# and still convert to paragraph
|
||||
i.name = 'p'
|
||||
@ -185,9 +187,15 @@ class OTCDocConvertor:
|
||||
if self.is_element_referred(local_ref, file_name):
|
||||
# We now know something in the document wants this anchor -
|
||||
# replace it with label
|
||||
if local_ref not in page_anchors:
|
||||
lnk.name = "p"
|
||||
lnk.string = f"..\\_{local_ref}:"
|
||||
del lnk["name"]
|
||||
page_anchors.add(local_ref)
|
||||
else:
|
||||
logging.debug(
|
||||
f"Not placing replaced anchor {local_ref} "
|
||||
f" since it already existed")
|
||||
else:
|
||||
logging.debug("Dropping unreferred link")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user