chiark / gitweb /
Cope with newlines in media descriptions.
authorSimon Tatham <anakin@pobox.com>
Sat, 2 Dec 2023 19:21:50 +0000 (19:21 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 2 Dec 2023 19:21:50 +0000 (19:21 +0000)
text.py

diff --git a/text.py b/text.py
index 710dc120e9f40039b4bf065c630ba45fda20cc06..21d0063b2c0566bc6679cfaeefd7d70b2b39a6d0 100644 (file)
--- a/text.py
+++ b/text.py
@@ -126,18 +126,20 @@ class BoosterLine(UsernameHeader):
 class Media:
     def __init__(self, url, description):
         self.url = url
-        if description is None:
-            self.description = None
-        else:
-            self.description = Paragraph()
-            self.description.add(ColouredString(description, 'm'))
-            self.description.end_word()
+        self.description = []
+        if description is not None:
+            for line in description.splitlines():
+                desc = Paragraph()
+                desc.add(ColouredString(line, 'm'))
+                desc.end_word()
+                self.description.append(desc)
 
     def render(self, width):
         yield ColouredString(self.url, "M")
         if self.description is not None:
-            for line in self.description.render(width-4):
-                yield ColouredString("  ") + line
+            for para in self.description:
+                for line in para.render(width-4):
+                    yield ColouredString("  ") + line
         yield ColouredString("")
 
 class Paragraph:
@@ -375,3 +377,14 @@ class RenderTests(unittest.TestCase):
                            '  mmm'),
             ColouredString(''),
         ])
+
+        ma = Media('https://a.b/c', 'foo\nbar')
+        self.assertEqual(list(ma.render(40)), [
+            ColouredString('https://a.b/c',
+                           'MMMMMMMMMMMMM'),
+            ColouredString('  foo',
+                           '  mmm'),
+            ColouredString('  bar',
+                           '  mmm'),
+            ColouredString(''),
+        ])