diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2006-04-24 19:00:58 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2006-04-24 19:00:58 (GMT) |
commit | 13b22192236565738f2105866659327b1784099d (patch) | |
tree | 66b769c14206479b8040e00d6bb75b2f66b5bd69 /chat | |
parent | 9f0348c00264a697204550a463abfdabfb6df5a6 (diff) |
Fix a serialization bug (inversed tags)
Diffstat (limited to 'chat')
-rw-r--r-- | chat/richtext.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/chat/richtext.py b/chat/richtext.py index ecf49e4..6c6c592 100644 --- a/chat/richtext.py +++ b/chat/richtext.py @@ -128,24 +128,24 @@ class RichTextSerializer: if not next_it.forward_to_tag_toggle(None): next_it = buf.get_end_iter() - reopen_tags = [] + tags_to_reopen = [] + for tag in it.get_toggled_tags(False): while 1: open_tag = self._open_tags.pop() - if open_tag != tag: - xml += self.serialize_tag_end(open_tag) - reopen_tags.append(open_tag) - else: - xml += self.serialize_tag_end(tag) - break - - for tag in reopen_tags + it.get_toggled_tags(True): + xml += self.serialize_tag_end(tag) + if open_tag == tag: + break + tags_to_reopen.append(open_tag) + + for tag in tags_to_reopen + it.get_toggled_tags(True): self._open_tags.append(tag) xml += self.serialize_tag_start(tag) xml += buf.get_text(it, next_it) if next_it.is_end(): + self._open_tags.reverse() for tag in self._open_tags: xml += self.serialize_tag_end(tag) @@ -171,8 +171,15 @@ if __name__ == "__main__": vbox = gtk.VBox() rich_buf = RichTextBuffer() - - xml_string = "<richtext><bold><italic>Hello</italic>World</bold></richtext>" + + xml_string = "<richtext>" + + #xml_string += "<bold><italic>Test</italic>one</bold>\n" + xml_string += "<bold><italic>Test two</italic></bold>" + + xml_string += "</richtext>" + + RichTextSerializer().deserialize(xml_string, rich_buf) view = gtk.TextView(rich_buf) |