changeset 41:0a81ccfa1941

strip excessive markup where it is not needed. (work in progress)
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Tue, 13 May 2008 00:35:42 +0900
parents e60e6cbdc4c4
children 68db38b5b401
files pidgin-twitter.c
diffstat 1 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Mon May 12 23:13:29 2008 +0900
+++ b/pidgin-twitter.c	Tue May 13 00:35:42 2008 +0900
@@ -35,7 +35,7 @@
 #define SENDER      1
 #define COMMAND     2
 #define PSEUDO      3
-#define SENDER_WITH_LINK  4
+#define EXCESS_MARKUP  4
 
 #define PLUGIN_ID	            "gtk-honeyplanet-pidgin_twitter"
 #define PLUGIN_NAME	            "pidgin-twitter"
@@ -66,7 +66,7 @@
 static gboolean suppress_oops = FALSE;
 
 /* prototypes */
-static void delete_sender_with_link(gchar **str);
+static void strip_excess_markup(gchar **str);
 static void escape(gchar **str);
 static gboolean sending_im_cb(PurpleAccount *account, char *recipient, char **buffer, void *data);
 static gboolean eval(const GMatchInfo *match_info, GString *result, gpointer user_data);
@@ -91,13 +91,13 @@
 
 /* implementation */
 static void
-delete_sender_with_link(gchar **str)
+strip_excess_markup(gchar **str)
 {
     gchar *newstr = NULL;
 
     /* replace senders with link */
     newstr =
-        g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL);
+        g_regex_replace(regp[EXCESS_MARKUP], *str, -1, 0, "\\1\\2\\3", 0, NULL);
 
     twitter_debug("*str = %s newstr = %s\n", *str, newstr);
 
@@ -156,14 +156,14 @@
 {
     /* check if the message is from twitter */
     if(is_twitter_account(account, recipient)) {
-        /* escape */
+        /* strip excess markup */
+        strip_excess_markup(buffer);
+
+        /* escape pseudo command */
         if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
             escape(buffer);
         }
 
-        /* strip excessive link from @username */
-        delete_sender_with_link(buffer);
-
         /* try to suppress oops message */
         gint utflen = g_utf8_strlen(*buffer, -1);
         gint bytes = strlen(*buffer);
@@ -266,6 +266,9 @@
             playsound(buffer, RECIPIENT);
         }
 
+        /* strip excess markup */
+        strip_excess_markup(buffer);
+
         /* translate */
         if(purple_prefs_get_bool(OPT_TRANSLATE_SENDER)) {
             translate(buffer, SENDER);
@@ -274,7 +277,7 @@
             translate(buffer, RECIPIENT);
         }
 
-        /* escape */
+        /* escape pseudo command */
         if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
             escape(buffer);
         }
@@ -505,15 +508,16 @@
     regp[RECIPIENT] = g_regex_new("@([A-Za-z0-9_]+)", 0, 0, NULL);
     regp[SENDER] = g_regex_new("<body>([A-Za-z0-9_]+): ", 0, 0, NULL);
     regp[COMMAND] =
-        g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)",
+//        g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)",
+        g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)",
                     G_REGEX_RAW, 0, NULL);
     regp[PSEUDO] =
         g_regex_new
         ("^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)",
          G_REGEX_RAW, 0, NULL);
-    regp[SENDER_WITH_LINK] =
+    regp[EXCESS_MARKUP] =
         g_regex_new
-        ("@(?:<font .+?>)?<a href=.+?>([A-Za-z0-9_]+?)</a>(?:</font>)?", 0, 0,
+        ("([@dDfFgGlLmMnNtTwW]{1})(\\s?)(?:<font .+>)?<a href=.+>(?:<font .+>)?([A-Za-z0-9_]+)(?:</font>)?</a>(?:</font>)?", 0, 0,
          NULL);
 
     /* attach counter to the existing twitter window */
@@ -549,7 +553,7 @@
     g_regex_unref(regp[SENDER]);
     g_regex_unref(regp[COMMAND]);
     g_regex_unref(regp[PSEUDO]);
-    g_regex_unref(regp[SENDER_WITH_LINK]);
+    g_regex_unref(regp[EXCESS_MARKUP]);
 
     /* detach from twitter window */
     detach_from_window();