From 42fc48adfe8e4fcbb94027a2039e05dc88cbe594 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 23 Jun 2018 19:57:11 +0300 Subject: [PATCH] Replace tabs with 4 spaces Telegram doesn't allow tabs and was converting them to a space. The local formatter needs to account for all of telegram's formatting rules as otherwise the content-based duplicate checker will fail. --- mautrix_telegram/formatter/from_matrix.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mautrix_telegram/formatter/from_matrix.py b/mautrix_telegram/formatter/from_matrix.py index 2c3755d2..ecdf22e2 100644 --- a/mautrix_telegram/formatter/from_matrix.py +++ b/mautrix_telegram/formatter/from_matrix.py @@ -264,6 +264,7 @@ def matrix_to_telegram(html: str) -> Tuple[str, List[TypeMessageEntity]]: try: parser = MatrixParser() html = command_regex.sub(r"\1", html) + html = html.replace("\t", " " * 4) html = not_command_regex.sub(r"\1", html) if should_bridge_plaintext_highlights: html = plain_mention_regex.sub(plain_mention_to_html, html) @@ -299,6 +300,7 @@ def matrix_reply_to_telegram(content: dict, tg_space: int, room_id: Optional[str def matrix_text_to_telegram(text: str) -> Tuple[str, List[TypeMessageEntity]]: text = command_regex.sub(r"/\1", text) + text = text.replace("\t", " " * 4) text = not_command_regex.sub(r"\1", text) if should_bridge_plaintext_highlights: entities, pmr_replacer = plain_mention_to_text()