Avoid returning empty anchors in html

This commit is contained in:
freamon 2024-04-06 10:43:06 +01:00
parent 66d05ea860
commit a1a4464304

View file

@ -211,7 +211,9 @@ def allowlist_html(html: str) -> str:
if tag.name == 'table': if tag.name == 'table':
tag.attrs['class'] = 'table' tag.attrs['class'] = 'table'
return str(soup) # avoid returning empty anchors
re_empty_anchor = re.compile(r'<a href="(.*?)" rel="nofollow ugc" target="_blank"><\/a>')
return re_empty_anchor.sub(r'<a href="\1" rel="nofollow ugc" target="_blank">\1</a>', str(soup))
def markdown_to_html(markdown_text) -> str: def markdown_to_html(markdown_text) -> str: