From c2c8b763409a37f0dd5cf77243935dc30496c802 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 10 Dec 2023 22:15:16 +0000 Subject: [PATCH] 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. --- text.py | 2 ++ 1 file changed, 2 insertions(+) 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): -- 2.30.2