From 40491f6f3abfbc9926b488753143214ff1b87e3c Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Mon, 10 May 2021 15:45:48 +0200 Subject: [PATCH] Fix switching content tabs, closes #45 --- mkdocs_print_site_plugin/urls.py | 55 +++++- .../projects/with_markdown_ext/docs/index.md | 17 ++ tests/test_urls.py | 166 ++++++++---------- 3 files changed, 141 insertions(+), 97 deletions(-) diff --git a/mkdocs_print_site_plugin/urls.py b/mkdocs_print_site_plugin/urls.py index 3ea202b..d27eb38 100644 --- a/mkdocs_print_site_plugin/urls.py +++ b/mkdocs_print_site_plugin/urls.py @@ -136,12 +136,16 @@ def update_anchor_ids(page_html, page_key): """ # Regex demo / tests: https://regex101.com/r/mlAPNH/1 href_regex = re.compile( - r"\<([h1|h2|h3|h4|h5|h6|sup|li]+).+id=\"([aA-zZ|0-9|\-|\_|\.|\:]+)\"", + r"<([^\s]+).*?id=\"([^\"]*?)\".*?>(.*?)<\/\1>", flags=re.IGNORECASE, ) matches = re.finditer(href_regex, page_html) + change_tags = ["h1", "h2", "h3", "h4", "h5", "h6", "sup", "li"] for m in matches: + tag_text = m.group(1) + if tag_text not in change_tags: + continue id_text = m.group(2) match_text = m.group() new_text = match_text.replace(id_text, page_key + "-" + id_text) @@ -151,6 +155,54 @@ def update_anchor_ids(page_html, page_key): return page_html +def fix_tabbed_content(page_html, page_key): + """ + Tabbed content have and