diff --git a/mautrix_telegram/formatter/from_matrix/__init__.py b/mautrix_telegram/formatter/from_matrix/__init__.py index f8f50ea2..47eafaef 100644 --- a/mautrix_telegram/formatter/from_matrix/__init__.py +++ b/mautrix_telegram/formatter/from_matrix/__init__.py @@ -78,7 +78,7 @@ def matrix_to_telegram(html: str) -> ParsedMessage: html = add_surrogates(html) text, entities = parse_html(add_surrogates(html)) - text = remove_surrogates(html.strip()) + text = remove_surrogates(text.strip()) text, entities = cut_long_message(text, entities) return text, entities diff --git a/mautrix_telegram/formatter/from_matrix/parser_common.py b/mautrix_telegram/formatter/from_matrix/parser_common.py index e83bce7e..6db8dc3a 100644 --- a/mautrix_telegram/formatter/from_matrix/parser_common.py +++ b/mautrix_telegram/formatter/from_matrix/parser_common.py @@ -15,17 +15,17 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import re -from typing import List, Tuple +from typing import List, Tuple, Pattern from telethon.tl.types import TypeMessageEntity class MatrixParserCommon: - mention_regex = re.compile("https://matrix.to/#/(@.+:.+)") - room_regex = re.compile("https://matrix.to/#/(#.+:.+)") + mention_regex = re.compile("https://matrix.to/#/(@.+:.+)") # type: Pattern + room_regex = re.compile("https://matrix.to/#/(#.+:.+)") # type: Pattern block_tags = ("br", "p", "pre", "blockquote", "ol", "ul", "li", "h1", "h2", "h3", "h4", "h5", "h6", - "div", "hr", "table") + "div", "hr", "table") # type: Tuple[str, ...] ParsedMessage = Tuple[str, List[TypeMessageEntity]] diff --git a/mautrix_telegram/formatter/from_matrix/parser_htmlparser.py b/mautrix_telegram/formatter/from_matrix/parser_htmlparser.py index ad3a2a84..4de0cba1 100644 --- a/mautrix_telegram/formatter/from_matrix/parser_htmlparser.py +++ b/mautrix_telegram/formatter/from_matrix/parser_htmlparser.py @@ -38,7 +38,7 @@ def parse_html(html: str) -> ParsedMessage: class MatrixParser(HTMLParser, MatrixParserCommon): def __init__(self): - super(HTMLParser, self).__init__() + super(MatrixParser, self).__init__() self.text = "" # type: str self.entities = [] # type: List[TypeMessageEntity] self._building_entities = {} # type: Dict[str, TypeMessageEntity] diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index a4f80776..a0488b91 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -789,9 +789,9 @@ class Portal: def _matrix_event_to_entities(event: dict) -> Tuple[str, Optional[List[TypeMessageEntity]]]: try: if event.get("format", None) == "org.matrix.custom.html": - message, entities = formatter.matrix_to_telegram(event["formatted_body"]) + message, entities = formatter.matrix_to_telegram(event.get("formatted_body", "")) else: - message, entities = formatter.matrix_text_to_telegram(event["body"]) + message, entities = formatter.matrix_text_to_telegram(event.get("body", "")) except KeyError: message, entities = None, None return message, entities