-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Same as fix_html_in_content_fields is should be possible to pass additional fixers.
An example I used recently is to scale all unscaled images:
def scale_unscaled_images(text, obj=None):
"""Scale unscaled image"""
if not text:
return text
fallback_scale = "huge"
soup = BeautifulSoup(text, "html.parser")
for tag in soup.find_all("img"):
if "data-val" not in tag.attrs:
# maybe external image
continue
scale = tag["data-scale"]
# Prevent unscaled images!
if not scale:
scale = fallback_scale
tag["data-scale"] = fallback_scale
if not tag["src"].endswith(scale):
tag["src"] = tag["src"] + "/" + scale
return soup.decode()
Metadata
Metadata
Assignees
Labels
No labels