diff options
-rw-r--r-- | html.c | 82 | ||||
-rw-r--r-- | mandoc_html.3 | 17 | ||||
-rw-r--r-- | mdoc_html.c | 67 |
3 files changed, 84 insertions, 82 deletions
@@ -449,7 +449,7 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) char numbuf[16]; struct tag *t; const char *attr; - char *s; + char *arg1, *arg2; double v; int i, have_style, tflags; @@ -494,12 +494,14 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) have_style = 0; while (*fmt != '\0') { if (*fmt == 's') { - print_word(h, " style=\""); have_style = 1; fmt++; break; } - s = va_arg(ap, char *); + + /* Parse a non-style attribute and its arguments. */ + + arg1 = va_arg(ap, char *); switch (*fmt++) { case 'c': attr = "class"; @@ -511,23 +513,31 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) attr = "id"; break; case '?': - attr = s; - s = va_arg(ap, char *); + attr = arg1; + arg1 = va_arg(ap, char *); break; default: abort(); } + arg2 = NULL; + if (*fmt == 'M') + arg2 = va_arg(ap, char *); + if (arg1 == NULL) + continue; + + /* Print the non-style attributes. */ + print_byte(h, ' '); print_word(h, attr); print_byte(h, '='); print_byte(h, '"'); switch (*fmt) { case 'M': - print_href(h, s, va_arg(ap, char *), 1); + print_href(h, arg1, arg2, 1); fmt++; break; case 'I': - print_href(h, s, NULL, 0); + print_href(h, arg1, NULL, 0); fmt++; break; case 'R': @@ -535,7 +545,7 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) fmt++; /* FALLTHROUGH */ default: - print_encode(h, s, NULL, 1); + print_encode(h, arg1, NULL, 1); break; } print_byte(h, '"'); @@ -543,31 +553,35 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) /* Print out styles. */ - s = NULL; - su = &mysu; while (*fmt != '\0') { + arg1 = NULL; + su = NULL; /* First letter: input argument type. */ switch (*fmt++) { case 'h': i = va_arg(ap, int); + su = &mysu; SCALE_HS_INIT(su, i); break; case 's': - s = va_arg(ap, char *); + arg1 = va_arg(ap, char *); break; case 'u': su = va_arg(ap, struct roffsu *); break; case 'v': i = va_arg(ap, int); + su = &mysu; SCALE_VS_INIT(su, i); break; case 'w': case 'W': - s = va_arg(ap, char *); - a2width(s, su); + if ((arg2 = va_arg(ap, char *)) == NULL) + break; + su = &mysu; + a2width(arg2, su); if (fmt[-1] == 'W') su->scale *= -1.0; break; @@ -600,33 +614,37 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) attr = "min-width"; break; case '?': - print_word(h, s); - print_byte(h, ':'); - print_byte(h, ' '); - print_word(h, va_arg(ap, char *)); - print_byte(h, ';'); - if (*fmt != '\0') - print_byte(h, ' '); - continue; + attr = arg1; + arg1 = va_arg(ap, char *); + break; default: abort(); } - v = su->scale; - if (su->unit == SCALE_MM && (v /= 100.0) == 0.0) - v = 1.0; - else if (su->unit == SCALE_BU) - v /= 24.0; + if (su == NULL && arg1 == NULL) + continue; + + if (have_style == 1) + print_word(h, " style=\""); + else + print_byte(h, ' '); print_word(h, attr); print_byte(h, ':'); print_byte(h, ' '); - (void)snprintf(numbuf, sizeof(numbuf), "%.2f", v); - print_word(h, numbuf); - print_word(h, roffscales[su->unit]); + if (su != NULL) { + v = su->scale; + if (su->unit == SCALE_MM && (v /= 100.0) == 0.0) + v = 1.0; + else if (su->unit == SCALE_BU) + v /= 24.0; + (void)snprintf(numbuf, sizeof(numbuf), "%.2f", v); + print_word(h, numbuf); + print_word(h, roffscales[su->unit]); + } else + print_word(h, arg1); print_byte(h, ';'); - if (*fmt != '\0') - print_byte(h, ' '); + have_style = 2; } - if (have_style) + if (have_style == 2) print_byte(h, '"'); va_end(ap); diff --git a/mandoc_html.3 b/mandoc_html.3 index 1ec5637b..40a4a2b7 100644 --- a/mandoc_html.3 +++ b/mandoc_html.3 @@ -137,6 +137,9 @@ Most attributes require one .Va char * argument which becomes the value of the attribute. The arguments have to be given in the same order as the attribute letters. +If an argument is +.Dv NULL , +the respective attribute is not written. .Bl -tag -width 1n -offset indent .It Cm c Print a @@ -175,13 +178,15 @@ Print an arbitrary attribute. This format letter requires two .Vt char * arguments, the attribute name and the value. +The name must not be +.Dv NULL . .It Cm s Print a .Cm style attribute. If present, it must be the last format letter. In contrast to the other format letters, this one does not yet -print the value and does not require an argument. +print the value and does not take an argument. Instead, the rest of the format string consists of pairs of argument type letters and style name letters. .El @@ -212,6 +217,9 @@ Requires one argument, interpreted as an .Xr mdoc 7 Ns -style width specifier. +If the argument is +.Dv NULL , +nothing is printed for this pair. .It Cm W Similar to .Cm w , @@ -255,6 +263,8 @@ requires two .Vt char * arguments. The first is the style name, the second its value. +The style name must not be +.Dv NULL . .El .Pp .Fn print_otag @@ -340,5 +350,6 @@ implementation of common mandoc utility functions .An -nosplit The mandoc HTML formatter was written by .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv . -This manual was written by -.An Ingo Schwarze Aq Mt schwarze@openbsd.org . +It is maintained by +.An Ingo Schwarze Aq Mt schwarze@openbsd.org , +who also wrote this manual. diff --git a/mdoc_html.c b/mdoc_html.c index ff635059..158c1e7f 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -507,22 +507,18 @@ mdoc_sh_pre(MDOC_ARGS) char *id; switch (n->type) { - case ROFFT_BLOCK: - return 1; + case ROFFT_HEAD: + id = make_id(n); + print_otag(h, TAG_H1, "ci", "Sh", id); + free(id); + break; case ROFFT_BODY: if (n->sec == SEC_AUTHORS) h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT); - return 1; + break; default: break; } - - if ((id = make_id(n)) != NULL) { - print_otag(h, TAG_H1, "ci", "Sh", id); - free(id); - } else - print_otag(h, TAG_H1, "c", "Sh"); - return 1; } @@ -534,12 +530,9 @@ mdoc_ss_pre(MDOC_ARGS) if (n->type != ROFFT_HEAD) return 1; - if ((id = make_id(n)) != NULL) { - print_otag(h, TAG_H2, "ci", "Ss", id); - free(id); - } else - print_otag(h, TAG_H2, "c", "Ss"); - + id = make_id(n); + print_otag(h, TAG_H2, "ci", "Ss", id); + free(id); return 1; } @@ -749,11 +742,8 @@ mdoc_it_pre(MDOC_ARGS) print_otag(h, TAG_B, "c", cattr); break; case ROFFT_BODY: - if (bl->norm->Bl.width == NULL) - print_otag(h, TAG_DD, "c", cattr); - else - print_otag(h, TAG_DD, "cswl", cattr, - bl->norm->Bl.width); + print_otag(h, TAG_DD, "cswl", cattr, + bl->norm->Bl.width); break; default: break; @@ -765,22 +755,16 @@ mdoc_it_pre(MDOC_ARGS) 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); + 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); + print_otag(h, TAG_DT, "csWl", cattr, + bl->norm->Bl.width); break; case ROFFT_BODY: if (n->child == NULL) { @@ -885,10 +869,7 @@ mdoc_bl_pre(MDOC_ARGS) cattr = "Bl-tag"; if (bl->offs) print_otag(h, TAG_DIV, "cswl", cattr, bl->offs); - if (bl->width == NULL) - print_otag(h, TAG_DL, "c", cattr); - else - print_otag(h, TAG_DL, "cswl", cattr, bl->width); + print_otag(h, TAG_DL, "cswl", cattr, bl->width); return 1; case LIST_column: elemtype = TAG_TABLE; @@ -897,12 +878,7 @@ mdoc_bl_pre(MDOC_ARGS) default: abort(); } - - if (bl->offs) - print_otag(h, elemtype, "cswl", cattr, bl->offs); - else - print_otag(h, elemtype, "c", cattr); - + print_otag(h, elemtype, "cswl", cattr, bl->offs); return 1; } @@ -940,12 +916,9 @@ mdoc_sx_pre(MDOC_ARGS) { char *id; - if ((id = make_id(n)) != NULL) { - print_otag(h, TAG_A, "chR", "Sx", id); - free(id); - } else - print_otag(h, TAG_A, "c", "Sx"); - + id = make_id(n); + print_otag(h, TAG_A, "chR", "Sx", id); + free(id); return 1; } |