dsfsdf
This commit is contained in:
parent
c76b2b4e63
commit
ee94ef91db
1 changed files with 23 additions and 11 deletions
|
@ -78,23 +78,35 @@ no_images = ['b',
|
||||||
_allowed_attributes = {'*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name', 'direction']}
|
_allowed_attributes = {'*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name', 'direction']}
|
||||||
|
|
||||||
|
|
||||||
def sanitize(sanitized):
|
def sanitize(sanitized, noimages=False):
|
||||||
|
|
||||||
sanitized = sanitized.replace("\ufeff", "").replace("m.youtube.com", "youtube.com")
|
sanitized = sanitized.replace("\ufeff", "").replace("m.youtube.com", "youtube.com")
|
||||||
|
|
||||||
for i in re.finditer('https://i.imgur.com/(([^_]*?)\.(jpg|png|jpeg))', sanitized):
|
for i in re.finditer('https://i.imgur.com/(([^_]*?)\.(jpg|png|jpeg))', sanitized):
|
||||||
sanitized = sanitized.replace(i.group(1), i.group(2) + "_d." + i.group(3) + "?maxwidth=9999")
|
sanitized = sanitized.replace(i.group(1), i.group(2) + "_d." + i.group(3) + "?maxwidth=9999")
|
||||||
|
|
||||||
sanitized = bleach.Cleaner(tags=_allowed_tags,
|
if noimages:
|
||||||
attributes=_allowed_attributes,
|
sanitized = bleach.Cleaner(tags=no_images,
|
||||||
protocols=['http', 'https'],
|
attributes=_allowed_attributes,
|
||||||
styles=['color','font-weight','transform','-webkit-transform'],
|
protocols=_allowed_protocols,
|
||||||
filters=[partial(LinkifyFilter,
|
styles=_allowed_styles,
|
||||||
skip_tags=["pre"],
|
filters=[partial(LinkifyFilter,
|
||||||
parse_email=False,
|
skip_tags=["pre"],
|
||||||
)
|
parse_email=False,
|
||||||
]
|
)
|
||||||
).clean(sanitized)
|
]
|
||||||
|
).clean(sanitized)
|
||||||
|
else:
|
||||||
|
sanitized = bleach.Cleaner(tags=_allowed_tags,
|
||||||
|
attributes=_allowed_attributes,
|
||||||
|
protocols=['http', 'https'],
|
||||||
|
styles=['color','font-weight','transform','-webkit-transform'],
|
||||||
|
filters=[partial(LinkifyFilter,
|
||||||
|
skip_tags=["pre"],
|
||||||
|
parse_email=False,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
).clean(sanitized)
|
||||||
|
|
||||||
soup = BeautifulSoup(sanitized, features="html.parser")
|
soup = BeautifulSoup(sanitized, features="html.parser")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue