diff options
author | 2017-01-25 02:14:43 +0000 | |
---|---|---|
committer | 2017-01-25 02:14:43 +0000 | |
commit | 1ec67c1af1b363b2138d23adb47cf9a20831b5d1 (patch) | |
tree | 9634a2c1e0aa1949c5c75ce5eb08378ee14ef3b8 | |
parent | 5d0a6a3dde9b1be9a0d4b91df936289aec6b292b (diff) | |
download | mandoc-1ec67c1af1b363b2138d23adb47cf9a20831b5d1.tar.gz mandoc-1ec67c1af1b363b2138d23adb47cf9a20831b5d1.tar.zst mandoc-1ec67c1af1b363b2138d23adb47cf9a20831b5d1.zip |
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.
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | cgi.c | 4 | ||||
-rw-r--r-- | html.c | 5 | ||||
-rw-r--r-- | mandoc.css | 17 | ||||
-rw-r--r-- | mandoc_html.3 | 8 | ||||
-rw-r--r-- | mdoc_html.c | 50 |
6 files changed, 73 insertions, 19 deletions
@@ -1,6 +1,6 @@ ************************************************************************ * Official mandoc TODO. -* $Id: TODO,v 1.223 2017/01/17 15:32:43 schwarze Exp $ +* $Id: TODO,v 1.224 2017/01/25 02:14:43 schwarze Exp $ ************************************************************************ Many issues are annotated for difficulty as follows: @@ -408,12 +408,6 @@ are mere guesses, and some may be wrong. --- HTML issues -------------------------------------------------------- -- <dl><dt><dd> formatting is ugly - hints are easy to find on the web, e.g. - http://stackoverflow.com/questions/1713048/ - see also matthew@ Fri, 18 Jul 2014 19:25:12 -0700 - loc * exist * algo ** size * imp *** - - In -man -Thtml, .nf does not preserve indentation. It should either convert blanks to or use <pre> rather than <div> (like .Bd -literal does). @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.144 2017/01/21 01:20:31 schwarze Exp $ */ +/* $Id: cgi.c,v 1.145 2017/01/25 02:14:43 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@usta.de> @@ -799,6 +799,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 ? "/" : ""); @@ -826,6 +827,7 @@ resp_format(const struct req *req, const char *file) mparse_free(mp); mchars_free(); free(conf.man); + free(conf.style); } static void @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.200 2017/01/21 02:29:57 schwarze Exp $ */ +/* $Id: html.c,v 1.201 2017/01/25 02:14:43 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -566,8 +566,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(); @@ -1,4 +1,4 @@ -/* $Id: mandoc.css,v 1.13 2017/01/21 02:29:57 schwarze Exp $ */ +/* $Id: mandoc.css,v 1.14 2017/01/25 02:14:43 schwarze Exp $ */ /* * Standard style sheet for mandoc(1) -Thtml and man.cgi(8). */ @@ -91,9 +91,18 @@ dd.It-inset { } dl.Bl-ohang { } dt.It-ohang { } dd.It-ohang { margin-left: 0ex; } -dl.Bl-tag { } -dt.It-tag { } -dd.It-tag { } +dl.Bl-tag { margin-left: 8ex; } +dt.It-tag { float: left; + clear: both; + margin-top: 0ex; + margin-left: -8ex; + padding-right: 2ex; + vertical-align: top; } +dd.It-tag { width: 100%; + margin-top: 0ex; + margin-left: 0ex; + vertical-align: top; + overflow: auto; } table.Bl-column { } tr.It-column { } diff --git a/mandoc_html.3 b/mandoc_html.3 index 80b1fe69..a77cdf45 100644 --- a/mandoc_html.3 +++ b/mandoc_html.3 @@ -1,4 +1,4 @@ -.\" $Id: mandoc_html.3,v 1.3 2017/01/17 15:32:44 schwarze Exp $ +.\" $Id: mandoc_html.3,v 1.4 2017/01/25 02:14:43 schwarze Exp $ .\" .\" Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 17 2017 $ +.Dd $Mdocdate: January 25 2017 $ .Dt MANDOC_HTML 3 .Os .Sh NAME @@ -212,6 +212,10 @@ Requires one argument, interpreted as an .Xr mdoc 7 Ns -style width specifier. +.It Cm W +Similar to +.Cm w , +but makes the width negative by multiplying it with \(mi1. .El .Pp Style name letters decide what to do with the preceding argument: diff --git a/mdoc_html.c b/mdoc_html.c index 3f757d20..ea9c0550 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.260 2017/01/21 02:09:51 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.261 2017/01/25 02:14:43 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -671,6 +671,7 @@ static int mdoc_it_pre(MDOC_ARGS) { const struct roff_node *bl; + struct tag *t; const char *cattr; enum mdoc_list type; @@ -738,7 +739,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) @@ -759,6 +759,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: @@ -845,9 +880,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"; |