=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.4 retrieving revision 1.7 diff -u -p -r1.4 -r1.7 --- mandoc/mdoc_html.c 2009/09/24 09:20:02 1.4 +++ mandoc/mdoc_html.c 2009/09/24 11:55:28 1.7 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.4 2009/09/24 09:20:02 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.7 2009/09/24 11:55:28 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 @@ -61,16 +62,19 @@ static int mdoc_tbl_head_pre(MDOC_ARGS, int, int); static int mdoc_ad_pre(MDOC_ARGS); static int mdoc_an_pre(MDOC_ARGS); +static int mdoc_ap_pre(MDOC_ARGS); static void mdoc_aq_post(MDOC_ARGS); static int mdoc_aq_pre(MDOC_ARGS); static int mdoc_ar_pre(MDOC_ARGS); static int mdoc_bd_pre(MDOC_ARGS); +static int mdoc_bf_pre(MDOC_ARGS); static void mdoc_bl_post(MDOC_ARGS); static int mdoc_bl_pre(MDOC_ARGS); 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); @@ -91,18 +95,22 @@ 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); static int mdoc_nd_pre(MDOC_ARGS); static int mdoc_nm_pre(MDOC_ARGS); static int mdoc_ns_pre(MDOC_ARGS); static void mdoc_op_post(MDOC_ARGS); static int mdoc_op_pre(MDOC_ARGS); static int mdoc_pa_pre(MDOC_ARGS); +static void mdoc_pf_post(MDOC_ARGS); +static int mdoc_pf_pre(MDOC_ARGS); static void mdoc_pq_post(MDOC_ARGS); static int mdoc_pq_pre(MDOC_ARGS); -static void mdoc_qq_post(MDOC_ARGS); -static int mdoc_qq_pre(MDOC_ARGS); +static int mdoc_rs_pre(MDOC_ARGS); static int mdoc_rv_pre(MDOC_ARGS); static int mdoc_sh_pre(MDOC_ARGS); static int mdoc_sp_pre(MDOC_ARGS); @@ -110,6 +118,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); @@ -121,7 +131,7 @@ extern size_t strlcat(char *, const char *, size_ #endif static const struct htmlmdoc mdocs[MDOC_MAX] = { - {NULL, NULL}, /* Ap */ + {mdoc_ap_pre, NULL}, /* Ap */ {NULL, NULL}, /* Dd */ {NULL, NULL}, /* Dt */ {NULL, NULL}, /* Os */ @@ -151,7 +161,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 */ @@ -178,7 +188,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_aq_pre, mdoc_aq_post}, /* Aq */ {NULL, NULL}, /* At */ {NULL, NULL}, /* Bc */ - {NULL, NULL}, /* Bf */ + {mdoc_bf_pre, NULL}, /* Bf */ {mdoc_bq_pre, mdoc_bq_post}, /* Bo */ {mdoc_bq_pre, mdoc_bq_post}, /* Bq */ {mdoc_xx_pre, NULL}, /* Bsx */ @@ -192,27 +202,27 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_em_pre, NULL}, /* Em */ {NULL, NULL}, /* Eo */ {mdoc_xx_pre, NULL}, /* Fx */ - {NULL, NULL}, /* Ms */ + {mdoc_ms_pre, NULL}, /* Ms */ /* FIXME: convert to symbol? */ {NULL, NULL}, /* No */ {mdoc_ns_pre, NULL}, /* Ns */ {mdoc_xx_pre, NULL}, /* Nx */ {mdoc_xx_pre, NULL}, /* Ox */ {NULL, NULL}, /* Pc */ - {NULL, NULL}, /* Pf */ + {mdoc_pf_pre, mdoc_pf_post}, /* Pf */ {mdoc_pq_pre, mdoc_pq_post}, /* Po */ {mdoc_pq_pre, mdoc_pq_post}, /* Pq */ {NULL, NULL}, /* Qc */ {mdoc_sq_pre, mdoc_sq_post}, /* Ql */ - {mdoc_qq_pre, mdoc_qq_post}, /* Qo */ - {mdoc_qq_pre, mdoc_qq_post}, /* Qq */ + {mdoc_dq_pre, mdoc_dq_post}, /* Qo */ + {mdoc_dq_pre, mdoc_dq_post}, /* Qq */ {NULL, NULL}, /* Re */ - {NULL, NULL}, /* Rs */ + {mdoc_rs_pre, NULL}, /* Rs */ {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 */ @@ -223,11 +233,11 @@ 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 */ @@ -1234,7 +1244,7 @@ mdoc_d1_pre(MDOC_ARGS) buffmt("margin-left: %dem;", INDENT); tag[0].key = ATTR_CLASS; - tag[0].val = "lit-block"; + tag[0].val = "lit"; tag[1].key = ATTR_STYLE; tag[1].val = buf; @@ -1353,7 +1363,7 @@ mdoc_bd_pre(MDOC_ARGS) tag[0].key = ATTR_STYLE; tag[0].val = buf; tag[1].key = ATTR_CLASS; - tag[1].val = "lit-block"; + tag[1].val = "lit"; print_otag(h, TAG_DIV, 2, tag); @@ -1384,31 +1394,6 @@ mdoc_pa_pre(MDOC_ARGS) /* ARGSUSED */ static int -mdoc_qq_pre(MDOC_ARGS) -{ - - if (MDOC_BODY != n->type) - return(1); - print_text(h, "\\*q"); - h->flags |= HTML_NOSPACE; - return(1); -} - - -/* ARGSUSED */ -static void -mdoc_qq_post(MDOC_ARGS) -{ - - if (MDOC_BODY != n->type) - return; - h->flags |= HTML_NOSPACE; - print_text(h, "\\*q"); -} - - -/* ARGSUSED */ -static int mdoc_ad_pre(MDOC_ARGS) { struct htmlpair tag; @@ -1576,7 +1561,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); } @@ -1589,6 +1574,9 @@ mdoc_fn_pre(MDOC_ARGS) struct tag *t; struct htmlpair tag; const struct mdoc_node *nn; + char nbuf[BUFSIZ]; + const char *sp, *ep; + int sz; if (SEC_SYNOPSIS == n->sec) { if (n->next) { @@ -1599,13 +1587,33 @@ mdoc_fn_pre(MDOC_ARGS) print_otag(h, TAG_DIV, 0, NULL); } + /* Split apart into type and name. */ + tag.key = ATTR_CLASS; - tag.val = "type"; + tag.val = "ftype"; + t = print_otag(h, TAG_SPAN, 1, &tag); - /* FIXME: can be "type funcname" "type varname"... */ + assert(n->child->string); + sp = n->child->string; + while ((ep = strchr(sp, ' '))) { + sz = MIN(ep - sp, BUFSIZ - 1); + (void)memcpy(nbuf, sp, sz); + nbuf[sz] = '\0'; + print_text(h, nbuf); + sp = ++ep; + } + print_tagq(h, t); + + tag.key = ATTR_CLASS; + tag.val = "fname"; t = print_otag(h, TAG_SPAN, 1, &tag); - print_text(h, n->child->string); + + if (sp) { + (void)strlcpy(nbuf, sp, BUFSIZ); + print_text(h, nbuf); + } + print_tagq(h, t); h->flags |= HTML_NOSPACE; @@ -1905,4 +1913,193 @@ mdoc_bq_post(MDOC_ARGS) return; h->flags |= HTML_NOSPACE; print_text(h, "\\(rB"); +} + + +/* ARGSUSED */ +static int +mdoc_ap_pre(MDOC_ARGS) +{ + + h->flags |= HTML_NOSPACE; + print_text(h, "\\(aq"); + h->flags |= HTML_NOSPACE; + return(1); +} + + +/* ARGSUSED */ +static int +mdoc_bf_pre(MDOC_ARGS) +{ + int i; + struct htmlpair tag[2]; + + if (MDOC_HEAD == n->type) + return(0); + else if (MDOC_BLOCK != n->type) + return(1); + + tag[0].key = ATTR_CLASS; + tag[0].val = NULL; + + if (n->head->child) { + if ( ! strcmp("Em", n->head->child->string)) + tag[0].val = "emph"; + else if ( ! strcmp("Sy", n->head->child->string)) + tag[0].val = "symb"; + else if ( ! strcmp("Li", n->head->child->string)) + tag[0].val = "lit"; + } else { + assert(n->args); + for (i = 0; i < (int)n->args->argc; i++) + switch (n->args->argv[i].arg) { + case (MDOC_Symbolic): + tag[0].val = "symb"; + break; + case (MDOC_Literal): + tag[0].val = "lit"; + break; + case (MDOC_Emphasis): + tag[0].val = "emph"; + break; + default: + break; + } + } + + /* FIXME: div's have spaces stripped--we want them. */ + + assert(tag[0].val); + tag[1].key = ATTR_STYLE; + tag[1].val = "display: inline; margin-right: 1em;"; + print_otag(h, TAG_DIV, 2, tag); + return(1); +} + + +/* ARGSUSED */ +static int +mdoc_ms_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_pf_pre(MDOC_ARGS) +{ + + h->flags |= HTML_IGNDELIM; + return(1); +} + + +/* ARGSUSED */ +static void +mdoc_pf_post(MDOC_ARGS) +{ + + h->flags &= ~HTML_IGNDELIM; + h->flags |= HTML_NOSPACE; +} + + +/* ARGSUSED */ +static int +mdoc_rs_pre(MDOC_ARGS) +{ + struct htmlpair tag[2]; + int i; + + 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"; + } + + /* FIXME: div's have spaces stripped--we want them. */ + + print_otag(h, TAG_DIV, i, tag); + return(1); +} + + + +/* 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); }