diff --git a/app/utils.py b/app/utils.py index e0199917..5ddc8819 100644 --- a/app/utils.py +++ b/app/utils.py @@ -284,6 +284,10 @@ def allowlist_html(html: str, a_target='_blank') -> str: clean_html = str(soup) + # avoid wrapping anchors around existing anchors (e.g. if raw URL already wrapped by remote PieFed instance) + re_double_anchor = re.compile(r'(.*?<\/a>)<\/a>') + clean_html = re_double_anchor.sub(r'\1', clean_html) + # avoid returning empty anchors re_empty_anchor = re.compile(r'<\/a>') clean_html = re_empty_anchor.sub(r'\1', clean_html)