[evolution/gnome-3-20] EHTMLEditorView - Correct the new lines handling in quoted content



commit 623bbb16687967f8e6bf14553e3a847f2709a336
Author: Tomas Popela <tpopela redhat com>
Date:   Wed Mar 30 10:16:29 2016 +0200

    EHTMLEditorView - Correct the new lines handling in quoted content
    
    There were situations where an extra new line was added after every citation
    start and its end and also situations where new line could be removed from the
    original quoted content.

 e-util/e-html-editor-view.c |   75 +++++++++++++++++++++++++++----------------
 1 files changed, 47 insertions(+), 28 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 0c8b72f..10313da 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -7502,42 +7502,61 @@ parse_html_into_blocks (EHTMLEditorView *view,
                with_br = strstr (to_insert, "<br>");
                citation = strstr (to_insert, "##CITATION_");
                if (citation) {
-                       gchar *citation_mark;
+                       gboolean processed = FALSE;
 
-                       has_citation = TRUE;
-                       if (strstr (citation, "END##")) {
-                               ignore_next_br = TRUE;
-                               if (block)
-                                       append_new_block (parent, &block);
-                       } else {
-                               previously_had_empty_citation_start = TRUE;
-                       }
+                       while (!processed) {
+                               gchar *citation_mark;
+                               gboolean citation_start = TRUE;
 
-                       citation_end = strstr (citation + 2, "##");
-                       if (citation_end)
-                               rest = citation_end + 2;
+                               has_citation = TRUE;
+                               if (g_str_has_prefix (citation + 11, "END##")) {
+                                       citation_start = FALSE;
+                                       if (block)
+                                               append_new_block (parent, &block);
+                               } else
+                                       previously_had_empty_citation_start = TRUE;
 
-                       if (rest && *rest)
-                               previously_had_empty_citation_start = FALSE;
+                               citation_end = strstr (citation + 2, "##");
+                               if (citation_end)
+                                       rest = citation_end + 2;
 
-                       if (first_element)
-                               citation_was_first_element = TRUE;
+                               if (rest && *rest && !g_str_has_prefix (rest, "##CITATION_"))
+                                       previously_had_empty_citation_start = FALSE;
 
-                       if (block)
-                               append_new_block (parent, &block);
-                       else if (with_br && rest && !*rest && previously_had_empty_citation_start && 
ignore_next_br) {
-                               /* Insert an empty block for an empty blockquote */
-                               block = create_and_append_new_block (
-                                       selection, document, parent, block_template, "<br>");
-                               previously_had_empty_citation_start = FALSE;
-                       }
+                               if (first_element)
+                                       citation_was_first_element = TRUE;
 
-                       citation_mark = g_utf8_substring (
-                               citation, 0, g_utf8_pointer_to_offset (citation, rest));
+                               if (block)
+                                       append_new_block (parent, &block);
+                               else if (with_br && rest && !*rest &&
+                                        previously_had_empty_citation_start &&
+                                        ignore_next_br) {
+                                       /* Insert an empty block for an empty blockquote */
+                                       block = create_and_append_new_block (
+                                               selection, document, parent, block_template, "<br>");
+                                       previously_had_empty_citation_start = FALSE;
+                               }
+
+                               if (citation_start)
+                                       ignore_next_br = TRUE;
+
+                               citation_mark = g_utf8_substring (
+                                       citation,
+                                       0,
+                                       g_utf8_pointer_to_offset (citation, rest));
 
-                       append_citation_mark (document, parent, citation_mark);
+                               append_citation_mark (document, parent, citation_mark);
 
-                       g_free (citation_mark);
+                               g_free (citation_mark);
+
+                               if (rest && *rest) {
+                                       if (g_str_has_prefix (rest, "##CITATION_"))
+                                               citation = rest;
+                                       else
+                                               processed = TRUE;
+                               } else
+                                       processed = TRUE;
+                       }
                } else {
                        rest = with_br ?
                                to_insert + 4 + (with_br - to_insert) : to_insert;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]