=================================================================== RCS file: /cvs/mandoc/man_html.c,v retrieving revision 1.134 retrieving revision 1.146 diff -u -p -r1.134 -r1.146 --- mandoc/man_html.c 2017/03/15 11:29:53 1.134 +++ mandoc/man_html.c 2018/04/11 17:11:13 1.146 @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.134 2017/03/15 11:29:53 schwarze Exp $ */ +/* $Id: man_html.c,v 1.146 2018/04/11 17:11:13 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -26,6 +26,7 @@ #include #include "mandoc_aux.h" +#include "mandoc.h" #include "roff.h" #include "man.h" #include "out.h" @@ -65,14 +66,12 @@ static int man_SM_pre(MAN_ARGS); static int man_SS_pre(MAN_ARGS); static int man_UR_pre(MAN_ARGS); static int man_alt_pre(MAN_ARGS); -static int man_br_pre(MAN_ARGS); static int man_ign_pre(MAN_ARGS); static int man_in_pre(MAN_ARGS); static void man_root_post(MAN_ARGS); static void man_root_pre(MAN_ARGS); -static const struct htmlman mans[MAN_MAX] = { - { man_br_pre, NULL }, /* br */ +static const struct htmlman __mans[MAN_MAX - MAN_TH] = { { NULL, NULL }, /* TH */ { man_SH_pre, NULL }, /* SH */ { man_SS_pre, NULL }, /* SS */ @@ -93,7 +92,6 @@ static const struct htmlman mans[MAN_MAX] = { { man_I_pre, NULL }, /* I */ { man_alt_pre, NULL }, /* IR */ { man_alt_pre, NULL }, /* RI */ - { man_br_pre, NULL }, /* sp */ { NULL, NULL }, /* nf */ { NULL, NULL }, /* fi */ { NULL, NULL }, /* RE */ @@ -103,14 +101,15 @@ static const struct htmlman mans[MAN_MAX] = { { man_ign_pre, NULL }, /* PD */ { man_ign_pre, NULL }, /* AT */ { man_in_pre, NULL }, /* in */ - { man_ign_pre, NULL }, /* ft */ { man_OP_pre, NULL }, /* OP */ { NULL, NULL }, /* EX */ { NULL, NULL }, /* EE */ { man_UR_pre, NULL }, /* UR */ { NULL, NULL }, /* UE */ - { man_ign_pre, NULL }, /* ll */ + { man_UR_pre, NULL }, /* MT */ + { NULL, NULL }, /* ME */ }; +static const struct htmlman *const mans = __mans - MAN_TH; /* @@ -233,6 +232,7 @@ print_man_node(MAN_ARGS) case MAN_P: /* reopen .nf in the body. */ case MAN_RS: case MAN_UR: + case MAN_MT: fillmode(h, MAN_fi); break; default: @@ -255,12 +255,15 @@ print_man_node(MAN_ARGS) case ROFFT_TEXT: if (fillmode(h, want_fillmode) == MAN_fi && want_fillmode == MAN_fi && - n->flags & NODE_LINE && *n->string == ' ') + n->flags & NODE_LINE && *n->string == ' ' && + (h->flags & HTML_NONEWLINE) == 0) print_otag(h, TAG_BR, ""); if (*n->string != '\0') break; print_paragraph(h); return; + case ROFFT_COMMENT: + return; default: break; } @@ -304,6 +307,13 @@ print_man_node(MAN_ARGS) print_tblclose(h); t = h->tag; + if (n->tok < ROFF_MAX) { + roff_html_pre(h, n); + child = 0; + break; + } + + assert(n->tok >= MAN_TH && n->tok < MAN_MAX); if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, h); @@ -354,13 +364,9 @@ fillmode(struct html *h, int want) static int a2width(const struct roff_node *n, struct roffsu *su) { - if (n->type != ROFFT_TEXT) return 0; - if (a2roffsu(n->string, su, SCALE_EN)) - return 1; - - return 0; + return a2roffsu(n->string, su, SCALE_EN) != NULL; } static void @@ -409,30 +415,7 @@ man_root_post(MAN_ARGS) print_tagq(h, t); } - static int -man_br_pre(MAN_ARGS) -{ - struct roffsu su; - - SCALE_VS_INIT(&su, 1); - - if (MAN_sp == n->tok) { - if (NULL != (n = n->child)) - if ( ! a2roffsu(n->string, &su, SCALE_VS)) - su.scale = 1.0; - } else - su.scale = 0.0; - - print_otag(h, TAG_DIV, "suh", &su); - - /* So the div isn't empty: */ - print_text(h, "\\~"); - - return 0; -} - -static int man_SH_pre(MAN_ARGS) { char *id; @@ -440,7 +423,8 @@ man_SH_pre(MAN_ARGS) if (n->type == ROFFT_HEAD) { id = html_make_id(n); print_otag(h, TAG_H1, "cTi", "Sh", id); - print_otag(h, TAG_A, "chR", "selflink", id); + if (id != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); free(id); } return 1; @@ -509,7 +493,8 @@ man_SS_pre(MAN_ARGS) if (n->type == ROFFT_HEAD) { id = html_make_id(n); print_otag(h, TAG_H2, "cTi", "Ss", id); - print_otag(h, TAG_A, "chR", "selflink", id); + if (id != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); free(id); } return 1; @@ -664,11 +649,17 @@ man_RS_pre(MAN_ARGS) static int man_UR_pre(MAN_ARGS) { + char *cp; n = n->child; assert(n->type == ROFFT_HEAD); if (n->child != NULL) { assert(n->child->type == ROFFT_TEXT); - print_otag(h, TAG_A, "cTh", "Lk", n->child->string); + if (n->tok == MAN_MT) { + mandoc_asprintf(&cp, "mailto:%s", n->child->string); + print_otag(h, TAG_A, "cTh", "Mt", cp); + free(cp); + } else + print_otag(h, TAG_A, "cTh", "Lk", n->child->string); } assert(n->next->type == ROFFT_BODY);