=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.119 retrieving revision 1.123 diff -u -p -r1.119 -r1.123 --- mandoc/mdoc_html.c 2010/12/15 16:35:21 1.119 +++ mandoc/mdoc_html.c 2010/12/17 00:18:29 1.123 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.119 2010/12/15 16:35:21 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.123 2010/12/17 00:18:29 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -103,6 +103,7 @@ static int mdoc_nm_pre(MDOC_ARGS); static int mdoc_ns_pre(MDOC_ARGS); static int mdoc_pa_pre(MDOC_ARGS); static void mdoc_pf_post(MDOC_ARGS); +static int mdoc_pp_pre(MDOC_ARGS); static void mdoc_quote_post(MDOC_ARGS); static int mdoc_quote_pre(MDOC_ARGS); static int mdoc_rs_pre(MDOC_ARGS); @@ -126,7 +127,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {NULL, NULL}, /* Os */ {mdoc_sh_pre, NULL }, /* Sh */ {mdoc_ss_pre, NULL }, /* Ss */ - {mdoc_sp_pre, NULL}, /* Pp */ + {mdoc_pp_pre, NULL}, /* Pp */ {mdoc_d1_pre, NULL}, /* D1 */ {mdoc_d1_pre, NULL}, /* Dl */ {mdoc_bd_pre, NULL}, /* Bd */ @@ -227,7 +228,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {NULL, NULL}, /* Fr */ {mdoc_ud_pre, NULL}, /* Ud */ {mdoc_lb_pre, NULL}, /* Lb */ - {mdoc_sp_pre, NULL}, /* Lp */ + {mdoc_pp_pre, NULL}, /* Lp */ {mdoc_lk_pre, NULL}, /* Lk */ {mdoc_mt_pre, NULL}, /* Mt */ {mdoc_quote_pre, mdoc_quote_post}, /* Brq */ @@ -556,46 +557,25 @@ mdoc_root_pre(MDOC_ARGS) static int mdoc_sh_pre(MDOC_ARGS) { - struct htmlpair tag[2]; - const struct mdoc_node *nn; - char buf[BUFSIZ]; - struct roffsu su; + struct htmlpair tag; + char buf[BUFSIZ]; - if (MDOC_BODY == n->type) { - SCALE_HS_INIT(&su, INDENT); - bufcat_su(h, "margin-left", &su); - PAIR_CLASS_INIT(&tag[0], "sec-body"); - PAIR_STYLE_INIT(&tag[1], h); - print_otag(h, TAG_DIV, 2, tag); + if (MDOC_BLOCK == n->type) { + PAIR_CLASS_INIT(&tag, "section"); + print_otag(h, TAG_DIV, 1, &tag); return(1); - } else if (MDOC_BLOCK == n->type) { - PAIR_CLASS_INIT(&tag[0], "sec-block"); - if (n->prev && NULL == n->prev->body->child) { - print_otag(h, TAG_DIV, 1, tag); - return(1); - } - - SCALE_VS_INIT(&su, 1); - bufcat_su(h, "margin-top", &su); - if (NULL == n->next) - bufcat_su(h, "margin-bottom", &su); - - PAIR_STYLE_INIT(&tag[1], h); - print_otag(h, TAG_DIV, 2, tag); + } else if (MDOC_BODY == n->type) return(1); - } buf[0] = '\0'; - for (nn = n->child; nn; nn = nn->next) { - html_idcat(buf, nn->string, BUFSIZ); - if (nn->next) + for (n = n->child; n; n = n->next) { + html_idcat(buf, n->string, BUFSIZ); + if (n->next) html_idcat(buf, " ", BUFSIZ); } - PAIR_CLASS_INIT(&tag[0], "sec-head"); - PAIR_ID_INIT(&tag[1], buf); - - print_otag(h, TAG_DIV, 2, tag); + PAIR_ID_INIT(&tag, buf); + print_otag(h, TAG_H1, 1, &tag); return(1); } @@ -604,51 +584,25 @@ mdoc_sh_pre(MDOC_ARGS) static int mdoc_ss_pre(MDOC_ARGS) { - struct htmlpair tag[3]; - const struct mdoc_node *nn; - char buf[BUFSIZ]; - struct roffsu su; + struct htmlpair tag; + char buf[BUFSIZ]; - SCALE_VS_INIT(&su, 1); - - if (MDOC_BODY == n->type) { - PAIR_CLASS_INIT(&tag[0], "ssec-body"); - if (n->parent->next && n->child) { - bufcat_su(h, "margin-bottom", &su); - PAIR_STYLE_INIT(&tag[1], h); - print_otag(h, TAG_DIV, 2, tag); - } else - print_otag(h, TAG_DIV, 1, tag); + if (MDOC_BLOCK == n->type) { + PAIR_CLASS_INIT(&tag, "subsection"); + print_otag(h, TAG_DIV, 1, &tag); return(1); - } else if (MDOC_BLOCK == n->type) { - PAIR_CLASS_INIT(&tag[0], "ssec-block"); - if (n->prev) { - bufcat_su(h, "margin-top", &su); - PAIR_STYLE_INIT(&tag[1], h); - print_otag(h, TAG_DIV, 2, tag); - } else - print_otag(h, TAG_DIV, 1, tag); + } else if (MDOC_BODY == n->type) return(1); - } - /* TODO: see note in mdoc_sh_pre() about duplicates. */ - buf[0] = '\0'; - for (nn = n->child; nn; nn = nn->next) { - html_idcat(buf, nn->string, BUFSIZ); - if (nn->next) + for (n = n->child; n; n = n->next) { + html_idcat(buf, n->string, BUFSIZ); + if (n->next) html_idcat(buf, " ", BUFSIZ); } - SCALE_HS_INIT(&su, INDENT - HALFINDENT); - su.scale = -su.scale; - bufcat_su(h, "margin-left", &su); - - PAIR_CLASS_INIT(&tag[0], "ssec-head"); - PAIR_STYLE_INIT(&tag[1], h); - PAIR_ID_INIT(&tag[2], buf); - - print_otag(h, TAG_DIV, 3, tag); + PAIR_ID_INIT(&tag, buf); + print_otag(h, TAG_H2, 1, &tag); return(1); } @@ -902,10 +856,6 @@ mdoc_it_pre(MDOC_ARGS) assert(lists[type]); PAIR_CLASS_INIT(&tag[0], lists[type]); - SCALE_VS_INIT(&su, ! bl->data.Bl->comp); - bufcat_su(h, "margin-top", &su); - PAIR_STYLE_INIT(&tag[1], h); - if (MDOC_HEAD == n->type) { switch (type) { case(LIST_bullet): @@ -927,6 +877,9 @@ mdoc_it_pre(MDOC_ARGS) case(LIST_ohang): /* FALLTHROUGH */ case(LIST_tag): + SCALE_VS_INIT(&su, ! bl->data.Bl->comp); + bufcat_su(h, "margin-top", &su); + PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_DT, 2, tag); break; case(LIST_column): @@ -945,7 +898,9 @@ mdoc_it_pre(MDOC_ARGS) case(LIST_enum): /* FALLTHROUGH */ case(LIST_item): - /* FALLTHROUGH */ + SCALE_VS_INIT(&su, ! bl->data.Bl->comp); + bufcat_su(h, "margin-top", &su); + PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_LI, 2, tag); break; case(LIST_diag): @@ -957,9 +912,19 @@ mdoc_it_pre(MDOC_ARGS) case(LIST_ohang): /* FALLTHROUGH */ case(LIST_tag): - print_otag(h, TAG_DD, 1, tag); + if (NULL == bl->data.Bl->width) { + print_otag(h, TAG_DD, 1, tag); + break; + } + a2width(bl->data.Bl->width, &su); + bufcat_su(h, "margin-left", &su); + PAIR_STYLE_INIT(&tag[1], h); + print_otag(h, TAG_DD, 2, tag); break; case(LIST_column): + SCALE_VS_INIT(&su, ! bl->data.Bl->comp); + bufcat_su(h, "margin-top", &su); + PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_TD, 2, tag); break; default: @@ -1132,12 +1097,15 @@ mdoc_d1_pre(MDOC_ARGS) bufcat_su(h, "margin-top", &su); bufcat_su(h, "margin-bottom", &su); PAIR_STYLE_INIT(&tag[0], h); + print_otag(h, TAG_BLOCKQUOTE, 1, tag); + /* BLOCKQUOTE needs a block body. */ + if (MDOC_Dl == n->tok) { PAIR_CLASS_INIT(&tag[1], "lit"); - print_otag(h, TAG_BLOCKQUOTE, 2, tag); + print_otag(h, TAG_DIV, 1, tag); } else - print_otag(h, TAG_BLOCKQUOTE, 1, tag); + print_otag(h, TAG_DIV, 0, tag); return(1); } @@ -1533,37 +1501,35 @@ mdoc_sm_pre(MDOC_ARGS) return(0); } +/* ARGSUSED */ +static int +mdoc_pp_pre(MDOC_ARGS) +{ + print_otag(h, TAG_P, 0, NULL); + return(0); + +} + /* ARGSUSED */ static int mdoc_sp_pre(MDOC_ARGS) { - int len; - struct htmlpair tag; struct roffsu su; + struct htmlpair tag; - switch (n->tok) { - case (MDOC_sp): - /* FIXME: can this have a scaling indicator? */ - len = n->child ? atoi(n->child->string) : 1; - break; - case (MDOC_br): - len = 0; - break; - default: - assert(n->parent); - if ((NULL == n->next || NULL == n->prev) && - (MDOC_Ss == n->parent->tok || - MDOC_Sh == n->parent->tok)) - return(0); - len = 1; - break; - } + SCALE_VS_INIT(&su, 1); - SCALE_VS_INIT(&su, len); + if (MDOC_sp == n->tok) { + if (n->child) + a2roffsu(n->child->string, &su, SCALE_VS); + } else + su.scale = 0; + bufcat_su(h, "height", &su); PAIR_STYLE_INIT(&tag, h); print_otag(h, TAG_DIV, 1, &tag); + /* So the div isn't empty: */ print_text(h, "\\~"); @@ -1571,7 +1537,6 @@ mdoc_sp_pre(MDOC_ARGS) } - /* ARGSUSED */ static int mdoc_lk_pre(MDOC_ARGS) @@ -1858,10 +1823,8 @@ mdoc_rs_pre(MDOC_ARGS) if (MDOC_BLOCK != n->type) return(1); - if (n->prev && SEC_SEE_ALSO == n->sec) { - print_otag(h, TAG_BR, 0, NULL); - print_otag(h, TAG_BR, 0, NULL); - } + if (n->prev && SEC_SEE_ALSO == n->sec) + print_otag(h, TAG_P, 0, NULL); PAIR_CLASS_INIT(&tag, "ref"); print_otag(h, TAG_SPAN, 1, &tag);