support AP Notes with content outside of HTML tags (e.g. pleroma)

This commit is contained in:
jesopo 2019-10-15 16:44:28 +01:00
parent 491ad531c2
commit fa97f12689

View file

@ -68,16 +68,19 @@ def _normalise_note(content):
element.decompose() element.decompose()
elif not element.name in KNOWN_TAGS: elif not element.name in KNOWN_TAGS:
element.unwrap() element.unwrap()
for element in soup.find_all(): for element in soup.children:
out = "" out = ""
if element.name == "p": if type(element) == bs4.element.Tag:
for subitem in element.contents: if element.name == "p":
if type(subitem) == bs4.element.Tag: for subitem in element.contents:
if subitem.name == "br": if type(subitem) == bs4.element.Tag:
lines.append(out) if subitem.name == "br":
out = "" lines.append(out)
else: out = ""
out += subitem else:
out += subitem
else:
out += element
lines.append(out.replace(" ", " ")) lines.append(out.replace(" ", " "))
return " ".join(lines) return " ".join(lines)