If converting both spaces and newlines, then convert tabs too. The joys of
* e-html-utils.c (e_text_to_html): If converting both spaces and newlines, then convert tabs too. The joys of pseudo-<PRE>. svn path=/trunk/; revision=4695
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
2000-08-10 Dan Winship <danw@helixcode.com>
|
||||||
|
|
||||||
|
* e-html-utils.c (e_text_to_html): If converting both spaces and
|
||||||
|
newlines, then convert tabs too. The joys of pseudo-<PRE>.
|
||||||
|
|
||||||
2000-08-09 Christopher James Lahey <clahey@helixcode.com>
|
2000-08-09 Christopher James Lahey <clahey@helixcode.com>
|
||||||
|
|
||||||
* e-popup-menu.c: Fix the bug where it truncates the last item
|
* e-popup-menu.c: Fix the bug where it truncates the last item
|
||||||
|
@ -113,6 +113,9 @@ url_extract (const unsigned char **text, gboolean check)
|
|||||||
* which probably means you don't want to use this flag on
|
* which probably means you don't want to use this flag on
|
||||||
* pieces of data that aren't delimited by at least line breaks.
|
* pieces of data that aren't delimited by at least line breaks.
|
||||||
*
|
*
|
||||||
|
* If E_TEXT_TO_HTML_CONVERT_NL and E_TEXT_TO_HTML_CONVERT_SPACES
|
||||||
|
* are both defined, then TABs will also be converted to spaces.
|
||||||
|
*
|
||||||
* - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a> around
|
* - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a> around
|
||||||
* strings that look like URLs.
|
* strings that look like URLs.
|
||||||
**/
|
**/
|
||||||
@ -122,7 +125,7 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
const unsigned char *cur = input, *end;
|
const unsigned char *cur = input, *end;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
char *out = NULL;
|
char *out = NULL;
|
||||||
int buffer_size = 0;
|
int buffer_size = 0, col;
|
||||||
|
|
||||||
/* Allocate a translation buffer. */
|
/* Allocate a translation buffer. */
|
||||||
buffer_size = strlen (input) * 2 + 5;
|
buffer_size = strlen (input) * 2 + 5;
|
||||||
@ -132,6 +135,7 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
if (flags & E_TEXT_TO_HTML_PRE)
|
if (flags & E_TEXT_TO_HTML_PRE)
|
||||||
out += sprintf (out, "<PRE>\n");
|
out += sprintf (out, "<PRE>\n");
|
||||||
|
|
||||||
|
col = 0;
|
||||||
while (*cur) {
|
while (*cur) {
|
||||||
if (isalpha (*cur) && (flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
|
if (isalpha (*cur) && (flags & E_TEXT_TO_HTML_CONVERT_URLS)) {
|
||||||
char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
|
char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL;
|
||||||
@ -162,6 +166,7 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
out += sprintf (out,
|
out += sprintf (out,
|
||||||
"<a href=\"%s\">%s</a>",
|
"<a href=\"%s\">%s</a>",
|
||||||
refurl, dispurl);
|
refurl, dispurl);
|
||||||
|
col += strlen (tmpurl);
|
||||||
g_free (tmpurl);
|
g_free (tmpurl);
|
||||||
g_free (refurl);
|
g_free (refurl);
|
||||||
g_free (dispurl);
|
g_free (dispurl);
|
||||||
@ -179,6 +184,7 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
end - cur + 10);
|
end - cur + 10);
|
||||||
memcpy (out, cur, end - cur);
|
memcpy (out, cur, end - cur);
|
||||||
out += end - cur;
|
out += end - cur;
|
||||||
|
col += end - cur;
|
||||||
|
|
||||||
if (!*end)
|
if (!*end)
|
||||||
break;
|
break;
|
||||||
@ -188,37 +194,55 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
case '<':
|
case '<':
|
||||||
strcpy (out, "<");
|
strcpy (out, "<");
|
||||||
out += 4;
|
out += 4;
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '>':
|
case '>':
|
||||||
strcpy (out, ">");
|
strcpy (out, ">");
|
||||||
out += 4;
|
out += 4;
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '&':
|
case '&':
|
||||||
strcpy (out, "&");
|
strcpy (out, "&");
|
||||||
out += 5;
|
out += 5;
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
strcpy (out, """);
|
strcpy (out, """);
|
||||||
out += 6;
|
out += 6;
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
*out++ = *cur;
|
|
||||||
if (flags & E_TEXT_TO_HTML_CONVERT_NL) {
|
if (flags & E_TEXT_TO_HTML_CONVERT_NL) {
|
||||||
strcpy (out, "<br>");
|
strcpy (out, "<br>");
|
||||||
out += 4;
|
out += 4;
|
||||||
}
|
}
|
||||||
|
*out++ = *cur;
|
||||||
|
col = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
if (flags & (E_TEXT_TO_HTML_CONVERT_SPACES |
|
||||||
|
E_TEXT_TO_HTML_CONVERT_NL)) {
|
||||||
|
do {
|
||||||
|
strcpy (out, " ");
|
||||||
|
out += 6;
|
||||||
|
col++;
|
||||||
|
} while (col % 8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* otherwise, FALL THROUGH */
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
if (flags & E_TEXT_TO_HTML_CONVERT_SPACES) {
|
if (flags & E_TEXT_TO_HTML_CONVERT_SPACES) {
|
||||||
if (cur == (const unsigned char *)input ||
|
if (cur == (const unsigned char *)input ||
|
||||||
*(cur + 1) == ' ') {
|
*(cur + 1) == ' ' || *(cur + 1) == '\t') {
|
||||||
strcpy (out, " ");
|
strcpy (out, " ");
|
||||||
out += 6;
|
out += 6;
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,6 +255,7 @@ e_text_to_html (const char *input, unsigned int flags)
|
|||||||
*out++ = *cur;
|
*out++ = *cur;
|
||||||
} else
|
} else
|
||||||
out += g_snprintf(out, 9, "&#%d;", *cur);
|
out += g_snprintf(out, 9, "&#%d;", *cur);
|
||||||
|
col++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user