=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.119 retrieving revision 1.124 diff -u -p -r1.119 -r1.124 --- mandoc/mdoc_html.c 2010/12/15 16:35:21 1.119 +++ mandoc/mdoc_html.c 2010/12/17 01:02:00 1.124 @@ -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.124 2010/12/17 01:02:00 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); } @@ -690,7 +644,7 @@ mdoc_nd_pre(MDOC_ARGS) /* XXX: this tag in theory can contain block elements. */ print_text(h, "\\(em"); - PAIR_CLASS_INIT(&tag, "desc-body"); + PAIR_CLASS_INIT(&tag, "desc"); print_otag(h, TAG_SPAN, 1, &tag); return(1); } @@ -701,68 +655,46 @@ mdoc_nm_pre(MDOC_ARGS) { struct htmlpair tag; struct roffsu su; - const char *cp; + size_t len; - /* - * Accomodate for `Nm' being both an element (which may have - * NULL children AND no m->name) and a block. - */ - - cp = NULL; - - if (MDOC_ELEM == n->type) { - if (NULL == n->child && NULL == m->name) - return(1); + switch (n->type) { + case (MDOC_ELEM): synopsis_pre(h, n); PAIR_CLASS_INIT(&tag, "name"); print_otag(h, TAG_SPAN, 1, &tag); - if (NULL == n->child) + if (NULL == n->child && m->name) print_text(h, m->name); - } else if (MDOC_BLOCK == n->type) { - synopsis_pre(h, n); + return(1); + case (MDOC_HEAD): + print_otag(h, TAG_TD, 0, NULL); + if (NULL == n->child && m->name) + print_text(h, m->name); + return(1); + case (MDOC_BODY): + print_otag(h, TAG_TD, 0, NULL); + return(1); + default: + break; + } - bufcat_style(h, "clear", "both"); - if (n->head->child || m->name) { - if (n->head->child && MDOC_TEXT == - n->head->child->type) - cp = n->head->child->string; - if (NULL == cp || '\0' == *cp) - cp = m->name; + synopsis_pre(h, n); + PAIR_CLASS_INIT(&tag, "synopsis"); + print_otag(h, TAG_TABLE, 1, &tag); - SCALE_HS_INIT(&su, (double)strlen(cp)); - bufcat_su(h, "padding-left", &su); - } + for (len = 0, n = n->child; n; n = n->next) + if (MDOC_TEXT == n->type) + len += strlen(n->string); - PAIR_STYLE_INIT(&tag, h); - print_otag(h, TAG_DIV, 1, &tag); - } else if (MDOC_HEAD == n->type) { - if (NULL == n->child && NULL == m->name) - return(1); + if (0 == len && m->name) + len = strlen(m->name); - if (n->child && MDOC_TEXT == n->child->type) - cp = n->child->string; - if (NULL == cp || '\0' == *cp) - cp = m->name; - - SCALE_HS_INIT(&su, (double)strlen(cp)); - - bufcat_style(h, "float", "left"); - bufcat_su(h, "min-width", &su); - SCALE_INVERT(&su); - bufcat_su(h, "margin-left", &su); - - PAIR_STYLE_INIT(&tag, h); - print_otag(h, TAG_DIV, 1, &tag); - - if (NULL == n->child) - print_text(h, m->name); - } else if (MDOC_BODY == n->type) { - SCALE_HS_INIT(&su, 2); - bufcat_su(h, "margin-left", &su); - PAIR_STYLE_INIT(&tag, h); - print_otag(h, TAG_DIV, 1, &tag); - } - + SCALE_HS_INIT(&su, (double)len); + bufcat_su(h, "width", &su); + PAIR_STYLE_INIT(&tag, h); + print_otag(h, TAG_COL, 1, &tag); + print_otag(h, TAG_COL, 0, NULL); + print_otag(h, TAG_TBODY, 0, NULL); + print_otag(h, TAG_TR, 0, NULL); return(1); } @@ -902,10 +834,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 +855,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 +876,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 +890,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 +1075,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 +1479,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 +1515,6 @@ mdoc_sp_pre(MDOC_ARGS) } - /* ARGSUSED */ static int mdoc_lk_pre(MDOC_ARGS) @@ -1858,10 +1801,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);