aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog12
-rw-r--r--e-util/e-html-utils.c51
-rw-r--r--e-util/e-html-utils.h6
3 files changed, 66 insertions, 3 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index f54c173b1e..b566b4d3cc 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,15 @@
+2001-03-20 Radek Doulik <rodo@ximian.com>
+
+ * e-html-utils.c (e_text_to_html_full): new function, extracted
+ from e_text_to_html, added color parameter
+
+2001-03-19 Radek Doulik <rodo@ximian.com>
+
+ * e-html-utils.c (e_text_to_html): support mark citation
+
+ * e-html-utils.h (E_TEXT_TO_HTML_MARK_CITATION): added
+ E_TEXT_TO_HTML_MARK_CITATION
+
2001-03-18 Damon Chaplin <damon@ximian.com>
* e-time-utils.c (e_time_format_time): added function to format just
diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c
index d1f069661e..f0c16e63a0 100644
--- a/e-util/e-html-utils.c
+++ b/e-util/e-html-utils.c
@@ -64,11 +64,28 @@ url_extract (const unsigned char **text, gboolean check)
return out;
}
+static gboolean
+is_citation (const unsigned char *c)
+{
+ unicode_char_t u;
+ gint i;
+
+ for (i = 0; c && *c && i < 10; i ++, c = unicode_next_utf8 (c)) {
+ unicode_get_utf8 (c, &u);
+ if (u == '>')
+ return TRUE;
+ if (!unicode_isalnum (u))
+ return FALSE;
+ }
+ return FALSE;
+}
+
/**
- * e_text_to_html:
+ * e_text_to_html_full:
* @input: a NUL-terminated input buffer
* @flags: some combination of the E_TEXT_TO_HTML_* flags defined
* in e-html-utils.h
+ * @color: color for citation highlighting
*
* This takes a buffer of text as input and produces a buffer of
* "equivalent" HTML, subject to certain transformation rules.
@@ -96,14 +113,18 @@ url_extract (const unsigned char **text, gboolean check)
*
* - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a> around
* strings that look like URLs.
+ *
+ * - E_TEXT_TO_HTML_MARK_CITATION: wrap <font color="blue"> </font> around
+ * citations (lines beginning with "> ").
**/
char *
-e_text_to_html (const char *input, unsigned int flags)
+e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
{
const unsigned char *cur = input;
char *buffer = NULL;
char *out = NULL;
int buffer_size = 0, col;
+ gboolean colored = FALSE;
/* Allocate a translation buffer. */
buffer_size = strlen (input) * 2 + 5;
@@ -119,6 +140,26 @@ e_text_to_html (const char *input, unsigned int flags)
unicode_char_t u;
unicode_get_utf8 (cur, &u);
+ if (flags & E_TEXT_TO_HTML_MARK_CITATION && col == 0) {
+ if (is_citation (cur)) {
+ if (!colored) {
+ gchar font [25];
+
+ g_snprintf (font, 25, "<FONT COLOR=\"#%06x\">", color);
+
+ check_size (&buffer, &buffer_size, out, 25);
+ out += sprintf (out, "%s", font);
+ colored = TRUE;
+ }
+ } else if (colored) {
+ gchar *no_font = "</FONT>";
+
+ check_size (&buffer, &buffer_size, out, 9);
+ out += sprintf (out, "%s", no_font);
+ colored = FALSE;
+ }
+ }
+
if (unicode_isalpha (u) &&
(flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
@@ -250,3 +291,9 @@ e_text_to_html (const char *input, unsigned int flags)
return buffer;
}
+
+char *
+e_text_to_html (const char *input, unsigned int flags)
+{
+ return e_text_to_html_full (input, flags, 0);
+}
diff --git a/e-util/e-html-utils.h b/e-util/e-html-utils.h
index a56889f4d9..346446956c 100644
--- a/e-util/e-html-utils.h
+++ b/e-util/e-html-utils.h
@@ -23,11 +23,15 @@
#ifndef __E_HTML_UTILS__
#define __E_HTML_UTILS__
+#include <glib.h>
+
#define E_TEXT_TO_HTML_PRE (1 << 0)
#define E_TEXT_TO_HTML_CONVERT_NL (1 << 1)
#define E_TEXT_TO_HTML_CONVERT_SPACES (1 << 2)
#define E_TEXT_TO_HTML_CONVERT_URLS (1 << 3)
+#define E_TEXT_TO_HTML_MARK_CITATION (1 << 4)
-char *e_text_to_html (const char *input, unsigned int flags);
+char *e_text_to_html_full (const char *input, unsigned int flags, guint32 color);
+char *e_text_to_html (const char *input, unsigned int flags);
#endif /* __E_HTML_UTILS__ */