From ac186529b6b5f80906c3215a67c98505db7bb156 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 13 Apr 2021 19:13:58 -0700 Subject: Implement .M2HT request for HTML passthrough. --- man2html/man2html.1 | 3 +++ man2html/man2html.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/man2html/man2html.1 b/man2html/man2html.1 index 089edf4..b374a96 100644 --- a/man2html/man2html.1 +++ b/man2html/man2html.1 @@ -149,6 +149,9 @@ The datum is the heading to be indexed and emitted into the HTML output. The standard .SH and .SS requests use levels 0 and 1, respectively, and HTML tags H2 and H3, respectively. +The request ".M2HT argument" can be used to emit raw HTML. The +argument is passed through as HTML without any escaping. + .SH BUGS There are many heuristics. The output will not always be perfect. The lynxcgi method will not work if lynx was compiled without diff --git a/man2html/man2html.c b/man2html/man2html.c index 8f9b0e5..3a06408 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -50,6 +50,7 @@ int maxtstop=12; int curpos=0; static char *scan_troff(char *c, int san, char **result); +static char *scan_troff_raw(char *c, int san, char **result); static char *scan_troff_mandoc(char *c, int san, char **result); static char **argument=NULL; @@ -2286,6 +2287,18 @@ scan_request(char *c) { free(wordlist[2]); } break; + case V4('M','2','H','T'): + { + char *h = NULL; + c=c+j; + c = fill_words(c, wordlist, SIZE(wordlist), &words, 0); + if (words!=1) + abort(); + scan_troff_raw(wordlist[0], 1, &h); + out_html(h); + free(h); + } + break; case V('T','S'): c=scan_table(c); nofillout=1; @@ -3002,7 +3015,7 @@ static int contained_tab=0; static int mandoc_line=0;/* Signals whether to look for embedded mandoc cmds */ static char * -scan_troff(char *c, int san, char **result) { /* san : stop at newline */ +do_scan_troff(char *c, int san, int htmlesc, char **result) { /* san : stop at newline */ char *h; char intbuff[500]; int ibp=0; @@ -3070,7 +3083,7 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ curpos=0; still_dd=0; } - switch (*h) { + if (htmlesc) switch (*h) { case '&': intbuff[ibp++]='&'; intbuff[ibp++]='a'; @@ -3177,6 +3190,21 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ } curpos++; break; + } else { + if (*h > 31 && *h < 127) { + intbuff[ibp++]=*h; + } else if (((unsigned char)(*h)) > 127) { +#ifdef NO_8BIT + intbuff[ibp++]='&'; + intbuff[ibp++]='#'; + intbuff[ibp++]='0'+((unsigned char)(*h))/100; + intbuff[ibp++]='0'+(((unsigned char)(*h))%100)/10; + intbuff[ibp++]='0'+((unsigned char)(*h))%10; + intbuff[ibp++]=';'; +#else + intbuff[ibp++]=*h; +#endif + } } if (ibp>480) FLUSHIBP; h++; @@ -3196,6 +3224,16 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ return h; } +static char * +scan_troff(char *c, int san, char **result) { + return do_scan_troff(c, san, 1, result); +} + +static char * +scan_troff_raw(char *c, int san, char **result) { + return do_scan_troff(c, san, 0, result); +} + static char *scan_troff_mandoc(char *c, int san, char **result) { char *ret, *end = c; int oldval = mandoc_line; -- cgit v1.2.3