From 9f8bdfc6fb4c18e121e7a8c1c2eef1cf5c411fc1 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 7 Sep 2019 01:28:02 -0400 Subject: [PATCH] Fix html quote regex Also allow quoting in title, e.g. "# > blah blah blah" --- TODO.md | 1 - src/python/html_filter.py | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index 814415f1..b050fc18 100644 --- a/TODO.md +++ b/TODO.md @@ -12,7 +12,6 @@ - Fixes - `minutesBetween()` for 13:13:58 and 14:15:07 - - `# > quote` doesn't color - Pressing backspace in composer sometimes doesn't work - Message order isn't preserved when sending a first message in a E2E room, then while keys are being shared sending one with another account, diff --git a/src/python/html_filter.py b/src/python/html_filter.py index 41c06f05..52f6f165 100644 --- a/src/python/html_filter.py +++ b/src/python/html_filter.py @@ -20,6 +20,12 @@ class HtmlFilter: r"(?Pmagnet:\?xt=urn:[a-z0-9]+:.+)(?P)", ]] + inline_quote_regex = re.compile(r"(^\s*>.*)") + + quote_regex = re.compile( + r"(^|

|
|)(\s*>.*?)(

|
||$)", + ) + def __init__(self) -> None: self._sanitizer = Sanitizer(self.sanitize_settings()) @@ -55,8 +61,8 @@ class HtmlFilter: if outgoing: return text - return re.sub( - r"(^\s*>.*)", r'\1', text, + return self.inline_quote_regex.sub( + r'\1', text, ) @@ -66,10 +72,8 @@ class HtmlFilter: if outgoing: return html - return re.sub( - r"<(p|br/?)>(\s*>.*)(!?)", - r'<\1>\2\3', - html, + return self.quote_regex.sub( + r'\1\2\3', html, re.MULTILINE, )