summaryrefslogtreecommitdiff
path: root/src/xhtml.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-03-29 20:36:02 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-03-29 20:36:02 +0200
commitba02b51554e2125d54de4b748838b9b0495df1e4 (patch)
treeb8ae8f53c89898abbd3220c8aaeb2f74a89b4802 /src/xhtml.py
parenta0248d4324faec7fd3d3ef0bee1f9cf86a33c08e (diff)
downloadpoezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.gz
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.bz2
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.xz
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.zip
Convert html markup received in xhtml_im elements to poezio colors
and use that as the body
Diffstat (limited to 'src/xhtml.py')
-rw-r--r--src/xhtml.py21
1 files changed, 21 insertions, 0 deletions
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: