aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-html-utils.c
diff options
context:
space:
mode:
authorRadek Doulik <rodo@ximian.com>2001-03-21 00:50:12 +0800
committerRadek Doulik <rodo@src.gnome.org>2001-03-21 00:50:12 +0800
commit3e105b5bb73b88a597ca56c14319644e4ca4c1ea (patch)
tree2defe8ef0db4cc3c1768fa5053c1f4e3bf98910b /e-util/e-html-utils.c
parent451c410dec4efdef1562417066fd7b7464b14004 (diff)
downloadgsoc2013-evolution-3e105b5bb73b88a597ca56c14319644e4ca4c1ea.tar.gz
gsoc2013-evolution-3e105b5bb73b88a597ca56c14319644e4ca4c1ea.tar.zst
gsoc2013-evolution-3e105b5bb73b88a597ca56c14319644e4ca4c1ea.zip
new function, extracted from e_text_to_html, added color parameter
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 svn path=/trunk/; revision=8847
Diffstat (limited to 'e-util/e-html-utils.c')
-rw-r--r--e-util/e-html-utils.c51
1 files changed, 49 insertions, 2 deletions
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);
+}