From 8fca7d19c77f8cb76dd03b38154e406e3927ba3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 9 Aug 2018 17:52:24 +0200 Subject: [PATCH] colors: Rework newline adding for blockquotes and

tags. --- matrix/colors.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/matrix/colors.py b/matrix/colors.py index dec9cab..2d71fcb 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -301,7 +301,7 @@ class Formatted(): return text weechat_strings = map(format_string, self.substrings) - return "".join(weechat_strings).rstrip("\n") + return "".join(weechat_strings).rstrip("\n").replace("\n\n", "\n") # TODO this should be a typed dict. @@ -357,6 +357,12 @@ class MatrixHtmlParser(HTMLParser): self._toggle_attribute("strikethrough") elif tag == "blockquote": self._toggle_attribute("quote") + elif tag == "p": + if self.text: + self.add_substring(self.text, self.attributes.copy()) + self.text = "\n" + self.add_substring(self.text, DEFAULT_ATRIBUTES.copy()) + self.text = "" elif tag == "br": if self.text: self.add_substring(self.text, self.attributes.copy()) @@ -389,9 +395,6 @@ class MatrixHtmlParser(HTMLParser): self._toggle_attribute("strikethrough") elif tag == "blockquote": self._toggle_attribute("quote") - elif tag == "p": - if self.text: - self.add_substring(self.text, self.attributes.copy()) self.text = "\n" self.add_substring(self.text, DEFAULT_ATRIBUTES.copy()) self.text = ""