From 5505ce64c82d120b580a9dc620a89dfdf4b4d9b2 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Tue, 1 Nov 2022 21:11:34 +0100 Subject: [PATCH] Squash consecutive newlines --- didier/data/embeds/ufora/announcements.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/didier/data/embeds/ufora/announcements.py b/didier/data/embeds/ufora/announcements.py index abca631..9b645ea 100644 --- a/didier/data/embeds/ufora/announcements.py +++ b/didier/data/embeds/ufora/announcements.py @@ -1,3 +1,4 @@ +import re from dataclasses import dataclass, field from datetime import datetime from typing import Optional @@ -71,8 +72,14 @@ class UforaNotification(EmbedBaseModel): def _clean_content(self, text: str): # Escape *-characters because they mess up the layout - text = text.replace("*", "\\*") - return md(text) + # and non-breaking-spaces + 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: """Get a datetime instance of the publication date"""