From cb1abbd9451af2062cc8f71f51e0ba903fa2f749 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 4 Apr 2011 19:19:27 +0200 Subject: Disable xhtml-im by default --- data/default_config.cfg | 10 ++++++++++ src/xhtml.py | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/data/default_config.cfg b/data/default_config.cfg index 42b27cb6..794ea91d 100644 --- a/data/default_config.cfg +++ b/data/default_config.cfg @@ -51,6 +51,16 @@ after_completion = , # highlighted if said by someone on a room highlight_on = +# XHTML-IM is an XMPP extension letting users send messages +# containing XHTML and CSS formating. We can use this to make +# colored text for example. +# It is disabled by default because this is only in an experimental +# state: you could miss some part of a message (mainly the URL) +# but you can still send colored messages. You just won’t be able te see +# the colors, though +# Set to true if you want to see colored messages +enable_xhtml_im = false + # Set a number for this setting. # The join OR status-change notices will be # displayed according to this number. diff --git a/src/xhtml.py b/src/xhtml.py index 55582066..a9f0af60 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -26,11 +26,11 @@ poezio colors to xhtml code import re import subprocess +from config import config import logging log = logging.getLogger(__name__) - shell_colors_re = re.compile(r'(\[(?:\d+;)*(?:\d+m))') start_indent_re = re.compile(r'\[0;30m\[0;37m ') newline_indent_re = re.compile('\n\[0;37m ') @@ -41,14 +41,15 @@ def get_body_from_message_stanza(message): poezio colors if there's an xhtml_im element, or the body (without any color) otherwise """ - xhtml_body = message['xhtml_im'] - if xhtml_body: - try: - shell_body = xhtml_code_to_shell_colors(xhtml_body) - except OSError: - log.error('html parsing failed') - else: - return shell_colors_to_poezio_colors(shell_body) + if config.get('enable_xhtml_im', 'false') == 'true': + xhtml_body = message['xhtml_im'] + if xhtml_body: + try: + shell_body = xhtml_code_to_shell_colors(xhtml_body) + except OSError: + log.error('html parsing failed') + else: + return shell_colors_to_poezio_colors(shell_body) return message['body'] def clean_text(string): @@ -133,7 +134,7 @@ def shell_colors_to_poezio_colors(string): elif num == 1: res += '\x19b' elif num >= 31 and num <= 37: - res += '\x19%d' % (num-30,) + res += '\x19%d' % ((num-30)%7,) return res def remove_elinks_indent(string): lines = string.split('\n') -- cgit v1.2.3