aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 12:38:04 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 12:38:04 +0200
commit2e8c6dfd876d25a00897e05ae2883a47f79d3eea (patch)
treee468a61aeb1a602ea14ae7afa6a5f0a8103b5c68 /utils
parentc29e1ab61ab659eb9ba1f440a3d52aa4294d70c3 (diff)
downloadmy_new_personal_website-2e8c6dfd876d25a00897e05ae2883a47f79d3eea.tar.xz
my_new_personal_website-2e8c6dfd876d25a00897e05ae2883a47f79d3eea.zip
Move postprocess_html_file function to external file
Diffstat (limited to '')
-rw-r--r--utils/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/utils.py b/utils/utils.py
index f8cb8ef6..1cabbdc8 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -177,3 +177,19 @@ def process_footnote_backlinks(soup):
tag.string == "\u21A9"): # U+21A9: LEFTWARDS ARROW WITH HOOK
fn_a_tag["class"] = "footnotes-backlink"
fn_a_tag.string = "\u21A9\uFE0E" # U+FE0E: VARIATION SELECTOR-15
+
+
+def postprocess_html_file(htmlfilepath):
+ """Perform a series of postprocessing to an HTML file."""
+ with open(htmlfilepath, "r+", encoding="utf-8") as htmlfileobj:
+ soup = bs4.BeautifulSoup(htmlfileobj.read(), "lxml")
+
+ # a series of postprocessing (extensible)
+ process_image_sizes(soup)
+ link_img_tags(soup)
+ process_footnote_backlinks(soup)
+
+ # write back
+ htmlfileobj.seek(0)
+ htmlfileobj.write(str(soup))
+ htmlfileobj.truncate()