diff --git a/src/xhtml.py b/src/xhtml.py
index eb0db829..fd50bb11 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -250,7 +250,7 @@ def xhtml_to_poezio_colors(text):
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'], elem.text)
+ message += '\x19u%s\x19o (%s)' % (elem.attrib['href'].strip(), elem.text.strip())
else:
message += '\x19u' + elem.text + '\x19o'
elif elem.tag == '{http://www.w3.org/1999/xhtml}blockquote':
@@ -265,7 +265,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'], elem.attrib['alt'])
+ message += '%s (%s)' % (elem.attrib['src'].strip(), elem.attrib['alt'].strip())
else:
message += elem.attrib['src']
elif elem.tag == '{http://www.w3.org/1999/xhtml}li':
@@ -289,7 +289,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
+ message += elem.text.strip()
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'
@@ -311,7 +311,7 @@ def xhtml_to_poezio_colors(text):
message += ' [' + elem.attrib['title'] + ']'
if elem.tail:
- message += elem.tail
+ message += elem.tail.strip()
return message