diff options
author | mjfernez <mjf@mjfer.net> | 2023-07-14 13:21:13 -0400 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2023-07-14 13:21:13 -0400 |
commit | 002118777ddf2f81d2894d81bc7fadc64dbbc36f (patch) | |
tree | e7552ee092e4f4601c96d3a1c97de5f066b637ec /update_targets.py | |
parent | d96c7cad92b025ad80a8fe64f91d1c215272e313 (diff) | |
download | site-files-002118777ddf2f81d2894d81bc7fadc64dbbc36f.tar.gz |
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"
Diffstat (limited to 'update_targets.py')
-rw-r--r-- | update_targets.py | 17 |
1 files changed, 17 insertions, 0 deletions
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") + |