X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=libcitadel%2Flib%2Fhtml_to_ascii.c;h=45beb2cbb079b97eeaa2041df905e8676ce3145a;hb=aca7dd04d80f04b9cd61f740549ce370e76bc332;hp=faa343710c1c19556b67cabd9be578e65dc38f78;hpb=bca06b89514d8d91c1442735272ab10ea0e19f9a;p=citadel.git diff --git a/libcitadel/lib/html_to_ascii.c b/libcitadel/lib/html_to_ascii.c index faa343710..45beb2cbb 100644 --- a/libcitadel/lib/html_to_ascii.c +++ b/libcitadel/lib/html_to_ascii.c @@ -1,6 +1,6 @@ /* * Functions which handle translation between HTML and plain text - * Copyright (c) 2000-2010 by the citadel.org team + * Copyright (c) 2000-2018 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,9 +47,8 @@ * * inputmsg = pointer to raw HTML message * screenwidth = desired output screenwidth - * do_citaformat = set to 1 to indent newlines with spaces */ -char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_citaformat) { +char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) { char inbuf[SIZ]; int inbuf_len = 0; char outbuf[SIZ]; @@ -67,6 +66,7 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci int bytes_processed = 0; char nl[128]; + tag[0] = '\0'; strcpy(nl, "\n"); inptr = inputmsg; strcpy(inbuf, ""); @@ -197,6 +197,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci strcat(outbuf, nl); } +#if 0 + These seemed like a good idea at the time, but it just makes a mess. + else if ( (!strcasecmp(tag, "B")) || (!strcasecmp(tag, "/B")) @@ -204,7 +207,6 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci || (!strcasecmp(tag, "/STRONG")) ) { strcat(outbuf, "*"); - } else if ( @@ -214,7 +216,6 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci || (!strcasecmp(tag, "/EM")) ) { strcat(outbuf, "/"); - } else if ( @@ -222,8 +223,8 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci || (!strcasecmp(tag, "/U")) ) { strcat(outbuf, "_"); - } +#endif else if (!strcasecmp(tag, "BR")) { strcat(outbuf, nl); @@ -273,7 +274,7 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci tag[strlen(tag)] = ch; } - else if (!nest) { + else if ((!nest) && (styletag == 0)) { outbuf[strlen(outbuf)+1] = 0; outbuf[strlen(outbuf)] = ch; } @@ -469,6 +470,16 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci strcpy(&outbuf[i+1], &outbuf[i+7]); } + else if (!strncasecmp(&outbuf[i], "’", 7)) { + outbuf[i] = '\''; + strcpy(&outbuf[i+1], &outbuf[i+7]); + } + + else if (!strncasecmp(&outbuf[i], "–", 7)) { + outbuf[i] = '-'; + strcpy(&outbuf[i+1], &outbuf[i+7]); + } + /* two-digit decimal equivalents */ else if (outbuf[i] == '&' && outbuf[i + 1] == '#' && @@ -508,7 +519,7 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci scanch = 0; sscanf(&outbuf[i+2], "%04d", &scanch); outbuf[i] = scanch; - strcpy(&outbuf[i+1], &outbuf[i+6]); + strcpy(&outbuf[i+1], &outbuf[i+7]); } } @@ -532,11 +543,6 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci strncpy(&outptr[output_len], outbuf, i+1); output_len += (i+1); - if (do_citaformat) { - strcpy(&outptr[output_len], " "); - ++output_len; - } - strcpy(outbuf, &outbuf[i+1]); i = 0; did_out = 1; @@ -556,10 +562,6 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci output_len += rb; strcpy(&outptr[output_len], nl); output_len += strlen(nl); - if (do_citaformat) { - strcpy(&outptr[output_len], " "); - ++output_len; - } strcpy(outbuf, &outbuf[rb+1]); } else { strncpy(&outptr[output_len], outbuf, @@ -567,10 +569,6 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int do_ci output_len += (screenwidth-2); strcpy(&outptr[output_len], nl); output_len += strlen(nl); - if (do_citaformat) { - strcpy(&outptr[output_len], " "); - ++output_len; - } strcpy(outbuf, &outbuf[screenwidth-2]); } }