aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 00:20:59 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 00:20:59 +0200
commit666bdbd21f92482be07c45cfdb57786e6d99748f (patch)
treecb6c75d4267a9f0221e74b8969260493749aba06
parent54dc5304b69a91ea7a48d311b394fba99a185b77 (diff)
downloadmy_new_personal_website-666bdbd21f92482be07c45cfdb57786e6d99748f.tar.xz
my_new_personal_website-666bdbd21f92482be07c45cfdb57786e6d99748f.zip
Move link_img_tags function to external file
-rwxr-xr-xpyblog12
-rw-r--r--utils/utils.py9
2 files changed, 10 insertions, 11 deletions
diff --git a/pyblog b/pyblog
index 845177fa..7bdf88ae 100755
--- a/pyblog
+++ b/pyblog
@@ -783,16 +783,6 @@ def _pre_tag_insert_line_numbers(soup, pre_tag):
pre_tag.code.append(ln_tag)
-def link_img_tags(soup):
- """Convert each <img> tag in <article> to a link to its original."""
- if not soup.article:
- return
- for img_tag in soup.article.find_all("img"):
- a_tag = soup.new_tag("a", href=img_tag["src"], target="_blank")
- a_tag.insert(0, copy.copy(img_tag))
- img_tag.replace_with(a_tag)
-
-
def process_footnote_backlinks(soup):
"""Add class attribute "footnotes-backlink" to each footnote backlink."""
for footnotes in soup.find_all("div", attrs={"class": "footnotes"}):
@@ -812,7 +802,7 @@ def postprocess_html_file(htmlfilepath):
# a series of postprocessing (extensible)
utils.process_image_sizes(soup)
- link_img_tags(soup)
+ utils.link_img_tags(soup)
process_footnote_backlinks(soup)
# write back
diff --git a/utils/utils.py b/utils/utils.py
index eec10adf..bc42291c 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -139,3 +139,12 @@ def make_sitemap_url_element(link, updated=None, changefreq=None, priority=None)
priority_elem.text = "%.1f" % priority
urlelem.append(priority_elem)
return urlelem
+
+def link_img_tags(soup):
+ """Convert each <img> tag in <article> to a link to its original."""
+ if not soup.article:
+ return
+ for img_tag in soup.article.find_all("img"):
+ a_tag = soup.new_tag("a", href=img_tag["src"], target="_blank")
+ a_tag.insert(0, copy.copy(img_tag))
+ img_tag.replace_with(a_tag)