Merge pull request #150 from stijndcl/squash-newlines-in-announcements

Squash consecutive newlines
pull/151/head
Stijn De Clercq 2022-11-01 21:16:11 +01:00 committed by GitHub
commit 87e5b1be9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
@ -71,8 +72,14 @@ class UforaNotification(EmbedBaseModel):
def _clean_content(self, text: str): def _clean_content(self, text: str):
# Escape *-characters because they mess up the layout # Escape *-characters because they mess up the layout
text = text.replace("*", "\\*") # and non-breaking-spaces
return md(text) text = text.replace("*", "\\*").replace("\xa0", " ")
text = md(text)
# Squash consecutive newlines and ignore spaces inbetween
subbed = re.sub(r"\n+\s?\n+", "\n\n", text)
return subbed
def _published_datetime(self) -> datetime: def _published_datetime(self) -> datetime:
"""Get a datetime instance of the publication date""" """Get a datetime instance of the publication date"""