From d2938f873063f6faf38623e9f21866781720f60f Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 21 Aug 2019 14:14:44 -0400 Subject: [PATCH] Don't linkify image links for outgoing html --- TODO.md | 8 +++----- src/python/html_filter.py | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/TODO.md b/TODO.md index a2c39bfd..1a573ffd 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,4 @@ - Refactoring - - Use HInterfaceBox for EditAccount Profile and Encryption - Banners - Theming @@ -21,10 +20,8 @@ - Run import in thread and AsyncClient.olm functions, they block async loop - Handle import keys errors - - Don't linkify images for outgoing html - - Keyboard flicking against top/bottom edge - Don't strip user spacing in html - + - Keyboard flicking against top/bottom edge - Do something when access token is invalid - Message position after daybreak delegate (fixed by commit 57b1313 ?) - [hr not working](https://bugreports.qt.io/browse/QTBUG-74342) @@ -33,6 +30,7 @@ - UI - Make HListView scrollbars visible - Remove first html lists left margin + - Adapt UI for small heights - Popup: - label size @@ -77,7 +75,6 @@ - Conversation breaks: show time of first new msg after break instead of big blank space - Replies - - `pyotherside.atexit()` - Sidepane - Header back button when reduced - Better look for arrows and option button when collapsed @@ -129,6 +126,7 @@ - Links preview - Client improvements + - `pyotherside.atexit()` - Logout previous session if adding an account that's already connected - Image provider: on failed conversion, way to show a "broken image" thumb? - Config file format diff --git a/src/python/html_filter.py b/src/python/html_filter.py index a95fe4a0..4269ec3d 100644 --- a/src/python/html_filter.py +++ b/src/python/html_filter.py @@ -51,16 +51,20 @@ class HtmlFilter: def filter_inline(self, html: str, outgoing: bool = False) -> str: text = self._inline_sanitizer.sanitize(html).strip("\n") - if not outgoing: - text = re.sub( - r"(^\s*>.*)", r'\1', text, - ) + if outgoing: + return text - return text + return re.sub( + r"(^\s*>.*)", r'\1', text, + ) def filter(self, html: str, outgoing: bool = False) -> str: html = self._sanitizer.sanitize(html) + + if outgoing: + return html + tree = etree.fromstring(html, parser=etree.HTMLParser()) if tree is None: @@ -77,14 +81,11 @@ class HtmlFilter: text = str(result, "utf-8").strip("\n") - if not outgoing: - text = re.sub( - r"<(p|br/?)>(\s*>.*)(!?)", - r'<\1>\2\3', - text, - ) - - return text + return re.sub( + r"<(p|br/?)>(\s*>.*)(!?)", + r'<\1>\2\3', + text, + ) def sanitize_settings(self, inline: bool = False) -> dict: