aboutsummaryrefslogtreecommitdiff
path: root/utils/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/utils.py')
-rw-r--r--utils/utils.py9
1 files changed, 9 insertions, 0 deletions
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)