Commit 20656421 authored by Marco Cavalli's avatar Marco Cavalli
Browse files

fix: reorder logic in if statement to prevent false friends with dynamic links

parent 4190b972
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -477,11 +477,7 @@ def fix_custom_tags(soup: BeautifulSoup):

    for a in a_tags:
        href = a.get("href", "")
        if href.startswith("#") and href.find("root") != -1 and notAnImage(href): # when root is used in md
            new_id_prefix = f"{h1_tag['id']}"
            a["href"] = href.replace("root", new_id_prefix)
            a.string = a.string.replace("root", new_id_prefix)
        elif "below" in href:
        if href.endswith("below"):
            is_table = "Table" in href
            class_name = "TH" if is_table else "FL"
            next_element = a.find_next("div", class_=class_name, id=True)
@@ -496,7 +492,7 @@ def fix_custom_tags(soup: BeautifulSoup):
                print(p_error(f"Error: Found a broken custom tag in file {h1_tag.string}"))
                print(p_error(f"Error: No next element found for '{a.string}'. There are not any figures/tables above this tag."))
                os._exit(1)
        elif "above" in href:
        elif href.endswith("above"):
            is_table = "Table" in href
            class_name = "TH" if is_table else "FL"
            previous_element = a.find_previous("div", class_=class_name, id=True)
@@ -511,6 +507,11 @@ def fix_custom_tags(soup: BeautifulSoup):
                print(p_error(f"Error: Found a broken custom tag in file {h1_tag.string}"))
                print(p_error(f"Error: No previous element found for '{a.string}'. There are not any figures/tables above this tag."))
                os._exit(1)
        elif href.find("#") != -1 and href.find("root") != -1 and notAnImage(href): # when root is used in md
            print(href)
            new_id_prefix = f"{h1_tag['id']}"
            a["href"] = href.replace("root", new_id_prefix)
            a.string = a.string.replace("root", new_id_prefix)
    return soup

def extract_images_from_html(soup: BeautifulSoup) -> dict: