diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-01-25 02:14:42 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-01-25 02:14:42 +0000 |
commit | 7b0f0047f8d6149c308cb3c969a4723bbe92ee21 (patch) | |
tree | 1585011665644f7cb3728d9b244f70fcd29fe4c4 /usr.bin | |
parent | c0801ebe7871359dfe0aee0034ddd22bceb2518a (diff) |
Improve HTML formatting of .Bl -tag.
In particular, when using the style sheet, put the body on the same
line as the head for short heads, or on the next line for long
heads, in a way that preserves both correct indentation and correct
vertical spacing with and without -compact, and with one or more
heads per body (hi, Zaphod) - eight use cases so far - and with and
without -tag, and with and without -offset, 32 use cases grand total.
Using many ideas from zhuk@, from <David dot Dahlberg at fkie dot
fraunhofer dot de>, and from Benny Lofgren <bl dash lists at lofgren
dot biz>, and a few of my own.
This is an excellent demonstration that CSS is an extremely hostile
language, much more trapful and much harder to use than, say, C.
When matthew@ reported this in July 2014 (!), it was already a known
issue, and i no longer remember for how long. My first serious
attempt at fixing it (in November 2015) failed miserably. I'd love
to see simplifications of both the generated HTML code and of the
style sheet, but without breaking any of the 32 use cases, please.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/cgi.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/html.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 50 |
3 files changed, 53 insertions, 6 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c index 7d52dcc1204..c8a9ee7ac58 100644 --- a/usr.bin/mandoc/cgi.c +++ b/usr.bin/mandoc/cgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cgi.c,v 1.83 2017/01/21 01:20:29 schwarze Exp $ */ +/* $OpenBSD: cgi.c,v 1.84 2017/01/25 02:14:41 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@usta.de> @@ -797,6 +797,7 @@ resp_format(const struct req *req, const char *file) memset(&conf, 0, sizeof(conf)); conf.fragment = 1; + conf.style = mandoc_strdup(CSS_DIR "/mandoc.css"); usepath = strcmp(req->q.manpath, req->p[0]); mandoc_asprintf(&conf.man, "/%s%s%%N.%%S", usepath ? req->q.manpath : "", usepath ? "/" : ""); @@ -824,6 +825,7 @@ resp_format(const struct req *req, const char *file) mparse_free(mp); mchars_free(); free(conf.man); + free(conf.style); } static void diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index c4694f6a5cd..d9eb9ce25e7 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: html.c,v 1.70 2017/01/21 02:28:42 schwarze Exp $ */ +/* $OpenBSD: html.c,v 1.71 2017/01/25 02:14:41 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -564,8 +564,11 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) SCALE_VS_INIT(su, i); break; case 'w': + case 'W': s = va_arg(ap, char *); a2width(s, su); + if (fmt[-1] == 'W') + su->scale *= -1.0; break; default: abort(); diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 54bd26a4633..5e0b986c3fd 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.135 2017/01/21 02:09:49 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.136 2017/01/25 02:14:41 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -669,6 +669,7 @@ static int mdoc_it_pre(MDOC_ARGS) { const struct roff_node *bl; + struct tag *t; const char *cattr; enum mdoc_list type; @@ -736,7 +737,6 @@ mdoc_it_pre(MDOC_ARGS) case LIST_hang: case LIST_inset: case LIST_ohang: - case LIST_tag: switch (n->type) { case ROFFT_HEAD: if (bl->norm->Bl.comp) @@ -757,6 +757,41 @@ mdoc_it_pre(MDOC_ARGS) break; } break; + case LIST_tag: + switch (n->type) { + case ROFFT_HEAD: + if (h->style != NULL && !bl->norm->Bl.comp && + (n->parent->prev == NULL || + n->parent->prev->body->child != NULL)) { + if (bl->norm->Bl.width == NULL) + t = print_otag(h, TAG_DT, "c", cattr); + else + t = print_otag(h, TAG_DT, "csWl", + cattr, bl->norm->Bl.width); + print_text(h, "\\ "); + print_tagq(h, t); + t = print_otag(h, TAG_DD, "c", cattr); + print_text(h, "\\ "); + print_tagq(h, t); + } + if (bl->norm->Bl.width == NULL) + print_otag(h, TAG_DT, "c", cattr); + else + print_otag(h, TAG_DT, "csWl", cattr, + bl->norm->Bl.width); + break; + case ROFFT_BODY: + if (n->child == NULL) { + print_otag(h, TAG_DD, "css?", cattr, + "width", "auto"); + print_text(h, "\\ "); + } else + print_otag(h, TAG_DD, "c", cattr); + break; + default: + break; + } + break; case LIST_column: switch (n->type) { case ROFFT_HEAD: @@ -843,9 +878,16 @@ mdoc_bl_pre(MDOC_ARGS) cattr = "Bl-ohang"; break; case LIST_tag: - elemtype = TAG_DL; cattr = "Bl-tag"; - break; + if (n->norm->Bl.offs) + print_otag(h, TAG_DIV, "cswl", cattr, + n->norm->Bl.offs); + if (n->norm->Bl.width == NULL) + print_otag(h, TAG_DL, "c", cattr); + else + print_otag(h, TAG_DL, "cswl", cattr, + n->norm->Bl.width); + return 1; case LIST_column: elemtype = TAG_TABLE; cattr = "Bl-column"; |