Prevent sending xHTML if not needed.

This commit is contained in:
Julien Pivotto 2009-01-21 18:00:33 +00:00
parent 109c9d1004
commit 194b41cfba

View file

@ -221,7 +221,9 @@ class MessageTextView(gtk.TextView):
tags['bold'] = False tags['bold'] = False
iter = buffer.get_start_iter() iter = buffer.get_start_iter()
old = buffer.get_start_iter() old = buffer.get_start_iter()
texte = '' start, finish = buffer.get_bounds()
plaintext = buffer.get_text(start, finish, False)
text = ''
modified = False modified = False
def xhtml_special(text): def xhtml_special(text):
text = text.replace('<', '&lt;') text = text.replace('<', '&lt;')
@ -233,11 +235,11 @@ class MessageTextView(gtk.TextView):
tag_name = tag.get_property('name') tag_name = tag.get_property('name')
if tag_name not in self.begin_tags: if tag_name not in self.begin_tags:
continue continue
texte += self.begin_tags[tag_name] text += self.begin_tags[tag_name]
modified = True modified = True
while (iter.forward_to_tag_toggle(None) and not iter.is_end()): while (iter.forward_to_tag_toggle(None) and not iter.is_end()):
modified = True modified = True
texte += xhtml_special(buffer.get_text(old, iter)) text += xhtml_special(buffer.get_text(old, iter))
old.forward_to_tag_toggle(None) old.forward_to_tag_toggle(None)
new_tags = [] new_tags = []
old_tags = [] old_tags = []
@ -262,23 +264,24 @@ class MessageTextView(gtk.TextView):
end_tags.append(tag_name) end_tags.append(tag_name)
for tag in old_tags: for tag in old_tags:
texte += self.end_tags[tag] text += self.end_tags[tag]
for tag in end_tags: for tag in end_tags:
texte += self.end_tags[tag] text += self.end_tags[tag]
for tag in new_tags: for tag in new_tags:
texte += self.begin_tags[tag] text += self.begin_tags[tag]
for tag in old_tags: for tag in old_tags:
texte += self.begin_tags[tag] text += self.begin_tags[tag]
texte += xhtml_special(buffer.get_text(old, buffer.get_end_iter())) text += xhtml_special(buffer.get_text(old, buffer.get_end_iter()))
for tag in iter.get_toggled_tags(False): for tag in iter.get_toggled_tags(False):
tag_name = tag.get_property('name') tag_name = tag.get_property('name')
if tag_name not in self.end_tags: if tag_name not in self.end_tags:
continue continue
texte += self.end_tags[tag_name] text += self.end_tags[tag_name]
if modified: print text, plaintext
return '<p>' + self.make_clickable_urls(texte) + '</p>' if modified and text != plaintext:
return '<p>' + self.make_clickable_urls(text) + '</p>'
else: else:
return None return None