diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-10-29 07:20:10 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-10-29 07:20:10 +0200 |
commit | 0451127ff8a1b96772b58ff9e246621d0df4c99e (patch) | |
tree | 00a650ba6f909ee1977bedeb3001798f39a38a0a /src/xhtml.py | |
parent | b98880b5269764ad69bb19262790d27b2575b174 (diff) | |
parent | aa6738800d67c5061d7e551b3d896f3366296045 (diff) | |
download | poezio-0451127ff8a1b96772b58ff9e246621d0df4c99e.tar.gz poezio-0451127ff8a1b96772b58ff9e246621d0df4c99e.tar.bz2 poezio-0451127ff8a1b96772b58ff9e246621d0df4c99e.tar.xz poezio-0451127ff8a1b96772b58ff9e246621d0df4c99e.zip |
Merge branch 'master' into plugins
Diffstat (limited to 'src/xhtml.py')
-rw-r--r-- | src/xhtml.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/xhtml.py b/src/xhtml.py index 9bb2705d..38239d18 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -176,6 +176,8 @@ log = logging.getLogger(__name__) whitespace_re = re.compile(r'\s+') +xhtml_attr_re = re.compile(r'\x19\d{0,3}\}|\x19[buaio]') + def get_body_from_message_stanza(message): """ Returns a string with xhtml markups converted to @@ -249,7 +251,11 @@ def xhtml_to_poezio_colors(text): log.debug(text) xml = ET.fromstring(text) message = '' - for elem in xml.iter(): + if version_info[1] == 2: + elems = xml.iter() + else: + elems = xml.getiterator() + for elem in elems: if elem.tag == '{http://www.w3.org/1999/xhtml}a': if 'href' in elem.attrib and elem.attrib['href'] != elem.text: message += '\x19u%s\x19o (%s)' % (trim(elem.attrib['href']), trim(elem.text)) @@ -317,9 +323,18 @@ def xhtml_to_poezio_colors(text): return message -def clean_text(string): +def clean_text(s): + """ + Remove all xhtml-im attributes (\x19etc) from the string with the + complete color format, i.e \x19xxx} + """ + s = re.sub(xhtml_attr_re, "", s) + return s + +def clean_text_simple(string): """ - Remove all \x19 from the string + Remove all \x19 from the string formatted with simple colors: + \x198 """ pos = string.find('\x19') while pos != -1: |