Fix #2510 (link displayed twice in xhtml-im)

- also, fix the /xhtml command that was nesting one <body/> too many
This commit is contained in:
mathieui 2014-04-30 00:43:21 +02:00
parent 5f0afab060
commit c3dd20fc74
2 changed files with 7 additions and 3 deletions

View file

@ -556,8 +556,6 @@ class ChatTab(Tab):
return
try:
body = xhtml.clean_text(xhtml.xhtml_to_poezio_colors(arg))
# The <body /> element is the only allowable child of the <xhtm-im>
arg = "<body xmlns='http://www.w3.org/1999/xhtml'>%s</body>" % (arg,)
ET.fromstring(arg)
except:
self.core.information('Could not send custom xhtml', 'Error')

View file

@ -287,6 +287,7 @@ class XHTMLHandler(sax.ContentHandler):
self.attrs = []
self.list_state = []
self.is_pre = False
self.a_start = 0
@property
def result(self):
@ -318,6 +319,7 @@ class XHTMLHandler(sax.ContentHandler):
name = name[1]
if name == 'a':
self.append_formatting('\x19u')
self.a_start = len(self.builder)
elif name == 'blockquote':
builder.append('')
elif name == 'br':
@ -363,7 +365,11 @@ class XHTMLHandler(sax.ContentHandler):
if name == 'a':
self.pop_formatting()
if 'href' in attrs:
# do not display the link twice
text_elements = filter(lambda x: not x.startswith('\x19'),
self.builder[self.a_start:])
link_text = ''.join(text_elements).strip()
if 'href' in attrs and attrs['href'] != link_text:
builder.append(' (%s)' % trim(attrs['href']))
elif name == 'blockquote':
builder.append('')