On rare occasions I'd like to use the following idiom to read manuals in browsers, mostly to better readability and navigation of long sections:
MANPAGER=netsurf-gtk3 man -Thtml jq (jq(1) has lots of examples and HTML is nicer to read when it comes to literal input and output for example.) My problem is that browsers fail to render HTML as such in case the temporary file generated by mandoc(1) lack a file extension, i.e. `$browser /tmp/man.abc123' will show literal HTML code whereas `$browser /tmp/man.abc123.html' will actually render it. HTML is the only output type I've encountered problem with so far. PDF/mupdf(1) for example works fine with arbitrary file names: MANPAGER=mupdf man -Tpdf jq Diff below makes mandoc produce temporary files with the ".html" suffix in case `-Thtml' was specified. It feels a bit off to do this for HTML only, but it greatly improves accessibility for me and is simple enough. If need be, the suffix handling could be easily extended to cover more output types in the future. Feedback? Objections? OK? Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.255 diff -u -p -r1.255 main.c --- main.c 21 Jul 2020 15:08:48 -0000 1.255 +++ main.c 16 Jan 2021 09:03:09 -0000 @@ -824,7 +824,7 @@ process_onefile(struct mparse *mp, struc if (outst->use_pager) { outst->use_pager = 0; outst->tag_files = term_tag_init(conf->output.outfilename, - conf->output.tagfilename); + conf->output.tagfilename, outst->outtype == OUTT_HTML); if ((conf->output.outfilename != NULL || conf->output.tagfilename != NULL) && pledge("stdio rpath cpath", NULL) == -1) { Index: term_tag.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/term_tag.c,v retrieving revision 1.5 diff -u -p -r1.5 term_tag.c --- term_tag.c 21 Jul 2020 15:08:49 -0000 1.5 +++ term_tag.c 16 Jan 2021 09:10:33 -0000 @@ -45,11 +45,13 @@ static struct tag_files tag_files; * but for simplicity, create it anyway. */ struct tag_files * -term_tag_init(const char *outfilename, const char *tagfilename) +term_tag_init(const char *outfilename, const char *tagfilename, int ishtml) { struct sigaction sa; int ofd; /* In /tmp/, dup(2)ed to stdout. */ int tfd; + char *suffix = ishtml ? ".html" : ""; + size_t suffixlen = strlen(suffix); ofd = tfd = -1; tag_files.tfs = NULL; @@ -83,9 +85,9 @@ term_tag_init(const char *outfilename, c /* Create both temporary output files. */ if (outfilename == NULL) { - (void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX", - sizeof(tag_files.ofn)); - if ((ofd = mkstemp(tag_files.ofn)) == -1) { + (void)snprintf(tag_files.ofn, sizeof(tag_files.ofn), + "/tmp/man.XXXXXXXXXX%s", suffix); + if ((ofd = mkstemps(tag_files.ofn, suffixlen)) == -1) { mandoc_msg(MANDOCERR_MKSTEMP, 0, 0, "%s: %s", tag_files.ofn, strerror(errno)); goto fail; Index: term_tag.h =================================================================== RCS file: /cvs/src/usr.bin/mandoc/term_tag.h,v retrieving revision 1.3 diff -u -p -r1.3 term_tag.h --- term_tag.h 21 Jul 2020 15:08:49 -0000 1.3 +++ term_tag.h 16 Jan 2021 09:03:30 -0000 @@ -28,7 +28,7 @@ struct tag_files { }; -struct tag_files *term_tag_init(const char *, const char *); +struct tag_files *term_tag_init(const char *, const char *, int); void term_tag_write(struct roff_node *, size_t); int term_tag_close(void); void term_tag_unlink(void);