[evolution/449-support-markdown-in-composer] EMarkdownEditor: Implement signature-related EContentEditor methods



commit 033af1c31c0a0dfb8b10d60c6ed71b52e4843f80
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 10 15:31:10 2022 +0100

    EMarkdownEditor: Implement signature-related EContentEditor methods

 src/composer/e-composer-private.c           |   6 +-
 src/e-util/e-content-editor.c               |  40 +++++-
 src/e-util/e-content-editor.h               |   8 +-
 src/e-util/e-mail-signature-combo-box.c     |  22 +++-
 src/e-util/e-mail-signature-combo-box.h     |   3 +-
 src/e-util/e-markdown-editor.c              | 187 +++++++++++++++++++++++++++-
 src/e-util/test-mail-signatures.c           |   6 +-
 src/modules/webkit-editor/e-webkit-editor.c |  45 ++-----
 8 files changed, 262 insertions(+), 55 deletions(-)
---
diff --git a/src/composer/e-composer-private.c b/src/composer/e-composer-private.c
index a8aa56c65a..020ae6c442 100644
--- a/src/composer/e-composer-private.c
+++ b/src/composer/e-composer-private.c
@@ -734,13 +734,13 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
        EMsgComposer *composer = usd->composer;
        gchar *contents = NULL, *new_signature_id;
        gsize length = 0;
-       gboolean is_html;
+       EContentEditorMode editor_mode = E_CONTENT_EDITOR_MODE_UNKNOWN;
        GError *error = NULL;
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
 
        e_mail_signature_combo_box_load_selected_finish (
-               combo_box, result, &contents, &length, &is_html, &error);
+               combo_box, result, &contents, &length, &editor_mode, &error);
 
        /* FIXME Use an EAlert here. */
        if (error != NULL) {
@@ -765,7 +765,7 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
        new_signature_id = e_content_editor_insert_signature (
                cnt_editor,
                contents,
-               is_html,
+               editor_mode,
                usd->can_reposition_caret,
                gtk_combo_box_get_active_id (GTK_COMBO_BOX (combo_box)),
                &composer->priv->set_signature_from_message,
diff --git a/src/e-util/e-content-editor.c b/src/e-util/e-content-editor.c
index 61971e6867..f8b1722639 100644
--- a/src/e-util/e-content-editor.c
+++ b/src/e-util/e-content-editor.c
@@ -2457,7 +2457,7 @@ e_content_editor_take_last_error (EContentEditor *editor,
 gchar *
 e_content_editor_insert_signature (EContentEditor *editor,
                                    const gchar *content,
-                                   gboolean is_html,
+                                   EContentEditorMode editor_mode,
                                   gboolean can_reposition_caret,
                                    const gchar *signature_id,
                                    gboolean *set_signature_from_message,
@@ -2475,7 +2475,7 @@ e_content_editor_insert_signature (EContentEditor *editor,
        return iface->insert_signature (
                editor,
                content,
-               is_html,
+               editor_mode,
                can_reposition_caret,
                signature_id,
                set_signature_from_message,
@@ -3973,3 +3973,39 @@ e_content_editor_delete_image (EContentEditor *editor)
 
        iface->delete_image (editor);
 }
+
+/**
+ * e_content_editor_util_three_state_to_bool:
+ * @value: an #EThreeState value
+ * @mail_key: (nullable): a key into 'org.gnome.evolution.mail'
+ *
+ * Converts the three-state @value into boolean, using the @mail_key
+ * boolean key from 'org.gnome.evolution.mail' in case the @value
+ * in %E_THREE_STATE_INCONSISTENT as a fallback, when non-%NULL.
+ *
+ * Returns: @value converted to boolean, optionally depending on @mail_key setting
+ *
+ * Since: 3.44
+ **/
+gboolean
+e_content_editor_util_three_state_to_bool (EThreeState value,
+                                          const gchar *mail_key)
+{
+       gboolean res = FALSE;
+
+       if (value == E_THREE_STATE_ON)
+               return TRUE;
+
+       if (value == E_THREE_STATE_OFF)
+               return FALSE;
+
+       if (mail_key && *mail_key) {
+               GSettings *settings;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.mail");
+               res = g_settings_get_boolean (settings, mail_key);
+               g_clear_object (&settings);
+       }
+
+       return res;
+}
diff --git a/src/e-util/e-content-editor.h b/src/e-util/e-content-editor.h
index 487e45ab66..8f376e6b2b 100644
--- a/src/e-util/e-content-editor.h
+++ b/src/e-util/e-content-editor.h
@@ -144,7 +144,7 @@ struct _EContentEditorInterface {
 
        gchar *         (*insert_signature)             (EContentEditor *editor,
                                                         const gchar *content,
-                                                        gboolean is_html,
+                                                        EContentEditorMode editor_mode,
                                                         gboolean can_reposition_caret,
                                                         const gchar *signature_id,
                                                         gboolean *set_signature_from_message,
@@ -655,7 +655,7 @@ void                e_content_editor_take_last_error(EContentEditor *editor,
 gchar *                e_content_editor_insert_signature
                                                (EContentEditor *editor,
                                                 const gchar *content,
-                                                gboolean is_html,
+                                                EContentEditorMode editor_mode,
                                                 gboolean can_reposition_caret,
                                                 const gchar *signature_id,
                                                 gboolean *set_signature_from_message,
@@ -1017,6 +1017,10 @@ CamelMimePart *  e_content_editor_emit_ref_mime_part
                                                (EContentEditor *editor,
                                                 const gchar *uri);
 
+gboolean       e_content_editor_util_three_state_to_bool
+                                               (EThreeState value,
+                                                const gchar *mail_key);
+
 G_END_DECLS
 
 #endif /* E_CONTENT_EDITOR_H */
diff --git a/src/e-util/e-mail-signature-combo-box.c b/src/e-util/e-mail-signature-combo-box.c
index 7dac48bc1e..34c313590a 100644
--- a/src/e-util/e-mail-signature-combo-box.c
+++ b/src/e-util/e-mail-signature-combo-box.c
@@ -618,7 +618,7 @@ struct _LoadContext {
        GCancellable *cancellable;
        gchar *contents;
        gsize length;
-       gboolean is_html;
+       EContentEditorMode editor_mode;
 };
 
 static void
@@ -708,7 +708,7 @@ mail_signature_combo_box_autogenerate (EMailSignatureComboBox *combo_box,
 
        context->length = buffer->len;
        context->contents = g_string_free (buffer, FALSE);
-       context->is_html = TRUE;
+       context->editor_mode = E_CONTENT_EDITOR_MODE_HTML;
 
        g_object_unref (source);
 }
@@ -740,7 +740,17 @@ mail_signature_combo_box_load_cb (ESource *source,
        extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
        extension = e_source_get_extension (source, extension_name);
        mime_type = e_source_mail_signature_get_mime_type (extension);
-       context->is_html = (g_strcmp0 (mime_type, "text/html") == 0);
+
+       if (g_strcmp0 (mime_type, "text/html") == 0)
+               context->editor_mode = E_CONTENT_EDITOR_MODE_HTML;
+       else if (g_strcmp0 (mime_type, "text/markdown") == 0)
+               context->editor_mode = E_CONTENT_EDITOR_MODE_MARKDOWN;
+       else if (g_strcmp0 (mime_type, "text/markdown-plain") == 0)
+               context->editor_mode = E_CONTENT_EDITOR_MODE_MARKDOWN_PLAIN_TEXT;
+       else if (g_strcmp0 (mime_type, "text/markdown-html") == 0)
+               context->editor_mode = E_CONTENT_EDITOR_MODE_MARKDOWN_HTML;
+       else
+               context->editor_mode = E_CONTENT_EDITOR_MODE_PLAIN_TEXT;
 
        g_simple_async_result_complete (simple);
 
@@ -810,7 +820,7 @@ e_mail_signature_combo_box_load_selected_finish (EMailSignatureComboBox *combo_b
                                                  GAsyncResult *result,
                                                  gchar **contents,
                                                  gsize *length,
-                                                 gboolean *is_html,
+                                                 EContentEditorMode *out_editor_mode,
                                                  GError **error)
 {
        GSimpleAsyncResult *simple;
@@ -838,8 +848,8 @@ e_mail_signature_combo_box_load_selected_finish (EMailSignatureComboBox *combo_b
        if (length != NULL)
                *length = context->length;
 
-       if (is_html != NULL)
-               *is_html = context->is_html;
+       if (out_editor_mode)
+               *out_editor_mode = context->editor_mode;
 
        return TRUE;
 }
diff --git a/src/e-util/e-mail-signature-combo-box.h b/src/e-util/e-mail-signature-combo-box.h
index 62c440aad7..ba88019a42 100644
--- a/src/e-util/e-mail-signature-combo-box.h
+++ b/src/e-util/e-mail-signature-combo-box.h
@@ -24,6 +24,7 @@
 
 #include <gtk/gtk.h>
 #include <libedataserver/libedataserver.h>
+#include <e-util/e-util-enums.h>
 
 /* Standard GObject macros */
 #define E_TYPE_MAIL_SIGNATURE_COMBO_BOX \
@@ -101,7 +102,7 @@ gboolean    e_mail_signature_combo_box_load_selected_finish
                                         GAsyncResult *result,
                                         gchar **contents,
                                         gsize *length,
-                                        gboolean *is_html,
+                                        EContentEditorMode *out_editor_mode,
                                         GError **error);
 
 G_END_DECLS
diff --git a/src/e-util/e-markdown-editor.c b/src/e-util/e-markdown-editor.c
index 7c1f7b50f9..160d7c5a24 100644
--- a/src/e-util/e-markdown-editor.c
+++ b/src/e-util/e-markdown-editor.c
@@ -20,6 +20,10 @@
 
 #include "e-markdown-editor.h"
 
+/* Where an existing signature is */
+#define EVO_SIGNATURE_START_MARK "x-evo-signature-start"
+#define EVO_SIGNATURE_END_MARK "x-evo-signature-end"
+
 struct _EMarkdownEditorPrivate {
        GtkNotebook *notebook;
        GtkTextView *text_view;
@@ -38,6 +42,10 @@ struct _EMarkdownEditorPrivate {
        ESpellChecker *spell_checker; /* this is not used internally */
        EThreeState start_bottom;
        EThreeState top_signature;
+       gchar *signature_uid;
+       gboolean selection_saved;
+       GtkTextIter selection_start; /* valid only if selection_saved is TRUE */
+       GtkTextIter selection_end; /* valid only if selection_saved is TRUE */
 };
 
 static void e_markdown_editor_content_editor_init (EContentEditorInterface *iface);
@@ -498,23 +506,187 @@ e_markdown_editor_replace_all (EContentEditor *cnt_editor,
 {
 }
 
+static void
+e_markdown_editor_selection_save (EContentEditor *cnt_editor)
+{
+       EMarkdownEditor *self = E_MARKDOWN_EDITOR (cnt_editor);
+       GtkTextBuffer *buffer;
+
+       buffer = gtk_text_view_get_buffer (self->priv->text_view);
+       gtk_text_buffer_get_selection_bounds (buffer, &self->priv->selection_start, 
&self->priv->selection_end);
+
+       self->priv->selection_saved = TRUE;
+}
+
+static void
+e_markdown_editor_selection_restore (EContentEditor *cnt_editor)
+{
+       EMarkdownEditor *self = E_MARKDOWN_EDITOR (cnt_editor);
+
+       if (self->priv->selection_saved) {
+               GtkTextBuffer *buffer;
+
+               self->priv->selection_saved = FALSE;
+
+               buffer = gtk_text_view_get_buffer (self->priv->text_view);
+               gtk_text_buffer_select_range (buffer, &self->priv->selection_start, 
&self->priv->selection_end);
+       }
+}
+
 static gchar *
 e_markdown_editor_get_current_signature_uid (EContentEditor *cnt_editor)
 {
-       return NULL;
+       EMarkdownEditor *self = E_MARKDOWN_EDITOR (cnt_editor);
+
+       return self->priv->signature_uid;
 }
 
 static gchar *
 e_markdown_editor_insert_signature (EContentEditor *cnt_editor,
                                    const gchar *content,
-                                   gboolean is_html,
+                                   EContentEditorMode editor_mode,
                                    gboolean can_reposition_caret,
                                    const gchar *signature_id,
                                    gboolean *set_signature_from_message,
                                    gboolean *check_if_signature_is_changed,
                                    gboolean *ignore_next_signature_change)
 {
-       return NULL;
+       EMarkdownEditor *self = E_MARKDOWN_EDITOR (cnt_editor);
+       GtkTextMark *sig_start_mark, *sig_end_mark;
+       GtkTextBuffer *buffer;
+       GtkTextIter start, end;
+       gchar *plain_text = NULL;
+
+       g_clear_pointer (&self->priv->signature_uid, g_free);
+       self->priv->signature_uid = g_strdup (signature_id);
+
+       if (content && *content && editor_mode == E_CONTENT_EDITOR_MODE_HTML) {
+               plain_text = e_markdown_utils_html_to_text (content, -1, 
E_MARKDOWN_HTML_TO_TEXT_FLAG_PLAIN_TEXT);
+               content = plain_text;
+               editor_mode = E_CONTENT_EDITOR_MODE_PLAIN_TEXT;
+       }
+
+       if (content && *content && editor_mode == E_CONTENT_EDITOR_MODE_PLAIN_TEXT) {
+               gchar *tmp;
+
+               tmp = g_strconcat ("```\n", content,
+                       g_str_has_suffix (content, "\n") ? "" : "\n",
+                       "```\n", NULL);
+
+               g_free (plain_text);
+               plain_text = tmp;
+               content = plain_text;
+       }
+
+       if (!e_content_editor_util_three_state_to_bool (E_THREE_STATE_INCONSISTENT, 
"composer-no-signature-delim") &&
+           content && *content && !g_str_has_prefix (content, "-- \n") && !strstr (content, "\n-- \n")) {
+               gchar *tmp;
+
+               tmp = g_strconcat ("-- \n",
+                       /* Add an empty line between the delimiter and the markdown signature */
+                       editor_mode == E_CONTENT_EDITOR_MODE_PLAIN_TEXT ? "" : "\n",
+                       content, NULL);
+
+               g_free (plain_text);
+               plain_text = tmp;
+               content = plain_text;
+       }
+
+       buffer = gtk_text_view_get_buffer (self->priv->text_view);
+       gtk_text_buffer_get_bounds (buffer, &start, &end);
+
+       sig_start_mark = gtk_text_buffer_get_mark (buffer, EVO_SIGNATURE_START_MARK);
+       sig_end_mark = gtk_text_buffer_get_mark (buffer, EVO_SIGNATURE_END_MARK);
+
+       if (content && *content) {
+               gtk_text_buffer_begin_user_action (buffer);
+
+               if (sig_start_mark && sig_end_mark) {
+                       GtkTextIter sig_start, sig_end;
+
+                       gtk_text_buffer_get_iter_at_mark (buffer, &sig_start, sig_start_mark);
+                       gtk_text_buffer_get_iter_at_mark (buffer, &sig_end, sig_end_mark);
+
+                       gtk_text_buffer_delete (buffer, &sig_start, &sig_end);
+
+                       gtk_text_buffer_insert (buffer, &sig_start, content, -1);
+
+                       gtk_text_buffer_get_bounds (buffer, &start, &end);
+               } else if (e_content_editor_util_three_state_to_bool (e_content_editor_get_top_signature 
(cnt_editor), "composer-top-signature")) {
+                       if (!g_str_has_suffix (content, "\n\n")) {
+                               if (g_str_has_suffix (content, "\n"))
+                                       gtk_text_buffer_insert (buffer, &start, "\n", 1);
+                               else
+                                       gtk_text_buffer_insert (buffer, &start, "\n\n", 2);
+
+                               gtk_text_buffer_get_start_iter (buffer, &start);
+                       }
+
+                       if (sig_start_mark)
+                               gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_START_MARK);
+                       if (sig_end_mark)
+                               gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_END_MARK);
+
+                       gtk_text_buffer_create_mark (buffer, EVO_SIGNATURE_END_MARK, &start, FALSE);
+
+                       gtk_text_buffer_insert (buffer, &start, content, -1);
+                       gtk_text_buffer_get_start_iter (buffer, &start);
+
+                       gtk_text_buffer_create_mark (buffer, EVO_SIGNATURE_START_MARK, &start, TRUE);
+
+                       gtk_text_buffer_insert (buffer, &start, "\n", 1);
+                       gtk_text_buffer_get_start_iter (buffer, &start);
+               } else {
+                       GtkTextIter iter = end;
+
+                       if (gtk_text_iter_backward_char (&iter) &&
+                           gtk_text_iter_get_char (&iter) != '\n') {
+                               gtk_text_buffer_insert (buffer, &end, "\n", 1);
+                               gtk_text_buffer_get_end_iter (buffer, &end);
+                       }
+
+                       if (sig_start_mark)
+                               gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_START_MARK);
+                       if (sig_end_mark)
+                               gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_END_MARK);
+
+                       gtk_text_buffer_create_mark (buffer, EVO_SIGNATURE_START_MARK, &end, TRUE);
+
+                       gtk_text_buffer_insert (buffer, &end, content, -1);
+                       gtk_text_buffer_get_end_iter (buffer, &end);
+
+                       gtk_text_buffer_create_mark (buffer, EVO_SIGNATURE_END_MARK, &end, FALSE);
+               }
+
+               gtk_text_buffer_end_user_action (buffer);
+       } else if (sig_start_mark && sig_end_mark) {
+               GtkTextIter sig_start, sig_end;
+
+               gtk_text_buffer_begin_user_action (buffer);
+               gtk_text_buffer_get_iter_at_mark (buffer, &sig_start, sig_start_mark);
+               gtk_text_buffer_get_iter_at_mark (buffer, &sig_end, sig_end_mark);
+               gtk_text_buffer_delete (buffer, &sig_start, &sig_end);
+               gtk_text_buffer_get_bounds (buffer, &start, &end);
+               gtk_text_buffer_end_user_action (buffer);
+       } else {
+               if (sig_start_mark)
+                       gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_START_MARK);
+               if (sig_end_mark)
+                       gtk_text_buffer_delete_mark_by_name (buffer, EVO_SIGNATURE_END_MARK);
+       }
+
+       if (can_reposition_caret) {
+               if (e_content_editor_util_three_state_to_bool (e_content_editor_get_start_bottom 
(cnt_editor), "composer-reply-start-bottom")) {
+                       gtk_text_buffer_select_range (buffer, &end, &end);
+               } else {
+                       gtk_text_buffer_get_start_iter (buffer, &start);
+                       gtk_text_buffer_select_range (buffer, &start, &start);
+               }
+       }
+
+       g_free (plain_text);
+
+       return g_strdup (self->priv->signature_uid);
 }
 
 static gboolean
@@ -1416,14 +1588,15 @@ e_markdown_editor_constructed (GObject *object)
 }
 
 static void
-e_markdown_editor_dispose (GObject *object)
+e_markdown_editor_finalize (GObject *object)
 {
        EMarkdownEditor *self = E_MARKDOWN_EDITOR (object);
 
        g_clear_object (&self->priv->spell_checker);
+       g_clear_pointer (&self->priv->signature_uid, g_free);
 
        /* Chain up to parent's method. */
-       G_OBJECT_CLASS (e_markdown_editor_parent_class)->dispose (object);
+       G_OBJECT_CLASS (e_markdown_editor_parent_class)->finalize (object);
 }
 
 static void
@@ -1446,7 +1619,7 @@ e_markdown_editor_class_init (EMarkdownEditorClass *klass)
        object_class->get_property = e_markdown_editor_get_property;
        object_class->set_property = e_markdown_editor_set_property;
        object_class->constructed = e_markdown_editor_constructed;
-       object_class->dispose = e_markdown_editor_dispose;
+       object_class->finalize = e_markdown_editor_finalize;
 
        g_object_class_override_property (object_class, PROP_IS_MALFUNCTION, "is-malfunction");
        g_object_class_override_property (object_class, PROP_CAN_COPY, "can-copy");
@@ -1681,6 +1854,8 @@ e_markdown_editor_content_editor_init (EContentEditorInterface *iface)
        iface->find = e_markdown_editor_find;
        iface->replace = e_markdown_editor_replace;
        iface->replace_all = e_markdown_editor_replace_all;
+       iface->selection_save = e_markdown_editor_selection_save;
+       iface->selection_restore = e_markdown_editor_selection_restore;
        iface->get_current_signature_uid = e_markdown_editor_get_current_signature_uid;
        iface->insert_signature = e_markdown_editor_insert_signature;
 }
diff --git a/src/e-util/test-mail-signatures.c b/src/e-util/test-mail-signatures.c
index 95ad835668..b0f5dd5da4 100644
--- a/src/e-util/test-mail-signatures.c
+++ b/src/e-util/test-mail-signatures.c
@@ -29,11 +29,11 @@ signature_loaded_cb (EMailSignatureComboBox *combo_box,
                      EWebView *web_view)
 {
        gchar *contents = NULL;
-       gboolean is_html;
+       EContentEditorMode editor_mode = E_CONTENT_EDITOR_MODE_UNKNOWN;
        GError *error = NULL;
 
        e_mail_signature_combo_box_load_selected_finish (
-               combo_box, result, &contents, NULL, &is_html, &error);
+               combo_box, result, &contents, NULL, &editor_mode, &error);
 
        /* Ignore cancellations. */
        if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
@@ -55,7 +55,7 @@ signature_loaded_cb (EMailSignatureComboBox *combo_box,
 
        if (contents == NULL)
                e_web_view_clear (web_view);
-       else if (is_html)
+       else if (editor_mode == E_CONTENT_EDITOR_MODE_HTML)
                e_web_view_load_string (web_view, contents);
        else {
                gchar *string;
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 06563caab4..0fc8b47afa 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -596,29 +596,6 @@ webkit_editor_dialog_utils_has_attribute (EWebKitEditor *wk_editor,
                FALSE);
 }
 
-static gboolean
-e_webkit_editor_three_state_to_bool (EThreeState value,
-                                    const gchar *mail_key)
-{
-       gboolean res = FALSE;
-
-       if (value == E_THREE_STATE_ON)
-               return TRUE;
-
-       if (value == E_THREE_STATE_OFF)
-               return FALSE;
-
-       if (mail_key && *mail_key) {
-               GSettings *settings;
-
-               settings = e_util_ref_settings ("org.gnome.evolution.mail");
-               res = g_settings_get_boolean (settings, mail_key);
-               g_clear_object (&settings);
-       }
-
-       return res;
-}
-
 EWebKitEditor *
 e_webkit_editor_new (void)
 {
@@ -2478,7 +2455,7 @@ webkit_editor_set_start_bottom (EWebKitEditor *wk_editor,
 
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
                "EvoEditor.START_BOTTOM = %x;",
-               e_webkit_editor_three_state_to_bool (value, "composer-reply-start-bottom"));
+               e_content_editor_util_three_state_to_bool (value, "composer-reply-start-bottom"));
 
        g_object_notify (G_OBJECT (wk_editor), "start-bottom");
 }
@@ -2606,7 +2583,7 @@ webkit_editor_get_current_signature_uid (EContentEditor *editor)
 static gchar *
 webkit_editor_insert_signature (EContentEditor *editor,
                                 const gchar *content,
-                                gboolean is_html,
+                                EContentEditorMode editor_mode,
                                gboolean can_reposition_caret,
                                 const gchar *signature_id,
                                 gboolean *set_signature_from_message,
@@ -2618,8 +2595,12 @@ webkit_editor_insert_signature (EContentEditor *editor,
 
        g_return_val_if_fail (E_IS_WEBKIT_EDITOR (editor), NULL);
 
-       if (!is_html && content && *content) {
-               tmp = camel_text_to_html (content, CAMEL_MIME_FILTER_TOHTML_PRE, 0);
+       if (editor_mode != E_CONTENT_EDITOR_MODE_HTML && content && *content) {
+               if (editor_mode == E_CONTENT_EDITOR_MODE_MARKDOWN_HTML)
+                       tmp = e_markdown_utils_text_to_html (content, -1);
+
+               if (!tmp)
+                       tmp = camel_text_to_html (content, CAMEL_MIME_FILTER_TOHTML_PRE, 0);
 
                if (tmp)
                        content = tmp;
@@ -2628,15 +2609,15 @@ webkit_editor_insert_signature (EContentEditor *editor,
        jsc_value = webkit_editor_call_jsc_sync (E_WEBKIT_EDITOR (editor),
                "EvoEditor.InsertSignature(%s, %x, %x, %s, %x, %x, %x, %x, %x, %x);",
                content ? content : "",
-               is_html,
+               editor_mode == E_CONTENT_EDITOR_MODE_HTML,
                can_reposition_caret,
                signature_id,
                *set_signature_from_message,
                *check_if_signature_is_changed,
                *ignore_next_signature_change,
-               e_webkit_editor_three_state_to_bool (e_content_editor_get_start_bottom (editor), 
"composer-reply-start-bottom"),
-               e_webkit_editor_three_state_to_bool (e_content_editor_get_top_signature (editor), 
"composer-top-signature"),
-               !e_webkit_editor_three_state_to_bool (E_THREE_STATE_INCONSISTENT, 
"composer-no-signature-delim"));
+               e_content_editor_util_three_state_to_bool (e_content_editor_get_start_bottom (editor), 
"composer-reply-start-bottom"),
+               e_content_editor_util_three_state_to_bool (e_content_editor_get_top_signature (editor), 
"composer-top-signature"),
+               !e_content_editor_util_three_state_to_bool (E_THREE_STATE_INCONSISTENT, 
"composer-no-signature-delim"));
 
        g_free (tmp);
 
@@ -4981,7 +4962,7 @@ webkit_editor_load_changed_cb (EWebKitEditor *wk_editor,
                "EvoEditor.UNICODE_SMILEYS = %x;"
                "EvoEditor.WRAP_QUOTED_TEXT_IN_REPLIES = %x;",
                wk_editor->priv->normal_paragraph_width,
-               e_webkit_editor_three_state_to_bool (wk_editor->priv->start_bottom, 
"composer-reply-start-bottom"),
+               e_content_editor_util_three_state_to_bool (wk_editor->priv->start_bottom, 
"composer-reply-start-bottom"),
                wk_editor->priv->magic_links,
                wk_editor->priv->magic_smileys,
                wk_editor->priv->unicode_smileys,


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