[evolution/gnome-3-16] EHTMLEditorView - Punctuation is added to the link



commit 3800d2372a099212cc5aaf5313cbaf65e44d010a
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Apr 3 10:28:00 2015 +0200

    EHTMLEditorView - Punctuation is added to the link
    
    If the link ends with some punctuation character, remove it from the link and
    move it behind the link as a text.

 e-util/e-html-editor-view.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 7694a84..93a78d8 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -5733,7 +5733,8 @@ create_anchor_for_link (const GMatchInfo *info,
                         GString *res,
                         gpointer data)
 {
-       gint offset = 0;
+       gint offset = 0, truncate_from_end = 0;
+       const gchar *end_of_match = NULL;
        gchar *match;
        gboolean address_surrounded;
 
@@ -5754,26 +5755,47 @@ create_anchor_for_link (const GMatchInfo *info,
        if (address_surrounded)
                g_string_append (res, "&lt;");
 
+       if (!address_surrounded) {
+               end_of_match = match + strlen (match) - 1;
+               /* Taken from camel-url-scanner.c */
+               /* URLs are extremely unlikely to end with any punctuation, so
+                * strip any trailing punctuation off from link and put it after
+                * the link. Do the same for any closing double-quotes as well. */
+               while (end_of_match && end_of_match != match && strchr (",.:;?!-|}])\"", *end_of_match)) {
+                       truncate_from_end++;
+                       end_of_match--;
+               }
+       }
        g_string_append (res, "<a href=\"");
        if (strstr (match, "@") && !strstr (match, "://")) {
                g_string_append (res, "mailto:";);
                g_string_append (res, match + offset);
                if (address_surrounded)
                        g_string_truncate (res, res->len - 4);
+               else if (truncate_from_end > 0)
+                       g_string_truncate (res, res->len - truncate_from_end);
 
                g_string_append (res, "\">");
                g_string_append (res, match + offset);
                if (address_surrounded)
                        g_string_truncate (res, res->len - 4);
+               else if (truncate_from_end > 0)
+                       g_string_truncate (res, res->len - truncate_from_end);
        } else {
                g_string_append (res, match + offset);
+               if (truncate_from_end > 0)
+                       g_string_truncate (res, res->len - truncate_from_end);
                g_string_append (res, "\">");
                g_string_append (res, match + offset);
+               if (truncate_from_end > 0)
+                       g_string_truncate (res, res->len - truncate_from_end);
        }
        g_string_append (res, "</a>");
 
        if (address_surrounded)
                g_string_append (res, "&gt;");
+       else if (truncate_from_end > 0)
+               g_string_append (res, end_of_match + 1);
 
        g_free (match);
 


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