From e63479a261518d0471934d8aebfb5cf1518b62dc Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 14 Dec 2022 12:08:02 -0600 Subject: [PATCH] Mastodon: Add line breaks when new paragraphs are present on posts content --- src/sessions/mastodon/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sessions/mastodon/utils.py b/src/sessions/mastodon/utils.py index b54923f7..49a4c4a3 100644 --- a/src/sessions/mastodon/utils.py +++ b/src/sessions/mastodon/utils.py @@ -5,12 +5,19 @@ url_re = re.compile('') class HTMLFilter(HTMLParser): text = "" + first_paragraph = True + def handle_data(self, data): self.text += data def handle_starttag(self, tag, attrs): if tag == "br": self.text = self.text+"\n" + elif tag == "p": + if self.first_paragraph: + self.first_paragraph = False + else: + self.text = self.text+"\n\n" def html_filter(data): f = HTMLFilter()