From 0ce5b658358dc1a0d7694e94f6b55835d8f14fe7 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 29 May 2020 21:29:44 +0200 Subject: [PATCH] Properly handle newlines in quote blocks --- matrix/colors.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index f049ecb..a0d02ad 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -356,11 +356,15 @@ class Formatted(object): quote_pair = color_pair(G.CONFIG.color.quote_fg, G.CONFIG.color.quote_bg) + # Remove leading and trailing newlines; Riot sends an extra + # quoted "\n" when a user quotes a message. + string = string.strip("\n") + if len(string) == 0: + return string + if G.CONFIG.look.quote_wrap >= 0: wrapper = self.textwrapper(G.CONFIG.look.quote_wrap, quote_pair) - return wrapper.fill( - W.string_remove_color(string.replace("\n", ""), "") - ) + return wrapper.fill(W.string_remove_color(string, "")) else: # Don't wrap, just add quote markers to all lines return "{color_on}{text}{color_off}".format(