From 127d946dffef95579d68cb195ec0b06f6032fcd9 Mon Sep 17 00:00:00 2001 From: Tomas Popela Date: Tue, 15 Jul 2014 10:52:20 +0200 Subject: EHTMLEditorView - Don't lose the empty lines when converting HTML to plain text Namely don't lose the new line on the beginning or on the end of processed content and also on the lines with zero width space character. --- e-util/e-html-editor-view.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c index 3ab77673fc..0c5c04147e 100644 --- a/e-util/e-html-editor-view.c +++ b/e-util/e-html-editor-view.c @@ -3419,6 +3419,7 @@ parse_html_into_paragraphs (EHTMLEditorView *view, GString *start, *end; gboolean ignore_next_br = FALSE; GRegex *regex_nbsp = NULL, *regex_links = NULL; + gboolean first_element = TRUE; webkit_dom_html_element_set_inner_html ( WEBKIT_DOM_HTML_ELEMENT (blockquote), "", NULL); @@ -3540,23 +3541,38 @@ parse_html_into_paragraphs (EHTMLEditorView *view, *rest_to_insert ? rest_to_insert : "
", NULL); + if (g_strcmp0 (rest_to_insert, UNICODE_ZERO_WIDTH_SPACE) == 0) + webkit_dom_html_element_set_inner_html ( + WEBKIT_DOM_HTML_ELEMENT (paragraph), "
", NULL); + webkit_dom_node_append_child ( WEBKIT_DOM_NODE (blockquote), WEBKIT_DOM_NODE (paragraph), NULL); g_free (rest_to_insert); + } else if (rest && !*rest && first_element) { + webkit_dom_html_element_set_inner_html ( + WEBKIT_DOM_HTML_ELEMENT (paragraph), + "
", + NULL); + + webkit_dom_node_append_child ( + WEBKIT_DOM_NODE (blockquote), + WEBKIT_DOM_NODE (paragraph), + NULL); } if (citation_end) ignore_next_br = TRUE; + first_element = FALSE; prev_br = next_br; next_br = strstr (prev_br + 4, "
"); g_free (to_insert); } - if (g_utf8_strlen (prev_br, -1) > 0 && (g_strcmp0 (prev_br, "
") != 0)) { + if (g_utf8_strlen (prev_br, -1) > 0) { gchar *truncated = g_strdup ( g_str_has_prefix (prev_br, "
") ? prev_br + 4 : prev_br); gchar *rest_to_insert; @@ -3598,9 +3614,16 @@ parse_html_into_paragraphs (EHTMLEditorView *view, webkit_dom_html_element_set_inner_html ( WEBKIT_DOM_HTML_ELEMENT (paragraph), - *rest_to_insert ? rest_to_insert : "
", + *rest_to_insert ? + rest_to_insert : "
", NULL); + if (g_strcmp0 (rest_to_insert, UNICODE_ZERO_WIDTH_SPACE) == 0) + webkit_dom_html_element_set_inner_html ( + WEBKIT_DOM_HTML_ELEMENT (paragraph), + "
", + NULL); + webkit_dom_node_append_child ( WEBKIT_DOM_NODE (blockquote), WEBKIT_DOM_NODE (paragraph), -- cgit v1.2.3