summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-24 00:02:09 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-24 00:02:09 +0200
commitc7a0659a1d4c652b13852cc8b547c25fe715645a (patch)
treefdcf6e0a77ef4a1e7cb3320bc79802816fab4b1b /src
parent1ff421075def58b31f06f32a481ab4d6f4c67fa8 (diff)
parent6f1481e830e76ac9bb434cca0f38343d22ebd644 (diff)
downloadpoezio-c7a0659a1d4c652b13852cc8b547c25fe715645a.tar.gz
poezio-c7a0659a1d4c652b13852cc8b547c25fe715645a.tar.bz2
poezio-c7a0659a1d4c652b13852cc8b547c25fe715645a.tar.xz
poezio-c7a0659a1d4c652b13852cc8b547c25fe715645a.zip
merge
Diffstat (limited to 'src')
-rw-r--r--src/xhtml.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/xhtml.py b/src/xhtml.py
index d25500f0..deb4c54f 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -174,6 +174,7 @@ colors = {
log = logging.getLogger(__name__)
+
def get_body_from_message_stanza(message):
"""
Returns a string with xhtml markups converted to
@@ -216,6 +217,8 @@ def xhtml_to_poezio_colors(text):
shell = ''
rules = css.split(';')
for rule in rules:
+ if ':' not in rule:
+ continue
key, value = rule.split(':', 1)
key = key.strip()
value = value.strip()
@@ -239,13 +242,16 @@ def xhtml_to_poezio_colors(text):
shell += '\x19a'
return shell
+ def trim(string):
+ return re.sub(whitespace_re, ' ', string)
+
log.debug(text)
xml = ET.fromstring(text)
message = ''
for elem in xml.iter():
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)' % (elem.attrib['href'].strip(), elem.text.strip())
+ message += '\x19u%s\x19o (%s)' % (trim(elem.attrib['href']), trim(elem.text))
else:
message += '\x19u' + elem.text + '\x19o'
elif elem.tag == '{http://www.w3.org/1999/xhtml}blockquote':
@@ -260,7 +266,7 @@ def xhtml_to_poezio_colors(text):
message += '\x19i'
elif elem.tag == '{http://www.w3.org/1999/xhtml}img' and 'src' in elem.attrib:
if 'alt' in elem.attrib:
- message += '%s (%s)' % (elem.attrib['src'].strip(), elem.attrib['alt'].strip())
+ message += '%s (%s)' % (trim(elem.attrib['src']), trim(elem.attrib['alt']))
else:
message += elem.attrib['src']
elif elem.tag == '{http://www.w3.org/1999/xhtml}li':
@@ -284,7 +290,7 @@ def xhtml_to_poezio_colors(text):
if (elem.text and elem.tag != '{http://www.w3.org/1999/xhtml}a'
and elem.tag != '{http://www.w3.org/1999/xhtml}br'
and elem.tag != '{http://www.w3.org/1999/xhtml}img'):
- message += elem.text.replace('\n', '')
+ message += trim(elem.text)
if ('style' in elem.attrib and elem.tag != '{http://www.w3.org/1999/xhtml}br'
and elem.tag != '{http://www.w3.org/1999/xhtml}em'
@@ -306,7 +312,7 @@ def xhtml_to_poezio_colors(text):
message += ' [' + elem.attrib['title'] + ']'
if elem.tail:
- message += elem.tail.strip()
+ message += trim(elem.tail)
return message