HtmlFilter: Remove excess newlines

To avoid additional blank lines with HTML/CSS using `white-space: pre`
This commit is contained in:
miruka 2019-09-10 21:22:42 -04:00
parent b3135601ed
commit 7797b0e1eb
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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'<span class="quote">\1</span>', text,
r'<span class="quote">\1</span>', 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