Fix html quote regex

Also allow quoting in title, e.g. "# > blah blah blah"
This commit is contained in:
miruka 2019-09-07 01:28:02 -04:00
parent 07fb63aa1e
commit 9f8bdfc6fb
2 changed files with 10 additions and 7 deletions

View File

@ -12,7 +12,6 @@
- Fixes - Fixes
- `minutesBetween()` for 13:13:58 and 14:15:07 - `minutesBetween()` for 13:13:58 and 14:15:07
- `# > quote` doesn't color
- Pressing backspace in composer sometimes doesn't work - Pressing backspace in composer sometimes doesn't work
- Message order isn't preserved when sending a first message in a E2E - 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, room, then while keys are being shared sending one with another account,

View File

@ -20,6 +20,12 @@ class HtmlFilter:
r"(?P<body>magnet:\?xt=urn:[a-z0-9]+:.+)(?P<host>)", r"(?P<body>magnet:\?xt=urn:[a-z0-9]+:.+)(?P<host>)",
]] ]]
inline_quote_regex = re.compile(r"(^\s*&gt;.*)")
quote_regex = re.compile(
r"(^|<p/?>|<br/?>|<h\d/?>)(\s*&gt;.*?)(<p/?>|<br/?>|<h\d/?>|$)",
)
def __init__(self) -> None: def __init__(self) -> None:
self._sanitizer = Sanitizer(self.sanitize_settings()) self._sanitizer = Sanitizer(self.sanitize_settings())
@ -55,8 +61,8 @@ class HtmlFilter:
if outgoing: if outgoing:
return text return text
return re.sub( return self.inline_quote_regex.sub(
r"(^\s*&gt;.*)", r'<span class="quote">\1</span>', text, r'<span class="quote">\1</span>', text,
) )
@ -66,10 +72,8 @@ class HtmlFilter:
if outgoing: if outgoing:
return html return html
return re.sub( return self.quote_regex.sub(
r"<(p|br/?)>(\s*&gt;.*)(!?</?(?:br|p)/?>)", r'\1<span class="quote">\2</span>\3', html, re.MULTILINE,
r'<\1><span class="quote">\2</span>\3',
html,
) )