comparison src/gtkimhtml.c @ 9071:2233d33b2285

[gaim-migrate @ 9847] This fixes the bug where other GtkTextTags (e.g. from gtkspell) would confuse us slightly and make us end and restart tags at seemingly random places. I.e. we would do like </b><b> for seemingly no good reason. This caused the double link bug on protocols where links didn't have descriptions. <a href="http://foo.bar">http://foo.bar</a> might be split into two links. On AIM that doesn't matter, but on Yahoo and MSN it does. I might have implemented this slightly differently, but I'm assuming that datallah tested this good and so I don't want to mess with it if it works. Oh yeah, did i mention datallah wrote this patch? Thanks! People might want to test this well and make sure we still generate good html. This is probably one of the most important functions in imhtml, with gtk_imhtml_insert_html_at_iter being the other one. The latter parses html and inserts it into a GtkTextBuffer, while the function this patch patches takes a GtkTextBuffer (or a piece of one) and turns it into html. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Wed, 26 May 2004 05:25:06 +0000
parents 960bb3bd9ba6
children f06013ff80d9
comparison
equal deleted inserted replaced
9070:f13172eed3ad 9071:2233d33b2285
3766 3766
3767 gtk_text_iter_order(start, end); 3767 gtk_text_iter_order(start, end);
3768 nextiter = iter = *start; 3768 nextiter = iter = *start;
3769 gtk_text_iter_forward_char(&nextiter); 3769 gtk_text_iter_forward_char(&nextiter);
3770 3770
3771 /* First add the tags that are already in progress */ 3771 /* First add the tags that are already in progress (we don't care about non-printing tags)*/
3772 tags = gtk_text_iter_get_tags(start); 3772 tags = gtk_text_iter_get_tags(start);
3773 3773
3774 for (sl = tags; sl; sl = sl->next) { 3774 for (sl = tags; sl; sl = sl->next) {
3775 tag = sl->data; 3775 tag = sl->data;
3776 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { 3776 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) {
3777 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag))); 3777 if (strlen(tag_to_html_end(tag)) > 0)
3778 g_string_append(str, tag_to_html_start(tag));
3778 g_queue_push_tail(q, tag); 3779 g_queue_push_tail(q, tag);
3779 } 3780 }
3780 } 3781 }
3781 g_slist_free(tags); 3782 g_slist_free(tags);
3782 3783
3785 tags = gtk_text_iter_get_tags(&iter); 3786 tags = gtk_text_iter_get_tags(&iter);
3786 3787
3787 for (sl = tags; sl; sl = sl->next) { 3788 for (sl = tags; sl; sl = sl->next) {
3788 tag = sl->data; 3789 tag = sl->data;
3789 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { 3790 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) {
3790 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tag))); 3791 if (strlen(tag_to_html_end(tag)) > 0)
3792 g_string_append(str, tag_to_html_start(tag));
3791 g_queue_push_tail(q, tag); 3793 g_queue_push_tail(q, tag);
3792 } 3794 }
3793 } 3795 }
3794 3796
3795 3797
3796 if (c == 0xFFFC) { 3798 if (c == 0xFFFC) {
3797 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); 3799 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter);
3798 char *text = NULL; 3800 if (anchor) {
3799 if (anchor) 3801 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext");
3800 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); 3802 if (text)
3801 if (text) 3803 str = g_string_append(str, text);
3802 str = g_string_append(str, text); 3804 }
3803 } else if (c == '<') { 3805 } else if (c == '<') {
3804 str = g_string_append(str, "&lt;"); 3806 str = g_string_append(str, "&lt;");
3805 } else if (c == '>') { 3807 } else if (c == '>') {
3806 str = g_string_append(str, "&gt;"); 3808 str = g_string_append(str, "&gt;");
3807 } else if (c == '&') { 3809 } else if (c == '&') {
3815 } 3817 }
3816 3818
3817 tags = g_slist_reverse(tags); 3819 tags = g_slist_reverse(tags);
3818 for (sl = tags; sl; sl = sl->next) { 3820 for (sl = tags; sl; sl = sl->next) {
3819 tag = sl->data; 3821 tag = sl->data;
3820 if (tag_ends_here(tag, &iter, &nextiter)) { 3822 /** don't worry about non-printing tags ending */
3823 if (tag_ends_here(tag, &iter, &nextiter) && strlen(tag_to_html_end(tag)) > 0) {
3821 3824
3822 GtkTextTag *tmp; 3825 GtkTextTag *tmp;
3823 3826
3824 while ((tmp = g_queue_pop_tail(q)) != tag) { 3827 while ((tmp = g_queue_pop_tail(q)) != tag) {
3825 if (tmp == NULL) 3828 if (tmp == NULL)
3826 break; 3829 break;
3827 3830
3828 if (!tag_ends_here(tmp, &iter, &nextiter)) 3831 if (!tag_ends_here(tmp, &iter, &nextiter) && strlen(tag_to_html_end(tmp)) > 0)
3829 g_queue_push_tail(r, tmp); 3832 g_queue_push_tail(r, tmp);
3830 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); 3833 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp)));
3831 } 3834 }
3832 3835
3833 if (tmp == NULL) 3836 if (tmp == NULL)