=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.5 retrieving revision 1.15 diff -u -p -r1.5 -r1.15 --- mandoc/mdoc_html.c 2009/09/24 09:50:31 1.5 +++ mandoc/mdoc_html.c 2009/09/26 18:31:36 1.15 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.5 2009/09/24 09:50:31 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.15 2009/09/26 18:31:36 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -15,6 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include #include @@ -59,6 +60,8 @@ static int mdoc_tbl_block_pre(MDOC_ARGS, int, int, static int mdoc_tbl_body_pre(MDOC_ARGS, int, int); static int mdoc_tbl_head_pre(MDOC_ARGS, int, int); +static void mdoc__x_post(MDOC_ARGS); +static int mdoc__x_pre(MDOC_ARGS); static int mdoc_ad_pre(MDOC_ARGS); static int mdoc_an_pre(MDOC_ARGS); static int mdoc_ap_pre(MDOC_ARGS); @@ -73,6 +76,7 @@ static void mdoc_bq_post(MDOC_ARGS); static int mdoc_bq_pre(MDOC_ARGS); static void mdoc_brq_post(MDOC_ARGS); static int mdoc_brq_pre(MDOC_ARGS); +static int mdoc_bt_pre(MDOC_ARGS); static int mdoc_bx_pre(MDOC_ARGS); static int mdoc_cd_pre(MDOC_ARGS); static int mdoc_d1_pre(MDOC_ARGS); @@ -93,6 +97,8 @@ static int mdoc_fo_pre(MDOC_ARGS); static int mdoc_ic_pre(MDOC_ARGS); static int mdoc_in_pre(MDOC_ARGS); static int mdoc_it_pre(MDOC_ARGS); +static int mdoc_lb_pre(MDOC_ARGS); +static int mdoc_li_pre(MDOC_ARGS); static int mdoc_lk_pre(MDOC_ARGS); static int mdoc_mt_pre(MDOC_ARGS); static int mdoc_ms_pre(MDOC_ARGS); @@ -114,6 +120,8 @@ static void mdoc_sq_post(MDOC_ARGS); static int mdoc_sq_pre(MDOC_ARGS); static int mdoc_ss_pre(MDOC_ARGS); static int mdoc_sx_pre(MDOC_ARGS); +static int mdoc_sy_pre(MDOC_ARGS); +static int mdoc_ud_pre(MDOC_ARGS); static int mdoc_va_pre(MDOC_ARGS); static int mdoc_vt_pre(MDOC_ARGS); static int mdoc_xr_pre(MDOC_ARGS); @@ -155,7 +163,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_ft_pre, NULL}, /* Ft */ {mdoc_ic_pre, NULL}, /* Ic */ {mdoc_in_pre, NULL}, /* In */ - {NULL, NULL}, /* Li */ + {mdoc_li_pre, NULL}, /* Li */ {mdoc_nd_pre, NULL}, /* Nd */ {mdoc_nm_pre, NULL}, /* Nm */ {mdoc_op_pre, mdoc_op_post}, /* Op */ @@ -166,17 +174,17 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_va_pre, NULL}, /* Va */ {mdoc_vt_pre, NULL}, /* Vt */ {mdoc_xr_pre, NULL}, /* Xr */ - {NULL, NULL}, /* %A */ - {NULL, NULL}, /* %B */ - {NULL, NULL}, /* %D */ - {NULL, NULL}, /* %I */ - {NULL, NULL}, /* %J */ - {NULL, NULL}, /* %N */ - {NULL, NULL}, /* %O */ - {NULL, NULL}, /* %P */ - {NULL, NULL}, /* %R */ - {NULL, NULL}, /* %T */ - {NULL, NULL}, /* %V */ + {mdoc__x_pre, mdoc__x_post}, /* %A */ + {mdoc__x_pre, mdoc__x_post}, /* %B */ + {mdoc__x_pre, mdoc__x_post}, /* %D */ + {mdoc__x_pre, mdoc__x_post}, /* %I */ + {mdoc__x_pre, mdoc__x_post}, /* %J */ + {mdoc__x_pre, mdoc__x_post}, /* %N */ + {mdoc__x_pre, mdoc__x_post}, /* %O */ + {mdoc__x_pre, mdoc__x_post}, /* %P */ + {mdoc__x_pre, mdoc__x_post}, /* %R */ + {mdoc__x_pre, mdoc__x_post}, /* %T */ + {mdoc__x_pre, mdoc__x_post}, /* %V */ {NULL, NULL}, /* Ac */ {mdoc_aq_pre, mdoc_aq_post}, /* Ao */ {mdoc_aq_pre, mdoc_aq_post}, /* Aq */ @@ -214,9 +222,9 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {NULL, NULL}, /* Sc */ {mdoc_sq_pre, mdoc_sq_post}, /* So */ {mdoc_sq_pre, mdoc_sq_post}, /* Sq */ - {NULL, NULL}, /* Sm */ + {NULL, NULL}, /* Sm */ /* FIXME - no idea. */ {mdoc_sx_pre, NULL}, /* Sx */ - {NULL, NULL}, /* Sy */ + {mdoc_sy_pre, NULL}, /* Sy */ {NULL, NULL}, /* Tn */ {mdoc_xx_pre, NULL}, /* Ux */ {NULL, NULL}, /* Xc */ @@ -227,22 +235,22 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {NULL, NULL}, /* Oc */ {NULL, NULL}, /* Bk */ {NULL, NULL}, /* Ek */ - {NULL, NULL}, /* Bt */ + {mdoc_bt_pre, NULL}, /* Bt */ {NULL, NULL}, /* Hf */ {NULL, NULL}, /* Fr */ - {NULL, NULL}, /* Ud */ - {NULL, NULL}, /* Lb */ + {mdoc_ud_pre, NULL}, /* Ud */ + {mdoc_lb_pre, NULL}, /* Lb */ {mdoc_sp_pre, NULL}, /* Lp */ {mdoc_lk_pre, NULL}, /* Lk */ {mdoc_mt_pre, NULL}, /* Mt */ {mdoc_brq_pre, mdoc_brq_post}, /* Brq */ {mdoc_brq_pre, mdoc_brq_post}, /* Bro */ {NULL, NULL}, /* Brc */ - {NULL, NULL}, /* %C */ + {mdoc__x_pre, mdoc__x_post}, /* %C */ {NULL, NULL}, /* Es */ /* TODO */ {NULL, NULL}, /* En */ /* TODO */ {mdoc_xx_pre, NULL}, /* Dx */ - {NULL, NULL}, /* %Q */ + {mdoc__x_pre, mdoc__x_post}, /* %Q */ {mdoc_sp_pre, NULL}, /* br */ {mdoc_sp_pre, NULL}, /* sp */ }; @@ -517,19 +525,19 @@ mdoc_root_pre(MDOC_ARGS) tt = print_otag(h, TAG_TR, 0, NULL); tag[0].key = ATTR_STYLE; - tag[0].val = "width: 33%;"; + tag[0].val = "width: 10%;"; print_otag(h, TAG_TD, 1, tag); print_text(h, title); print_stagq(h, tt); tag[0].key = ATTR_STYLE; - tag[0].val = "width: 33%; text-align: center;"; + tag[0].val = "width: 80%; white-space: nowrap; text-align: center;"; print_otag(h, TAG_TD, 1, tag); print_text(h, b); print_stagq(h, tt); tag[0].key = ATTR_STYLE; - tag[0].val = "width: 33%; text-align: right;"; + tag[0].val = "width: 10%; text-align: right;"; print_otag(h, TAG_TD, 1, tag); print_text(h, title); print_tagq(h, t); @@ -865,7 +873,8 @@ mdoc_bx_pre(MDOC_ARGS) static int mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int c) { - struct htmlpair tag; + struct htmlpair tag; + const struct mdoc_node *nn; switch (t) { case (MDOC_Column): @@ -881,10 +890,26 @@ mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int } if ( ! c && MDOC_Column != t) { - if (n->prev && n->prev->body->child) - bufcat("padding-top: 1em;"); - else if (NULL == n->prev) - bufcat("padding-top: 1em;"); + for (nn = n; nn; nn = nn->parent) { + if (MDOC_BLOCK != nn->type) + continue; + switch (nn->tok) { + case (MDOC_Ss): + /* FALLTHROUGH */ + case (MDOC_Sh): + c = 1; + break; + default: + break; + } + if (nn->prev) + break; + } + if (MDOC_Diag == t && n->prev) + if (NULL == n->prev->body->child) + c = 1; + if ( ! c) + bufcat("padding-top: 1em;"); } tag.key = ATTR_STYLE; @@ -980,8 +1005,6 @@ mdoc_tbl_pre(MDOC_ARGS, int type) if (MDOC_BLOCK != n->type) bl = bl->parent; - /* FIXME: fmt_vspace() equivalent. */ - assert(bl->args); w = o = c = 0; @@ -1057,6 +1080,8 @@ mdoc_bl_pre(MDOC_ARGS) if (MDOC_Enum != a2list(n)) return(1); + /* Allocate an -enum on the stack of indices. */ + ord = malloc(sizeof(struct ord)); if (NULL == ord) err(EXIT_FAILURE, "malloc"); @@ -1302,10 +1327,8 @@ mdoc_bd_pre(MDOC_ARGS) { struct htmlpair tag[2]; int t, c, o, i; - const struct mdoc_node *bl; + const struct mdoc_node *bl, *nn; - /* FIXME: fmt_vspace() shit. */ - if (MDOC_BLOCK == n->type) bl = n; else if (MDOC_HEAD == n->type) @@ -1319,7 +1342,7 @@ mdoc_bd_pre(MDOC_ARGS) switch (bl->args->argv[i].arg) { case (MDOC_Offset): assert(bl->args->argv[i].sz); - o = a2offs (bl->args->argv[i].value[0]); + o = a2offs(bl->args->argv[i].value[0]); break; case (MDOC_Compact): c = 1; @@ -1338,20 +1361,33 @@ mdoc_bd_pre(MDOC_ARGS) if (MDOC_BLOCK == n->type) { if (o) buffmt("margin-left: %dem;", o); - bufcat("margin-top: 1em;"); + if ( ! c) { + for (nn = n; nn; nn = nn->parent) { + if (MDOC_BLOCK != nn->type) + continue; + switch (nn->tok) { + case (MDOC_Ss): + /* FALLTHROUGH */ + case (MDOC_Sh): + c = 1; + break; + default: + break; + } + if (nn->prev) + break; + } + if ( ! c) + bufcat("margin-top: 1em;"); + } tag[0].key = ATTR_STYLE; tag[0].val = buf; print_otag(h, TAG_DIV, 1, tag); return(1); } - switch (t) { - case (MDOC_Unfilled): - case (MDOC_Literal): - break; - default: + if (MDOC_Unfilled != t && MDOC_Literal != t) return(1); - } bufcat("white-space: pre;"); tag[0].key = ATTR_STYLE; @@ -1361,10 +1397,11 @@ mdoc_bd_pre(MDOC_ARGS) print_otag(h, TAG_DIV, 2, tag); - for (n = n->child; n; n = n->next) { - h->flags |= HTML_NOSPACE; - print_mdoc_node(m, n, h); - if (n->next) + for (nn = n->child; nn; nn = nn->next) { + print_mdoc_node(m, nn, h); + if (NULL == nn->next) + continue; + if (nn->prev && nn->prev->line < nn->line) print_text(h, "\n"); } @@ -1555,7 +1592,7 @@ mdoc_ft_pre(MDOC_ARGS) } tag.key = ATTR_CLASS; - tag.val = "type"; + tag.val = "ftype"; print_otag(h, TAG_SPAN, 1, &tag); return(1); } @@ -1566,34 +1603,64 @@ static int mdoc_fn_pre(MDOC_ARGS) { struct tag *t; - struct htmlpair tag; + struct htmlpair tag[2]; const struct mdoc_node *nn; + char nbuf[BUFSIZ]; + const char *sp, *ep; + int sz, i; if (SEC_SYNOPSIS == n->sec) { - if (n->next) { - tag.key = ATTR_STYLE; - tag.val = "margin-bottom: 1em"; - print_otag(h, TAG_DIV, 1, &tag); - } else - print_otag(h, TAG_DIV, 0, NULL); + bufcat("margin-left: 6em;"); + bufcat("text-indent: -6em;"); + if (n->next) + bufcat("margin-bottom: 1em;"); + tag[0].key = ATTR_STYLE; + tag[0].val = buf; + print_otag(h, TAG_DIV, 1, tag); } - tag.key = ATTR_CLASS; - tag.val = "type"; + /* Split apart into type and name. */ - /* FIXME: can be "type funcname" "type varname"... */ + tag[0].key = ATTR_CLASS; + tag[0].val = "ftype"; + t = print_otag(h, TAG_SPAN, 1, tag); - t = print_otag(h, TAG_SPAN, 1, &tag); - print_text(h, n->child->string); + assert(n->child->string); + sp = n->child->string; + while (NULL != (ep = strchr(sp, ' '))) { + sz = MIN((int)(ep - sp), BUFSIZ - 1); + (void)memcpy(nbuf, sp, (size_t)sz); + nbuf[sz] = '\0'; + print_text(h, nbuf); + sp = ++ep; + } + print_tagq(h, t); + tag[0].key = ATTR_CLASS; + tag[0].val = "fname"; + t = print_otag(h, TAG_SPAN, 1, tag); + + if (sp) { + (void)strlcpy(nbuf, sp, BUFSIZ); + print_text(h, nbuf); + } + + print_tagq(h, t); + h->flags |= HTML_NOSPACE; print_text(h, "("); for (nn = n->child->next; nn; nn = nn->next) { - tag.key = ATTR_CLASS; - tag.val = "farg"; - t = print_otag(h, TAG_SPAN, 1, &tag); + i = 0; + tag[i].key = ATTR_CLASS; + tag[i++].val = "farg"; + if (SEC_SYNOPSIS == n->sec) { + tag[i].key = ATTR_STYLE; + tag[i++].val = "white-space: nowrap;"; + } + + t = print_otag(h, TAG_SPAN, i, tag); print_text(h, nn->string); print_tagq(h, t); if (nn->next) @@ -1986,25 +2053,163 @@ mdoc_pf_post(MDOC_ARGS) static int mdoc_rs_pre(MDOC_ARGS) { - struct htmlpair tag[2]; - int i; + struct htmlpair tag; if (MDOC_BLOCK != n->type) return(1); - tag[i = 0].key = ATTR_CLASS; - tag[i++].val = "ref"; - - if (n->prev && SEC_SYNOPSIS == n->sec) { - tag[i].key = ATTR_STYLE; - tag[i++].val = "margin-top: 1em;"; - } else if (SEC_SYNOPSIS != n->sec) { - tag[i].key = ATTR_STYLE; - tag[i++].val = "display: inline; margin-right: 1em"; + if (n->prev && SEC_SEE_ALSO == n->sec) { + tag.key = ATTR_STYLE; + tag.val = "margin-top: 1em;"; + print_otag(h, TAG_DIV, 1, &tag); } - /* FIXME: div's have spaces stripped--we want them. */ + tag.key = ATTR_CLASS; + tag.val = "ref"; + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} - print_otag(h, TAG_DIV, i, tag); + + +/* ARGSUSED */ +static int +mdoc_li_pre(MDOC_ARGS) +{ + struct htmlpair tag; + + tag.key = ATTR_CLASS; + tag.val = "lit"; + + print_otag(h, TAG_SPAN, 1, &tag); return(1); +} + + +/* ARGSUSED */ +static int +mdoc_sy_pre(MDOC_ARGS) +{ + struct htmlpair tag; + + tag.key = ATTR_CLASS; + tag.val = "symb"; + + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static int +mdoc_bt_pre(MDOC_ARGS) +{ + + print_text(h, "is currently in beta test."); + return(0); +} + + +/* ARGSUSED */ +static int +mdoc_ud_pre(MDOC_ARGS) +{ + + print_text(h, "currently under development."); + return(0); +} + + +/* ARGSUSED */ +static int +mdoc_lb_pre(MDOC_ARGS) +{ + struct htmlpair tag; + + tag.key = ATTR_CLASS; + tag.val = "lib"; + + if (SEC_SYNOPSIS == n->sec) + print_otag(h, TAG_DIV, 0, NULL); + + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static int +mdoc__x_pre(MDOC_ARGS) +{ + struct htmlpair tag; + + tag.key = ATTR_CLASS; + + switch (n->tok) { + case(MDOC__A): + tag.val = "ref-auth"; + break; + case(MDOC__B): + tag.val = "ref-book"; + break; + case(MDOC__C): + tag.val = "ref-city"; + break; + case(MDOC__D): + tag.val = "ref-date"; + break; + case(MDOC__I): + tag.val = "ref-issue"; + break; + case(MDOC__J): + tag.val = "ref-jrnl"; + break; + case(MDOC__N): + tag.val = "ref-num"; + break; + case(MDOC__O): + tag.val = "ref-opt"; + break; + case(MDOC__P): + tag.val = "ref-page"; + break; + case(MDOC__Q): + tag.val = "ref-corp"; + break; + case(MDOC__R): + tag.val = "ref-rep"; + break; + case(MDOC__T): + print_text(h, "\\(lq"); + h->flags |= HTML_NOSPACE; + tag.val = "ref-title"; + break; + case(MDOC__V): + tag.val = "ref-vol"; + break; + default: + abort(); + /* NOTREACHED */ + } + + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static void +mdoc__x_post(MDOC_ARGS) +{ + + h->flags |= HTML_NOSPACE; + switch (n->tok) { + case (MDOC__T): + print_text(h, "\\(rq"); + h->flags |= HTML_NOSPACE; + break; + default: + break; + } + print_text(h, n->next ? "," : "."); }