summaryrefslogtreecommitdiff
path: root/src/xhtml.py
diff options
context:
space:
mode:
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: