From c3dd20fc745b0f4c8fa402052182b5383afbb7f8 Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 30 Apr 2014 00:43:21 +0200 Subject: Fix #2510 (link displayed twice in xhtml-im) - also, fix the /xhtml command that was nesting one too many --- src/tabs/basetabs.py | 2 -- src/xhtml.py | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py index ed40ce4a..f16e3f93 100644 --- a/src/tabs/basetabs.py +++ b/src/tabs/basetabs.py @@ -556,8 +556,6 @@ class ChatTab(Tab): return try: body = xhtml.clean_text(xhtml.xhtml_to_poezio_colors(arg)) - # The element is the only allowable child of the - arg = "%s" % (arg,) ET.fromstring(arg) except: self.core.information('Could not send custom xhtml', 'Error') diff --git a/src/xhtml.py b/src/xhtml.py index ed45ff53..33a89b5e 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -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('”') -- cgit v1.2.3