From fa97f12689d3ef3e3da81ebdb8b199fbbf40e29a Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 15 Oct 2019 16:44:28 +0100 Subject: [PATCH] support AP Notes with content outside of HTML tags (e.g. pleroma) --- modules/fediverse/ap_utils.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/fediverse/ap_utils.py b/modules/fediverse/ap_utils.py index e8f25bbc..412d84c1 100644 --- a/modules/fediverse/ap_utils.py +++ b/modules/fediverse/ap_utils.py @@ -68,16 +68,19 @@ def _normalise_note(content): element.decompose() elif not element.name in KNOWN_TAGS: element.unwrap() - for element in soup.find_all(): + for element in soup.children: out = "" - if element.name == "p": - for subitem in element.contents: - if type(subitem) == bs4.element.Tag: - if subitem.name == "br": - lines.append(out) - out = "" - else: - out += subitem + if type(element) == bs4.element.Tag: + if element.name == "p": + for subitem in element.contents: + if type(subitem) == bs4.element.Tag: + if subitem.name == "br": + lines.append(out) + out = "" + else: + out += subitem + else: + out += element lines.append(out.replace(" ", " ")) return " ".join(lines)