diff --git a/TODO.md b/TODO.md index a11910b5..1d63b8d2 100644 --- a/TODO.md +++ b/TODO.md @@ -13,7 +13,6 @@ - When qml syntax highlighting supports ES6 string interpolation, use that - Fixes - - Quote newline spacing - 256 min width when a non-image link preview is present - Pressing backspace in composer sometimes doesn't work - Message order isn't preserved when sending a first message in a E2E @@ -21,7 +20,6 @@ then sending one with the first account again - If account not in config anymore, discard ui state last page on startup - - Don't strip user spacing in html - Do something when access token is invalid - Don't store states in delegates diff --git a/src/python/html_filter.py b/src/python/html_filter.py index 85dd4d4a..8d545f79 100644 --- a/src/python/html_filter.py +++ b/src/python/html_filter.py @@ -27,6 +27,8 @@ class HtmlFilter: re.MULTILINE, ) + newlines_regex = re.compile(r"\n(\n*)") + def __init__(self) -> None: self._sanitizer = Sanitizer(self.sanitize_settings()) @@ -57,15 +59,24 @@ class HtmlFilter: def filter_inline(self, html: str, outgoing: bool = False) -> str: - text = self._inline_sanitizer.sanitize(html).strip("\n") + html = self._inline_sanitizer.sanitize(html) + # Remove excess newlines to avoid additional blank lines with + # HTML/CSS using `white-space: pre` + html = self.newlines_regex.sub(r"\1", html) + + if outgoing: + return html + + # Client-side modifications return self.inline_quote_regex.sub( - r'\1', text, + r'\1', html, ) def filter(self, html: str, outgoing: bool = False) -> str: html = self._sanitizer.sanitize(html).rstrip("\n") + html = self.newlines_regex.sub(r"\1", html) if outgoing: return html