Fix inline img support in object

This commit is contained in:
Thomas Sileo 2022-07-14 15:16:58 +02:00
parent d245201851
commit c8e0c813b5
2 changed files with 15 additions and 2 deletions

View File

@ -226,6 +226,9 @@ nav.flexbox {
margin: 30px 0;
}
}
img.inline-img {
max-width: 740px;
}
}
.ap-object-expanded {
border: 2px dashed $secondary-color;

View File

@ -245,11 +245,20 @@ def _allow_class(_tag: str, name: str, value: str) -> bool:
return name == "class" and value in ALLOWED_CSS_CLASSES
def _allow_img_attrs(_tag: str, name: str, value: str) -> bool:
if name in ["src", "alt", "title"]:
return True
if name == "class" and value == "inline-img":
return True
return False
ALLOWED_ATTRIBUTES: dict[str, list[str] | Callable[[str, str, str], bool]] = {
"a": ["href", "title"],
"abbr": ["title"],
"acronym": ["title"],
"img": ["src", "alt", "title"],
"img": _allow_img_attrs,
"div": _allow_class,
"span": _allow_class,
"code": _allow_class,
@ -267,7 +276,8 @@ def _update_inline_imgs(content):
if not img.attrs.get("src"):
continue
img.attrs["src"] = _media_proxy_url(img.attrs["src"])
img.attrs["src"] = _media_proxy_url(img.attrs["src"]) + "/740"
img["class"] = "inline-img"
return soup.find("body").decode_contents()