Mastodon: Add line breaks when new paragraphs are present on posts content

This commit is contained in:
Manuel Cortez 2022-12-14 12:08:02 -06:00
parent ae0dcc7b21
commit e63479a261
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790

View File

@ -5,12 +5,19 @@ url_re = re.compile('<a\s*href=[\'|"](.*?)[\'"].*?>')
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()