From: Simon Tatham Date: Sun, 10 Dec 2023 22:15:16 +0000 (+0000) Subject: Squelch literal \n appearing in post HTML. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=c2c8b763409a37f0dd5cf77243935dc30496c802;p=mastodonochrome.git Squelch literal \n appearing in post HTML. For some reason this doesn't happen very often, but I just saw it for the first time, and it totally confused Paragraph and also ColouredString.frags. Avoid getting into that sitation in the first place. --- diff --git a/text.py b/text.py index 36af714..57a4d27 100644 --- a/text.py +++ b/text.py @@ -51,6 +51,7 @@ class ColouredString: assert len(colour) == 1, "Colour ids are single characters" colour = colour * len(string) self.s, self.c = string, colour + assert '\n' not in self.s, "Newlines ought to be handled elsewhere" self.width = cached_wcswidth(self.s) def __add__(self, rhs): @@ -503,6 +504,7 @@ class HTMLParser(html.parser.HTMLParser): return def handle_data(self, data): + data = data.replace('\n', ' ') self.paras[-1].add(ColouredString(data, self.colourstack[-1])) def done(self):