From 632175b79fb4d15a2358fc0604fe1bb85a076188 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 11 Nov 2011 23:55:31 +0100 Subject: Fix the xhtml parser (do not add wrong colors) --- src/xhtml.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/xhtml.py b/src/xhtml.py index 99e0bf01..e7a045fa 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -258,7 +258,9 @@ def xhtml_to_poezio_colors(text): if key == 'background-color': pass#shell += '\x191' elif key == 'color': - shell += '\x19%d}' % get_color(value) + color = get_color(value) + if color != -1: + shell += '\x19%d}' % color elif key == 'font-style': shell += '\x19i' elif key == 'font-weight': -- cgit v1.2.3 From 4d5e2d21a464e6af56e5c968490c2dea61670011 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 12 Nov 2011 00:00:17 +0100 Subject: /xhtml command, Fixes #2237 --- src/tabs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tabs.py b/src/tabs.py index e0419fda..02678e7e 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -46,6 +46,7 @@ from os import getenv, path from logger import logger from datetime import datetime, timedelta +from xml.etree import cElementTree as ET SHOW_NAME = { 'dnd': _('busy'), @@ -308,6 +309,7 @@ class ChatTab(Tab): self.commands['say'] = (self.command_say, _("""Usage: /say \nSay: Just send the message. Useful if you want your message to begin with a '/'."""), None) + self.commands['xhtml'] = (self.command_xhtml, _("Usage: /xhtml \nXHTML: Send custom XHTML."), None) self.chat_state = None self.update_commands() @@ -339,6 +341,29 @@ class ChatTab(Tab): self.command_say(xhtml.convert_simple_to_full_colors(txt)) self.cancel_paused_delay() + def command_xhtml(self, arg): + """" + /xhtml + """ + if not arg: + return + try: + body = xhtml.clean_text(xhtml.xhtml_to_poezio_colors(arg)) + ET.fromstring(arg) + except: + self.core.information('Could not send custom xhtml', 'Error') + return + + msg = self.core.xmpp.make_message(self.get_name()) + msg['body'] = body + msg['xhtml_im'] = arg + if isinstance(self, MucTab): + msg['type'] = 'groupchat' + if isinstance(self, ConversationTab): + self.core.add_message_to_text_buffer(self._text_buffer, body, None, self.core.own_nick) + self.refresh() + msg.send() + def send_chat_state(self, state, always_send=False): """ Send an empty chatstate message -- cgit v1.2.3 From a6bcb244f71996de6b873a4148bff081e5fb55eb Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 12 Nov 2011 00:01:47 +0100 Subject: Doc for /xhtml --- doc/en/usage.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/en/usage.txt b/doc/en/usage.txt index 7671c628..30bdf886 100644 --- a/doc/en/usage.txt +++ b/doc/en/usage.txt @@ -246,6 +246,8 @@ These commands will work in any conversation tab (MultiUserChat, Private, or to begin with a _/_). Note that you can also send message starting with a _/_ by starting it with _//_. +*/xhtml *:: Send a custom xhtml message to the current tab. + MultiUserChat tab commands ~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3