chiark / gitweb /
Squelch literal \n appearing in post HTML.
authorSimon Tatham <anakin@pobox.com>
Sun, 10 Dec 2023 22:15:16 +0000 (22:15 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 10 Dec 2023 22:15:16 +0000 (22:15 +0000)
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

diff --git a/text.py b/text.py
index 36af7147cff356f9ce33f8f0171aeb4ef607591e..57a4d27b4494d8f246330e7884385d132e9e16c5 100644 (file)
--- 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):