Fix inline img support in object

main
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; margin: 30px 0;
} }
} }
img.inline-img {
max-width: 740px;
}
} }
.ap-object-expanded { .ap-object-expanded {
border: 2px dashed $secondary-color; 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 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]] = { ALLOWED_ATTRIBUTES: dict[str, list[str] | Callable[[str, str, str], bool]] = {
"a": ["href", "title"], "a": ["href", "title"],
"abbr": ["title"], "abbr": ["title"],
"acronym": ["title"], "acronym": ["title"],
"img": ["src", "alt", "title"], "img": _allow_img_attrs,
"div": _allow_class, "div": _allow_class,
"span": _allow_class, "span": _allow_class,
"code": _allow_class, "code": _allow_class,
@ -267,7 +276,8 @@ def _update_inline_imgs(content):
if not img.attrs.get("src"): if not img.attrs.get("src"):
continue 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() return soup.find("body").decode_contents()