=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.6 retrieving revision 1.22 diff -u -p -r1.6 -r1.22 --- mandoc/mdoc_html.c 2009/09/24 11:05:45 1.6 +++ mandoc/mdoc_html.c 2009/10/04 15:24:54 1.22 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.6 2009/09/24 11:05:45 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.22 2009/10/04 15:24:54 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 @@ -34,9 +35,6 @@ #define MDOC_ARGS const struct mdoc_meta *m, \ const struct mdoc_node *n, \ struct html *h -#define MAN_ARGS const struct man_meta *m, \ - const struct man_node *n, \ - struct html *h struct htmlmdoc { int (*pre)(MDOC_ARGS); @@ -59,6 +57,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); @@ -171,17 +171,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 */ @@ -243,21 +243,16 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {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 */ }; -static char buf[BUFSIZ]; /* XXX */ -#define bufcat(x) (void)strlcat(buf, (x), BUFSIZ) -#define bufinit() buf[0] = 0 -#define buffmt(...) (void)snprintf(buf, BUFSIZ - 1, __VA_ARGS__) - void html_mdoc(void *arg, const struct mdoc *m) { @@ -387,21 +382,19 @@ print_mdoc(MDOC_ARGS) static void print_mdoc_head(MDOC_ARGS) { - char b[BUFSIZ]; print_gen_head(h); + bufinit(h); + buffmt(h, "%s(%d)", m->title, m->msec); - (void)snprintf(b, BUFSIZ - 1, - "%s(%d)", m->title, m->msec); - if (m->arch) { - (void)strlcat(b, " (", BUFSIZ); - (void)strlcat(b, m->arch, BUFSIZ); - (void)strlcat(b, ")", BUFSIZ); + bufcat(h, " ("); + bufcat(h, m->arch); + bufcat(h, ")"); } print_otag(h, TAG_TITLE, 0, NULL); - print_text(h, b); + print_text(h, h->buf); } @@ -424,7 +417,7 @@ print_mdoc_node(MDOC_ARGS) child = 1; t = SLIST_FIRST(&h->tags); - bufinit(); + bufinit(h); switch (n->type) { case (MDOC_ROOT): @@ -444,7 +437,7 @@ print_mdoc_node(MDOC_ARGS) print_stagq(h, t); - bufinit(); + bufinit(h); switch (n->type) { case (MDOC_ROOT): @@ -522,19 +515,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); @@ -549,21 +542,17 @@ mdoc_sh_pre(MDOC_ARGS) { struct htmlpair tag[2]; const struct mdoc_node *nn; + char link[BUFSIZ]; - if (MDOC_HEAD == n->type) { + if (MDOC_BODY == n->type) { + buffmt(h, "margin-left: %dem;", INDENT); + tag[0].key = ATTR_CLASS; - tag[0].val = "sec-head"; - print_otag(h, TAG_DIV, 1, tag); - print_otag(h, TAG_SPAN, 1, tag); + tag[0].val = "sec-body"; + tag[1].key = ATTR_STYLE; + tag[1].val = h->buf; - for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); - if (nn->next) - bufcat(" "); - } - tag[0].key = ATTR_NAME; - tag[0].val = buf; - print_otag(h, TAG_A, 1, tag); + print_otag(h, TAG_DIV, 2, tag); return(1); } else if (MDOC_BLOCK == n->type) { tag[0].key = ATTR_CLASS; @@ -574,23 +563,29 @@ mdoc_sh_pre(MDOC_ARGS) return(1); } - bufcat("margin-top: 1em;"); + bufcat(h, "margin-top: 1em;"); if (NULL == n->next) - bufcat("margin-bottom: 1em;"); + bufcat(h, "margin-bottom: 1em;"); tag[1].key = ATTR_STYLE; - tag[1].val = buf; - + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); return(1); } - buffmt("margin-left: %dem;", INDENT); - + link[0] = 0; + for (nn = n->child; nn; nn = nn->next) { + (void)strlcat(link, nn->string, BUFSIZ); + if (nn->next) + (void)strlcat(link, "_", BUFSIZ); + } + + /* FIXME: make sure no duplicates! */ + tag[0].key = ATTR_CLASS; - tag[0].val = "sec-body"; - tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[0].val = "sec-head"; + tag[1].key = ATTR_ID; + tag[1].val = link; print_otag(h, TAG_DIV, 2, tag); return(1); @@ -601,54 +596,58 @@ mdoc_sh_pre(MDOC_ARGS) static int mdoc_ss_pre(MDOC_ARGS) { - struct htmlpair tag[2]; + struct htmlpair tag[3]; int i; const struct mdoc_node *nn; + char link[BUFSIZ]; i = 0; if (MDOC_BODY == n->type) { tag[i].key = ATTR_CLASS; tag[i++].val = "ssec-body"; + if (n->parent->next && n->child) { - bufcat("margin-bottom: 1em;"); + bufcat(h, "margin-bottom: 1em;"); tag[i].key = ATTR_STYLE; - tag[i++].val = buf; + tag[i++].val = h->buf; } + print_otag(h, TAG_DIV, i, tag); return(1); } else if (MDOC_BLOCK == n->type) { tag[i].key = ATTR_CLASS; tag[i++].val = "ssec-block"; + if (n->prev) { - bufcat("margin-top: 1em;"); + bufcat(h, "margin-top: 1em;"); tag[i].key = ATTR_STYLE; - tag[i++].val = buf; + tag[i++].val = h->buf; } + print_otag(h, TAG_DIV, i, tag); return(1); } - buffmt("margin-left: -%dem;", INDENT - HALFINDENT); + link[0] = 0; + for (nn = n->child; nn; nn = nn->next) { + (void)strlcat(link, nn->string, BUFSIZ); + if (nn->next) + (void)strlcat(link, "_", BUFSIZ); + } + buffmt(h, "margin-left: -%dem;", INDENT - HALFINDENT); + + /* FIXME: make sure no duplicates! */ + tag[0].key = ATTR_CLASS; tag[0].val = "ssec-head"; tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; + tag[2].key = ATTR_ID; + tag[2].val = link; - print_otag(h, TAG_DIV, 2, tag); - print_otag(h, TAG_SPAN, 1, tag); - - bufinit(); - for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); - if (nn->next) - bufcat(" "); - } - tag[0].key = ATTR_NAME; - tag[0].val = buf; - print_otag(h, TAG_A, 1, tag); - + print_otag(h, TAG_DIV, 3, tag); return(1); } @@ -748,24 +747,25 @@ static int mdoc_xr_pre(MDOC_ARGS) { struct htmlpair tag[2]; - const char *name, *sec; const struct mdoc_node *nn; + int i; - nn = n->child; - name = nn && nn->string ? nn->string : ""; - nn = nn ? nn->next : NULL; - sec = nn && nn->string ? nn->string : ""; + i = 0; + tag[i].key = ATTR_CLASS; + tag[i++].val = "link-man"; - buffmt("%s%s%s.html", name, name && sec ? "." : "", sec); + if (h->base_man) { + buffmt_man(h, n->child->string, n->child->next ? + n->child->next->string : NULL); + tag[i].key = ATTR_HREF; + tag[i++].val = h->buf; + } - tag[0].key = ATTR_CLASS; - tag[0].val = "link-man"; - tag[1].key = ATTR_HREF; - tag[1].val = buf; - print_otag(h, TAG_A, 2, tag); + print_otag(h, TAG_A, i, tag); nn = n->child; print_text(h, nn->string); + if (NULL == (nn = nn->next)) return(0); @@ -870,7 +870,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): @@ -878,22 +879,38 @@ mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int case (MDOC_Item): /* FALLTHROUGH */ case (MDOC_Ohang): - buffmt("margin-left: %dem; clear: both;", o); + buffmt(h, "margin-left: %dem; clear: both;", o); break; default: - buffmt("margin-left: %dem; clear: both;", w + o); + buffmt(h, "margin-left: %dem; clear: both;", w + o); break; } 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(h, "padding-top: 1em;"); } tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); return(1); } @@ -924,23 +941,23 @@ mdoc_tbl_head_pre(MDOC_ARGS, int t, int w) print_otag(h, TAG_DIV, 0, NULL); break; case (MDOC_Column): - buffmt("min-width: %dem;", w); - bufcat("clear: none;"); + buffmt(h, "min-width: %dem;", w); + bufcat(h, "clear: none;"); if (n->next && MDOC_HEAD == n->next->type) - bufcat("float: left;"); + bufcat(h, "float: left;"); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); break; default: - buffmt("margin-left: -%dem; min-width: %dem;", + buffmt(h, "margin-left: -%dem; min-width: %dem;", w, w ? w - 1 : 0); - bufcat("clear: left;"); + bufcat(h, "clear: left;"); if (n->next && n->next->child) - bufcat("float: left;"); - bufcat("padding-right: 1em;"); + bufcat(h, "float: left;"); + bufcat(h, "padding-right: 1em;"); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); break; } @@ -985,8 +1002,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; @@ -1062,6 +1077,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"); @@ -1240,12 +1257,12 @@ mdoc_d1_pre(MDOC_ARGS) if (MDOC_BLOCK != n->type) return(1); - buffmt("margin-left: %dem;", INDENT); + buffmt(h, "margin-left: %dem;", INDENT); tag[0].key = ATTR_CLASS; tag[0].val = "lit"; tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); return(1); @@ -1258,18 +1275,19 @@ mdoc_sx_pre(MDOC_ARGS) { struct htmlpair tag[2]; const struct mdoc_node *nn; + char link[BUFSIZ]; - bufcat("#"); + (void)strlcpy(link, "#", BUFSIZ); for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); + (void)strlcat(link, nn->string, BUFSIZ); if (nn->next) - bufcat(" "); + (void)strlcat(link, "_", BUFSIZ); } - tag[0].key = ATTR_HREF; - tag[0].val = buf; - tag[1].key = ATTR_CLASS; - tag[1].val = "link-sec"; + tag[0].key = ATTR_CLASS; + tag[0].val = "link-sec"; + tag[1].key = ATTR_HREF; + tag[1].val = link; print_otag(h, TAG_A, 2, tag); return(1); @@ -1307,10 +1325,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) @@ -1324,7 +1340,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; @@ -1342,34 +1358,48 @@ mdoc_bd_pre(MDOC_ARGS) if (MDOC_BLOCK == n->type) { if (o) - buffmt("margin-left: %dem;", o); - bufcat("margin-top: 1em;"); + buffmt(h, "margin-left: %dem;", o); + 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(h, "margin-top: 1em;"); + } tag[0].key = ATTR_STYLE; - tag[0].val = buf; + tag[0].val = h->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;"); + bufcat(h, "white-space: pre;"); tag[0].key = ATTR_STYLE; - tag[0].val = buf; + tag[0].val = h->buf; tag[1].key = ATTR_CLASS; tag[1].val = "lit"; 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"); } @@ -1410,6 +1440,8 @@ mdoc_an_pre(MDOC_ARGS) { struct htmlpair tag; + /* TODO: -split and -nosplit (see termp_an_pre()). */ + tag.key = ATTR_CLASS; tag.val = "author"; print_otag(h, TAG_SPAN, 1, &tag); @@ -1560,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); } @@ -1571,34 +1603,67 @@ 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(h, "margin-left: 6em;"); + bufcat(h, "text-indent: -6em;"); + if (n->next) + bufcat(h, "margin-bottom: 1em;"); + tag[0].key = ATTR_STYLE; + tag[0].val = h->buf; + print_otag(h, TAG_DIV, 1, tag); } - tag.key = ATTR_CLASS; - tag.val = "type"; + /* Split apart into type and name. */ + assert(n->child->string); + sp = n->child->string; - /* FIXME: can be "type funcname" "type varname"... */ + if ((ep = strchr(sp, ' '))) { + tag[0].key = ATTR_CLASS; + tag[0].val = "ftype"; + + t = print_otag(h, TAG_SPAN, 1, tag); + + while (ep) { + sz = MIN((int)(ep - sp), BUFSIZ - 1); + (void)memcpy(nbuf, sp, (size_t)sz); + nbuf[sz] = '\0'; + print_text(h, nbuf); + sp = ++ep; + ep = strchr(sp, ' '); + } + print_tagq(h, t); + } - t = print_otag(h, TAG_SPAN, 1, &tag); - print_text(h, n->child->string); + 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) @@ -1633,9 +1698,9 @@ mdoc_sp_pre(MDOC_ARGS) break; } - buffmt("height: %dem", len); + buffmt(h, "height: %dem;", len); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); return(1); @@ -1705,12 +1770,12 @@ mdoc_mt_pre(MDOC_ARGS) tag[0].val = "link-mail"; for (nn = n->child; nn; nn = nn->next) { - bufinit(); - bufcat("mailto:"); - bufcat(nn->string); + bufinit(h); + bufcat(h, "mailto:"); + bufcat(h, nn->string); tag[1].key = ATTR_HREF; - tag[1].val = buf; + tag[1].val = h->buf; t = print_otag(h, TAG_A, 2, tag); print_text(h, nn->string); @@ -1760,21 +1825,23 @@ static int mdoc_in_pre(MDOC_ARGS) { const struct mdoc_node *nn; - struct htmlpair tag; + struct htmlpair tag[2]; + struct tag *t; + int i; if (SEC_SYNOPSIS == n->sec) { if (n->next && MDOC_In != n->next->tok) { - tag.key = ATTR_STYLE; - tag.val = "margin-bottom: 1em;"; - print_otag(h, TAG_DIV, 1, &tag); + tag[0].key = ATTR_STYLE; + tag[0].val = "margin-bottom: 1em;"; + print_otag(h, TAG_DIV, 1, tag); } else print_otag(h, TAG_DIV, 0, NULL); } - tag.key = ATTR_CLASS; - tag.val = "includes"; + tag[0].key = ATTR_CLASS; + tag[0].val = "includes"; - print_otag(h, TAG_SPAN, 1, &tag); + print_otag(h, TAG_SPAN, 1, tag); if (SEC_SYNOPSIS == n->sec) print_text(h, "#include"); @@ -1784,8 +1851,20 @@ mdoc_in_pre(MDOC_ARGS) /* XXX -- see warning in termp_in_post(). */ - for (nn = n->child; nn; nn = nn->next) + for (nn = n->child; nn; nn = nn->next) { + assert(MDOC_TEXT == nn->type); + i = 0; + tag[i].key = ATTR_CLASS; + tag[i++].val = "link-includes"; + if (h->base_includes) { + buffmt_includes(h, nn->string); + tag[i].key = ATTR_HREF; + tag[i++].val = h->buf; + } + t = print_otag(h, TAG_A, i, tag); print_mdoc_node(m, nn, h); + print_tagq(h, t); + } h->flags |= HTML_NOSPACE; print_text(h, ">"); @@ -1991,26 +2070,20 @@ 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. */ - - print_otag(h, TAG_DIV, i, tag); + tag.key = ATTR_CLASS; + tag.val = "ref"; + print_otag(h, TAG_SPAN, 1, &tag); return(1); } @@ -2078,4 +2151,82 @@ mdoc_lb_pre(MDOC_ARGS) 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 ? "," : "."); }