diff options
-rw-r--r-- | src/tabs.py | 10 | ||||
-rw-r--r-- | src/xhtml.py | 15 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/tabs.py b/src/tabs.py index 2b1b586a..cd9450a7 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -289,7 +289,7 @@ class ChatTab(Tab): for msg in self._room.messages[:-40:-1]: if not msg: continue - txt = msg.txt + txt = xhtml.clean_text(msg.txt) for char in char_we_dont_want: txt = txt.replace(char, ' ') for word in txt.split(): @@ -300,7 +300,7 @@ class ChatTab(Tab): def on_enter(self): txt = self.input.key_enter() if txt: - clean_text = xhtml.clean_text(txt) + clean_text = xhtml.clean_text_simple(txt) if not self.execute_command(clean_text): if txt.startswith('//'): txt = txt[1:] @@ -683,7 +683,7 @@ class MucTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text(line) + msg['body'] = xhtml.clean_text_simple(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: msg['chat_state'] = needed @@ -1075,7 +1075,7 @@ class PrivateTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text(line) + msg['body'] = xhtml.clean_text_simple(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' @@ -1746,7 +1746,7 @@ class ConversationTab(ChatTab): if line.find('\x19') == -1: msg['body'] = line else: - msg['body'] = xhtml.clean_text(line) + msg['body'] = xhtml.clean_text_simple(line) msg['xhtml_im'] = xhtml.poezio_colors_to_html(line) if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' diff --git a/src/xhtml.py b/src/xhtml.py index c14382b8..38239d18 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -176,6 +176,8 @@ log = logging.getLogger(__name__) whitespace_re = re.compile(r'\s+') +xhtml_attr_re = re.compile(r'\x19\d{0,3}\}|\x19[buaio]') + def get_body_from_message_stanza(message): """ Returns a string with xhtml markups converted to @@ -321,9 +323,18 @@ def xhtml_to_poezio_colors(text): return message -def clean_text(string): +def clean_text(s): + """ + Remove all xhtml-im attributes (\x19etc) from the string with the + complete color format, i.e \x19xxx} + """ + s = re.sub(xhtml_attr_re, "", s) + return s + +def clean_text_simple(string): """ - Remove all \x19 from the string + Remove all \x19 from the string formatted with simple colors: + \x198 """ pos = string.find('\x19') while pos != -1: |