From 002118777ddf2f81d2894d81bc7fadc64dbbc36f Mon Sep 17 00:00:00 2001 From: mjfernez Date: Fri, 14 Jul 2023 13:21:13 -0400 Subject: Add script to update TOC links With commit 50b72b5787338ee3c0ef0a4aebfcdf8acf3c3a08 in ezcms, the default behavior for links changes to open in a new tab. This script helps override the option for table of content links by updating "target" to point to "_self" --- update_targets.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 update_targets.py (limited to 'update_targets.py') diff --git a/update_targets.py b/update_targets.py new file mode 100644 index 0000000..2052e68 --- /dev/null +++ b/update_targets.py @@ -0,0 +1,17 @@ +import sys +from bs4 import BeautifulSoup + +html_doc = open(sys.argv[1], mode="r") +html = html_doc.read() +soup = BeautifulSoup(html, features="lxml") +for link in soup.find_all("a"): + if "href" in link.attrs.keys(): + if (link['href'].startswith("#") + and "tabindex" not in link.attrs.keys() + and "target" not in link.attrs.keys()): + link['target'] = "_self" +html_doc.close() +html_doc = open(sys.argv[1], mode="w") +print(soup, file=html_doc) +print("File written") + -- cgit v1.2.3