=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.119 retrieving revision 1.130 diff -u -p -r1.119 -r1.130 --- mandoc/mdoc_html.c 2010/12/15 16:35:21 1.119 +++ mandoc/mdoc_html.c 2010/12/17 12:57:49 1.130 @@ -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.130 2010/12/17 12:57:49 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 */ @@ -286,7 +287,7 @@ a2width(const char *p, struct roffsu *su) { if ( ! a2roffsu(p, su, SCALE_MAX)) { - su->unit = SCALE_EM; + su->unit = SCALE_BU; su->scale = (int)strlen(p); } } @@ -298,21 +299,15 @@ a2width(const char *p, struct roffsu *su) static void synopsis_pre(struct html *h, const struct mdoc_node *n) { - struct roffsu su; - struct htmlpair tag; if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) return; - SCALE_VS_INIT(&su, 1); - bufcat_su(h, "margin-top", &su); - PAIR_STYLE_INIT(&tag, h); - if (n->prev->tok == n->tok && MDOC_Fo != n->tok && MDOC_Ft != n->tok && MDOC_Fn != n->tok) { - print_otag(h, TAG_DIV, 0, NULL); + print_otag(h, TAG_BR, 0, NULL); return; } @@ -326,16 +321,16 @@ synopsis_pre(struct html *h, const struct mdoc_node *n case (MDOC_In): /* FALLTHROUGH */ case (MDOC_Vt): - print_otag(h, TAG_DIV, 1, &tag); + print_otag(h, TAG_P, 0, NULL); break; case (MDOC_Ft): if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) { - print_otag(h, TAG_DIV, 1, &tag); + print_otag(h, TAG_P, 0, NULL); break; } /* FALLTHROUGH */ default: - print_otag(h, TAG_DIV, 0, NULL); + print_otag(h, TAG_BR, 0, NULL); break; } } @@ -359,7 +354,7 @@ a2offs(const char *p, struct roffsu *su) else if (0 == strcmp(p, "indent-two")) SCALE_HS_INIT(su, INDENT * 2); else if ( ! a2roffsu(p, su, SCALE_MAX)) { - su->unit = SCALE_EM; + su->unit = SCALE_BU; su->scale = (int)strlen(p); } } @@ -462,37 +457,31 @@ print_mdoc_node(MDOC_ARGS) } } - /* ARGSUSED */ static void mdoc_root_post(MDOC_ARGS) { - struct htmlpair tag[3]; + struct htmlpair tag[2]; struct tag *t, *tt; char b[DATESIZ]; time2a(m->date, b, DATESIZ); - PAIR_CLASS_INIT(&tag[0], "footer"); - bufcat_style(h, "width", "100%"); - PAIR_STYLE_INIT(&tag[1], h); - PAIR_SUMMARY_INIT(&tag[2], "footer"); + PAIR_CLASS_INIT(&tag[0], "foot"); + PAIR_SUMMARY_INIT(&tag[1], "Document Footer"); + t = print_otag(h, TAG_TABLE, 2, tag); - t = print_otag(h, TAG_TABLE, 3, tag); tt = print_otag(h, TAG_TR, 0, NULL); - bufinit(h); - bufcat_style(h, "width", "50%"); - PAIR_STYLE_INIT(&tag[0], h); + PAIR_CLASS_INIT(&tag[0], "foot-date"); print_otag(h, TAG_TD, 1, tag); + print_text(h, b); print_stagq(h, tt); - bufinit(h); - bufcat_style(h, "width", "50%"); - bufcat_style(h, "text-align", "right"); - PAIR_STYLE_INIT(&tag[0], h); + PAIR_CLASS_INIT(&tag[0], "foot-os"); print_otag(h, TAG_TD, 1, tag); + print_text(h, m->os); print_tagq(h, t); } @@ -516,36 +505,27 @@ mdoc_root_pre(MDOC_ARGS) snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec); - PAIR_CLASS_INIT(&tag[0], "header"); - bufcat_style(h, "width", "100%"); - PAIR_STYLE_INIT(&tag[1], h); - PAIR_SUMMARY_INIT(&tag[2], "header"); + PAIR_CLASS_INIT(&tag[0], "head"); + PAIR_SUMMARY_INIT(&tag[1], "Document Header"); + t = print_otag(h, TAG_TABLE, 2, tag); - t = print_otag(h, TAG_TABLE, 3, tag); - tt = print_otag(h, TAG_TR, 0, NULL); - bufinit(h); - bufcat_style(h, "width", "10%"); - PAIR_STYLE_INIT(&tag[0], h); + PAIR_CLASS_INIT(&tag[0], "head-ltitle"); print_otag(h, TAG_TD, 1, tag); + print_text(h, title); print_stagq(h, tt); - bufinit(h); - bufcat_style(h, "text-align", "center"); - bufcat_style(h, "white-space", "nowrap"); - bufcat_style(h, "width", "80%"); - PAIR_STYLE_INIT(&tag[0], h); + PAIR_CLASS_INIT(&tag[0], "head-vol"); print_otag(h, TAG_TD, 1, tag); + print_text(h, b); print_stagq(h, tt); - bufinit(h); - bufcat_style(h, "text-align", "right"); - bufcat_style(h, "width", "10%"); - PAIR_STYLE_INIT(&tag[0], h); + PAIR_CLASS_INIT(&tag[0], "head-rtitle"); print_otag(h, TAG_TD, 1, tag); + print_text(h, title); print_tagq(h, t); return(1); @@ -556,46 +536,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 +563,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 +623,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 +634,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 +813,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 +834,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 +855,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 +869,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: @@ -1023,7 +945,10 @@ mdoc_bl_pre(MDOC_ARGS) PAIR_STYLE_INIT(&tag[0], h); assert(lists[n->data.Bl->type]); - PAIR_CLASS_INIT(&tag[1], lists[n->data.Bl->type]); + bufinit(h); + bufcat(h, "list "); + bufcat(h, lists[n->data.Bl->type]); + PAIR_INIT(&tag[1], ATTR_CLASS, h->buf); i = 2; /* Set the block's left-hand margin. */ @@ -1078,6 +1003,9 @@ mdoc_ex_pre(MDOC_ARGS) struct tag *t; struct htmlpair tag; + if (n->prev) + print_otag(h, TAG_BR, 0, NULL); + PAIR_CLASS_INIT(&tag, "utility"); print_text(h, "The"); @@ -1132,13 +1060,16 @@ 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); - if (MDOC_Dl == n->tok) { - PAIR_CLASS_INIT(&tag[1], "lit"); - print_otag(h, TAG_BLOCKQUOTE, 2, tag); - } else - print_otag(h, TAG_BLOCKQUOTE, 1, tag); + /* BLOCKQUOTE needs a block body. */ + if (MDOC_Dl == n->tok) + PAIR_CLASS_INIT(&tag[0], "lit display"); + else + PAIR_CLASS_INIT(&tag[0], "display"); + + print_otag(h, TAG_DIV, 1, tag); return(1); } @@ -1178,19 +1109,8 @@ mdoc_bd_pre(MDOC_ARGS) if (MDOC_HEAD == n->type) return(0); - SCALE_VS_INIT(&su, 0); - - assert(n->data.Bd); - if (n->data.Bd->offs) - a2offs(n->data.Bd->offs, &su); - - comp = n->data.Bd->comp; - - /* FIXME: -centered, etc. formatting. */ - /* FIXME: does not respect -offset ??? */ - if (MDOC_BLOCK == n->type) { - bufcat_su(h, "margin-left", &su); + comp = n->data.Bd->comp; for (nn = n; nn && ! comp; nn = nn->parent) { if (MDOC_BLOCK != nn->type) continue; @@ -1199,26 +1119,27 @@ mdoc_bd_pre(MDOC_ARGS) if (nn->prev) break; } - if (comp) { - PAIR_STYLE_INIT(&tag[0], h); - print_otag(h, TAG_DIV, 1, tag); - return(1); - } - SCALE_VS_INIT(&su, 1); - bufcat_su(h, "margin-top", &su); - PAIR_STYLE_INIT(&tag[0], h); - print_otag(h, TAG_DIV, 1, tag); + if ( ! comp) + print_otag(h, TAG_P, 0, NULL); return(1); } + SCALE_HS_INIT(&su, 0); + if (n->data.Bd->offs) + a2offs(n->data.Bd->offs, &su); + + bufcat_su(h, "margin-left", &su); + PAIR_STYLE_INIT(&tag[0], h); + if (DISP_unfilled != n->data.Bd->type && - DISP_literal != n->data.Bd->type) + DISP_literal != n->data.Bd->type) { + PAIR_CLASS_INIT(&tag[1], "display"); + print_otag(h, TAG_DIV, 2, tag); return(1); + } - PAIR_CLASS_INIT(&tag[0], "lit"); - bufcat_style(h, "white-space", "pre"); - PAIR_STYLE_INIT(&tag[1], h); - print_otag(h, TAG_DIV, 2, tag); + PAIR_CLASS_INIT(&tag[1], "lit display"); + print_otag(h, TAG_PRE, 2, tag); for (nn = n->child; nn; nn = nn->next) { print_mdoc_node(m, nn, h); @@ -1250,7 +1171,9 @@ mdoc_bd_pre(MDOC_ARGS) } if (nn->next && nn->next->line == nn->line) continue; - print_text(h, "\n"); + else if (nn->next) + print_text(h, "\n"); + h->flags |= HTML_NOSPACE; } @@ -1533,37 +1456,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 +1492,6 @@ mdoc_sp_pre(MDOC_ARGS) } - /* ARGSUSED */ static int mdoc_lk_pre(MDOC_ARGS) @@ -1722,7 +1642,9 @@ mdoc_rv_pre(MDOC_ARGS) struct htmlpair tag; struct tag *t; - print_otag(h, TAG_DIV, 0, NULL); + if (n->prev) + print_otag(h, TAG_BR, 0, NULL); + print_text(h, "The"); for (nn = n->child; nn; nn = nn->next) { @@ -1858,10 +1780,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); @@ -1920,8 +1840,9 @@ mdoc_lb_pre(MDOC_ARGS) { struct htmlpair tag; - if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags) - print_otag(h, TAG_DIV, 0, NULL); + if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev) + print_otag(h, TAG_BR, 0, NULL); + PAIR_CLASS_INIT(&tag, "lib"); print_otag(h, TAG_SPAN, 1, &tag); return(1);