]> asedeno.scripts.mit.edu Git - vt_decor.git/commitdiff
Try to detect post-list content
authorAlejandro R. Sedeño <asedeno@mit.edu>
Tue, 19 Apr 2022 17:50:41 +0000 (13:50 -0400)
committerAlejandro R. Sedeño <asedeno@mit.edu>
Tue, 19 Apr 2022 17:50:41 +0000 (13:50 -0400)
vt_decor.py

index 7a1ee480fb1186fb937673fab25a6117a7e12d90..ff56319fe96ec8f0df5fc64bc0ee110a7eb87683 100644 (file)
@@ -163,12 +163,31 @@ class RoostVTDecor(roost.RoostMessage.Decor):
                 else:
                     # Content
                     # collapse whitespace and wrap.
-                    ret += textwrap.fill(re.sub(r'\s+', ' ', m), width,
-                                         initial_indent=indent+bindent,
-                                         subsequent_indent=indent+bindent,
-                                         break_long_words=False,
-                                         break_on_hyphens=False).lstrip()
-                    ret += '\n'
+                    if '\n\n' in m:
+                        # list appears to end and have further content.
+                        # deal with final (?) bullet...
+                        bm, rest = m.split('\n\n', 1)
+                        ret += textwrap.fill(re.sub(r'\s+', ' ', bm), width,
+                                             initial_indent=indent+bindent,
+                                             subsequent_indent=indent+bindent,
+                                             break_long_words=False,
+                                             break_on_hyphens=False).lstrip()
+
+                        # ... and then indent and wrap following content normally.
+                        ret += '\n\n'
+                        ret += textwrap.fill(re.sub(r'\s+', ' ', rest), width,
+                                             initial_indent=indent,
+                                             subsequent_indent=indent,
+                                             break_long_words=False,
+                                             break_on_hyphens=False)
+                        ret += '\n'
+                    else:
+                        ret += textwrap.fill(re.sub(r'\s+', ' ', m), width,
+                                             initial_indent=indent+bindent,
+                                             subsequent_indent=indent+bindent,
+                                             break_long_words=False,
+                                             break_on_hyphens=False).lstrip()
+                        ret += '\n'
 
             return ret.rstrip()
         except Exception as e: