[evolution] EHTMLEditorView - Remove unwanted attributes from HTML, HEAD and BODY elements when converting from



commit 60452619538b48fd17a164d03b138010dedc8b91
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Nov 20 14:03:34 2014 +0100

    EHTMLEditorView - Remove unwanted attributes from HTML, HEAD and BODY elements when converting from HTML 
to plain text message

 e-util/e-html-editor-view.c |   95 +++++++++++++++++++++----------------------
 1 files changed, 47 insertions(+), 48 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index a068488..4858fe0 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -4465,6 +4465,51 @@ quote_plain_text_elements_after_wrapping_in_document (WebKitDOMDocument *documen
 }
 
 static void
+clear_attributes (WebKitDOMDocument *document)
+{
+       gint length, ii;
+       WebKitDOMNamedNodeMap *attributes;
+       WebKitDOMHTMLElement *body = webkit_dom_document_get_body (document);
+       WebKitDOMHTMLHeadElement *head = webkit_dom_document_get_head (document);
+       WebKitDOMElement *document_element =
+               webkit_dom_document_get_document_element (document);
+
+       /* Remove all attributes from HTML element */
+       attributes = webkit_dom_element_get_attributes (document_element);
+       length = webkit_dom_named_node_map_get_length (attributes);
+       for (ii = length - 1; ii >= 0; ii--) {
+               WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
+
+               webkit_dom_element_remove_attribute_node (
+                       document_element, WEBKIT_DOM_ATTR (node), NULL);
+       }
+       g_object_unref (attributes);
+
+       /* Remove everything from HEAD element */
+       while (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (head)))
+               remove_node (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (head)));
+
+       /* Remove non Evolution attributes from BODY element */
+       attributes = webkit_dom_element_get_attributes (WEBKIT_DOM_ELEMENT (body));
+       length = webkit_dom_named_node_map_get_length (attributes);
+       for (ii = length - 1; ii >= 0; ii--) {
+               gchar *name;
+               WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
+
+               name = webkit_dom_node_get_local_name (node);
+
+               if (g_str_has_prefix (name, "data-"))
+                       webkit_dom_element_remove_attribute_node (
+                               WEBKIT_DOM_ELEMENT (body),
+                               WEBKIT_DOM_ATTR (node),
+                               NULL);
+
+               g_free (name);
+       }
+       g_object_unref (attributes);
+}
+
+static void
 html_editor_convert_view_content (EHTMLEditorView *view,
                                   const gchar *preferred_text)
 {
@@ -4694,6 +4739,8 @@ html_editor_convert_view_content (EHTMLEditorView *view,
                quote_plain_text_elements_after_wrapping_in_document (document);
        }
 
+       clear_attributes (document);
+
        e_html_editor_selection_restore (selection);
        e_html_editor_view_force_spell_check (view);
 
@@ -6789,54 +6836,6 @@ show_lose_formatting_dialog (EHTMLEditorView *view)
 }
 
 static void
-clear_attributes (WebKitDOMDocument *document)
-{
-       gint length, ii;
-       WebKitDOMNamedNodeMap *attributes;
-       WebKitDOMHTMLElement *body = webkit_dom_document_get_body (document);
-       WebKitDOMHTMLHeadElement *head = webkit_dom_document_get_head (document);
-       WebKitDOMElement *document_element =
-               webkit_dom_document_get_document_element (document);
-
-       /* Remove all attributes from HTML element */
-       attributes = webkit_dom_element_get_attributes (document_element);
-       length = webkit_dom_named_node_map_get_length (attributes);
-       for (ii = length - 1; ii >= 0; ii--) {
-               WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
-
-               webkit_dom_element_remove_attribute_node (
-                       document_element, WEBKIT_DOM_ATTR (node), NULL);
-       }
-       g_object_unref (attributes);
-
-       /* Remove everything from HEAD element */
-       while (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (head)))
-               remove_node (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (head)));
-
-       /* Remove non Evolution attributes from BODY element */
-       attributes = webkit_dom_element_get_attributes (WEBKIT_DOM_ELEMENT (body));
-       length = webkit_dom_named_node_map_get_length (attributes);
-       for (ii = length - 1; ii >= 0; ii--) {
-               gchar *name;
-               WebKitDOMNode *node = webkit_dom_named_node_map_item (attributes, ii);
-
-               name = webkit_dom_node_get_local_name (node);
-
-               if (!g_str_has_prefix (name, "data-") ||
-                   g_str_has_prefix (name, "data-inline") ||
-                   g_str_has_prefix (name, "data-name")) {
-                       webkit_dom_element_remove_attribute_node (
-                               WEBKIT_DOM_ELEMENT (body),
-                               WEBKIT_DOM_ATTR (node),
-                               NULL);
-               }
-
-               g_free (name);
-       }
-       g_object_unref (attributes);
-}
-
-static void
 convert_when_changing_composer_mode (EHTMLEditorView *view)
 {
        EHTMLEditorSelection *selection;


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