diff --git a/CHANGELOG.md b/CHANGELOG.md index 530c0b3e..edf70259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.15.1 (2022-03-23) + +* Added `ensure_has_html` method for `TextMessageEventContent` to generate + a HTML `formatted_body` from the plaintext `body` correctly (i.e. escaping + HTML and replacing newlines). + ## v0.15.0 (2022-03-16) * **Breaking change** Removed Python 3.7 support. diff --git a/mautrix/__init__.py b/mautrix/__init__.py index 401a2d72..2446a694 100644 --- a/mautrix/__init__.py +++ b/mautrix/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.15.0" +__version__ = "0.15.1" __author__ = "Tulir Asokan " __all__ = [ "api", diff --git a/mautrix/types/event/message.py b/mautrix/types/event/message.py index 2fcbcdf9..6285b2e0 100644 --- a/mautrix/types/event/message.py +++ b/mautrix/types/event/message.py @@ -342,15 +342,18 @@ def set_reply( super().set_reply(reply_to) if isinstance(reply_to, str): return - if not self.formatted_body or len(self.formatted_body) == 0 or self.format != Format.HTML: - self.format = Format.HTML - self.formatted_body = escape(self.body).replace("\n", "
") if isinstance(reply_to, MessageEvent): + self.ensure_has_html() self.formatted_body = ( reply_to.make_reply_fallback_html(displayname) + self.formatted_body ) self.body = reply_to.make_reply_fallback_text(displayname) + self.body + def ensure_has_html(self) -> None: + if not self.formatted_body or self.format != Format.HTML: + self.format = Format.HTML + self.formatted_body = escape(self.body).replace("\n", "
") + def formatted(self, format: Format) -> Optional[str]: if self.format == format: return self.formatted_body