From ba02b51554e2125d54de4b748838b9b0495df1e4 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 29 Mar 2011 20:36:02 +0200 Subject: Convert html markup received in xhtml_im elements to poezio colors and use that as the body --- src/xhtml.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/xhtml.py') diff --git a/src/xhtml.py b/src/xhtml.py index 71a3ad3e..5f0e9927 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -26,8 +26,29 @@ poezio colors to xhtml code import re import subprocess +import logging + +log = logging.getLogger(__name__) + + shell_colors_re = re.compile(r'(\[(?:\d+;)*(?:\d+m))') +def get_body_from_message_stanza(message): + """ + Returns a string with xhtml markups converted to + 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) + return message['body'] + def shell_colors_to_poezio_colors(string): """ 'shell colors' means something like: -- cgit v1.2.3