summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-01-25 02:14:43 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-01-25 02:14:43 +0000
commit75f0aa87c57b152c84c7f856cb1ab705769c6478 (patch)
treebdc6aeee5b3f0315cb57f4964f4d43ac809aafb9
parent2678c5ab0377c06b6806c2fafd2df37e3c7d23c7 (diff)
downloadmandoc-75f0aa87c57b152c84c7f856cb1ab705769c6478.tar.gz
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--TODO6
-rw-r--r--cgi.c2
-rw-r--r--html.c3
-rw-r--r--mandoc.css15
-rw-r--r--mandoc_html.34
-rw-r--r--mdoc_html.c48
6 files changed, 66 insertions, 12 deletions
diff --git a/TODO b/TODO
index e79d3614..dab8ea72 100644
--- a/TODO
+++ b/TODO
@@ -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 &nbsp;
or use <pre> rather than <div> (like .Bd -literal does).
diff --git a/cgi.c b/cgi.c
index c7422139..434f2223 100644
--- a/cgi.c
+++ b/cgi.c
@@ -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
diff --git a/html.c b/html.c
index cc4e0a26..27ae08b0 100644
--- a/html.c
+++ b/html.c
@@ -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();
diff --git a/mandoc.css b/mandoc.css
index 582ac39a..3f0b03b5 100644
--- a/mandoc.css
+++ b/mandoc.css
@@ -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 517b0eff..1ec5637b 100644
--- a/mandoc_html.3
+++ b/mandoc_html.3
@@ -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 a09f2f42..e5ac0a2c 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -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";