Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_html_in_portlets should also support additional fixers #195

Open
pbauer opened this issue Apr 13, 2023 · 0 comments
Open

fix_html_in_portlets should also support additional fixers #195

pbauer opened this issue Apr 13, 2023 · 0 comments

Comments

@pbauer
Copy link
Member

pbauer commented Apr 13, 2023

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant