From 4df5f560d552000f252a0e4dda2026b7a0373f0c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 Sep 2022 18:44:43 -0400 Subject: [PATCH] Added a new parameter to html_to_ascii() to let it know when it's rendering to a terminal that supports ANSI escape sequences. When this support is active, render blockquotes in dimmer video and italic (if supported by the terminal). --- citadel/server/msgbase.c | 2 +- libcitadel/lib/html_to_ascii.c | 35 +++++++++++++++++++--------------- libcitadel/lib/libcitadel.h | 14 ++++++-------- textclient/messages.c | 2 +- webcit/messages.c | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/citadel/server/msgbase.c b/citadel/server/msgbase.c index 0da39fc87..4ddd9aa42 100644 --- a/citadel/server/msgbase.c +++ b/citadel/server/msgbase.c @@ -1254,7 +1254,7 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp, } if (!strcasecmp(cbtype, "text/html")) { - ptr = html_to_ascii(content, length, 80); + ptr = html_to_ascii(content, length, 80, 0); wlen = strlen(ptr); client_write(ptr, wlen); if ((wlen > 0) && (ptr[wlen-1] != '\n')) { diff --git a/libcitadel/lib/html_to_ascii.c b/libcitadel/lib/html_to_ascii.c index d325e4a89..2d604ac4f 100644 --- a/libcitadel/lib/html_to_ascii.c +++ b/libcitadel/lib/html_to_ascii.c @@ -1,10 +1,8 @@ -/* - * Functions which handle translation between HTML and plain text - * Copyright (c) 2000-2018 by the citadel.org team - * +// Functions which handle translation between HTML and plain text +// Copyright (c) 2000-2022 by the citadel.org team +// // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. - */ #include #include @@ -31,13 +29,14 @@ #include "libcitadel.h" -/* - * Convert HTML to plain text. - * - * inputmsg = pointer to raw HTML message - * screenwidth = desired output screenwidth - */ -char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) { +// Convert HTML to plain text. +// +// inputmsg = pointer to raw HTML message +// msglen = stop reading after this many bytes +// screenwidth = desired output screenwidth +// ansi = if nonzero, assume output is to a terminal that supports ANSI escape codes +// +char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int ansi) { char inbuf[SIZ]; int inbuf_len = 0; char outbuf[SIZ]; @@ -48,9 +47,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) { size_t outptr_buffer_size; size_t output_len = 0; int i, j, ch, did_out, rb, scanch; - int nest = 0; /* Bracket nesting level */ - int blockquote = 0; /* BLOCKQUOTE nesting level */ - int styletag = 0; /* STYLE tag nesting level */ + int nest = 0; // Bracket nesting level + int blockquote = 0; // BLOCKQUOTE nesting level + int styletag = 0; // STYLE tag nesting level int styletag_start = 0; int bytes_processed = 0; char nl[128]; @@ -230,6 +229,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) { else if (!strcasecmp(tag, "BLOCKQUOTE")) { ++blockquote; strcpy(nl, "\n"); + if ( (blockquote == 1) && (ansi) ) { + strcat(nl, "\033[2m\033[3m"); + } for (j=0; j"); strcat(outbuf, nl); } @@ -237,6 +239,9 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth) { else if (!strcasecmp(tag, "/BLOCKQUOTE")) { strcat(outbuf, "\n"); --blockquote; + if ( (blockquote == 0) && (ansi) ) { + strcat(outbuf, "\033[22m\033[23m"); + } strcpy(nl, "\n"); for (j=0; j"); strcat(outbuf, nl); diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 5f50539c2..891941c13 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -1,13 +1,11 @@ -/* - * Header file for libcitadel - * - * Copyright (c) 1987-2022 by the citadel.org team - * +// Header file for libcitadel +// +// Copyright (c) 1987-2022 by the citadel.org team +// // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. - */ -/* protect against double includes */ +// protect against double includes #ifndef LIBCITADEL_H #define LIBCITADEL_H @@ -433,7 +431,7 @@ char *rfc2047encode(const char *line, long length); int is_msg_in_mset(const char *mset, long msgnum); int pattern2(char *search, char *patn); void stripltlen(char *, int *); -char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth); +char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth, int ansi); void LoadEntityList(char *FileName); void utf8ify_rfc822_string(char *buf); diff --git a/textclient/messages.c b/textclient/messages.c index 34e188228..93641b723 100644 --- a/textclient/messages.c +++ b/textclient/messages.c @@ -611,7 +611,7 @@ int read_message(CtdlIPC * ipc, long num, /* message number */ * of the client screen. */ if (!strcasecmp(message->content_type, "text/html")) { - converted_text = html_to_ascii(message->text, 0, screenwidth); + converted_text = html_to_ascii(message->text, 0, screenwidth, (enable_color ? 1 : 0)); if (converted_text != NULL) { free(message->text); message->text = converted_text; diff --git a/webcit/messages.c b/webcit/messages.c index d0ad4d67c..785331712 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -905,7 +905,7 @@ void post_mime_to_server(void) { serv_puts("Content-type: text/plain; charset=utf-8"); serv_puts("Content-Transfer-Encoding: quoted-printable"); serv_puts(""); - txtmail = html_to_ascii(bstr("msgtext"), 0, 80); + txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0); Buf = NewStrBufPlain(txtmail, -1); free(txtmail); -- 2.30.2