[BACK]Return to mdoc_html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mdoc_html.c, Revision 1.76

1.76    ! kristaps    1: /*     $Id: mdoc_html.c,v 1.75 2010/06/04 22:16:27 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
1.52      kristaps   17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
1.1       kristaps   21: #include <sys/types.h>
                     22:
                     23: #include <assert.h>
                     24: #include <ctype.h>
                     25: #include <stdio.h>
                     26: #include <stdlib.h>
                     27: #include <string.h>
                     28: #include <unistd.h>
                     29:
1.65      kristaps   30: #include "mandoc.h"
1.23      kristaps   31: #include "out.h"
1.1       kristaps   32: #include "html.h"
                     33: #include "mdoc.h"
1.29      kristaps   34: #include "main.h"
1.1       kristaps   35:
                     36: #define        INDENT           5
                     37: #define        HALFINDENT       3
                     38:
                     39: #define        MDOC_ARGS         const struct mdoc_meta *m, \
                     40:                          const struct mdoc_node *n, \
                     41:                          struct html *h
                     42:
1.52      kristaps   43: #ifndef MIN
                     44: #define        MIN(a,b)        ((/*CONSTCOND*/(a)<(b))?(a):(b))
                     45: #endif
                     46:
1.1       kristaps   47: struct htmlmdoc {
                     48:        int             (*pre)(MDOC_ARGS);
                     49:        void            (*post)(MDOC_ARGS);
                     50: };
                     51:
                     52: static void              print_mdoc(MDOC_ARGS);
                     53: static void              print_mdoc_head(MDOC_ARGS);
                     54: static void              print_mdoc_node(MDOC_ARGS);
                     55: static void              print_mdoc_nodelist(MDOC_ARGS);
                     56:
1.23      kristaps   57: static void              a2width(const char *, struct roffsu *);
                     58: static void              a2offs(const char *, struct roffsu *);
1.27      kristaps   59:
1.1       kristaps   60: static void              mdoc_root_post(MDOC_ARGS);
                     61: static int               mdoc_root_pre(MDOC_ARGS);
                     62:
1.10      kristaps   63: static void              mdoc__x_post(MDOC_ARGS);
                     64: static int               mdoc__x_pre(MDOC_ARGS);
1.1       kristaps   65: static int               mdoc_ad_pre(MDOC_ARGS);
                     66: static int               mdoc_an_pre(MDOC_ARGS);
1.5       kristaps   67: static int               mdoc_ap_pre(MDOC_ARGS);
1.1       kristaps   68: static void              mdoc_aq_post(MDOC_ARGS);
                     69: static int               mdoc_aq_pre(MDOC_ARGS);
                     70: static int               mdoc_ar_pre(MDOC_ARGS);
                     71: static int               mdoc_bd_pre(MDOC_ARGS);
1.5       kristaps   72: static int               mdoc_bf_pre(MDOC_ARGS);
1.1       kristaps   73: static void              mdoc_bl_post(MDOC_ARGS);
                     74: static int               mdoc_bl_pre(MDOC_ARGS);
1.4       kristaps   75: static void              mdoc_bq_post(MDOC_ARGS);
                     76: static int               mdoc_bq_pre(MDOC_ARGS);
1.2       kristaps   77: static void              mdoc_brq_post(MDOC_ARGS);
                     78: static int               mdoc_brq_pre(MDOC_ARGS);
1.6       kristaps   79: static int               mdoc_bt_pre(MDOC_ARGS);
1.4       kristaps   80: static int               mdoc_bx_pre(MDOC_ARGS);
1.1       kristaps   81: static int               mdoc_cd_pre(MDOC_ARGS);
                     82: static int               mdoc_d1_pre(MDOC_ARGS);
                     83: static void              mdoc_dq_post(MDOC_ARGS);
                     84: static int               mdoc_dq_pre(MDOC_ARGS);
                     85: static int               mdoc_dv_pre(MDOC_ARGS);
                     86: static int               mdoc_fa_pre(MDOC_ARGS);
1.73      kristaps   87: static void              mdoc_fd_post(MDOC_ARGS);
1.1       kristaps   88: static int               mdoc_fd_pre(MDOC_ARGS);
                     89: static int               mdoc_fl_pre(MDOC_ARGS);
                     90: static int               mdoc_fn_pre(MDOC_ARGS);
                     91: static int               mdoc_ft_pre(MDOC_ARGS);
                     92: static int               mdoc_em_pre(MDOC_ARGS);
                     93: static int               mdoc_er_pre(MDOC_ARGS);
                     94: static int               mdoc_ev_pre(MDOC_ARGS);
                     95: static int               mdoc_ex_pre(MDOC_ARGS);
1.4       kristaps   96: static void              mdoc_fo_post(MDOC_ARGS);
                     97: static int               mdoc_fo_pre(MDOC_ARGS);
                     98: static int               mdoc_ic_pre(MDOC_ARGS);
                     99: static int               mdoc_in_pre(MDOC_ARGS);
1.66      kristaps  100: static int               mdoc_it_block_pre(MDOC_ARGS, enum mdoc_list,
                    101:                                int, struct roffsu *, struct roffsu *);
                    102: static int               mdoc_it_head_pre(MDOC_ARGS, enum mdoc_list,
1.27      kristaps  103:                                struct roffsu *);
1.70      kristaps  104: static int               mdoc_it_body_pre(MDOC_ARGS, enum mdoc_list,
                    105:                                struct roffsu *);
1.1       kristaps  106: static int               mdoc_it_pre(MDOC_ARGS);
1.6       kristaps  107: static int               mdoc_lb_pre(MDOC_ARGS);
                    108: static int               mdoc_li_pre(MDOC_ARGS);
1.2       kristaps  109: static int               mdoc_lk_pre(MDOC_ARGS);
                    110: static int               mdoc_mt_pre(MDOC_ARGS);
1.5       kristaps  111: static int               mdoc_ms_pre(MDOC_ARGS);
1.1       kristaps  112: static int               mdoc_nd_pre(MDOC_ARGS);
                    113: static int               mdoc_nm_pre(MDOC_ARGS);
                    114: static int               mdoc_ns_pre(MDOC_ARGS);
                    115: static void              mdoc_op_post(MDOC_ARGS);
                    116: static int               mdoc_op_pre(MDOC_ARGS);
                    117: static int               mdoc_pa_pre(MDOC_ARGS);
1.5       kristaps  118: static void              mdoc_pf_post(MDOC_ARGS);
                    119: static int               mdoc_pf_pre(MDOC_ARGS);
1.1       kristaps  120: static void              mdoc_pq_post(MDOC_ARGS);
                    121: static int               mdoc_pq_pre(MDOC_ARGS);
1.5       kristaps  122: static int               mdoc_rs_pre(MDOC_ARGS);
1.4       kristaps  123: static int               mdoc_rv_pre(MDOC_ARGS);
1.1       kristaps  124: static int               mdoc_sh_pre(MDOC_ARGS);
                    125: static int               mdoc_sp_pre(MDOC_ARGS);
                    126: static void              mdoc_sq_post(MDOC_ARGS);
                    127: static int               mdoc_sq_pre(MDOC_ARGS);
                    128: static int               mdoc_ss_pre(MDOC_ARGS);
                    129: static int               mdoc_sx_pre(MDOC_ARGS);
1.6       kristaps  130: static int               mdoc_sy_pre(MDOC_ARGS);
                    131: static int               mdoc_ud_pre(MDOC_ARGS);
1.4       kristaps  132: static int               mdoc_va_pre(MDOC_ARGS);
1.1       kristaps  133: static int               mdoc_vt_pre(MDOC_ARGS);
                    134: static int               mdoc_xr_pre(MDOC_ARGS);
                    135: static int               mdoc_xx_pre(MDOC_ARGS);
                    136:
                    137: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5       kristaps  138:        {mdoc_ap_pre, NULL}, /* Ap */
1.1       kristaps  139:        {NULL, NULL}, /* Dd */
                    140:        {NULL, NULL}, /* Dt */
                    141:        {NULL, NULL}, /* Os */
                    142:        {mdoc_sh_pre, NULL }, /* Sh */
                    143:        {mdoc_ss_pre, NULL }, /* Ss */
                    144:        {mdoc_sp_pre, NULL}, /* Pp */
                    145:        {mdoc_d1_pre, NULL}, /* D1 */
                    146:        {mdoc_d1_pre, NULL}, /* Dl */
                    147:        {mdoc_bd_pre, NULL}, /* Bd */
                    148:        {NULL, NULL}, /* Ed */
                    149:        {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
                    150:        {NULL, NULL}, /* El */
                    151:        {mdoc_it_pre, NULL}, /* It */
                    152:        {mdoc_ad_pre, NULL}, /* Ad */
                    153:        {mdoc_an_pre, NULL}, /* An */
                    154:        {mdoc_ar_pre, NULL}, /* Ar */
                    155:        {mdoc_cd_pre, NULL}, /* Cd */
                    156:        {mdoc_fl_pre, NULL}, /* Cm */
                    157:        {mdoc_dv_pre, NULL}, /* Dv */
                    158:        {mdoc_er_pre, NULL}, /* Er */
                    159:        {mdoc_ev_pre, NULL}, /* Ev */
                    160:        {mdoc_ex_pre, NULL}, /* Ex */
                    161:        {mdoc_fa_pre, NULL}, /* Fa */
1.73      kristaps  162:        {mdoc_fd_pre, mdoc_fd_post}, /* Fd */
1.1       kristaps  163:        {mdoc_fl_pre, NULL}, /* Fl */
                    164:        {mdoc_fn_pre, NULL}, /* Fn */
                    165:        {mdoc_ft_pre, NULL}, /* Ft */
1.4       kristaps  166:        {mdoc_ic_pre, NULL}, /* Ic */
                    167:        {mdoc_in_pre, NULL}, /* In */
1.6       kristaps  168:        {mdoc_li_pre, NULL}, /* Li */
1.1       kristaps  169:        {mdoc_nd_pre, NULL}, /* Nd */
                    170:        {mdoc_nm_pre, NULL}, /* Nm */
                    171:        {mdoc_op_pre, mdoc_op_post}, /* Op */
                    172:        {NULL, NULL}, /* Ot */
                    173:        {mdoc_pa_pre, NULL}, /* Pa */
1.4       kristaps  174:        {mdoc_rv_pre, NULL}, /* Rv */
1.1       kristaps  175:        {NULL, NULL}, /* St */
1.4       kristaps  176:        {mdoc_va_pre, NULL}, /* Va */
1.1       kristaps  177:        {mdoc_vt_pre, NULL}, /* Vt */
                    178:        {mdoc_xr_pre, NULL}, /* Xr */
1.10      kristaps  179:        {mdoc__x_pre, mdoc__x_post}, /* %A */
                    180:        {mdoc__x_pre, mdoc__x_post}, /* %B */
                    181:        {mdoc__x_pre, mdoc__x_post}, /* %D */
                    182:        {mdoc__x_pre, mdoc__x_post}, /* %I */
                    183:        {mdoc__x_pre, mdoc__x_post}, /* %J */
                    184:        {mdoc__x_pre, mdoc__x_post}, /* %N */
                    185:        {mdoc__x_pre, mdoc__x_post}, /* %O */
                    186:        {mdoc__x_pre, mdoc__x_post}, /* %P */
                    187:        {mdoc__x_pre, mdoc__x_post}, /* %R */
                    188:        {mdoc__x_pre, mdoc__x_post}, /* %T */
                    189:        {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1       kristaps  190:        {NULL, NULL}, /* Ac */
                    191:        {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
                    192:        {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
                    193:        {NULL, NULL}, /* At */
                    194:        {NULL, NULL}, /* Bc */
1.5       kristaps  195:        {mdoc_bf_pre, NULL}, /* Bf */
1.4       kristaps  196:        {mdoc_bq_pre, mdoc_bq_post}, /* Bo */
                    197:        {mdoc_bq_pre, mdoc_bq_post}, /* Bq */
1.1       kristaps  198:        {mdoc_xx_pre, NULL}, /* Bsx */
1.4       kristaps  199:        {mdoc_bx_pre, NULL}, /* Bx */
1.1       kristaps  200:        {NULL, NULL}, /* Db */
                    201:        {NULL, NULL}, /* Dc */
1.4       kristaps  202:        {mdoc_dq_pre, mdoc_dq_post}, /* Do */
1.1       kristaps  203:        {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
1.55      kristaps  204:        {NULL, NULL}, /* Ec */ /* FIXME: no space */
1.1       kristaps  205:        {NULL, NULL}, /* Ef */
                    206:        {mdoc_em_pre, NULL}, /* Em */
                    207:        {NULL, NULL}, /* Eo */
                    208:        {mdoc_xx_pre, NULL}, /* Fx */
1.5       kristaps  209:        {mdoc_ms_pre, NULL}, /* Ms */ /* FIXME: convert to symbol? */
1.1       kristaps  210:        {NULL, NULL}, /* No */
                    211:        {mdoc_ns_pre, NULL}, /* Ns */
                    212:        {mdoc_xx_pre, NULL}, /* Nx */
                    213:        {mdoc_xx_pre, NULL}, /* Ox */
                    214:        {NULL, NULL}, /* Pc */
1.5       kristaps  215:        {mdoc_pf_pre, mdoc_pf_post}, /* Pf */
1.1       kristaps  216:        {mdoc_pq_pre, mdoc_pq_post}, /* Po */
                    217:        {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
                    218:        {NULL, NULL}, /* Qc */
1.4       kristaps  219:        {mdoc_sq_pre, mdoc_sq_post}, /* Ql */
1.5       kristaps  220:        {mdoc_dq_pre, mdoc_dq_post}, /* Qo */
                    221:        {mdoc_dq_pre, mdoc_dq_post}, /* Qq */
1.1       kristaps  222:        {NULL, NULL}, /* Re */
1.5       kristaps  223:        {mdoc_rs_pre, NULL}, /* Rs */
1.1       kristaps  224:        {NULL, NULL}, /* Sc */
                    225:        {mdoc_sq_pre, mdoc_sq_post}, /* So */
                    226:        {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
1.6       kristaps  227:        {NULL, NULL}, /* Sm */ /* FIXME - no idea. */
1.1       kristaps  228:        {mdoc_sx_pre, NULL}, /* Sx */
1.6       kristaps  229:        {mdoc_sy_pre, NULL}, /* Sy */
1.1       kristaps  230:        {NULL, NULL}, /* Tn */
                    231:        {mdoc_xx_pre, NULL}, /* Ux */
                    232:        {NULL, NULL}, /* Xc */
                    233:        {NULL, NULL}, /* Xo */
1.4       kristaps  234:        {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
1.1       kristaps  235:        {NULL, NULL}, /* Fc */
1.4       kristaps  236:        {mdoc_op_pre, mdoc_op_post}, /* Oo */
1.1       kristaps  237:        {NULL, NULL}, /* Oc */
                    238:        {NULL, NULL}, /* Bk */
                    239:        {NULL, NULL}, /* Ek */
1.6       kristaps  240:        {mdoc_bt_pre, NULL}, /* Bt */
1.1       kristaps  241:        {NULL, NULL}, /* Hf */
                    242:        {NULL, NULL}, /* Fr */
1.6       kristaps  243:        {mdoc_ud_pre, NULL}, /* Ud */
                    244:        {mdoc_lb_pre, NULL}, /* Lb */
1.1       kristaps  245:        {mdoc_sp_pre, NULL}, /* Lp */
1.2       kristaps  246:        {mdoc_lk_pre, NULL}, /* Lk */
                    247:        {mdoc_mt_pre, NULL}, /* Mt */
                    248:        {mdoc_brq_pre, mdoc_brq_post}, /* Brq */
                    249:        {mdoc_brq_pre, mdoc_brq_post}, /* Bro */
1.1       kristaps  250:        {NULL, NULL}, /* Brc */
1.10      kristaps  251:        {mdoc__x_pre, mdoc__x_post}, /* %C */
1.2       kristaps  252:        {NULL, NULL}, /* Es */  /* TODO */
                    253:        {NULL, NULL}, /* En */  /* TODO */
1.1       kristaps  254:        {mdoc_xx_pre, NULL}, /* Dx */
1.10      kristaps  255:        {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1       kristaps  256:        {mdoc_sp_pre, NULL}, /* br */
                    257:        {mdoc_sp_pre, NULL}, /* sp */
1.37      kristaps  258:        {mdoc__x_pre, mdoc__x_post}, /* %U */
1.71      kristaps  259:        {NULL, NULL}, /* Ta */
1.1       kristaps  260: };
                    261:
                    262:
                    263: void
                    264: html_mdoc(void *arg, const struct mdoc *m)
                    265: {
                    266:        struct html     *h;
                    267:        struct tag      *t;
                    268:
                    269:        h = (struct html *)arg;
                    270:
1.53      kristaps  271:        print_gen_decls(h);
1.1       kristaps  272:        t = print_otag(h, TAG_HTML, 0, NULL);
                    273:        print_mdoc(mdoc_meta(m), mdoc_node(m), h);
                    274:        print_tagq(h, t);
                    275:
                    276:        printf("\n");
                    277: }
                    278:
                    279:
1.23      kristaps  280: /*
                    281:  * Calculate the scaling unit passed in a `-width' argument.  This uses
                    282:  * either a native scaling unit (e.g., 1i, 2m) or the string length of
                    283:  * the value.
                    284:  */
                    285: static void
                    286: a2width(const char *p, struct roffsu *su)
1.1       kristaps  287: {
                    288:
1.32      kristaps  289:        if ( ! a2roffsu(p, su, SCALE_MAX)) {
                    290:                su->unit = SCALE_EM;
                    291:                su->scale = (int)strlen(p);
                    292:        }
1.1       kristaps  293: }
                    294:
                    295:
1.23      kristaps  296: /*
                    297:  * Calculate the scaling unit passed in an `-offset' argument.  This
                    298:  * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
                    299:  * predefined strings (indent, etc.), or the string length of the value.
                    300:  */
                    301: static void
                    302: a2offs(const char *p, struct roffsu *su)
1.1       kristaps  303: {
                    304:
1.31      kristaps  305:        /* FIXME: "right"? */
                    306:
1.1       kristaps  307:        if (0 == strcmp(p, "left"))
1.23      kristaps  308:                SCALE_HS_INIT(su, 0);
                    309:        else if (0 == strcmp(p, "indent"))
                    310:                SCALE_HS_INIT(su, INDENT);
                    311:        else if (0 == strcmp(p, "indent-two"))
                    312:                SCALE_HS_INIT(su, INDENT * 2);
1.32      kristaps  313:        else if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.24      kristaps  314:                su->unit = SCALE_EM;
                    315:                su->scale = (int)strlen(p);
                    316:        }
1.1       kristaps  317: }
                    318:
                    319:
                    320: static void
                    321: print_mdoc(MDOC_ARGS)
                    322: {
                    323:        struct tag      *t;
                    324:        struct htmlpair  tag;
                    325:
                    326:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    327:        print_mdoc_head(m, n, h);
                    328:        print_tagq(h, t);
                    329:
                    330:        t = print_otag(h, TAG_BODY, 0, NULL);
                    331:
                    332:        tag.key = ATTR_CLASS;
                    333:        tag.val = "body";
                    334:        print_otag(h, TAG_DIV, 1, &tag);
                    335:
                    336:        print_mdoc_nodelist(m, n, h);
                    337:        print_tagq(h, t);
                    338: }
                    339:
                    340:
                    341: /* ARGSUSED */
                    342: static void
                    343: print_mdoc_head(MDOC_ARGS)
                    344: {
                    345:
                    346:        print_gen_head(h);
1.20      kristaps  347:        bufinit(h);
1.63      kristaps  348:        buffmt(h, "%s(%s)", m->title, m->msec);
1.1       kristaps  349:
                    350:        if (m->arch) {
1.20      kristaps  351:                bufcat(h, " (");
                    352:                bufcat(h, m->arch);
                    353:                bufcat(h, ")");
1.1       kristaps  354:        }
                    355:
                    356:        print_otag(h, TAG_TITLE, 0, NULL);
1.20      kristaps  357:        print_text(h, h->buf);
1.1       kristaps  358: }
                    359:
                    360:
                    361: static void
                    362: print_mdoc_nodelist(MDOC_ARGS)
                    363: {
                    364:
                    365:        print_mdoc_node(m, n, h);
                    366:        if (n->next)
                    367:                print_mdoc_nodelist(m, n->next, h);
                    368: }
                    369:
                    370:
                    371: static void
                    372: print_mdoc_node(MDOC_ARGS)
                    373: {
                    374:        int              child;
                    375:        struct tag      *t;
                    376:
                    377:        child = 1;
1.39      kristaps  378:        t = h->tags.head;
1.1       kristaps  379:
1.16      kristaps  380:        bufinit(h);
1.1       kristaps  381:        switch (n->type) {
                    382:        case (MDOC_ROOT):
                    383:                child = mdoc_root_pre(m, n, h);
                    384:                break;
                    385:        case (MDOC_TEXT):
                    386:                print_text(h, n->string);
1.48      kristaps  387:                return;
1.1       kristaps  388:        default:
                    389:                if (mdocs[n->tok].pre)
                    390:                        child = (*mdocs[n->tok].pre)(m, n, h);
                    391:                break;
                    392:        }
                    393:
                    394:        if (child && n->child)
                    395:                print_mdoc_nodelist(m, n->child, h);
                    396:
                    397:        print_stagq(h, t);
                    398:
1.16      kristaps  399:        bufinit(h);
1.1       kristaps  400:        switch (n->type) {
                    401:        case (MDOC_ROOT):
                    402:                mdoc_root_post(m, n, h);
                    403:                break;
                    404:        default:
                    405:                if (mdocs[n->tok].post)
                    406:                        (*mdocs[n->tok].post)(m, n, h);
                    407:                break;
                    408:        }
                    409: }
                    410:
                    411:
                    412: /* ARGSUSED */
                    413: static void
                    414: mdoc_root_post(MDOC_ARGS)
                    415: {
1.40      kristaps  416:        struct htmlpair  tag[3];
1.1       kristaps  417:        struct tag      *t, *tt;
1.36      kristaps  418:        char             b[DATESIZ];
                    419:
                    420:        time2a(m->date, b, DATESIZ);
1.1       kristaps  421:
1.23      kristaps  422:        /*
                    423:         * XXX: this should use divs, but in Firefox, divs with nested
                    424:         * divs for some reason puke when trying to put a border line
                    425:         * below.  So I use tables, instead.
                    426:         */
                    427:
                    428:        PAIR_CLASS_INIT(&tag[0], "footer");
                    429:        bufcat_style(h, "width", "100%");
                    430:        PAIR_STYLE_INIT(&tag[1], h);
1.40      kristaps  431:        PAIR_SUMMARY_INIT(&tag[2], "footer");
                    432:
                    433:        t = print_otag(h, TAG_TABLE, 3, tag);
1.1       kristaps  434:        tt = print_otag(h, TAG_TR, 0, NULL);
                    435:
1.23      kristaps  436:        bufinit(h);
                    437:        bufcat_style(h, "width", "50%");
                    438:        PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps  439:        print_otag(h, TAG_TD, 1, tag);
                    440:        print_text(h, b);
                    441:        print_stagq(h, tt);
                    442:
1.23      kristaps  443:        bufinit(h);
                    444:        bufcat_style(h, "width", "50%");
                    445:        bufcat_style(h, "text-align", "right");
                    446:        PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps  447:        print_otag(h, TAG_TD, 1, tag);
                    448:        print_text(h, m->os);
                    449:        print_tagq(h, t);
                    450: }
                    451:
                    452:
                    453: /* ARGSUSED */
                    454: static int
                    455: mdoc_root_pre(MDOC_ARGS)
                    456: {
1.40      kristaps  457:        struct htmlpair  tag[3];
1.1       kristaps  458:        struct tag      *t, *tt;
                    459:        char             b[BUFSIZ], title[BUFSIZ];
                    460:
                    461:        (void)strlcpy(b, m->vol, BUFSIZ);
                    462:
                    463:        if (m->arch) {
                    464:                (void)strlcat(b, " (", BUFSIZ);
                    465:                (void)strlcat(b, m->arch, BUFSIZ);
                    466:                (void)strlcat(b, ")", BUFSIZ);
                    467:        }
                    468:
                    469:        (void)snprintf(title, BUFSIZ - 1,
1.63      kristaps  470:                        "%s(%s)", m->title, m->msec);
1.1       kristaps  471:
1.23      kristaps  472:        /* XXX: see note in mdoc_root_post() about divs. */
                    473:
                    474:        PAIR_CLASS_INIT(&tag[0], "header");
                    475:        bufcat_style(h, "width", "100%");
                    476:        PAIR_STYLE_INIT(&tag[1], h);
1.40      kristaps  477:        PAIR_SUMMARY_INIT(&tag[2], "header");
                    478:
                    479:        t = print_otag(h, TAG_TABLE, 3, tag);
                    480:
1.1       kristaps  481:        tt = print_otag(h, TAG_TR, 0, NULL);
                    482:
1.23      kristaps  483:        bufinit(h);
                    484:        bufcat_style(h, "width", "10%");
                    485:        PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps  486:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  487:        print_text(h, title);
1.1       kristaps  488:        print_stagq(h, tt);
                    489:
1.23      kristaps  490:        bufinit(h);
                    491:        bufcat_style(h, "text-align", "center");
                    492:        bufcat_style(h, "white-space", "nowrap");
                    493:        bufcat_style(h, "width", "80%");
                    494:        PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps  495:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  496:        print_text(h, b);
1.1       kristaps  497:        print_stagq(h, tt);
                    498:
1.23      kristaps  499:        bufinit(h);
                    500:        bufcat_style(h, "text-align", "right");
                    501:        bufcat_style(h, "width", "10%");
                    502:        PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps  503:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  504:        print_text(h, title);
1.1       kristaps  505:        print_tagq(h, t);
                    506:        return(1);
                    507: }
                    508:
                    509:
                    510: /* ARGSUSED */
                    511: static int
                    512: mdoc_sh_pre(MDOC_ARGS)
                    513: {
                    514:        struct htmlpair          tag[2];
                    515:        const struct mdoc_node  *nn;
1.41      kristaps  516:        char                     buf[BUFSIZ];
1.23      kristaps  517:        struct roffsu            su;
1.21      kristaps  518:
                    519:        if (MDOC_BODY == n->type) {
1.23      kristaps  520:                SCALE_HS_INIT(&su, INDENT);
                    521:                bufcat_su(h, "margin-left", &su);
                    522:                PAIR_CLASS_INIT(&tag[0], "sec-body");
                    523:                PAIR_STYLE_INIT(&tag[1], h);
1.21      kristaps  524:                print_otag(h, TAG_DIV, 2, tag);
1.1       kristaps  525:                return(1);
                    526:        } else if (MDOC_BLOCK == n->type) {
1.23      kristaps  527:                PAIR_CLASS_INIT(&tag[0], "sec-block");
1.1       kristaps  528:                if (n->prev && NULL == n->prev->body->child) {
                    529:                        print_otag(h, TAG_DIV, 1, tag);
                    530:                        return(1);
                    531:                }
1.23      kristaps  532:
                    533:                SCALE_VS_INIT(&su, 1);
                    534:                bufcat_su(h, "margin-top", &su);
1.1       kristaps  535:                if (NULL == n->next)
1.23      kristaps  536:                        bufcat_su(h, "margin-bottom", &su);
1.1       kristaps  537:
1.23      kristaps  538:                PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps  539:                print_otag(h, TAG_DIV, 2, tag);
                    540:                return(1);
                    541:        }
                    542:
1.42      kristaps  543:        buf[0] = '\0';
1.21      kristaps  544:        for (nn = n->child; nn; nn = nn->next) {
1.41      kristaps  545:                html_idcat(buf, nn->string, BUFSIZ);
1.21      kristaps  546:                if (nn->next)
1.42      kristaps  547:                        html_idcat(buf, " ", BUFSIZ);
1.21      kristaps  548:        }
                    549:
1.57      kristaps  550:        PAIR_CLASS_INIT(&tag[0], "sec-head");
                    551:        PAIR_ID_INIT(&tag[1], buf);
1.22      kristaps  552:
1.1       kristaps  553:        print_otag(h, TAG_DIV, 2, tag);
                    554:        return(1);
                    555: }
                    556:
                    557:
                    558: /* ARGSUSED */
                    559: static int
                    560: mdoc_ss_pre(MDOC_ARGS)
                    561: {
1.21      kristaps  562:        struct htmlpair          tag[3];
1.1       kristaps  563:        const struct mdoc_node  *nn;
1.41      kristaps  564:        char                     buf[BUFSIZ];
1.23      kristaps  565:        struct roffsu            su;
1.1       kristaps  566:
1.23      kristaps  567:        SCALE_VS_INIT(&su, 1);
1.1       kristaps  568:
                    569:        if (MDOC_BODY == n->type) {
1.23      kristaps  570:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.1       kristaps  571:                if (n->parent->next && n->child) {
1.23      kristaps  572:                        bufcat_su(h, "margin-bottom", &su);
                    573:                        PAIR_STYLE_INIT(&tag[1], h);
                    574:                        print_otag(h, TAG_DIV, 2, tag);
                    575:                } else
                    576:                        print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps  577:                return(1);
                    578:        } else if (MDOC_BLOCK == n->type) {
1.23      kristaps  579:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.1       kristaps  580:                if (n->prev) {
1.23      kristaps  581:                        bufcat_su(h, "margin-top", &su);
                    582:                        PAIR_STYLE_INIT(&tag[1], h);
                    583:                        print_otag(h, TAG_DIV, 2, tag);
                    584:                } else
                    585:                        print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps  586:                return(1);
                    587:        }
                    588:
1.23      kristaps  589:        /* TODO: see note in mdoc_sh_pre() about duplicates. */
                    590:
1.42      kristaps  591:        buf[0] = '\0';
1.21      kristaps  592:        for (nn = n->child; nn; nn = nn->next) {
1.41      kristaps  593:                html_idcat(buf, nn->string, BUFSIZ);
1.21      kristaps  594:                if (nn->next)
1.42      kristaps  595:                        html_idcat(buf, " ", BUFSIZ);
1.21      kristaps  596:        }
                    597:
1.23      kristaps  598:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    599:        su.scale = -su.scale;
                    600:        bufcat_su(h, "margin-left", &su);
1.22      kristaps  601:
1.23      kristaps  602:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    603:        PAIR_STYLE_INIT(&tag[1], h);
1.57      kristaps  604:        PAIR_ID_INIT(&tag[2], buf);
                    605:
1.21      kristaps  606:        print_otag(h, TAG_DIV, 3, tag);
1.1       kristaps  607:        return(1);
                    608: }
                    609:
                    610:
                    611: /* ARGSUSED */
                    612: static int
                    613: mdoc_fl_pre(MDOC_ARGS)
                    614: {
                    615:        struct htmlpair  tag;
                    616:
1.51      kristaps  617:        PAIR_CLASS_INIT(&tag, "flag");
                    618:        print_otag(h, TAG_SPAN, 1, &tag);
                    619:
1.50      kristaps  620:        /* `Cm' has no leading hyphen. */
                    621:
1.51      kristaps  622:        if (MDOC_Cm == n->tok)
1.50      kristaps  623:                return(1);
                    624:
                    625:        print_text(h, "\\-");
                    626:
                    627:        if (n->child)
1.58      kristaps  628:                h->flags |= HTML_NOSPACE;
                    629:        else if (n->next && n->next->line == n->line)
1.1       kristaps  630:                h->flags |= HTML_NOSPACE;
1.50      kristaps  631:
1.1       kristaps  632:        return(1);
                    633: }
                    634:
                    635:
                    636: /* ARGSUSED */
                    637: static int
                    638: mdoc_nd_pre(MDOC_ARGS)
                    639: {
                    640:        struct htmlpair  tag;
                    641:
                    642:        if (MDOC_BODY != n->type)
                    643:                return(1);
                    644:
1.24      kristaps  645:        /* XXX: this tag in theory can contain block elements. */
                    646:
1.1       kristaps  647:        print_text(h, "\\(em");
1.23      kristaps  648:        PAIR_CLASS_INIT(&tag, "desc-body");
1.1       kristaps  649:        print_otag(h, TAG_SPAN, 1, &tag);
                    650:        return(1);
                    651: }
                    652:
                    653:
                    654: /* ARGSUSED */
                    655: static int
                    656: mdoc_op_pre(MDOC_ARGS)
                    657: {
                    658:        struct htmlpair  tag;
                    659:
                    660:        if (MDOC_BODY != n->type)
                    661:                return(1);
                    662:
1.24      kristaps  663:        /* XXX: this tag in theory can contain block elements. */
                    664:
1.1       kristaps  665:        print_text(h, "\\(lB");
                    666:        h->flags |= HTML_NOSPACE;
1.23      kristaps  667:        PAIR_CLASS_INIT(&tag, "opt");
1.1       kristaps  668:        print_otag(h, TAG_SPAN, 1, &tag);
                    669:        return(1);
                    670: }
                    671:
                    672:
                    673: /* ARGSUSED */
                    674: static void
                    675: mdoc_op_post(MDOC_ARGS)
                    676: {
                    677:
                    678:        if (MDOC_BODY != n->type)
                    679:                return;
                    680:        h->flags |= HTML_NOSPACE;
                    681:        print_text(h, "\\(rB");
                    682: }
                    683:
                    684:
                    685: static int
                    686: mdoc_nm_pre(MDOC_ARGS)
                    687: {
                    688:        struct htmlpair tag;
                    689:
1.65      kristaps  690:        if (NULL == n->child && NULL == m->name)
                    691:                return(1);
                    692:
1.62      kristaps  693:        if (SEC_SYNOPSIS == n->sec &&
                    694:                        n->prev && MDOC_LINE & n->flags) {
1.47      kristaps  695:                bufcat_style(h, "clear", "both");
                    696:                PAIR_STYLE_INIT(&tag, h);
                    697:                print_otag(h, TAG_BR, 1, &tag);
                    698:        }
1.1       kristaps  699:
1.23      kristaps  700:        PAIR_CLASS_INIT(&tag, "name");
1.1       kristaps  701:        print_otag(h, TAG_SPAN, 1, &tag);
                    702:        if (NULL == n->child)
                    703:                print_text(h, m->name);
                    704:
                    705:        return(1);
                    706: }
                    707:
                    708:
                    709: /* ARGSUSED */
                    710: static int
                    711: mdoc_xr_pre(MDOC_ARGS)
                    712: {
                    713:        struct htmlpair          tag[2];
                    714:        const struct mdoc_node  *nn;
1.56      kristaps  715:
                    716:        if (NULL == n->child)
                    717:                return(0);
1.17      kristaps  718:
1.23      kristaps  719:        PAIR_CLASS_INIT(&tag[0], "link-man");
1.1       kristaps  720:
1.17      kristaps  721:        if (h->base_man) {
1.23      kristaps  722:                buffmt_man(h, n->child->string,
                    723:                                n->child->next ?
1.17      kristaps  724:                                n->child->next->string : NULL);
1.57      kristaps  725:                PAIR_HREF_INIT(&tag[1], h->buf);
1.23      kristaps  726:                print_otag(h, TAG_A, 2, tag);
                    727:        } else
                    728:                print_otag(h, TAG_A, 1, tag);
1.1       kristaps  729:
                    730:        nn = n->child;
                    731:        print_text(h, nn->string);
1.16      kristaps  732:
1.1       kristaps  733:        if (NULL == (nn = nn->next))
                    734:                return(0);
                    735:
                    736:        h->flags |= HTML_NOSPACE;
                    737:        print_text(h, "(");
                    738:        h->flags |= HTML_NOSPACE;
                    739:        print_text(h, nn->string);
                    740:        h->flags |= HTML_NOSPACE;
                    741:        print_text(h, ")");
                    742:        return(0);
                    743: }
                    744:
                    745:
                    746: /* ARGSUSED */
                    747: static int
                    748: mdoc_ns_pre(MDOC_ARGS)
                    749: {
                    750:
                    751:        h->flags |= HTML_NOSPACE;
                    752:        return(1);
                    753: }
                    754:
                    755:
                    756: /* ARGSUSED */
                    757: static int
                    758: mdoc_ar_pre(MDOC_ARGS)
                    759: {
                    760:        struct htmlpair tag;
                    761:
1.23      kristaps  762:        PAIR_CLASS_INIT(&tag, "arg");
1.1       kristaps  763:        print_otag(h, TAG_SPAN, 1, &tag);
                    764:        return(1);
                    765: }
                    766:
                    767:
                    768: /* ARGSUSED */
                    769: static int
                    770: mdoc_xx_pre(MDOC_ARGS)
                    771: {
                    772:        const char      *pp;
                    773:        struct htmlpair  tag;
                    774:
                    775:        switch (n->tok) {
                    776:        case (MDOC_Bsx):
                    777:                pp = "BSDI BSD/OS";
                    778:                break;
                    779:        case (MDOC_Dx):
1.45      kristaps  780:                pp = "DragonFly";
1.1       kristaps  781:                break;
                    782:        case (MDOC_Fx):
                    783:                pp = "FreeBSD";
                    784:                break;
                    785:        case (MDOC_Nx):
                    786:                pp = "NetBSD";
                    787:                break;
                    788:        case (MDOC_Ox):
                    789:                pp = "OpenBSD";
                    790:                break;
                    791:        case (MDOC_Ux):
                    792:                pp = "UNIX";
                    793:                break;
                    794:        default:
                    795:                return(1);
                    796:        }
                    797:
1.23      kristaps  798:        PAIR_CLASS_INIT(&tag, "unix");
1.1       kristaps  799:        print_otag(h, TAG_SPAN, 1, &tag);
                    800:        print_text(h, pp);
                    801:        return(1);
                    802: }
                    803:
                    804:
                    805: /* ARGSUSED */
                    806: static int
1.4       kristaps  807: mdoc_bx_pre(MDOC_ARGS)
                    808: {
                    809:        const struct mdoc_node  *nn;
                    810:        struct htmlpair          tag;
                    811:
1.23      kristaps  812:        PAIR_CLASS_INIT(&tag, "unix");
1.4       kristaps  813:        print_otag(h, TAG_SPAN, 1, &tag);
                    814:
                    815:        for (nn = n->child; nn; nn = nn->next)
                    816:                print_mdoc_node(m, nn, h);
                    817:
                    818:        if (n->child)
                    819:                h->flags |= HTML_NOSPACE;
                    820:
                    821:        print_text(h, "BSD");
                    822:        return(0);
                    823: }
                    824:
                    825:
                    826: /* ARGSUSED */
                    827: static int
1.66      kristaps  828: mdoc_it_block_pre(MDOC_ARGS, enum mdoc_list type, int comp,
1.27      kristaps  829:                struct roffsu *offs, struct roffsu *width)
1.1       kristaps  830: {
1.14      kristaps  831:        struct htmlpair          tag;
                    832:        const struct mdoc_node  *nn;
1.23      kristaps  833:        struct roffsu            su;
                    834:
                    835:        nn = n->parent->parent;
                    836:
1.24      kristaps  837:        /* XXX: see notes in mdoc_it_pre(). */
                    838:
1.66      kristaps  839:        if (LIST_column == type) {
1.24      kristaps  840:                /* Don't width-pad on the left. */
                    841:                SCALE_HS_INIT(width, 0);
                    842:                /* Also disallow non-compact. */
                    843:                comp = 1;
                    844:        }
1.66      kristaps  845:        if (LIST_diag == type)
1.24      kristaps  846:                /* Mandate non-compact with empty prior. */
1.23      kristaps  847:                if (n->prev && NULL == n->prev->body->child)
                    848:                        comp = 1;
                    849:
1.24      kristaps  850:        bufcat_style(h, "clear", "both");
1.23      kristaps  851:        if (offs->scale > 0)
                    852:                bufcat_su(h, "margin-left", offs);
                    853:        if (width->scale > 0)
                    854:                bufcat_su(h, "padding-left", width);
1.1       kristaps  855:
1.23      kristaps  856:        PAIR_STYLE_INIT(&tag, h);
                    857:
1.24      kristaps  858:        /* Mandate compact following `Ss' and `Sh' starts. */
                    859:
1.23      kristaps  860:        for (nn = n; nn && ! comp; nn = nn->parent) {
                    861:                if (MDOC_BLOCK != nn->type)
                    862:                        continue;
                    863:                if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                    864:                        comp = 1;
                    865:                if (nn->prev)
                    866:                        break;
1.1       kristaps  867:        }
                    868:
1.23      kristaps  869:        if ( ! comp) {
                    870:                SCALE_VS_INIT(&su, 1);
                    871:                bufcat_su(h, "padding-top", &su);
1.1       kristaps  872:        }
                    873:
1.23      kristaps  874:        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  875:        print_otag(h, TAG_DIV, 1, &tag);
                    876:        return(1);
                    877: }
                    878:
                    879:
1.25      kristaps  880: /* ARGSUSED */
1.1       kristaps  881: static int
1.70      kristaps  882: mdoc_it_body_pre(MDOC_ARGS, enum mdoc_list type, struct roffsu *width)
1.1       kristaps  883: {
1.23      kristaps  884:        struct htmlpair  tag;
                    885:        struct roffsu    su;
                    886:
                    887:        switch (type) {
1.66      kristaps  888:        case (LIST_item):
1.23      kristaps  889:                /* FALLTHROUGH */
1.66      kristaps  890:        case (LIST_ohang):
1.23      kristaps  891:                /* FALLTHROUGH */
1.66      kristaps  892:        case (LIST_column):
1.70      kristaps  893:                bufcat_su(h, "min-width", width);
                    894:                bufcat_style(h, "clear", "none");
                    895:                if (n->next)
                    896:                        bufcat_style(h, "float", "left");
                    897:                PAIR_STYLE_INIT(&tag, h);
                    898:                print_otag(h, TAG_DIV, 1, &tag);
1.23      kristaps  899:                break;
                    900:        default:
1.24      kristaps  901:                /*
                    902:                 * XXX: this tricks CSS into aligning the bodies with
                    903:                 * the right-padding in the head.
                    904:                 */
1.23      kristaps  905:                SCALE_HS_INIT(&su, 2);
                    906:                bufcat_su(h, "margin-left", &su);
                    907:                PAIR_STYLE_INIT(&tag, h);
                    908:                print_otag(h, TAG_DIV, 1, &tag);
                    909:                break;
                    910:        }
1.1       kristaps  911:
                    912:        return(1);
                    913: }
                    914:
                    915:
1.25      kristaps  916: /* ARGSUSED */
1.1       kristaps  917: static int
1.66      kristaps  918: mdoc_it_head_pre(MDOC_ARGS, enum mdoc_list type, struct roffsu *width)
1.1       kristaps  919: {
                    920:        struct htmlpair  tag;
                    921:        struct ord      *ord;
                    922:        char             nbuf[BUFSIZ];
                    923:
1.23      kristaps  924:        switch (type) {
1.66      kristaps  925:        case (LIST_item):
1.46      kristaps  926:                return(0);
1.66      kristaps  927:        case (LIST_ohang):
1.46      kristaps  928:                print_otag(h, TAG_DIV, 0, &tag);
                    929:                return(1);
1.66      kristaps  930:        case (LIST_column):
1.1       kristaps  931:                break;
                    932:        default:
1.23      kristaps  933:                bufcat_su(h, "min-width", width);
                    934:                SCALE_INVERT(width);
                    935:                bufcat_su(h, "margin-left", width);
1.2       kristaps  936:                if (n->next && n->next->child)
1.23      kristaps  937:                        bufcat_style(h, "float", "left");
1.24      kristaps  938:
                    939:                /* XXX: buffer if we run into body. */
1.23      kristaps  940:                SCALE_HS_INIT(width, 1);
                    941:                bufcat_su(h, "margin-right", width);
                    942:                PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  943:                print_otag(h, TAG_DIV, 1, &tag);
                    944:                break;
                    945:        }
                    946:
1.23      kristaps  947:        switch (type) {
1.66      kristaps  948:        case (LIST_diag):
1.23      kristaps  949:                PAIR_CLASS_INIT(&tag, "diag");
1.1       kristaps  950:                print_otag(h, TAG_SPAN, 1, &tag);
                    951:                break;
1.66      kristaps  952:        case (LIST_enum):
1.39      kristaps  953:                ord = h->ords.head;
1.1       kristaps  954:                assert(ord);
                    955:                nbuf[BUFSIZ - 1] = 0;
                    956:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    957:                print_text(h, nbuf);
                    958:                return(0);
1.66      kristaps  959:        case (LIST_dash):
1.1       kristaps  960:                print_text(h, "\\(en");
                    961:                return(0);
1.66      kristaps  962:        case (LIST_hyphen):
1.4       kristaps  963:                print_text(h, "\\(hy");
1.1       kristaps  964:                return(0);
1.66      kristaps  965:        case (LIST_bullet):
1.1       kristaps  966:                print_text(h, "\\(bu");
                    967:                return(0);
                    968:        default:
                    969:                break;
                    970:        }
                    971:
                    972:        return(1);
                    973: }
                    974:
                    975:
                    976: static int
1.23      kristaps  977: mdoc_it_pre(MDOC_ARGS)
1.1       kristaps  978: {
1.66      kristaps  979:        int                      i, wp, comp;
1.1       kristaps  980:        const struct mdoc_node  *bl, *nn;
1.23      kristaps  981:        struct roffsu            width, offs;
1.66      kristaps  982:        enum mdoc_list           type;
1.23      kristaps  983:
1.24      kristaps  984:        /*
                    985:         * XXX: be very careful in changing anything, here.  Lists in
                    986:         * mandoc have many peculiarities; furthermore, they don't
                    987:         * translate well into HTML and require a bit of mangling.
                    988:         */
1.1       kristaps  989:
                    990:        bl = n->parent->parent;
1.23      kristaps  991:        if (MDOC_BLOCK != n->type)
1.1       kristaps  992:                bl = bl->parent;
                    993:
1.66      kristaps  994:        type = bl->data.list;
1.1       kristaps  995:
1.23      kristaps  996:        /* Set default width and offset. */
1.1       kristaps  997:
1.24      kristaps  998:        SCALE_HS_INIT(&offs, 0);
                    999:
1.1       kristaps 1000:        switch (type) {
1.66      kristaps 1001:        case (LIST_enum):
1.1       kristaps 1002:                /* FALLTHROUGH */
1.66      kristaps 1003:        case (LIST_dash):
1.1       kristaps 1004:                /* FALLTHROUGH */
1.66      kristaps 1005:        case (LIST_hyphen):
1.1       kristaps 1006:                /* FALLTHROUGH */
1.66      kristaps 1007:        case (LIST_bullet):
1.23      kristaps 1008:                SCALE_HS_INIT(&width, 2);
1.1       kristaps 1009:                break;
1.23      kristaps 1010:        default:
                   1011:                SCALE_HS_INIT(&width, INDENT);
                   1012:                break;
                   1013:        }
                   1014:
                   1015:        /* Get width, offset, and compact arguments. */
                   1016:
1.72      kristaps 1017:        wp = -1;
                   1018:        for (comp = i = 0; bl->args && i < (int)bl->args->argc; i++)
1.23      kristaps 1019:                switch (bl->args->argv[i].arg) {
1.24      kristaps 1020:                case (MDOC_Column):
                   1021:                        wp = i; /* Save for later. */
                   1022:                        break;
1.23      kristaps 1023:                case (MDOC_Width):
                   1024:                        a2width(bl->args->argv[i].value[0], &width);
                   1025:                        break;
                   1026:                case (MDOC_Offset):
                   1027:                        a2offs(bl->args->argv[i].value[0], &offs);
                   1028:                        break;
                   1029:                case (MDOC_Compact):
                   1030:                        comp = 1;
                   1031:                        break;
                   1032:                default:
                   1033:                        break;
                   1034:                }
                   1035:
                   1036:        /* Override width in some cases. */
                   1037:
                   1038:        switch (type) {
1.66      kristaps 1039:        case (LIST_ohang):
1.46      kristaps 1040:                /* FALLTHROUGH */
1.66      kristaps 1041:        case (LIST_item):
1.33      kristaps 1042:                /* FALLTHROUGH */
1.66      kristaps 1043:        case (LIST_inset):
1.1       kristaps 1044:                /* FALLTHROUGH */
1.66      kristaps 1045:        case (LIST_diag):
1.23      kristaps 1046:                SCALE_HS_INIT(&width, 0);
1.1       kristaps 1047:                break;
                   1048:        default:
1.23      kristaps 1049:                if (0 == width.scale)
                   1050:                        SCALE_HS_INIT(&width, INDENT);
1.1       kristaps 1051:                break;
                   1052:        }
                   1053:
1.70      kristaps 1054:        if (LIST_column == type && MDOC_BODY == n->type) {
1.23      kristaps 1055:                nn = n->parent->child;
1.70      kristaps 1056:                for (i = 0; nn && nn != n; nn = nn->next)
                   1057:                        if (MDOC_BODY == nn->type)
                   1058:                                i++;
1.24      kristaps 1059:                if (i < (int)bl->args->argv[wp].sz)
1.23      kristaps 1060:                        a2width(bl->args->argv[wp].value[i], &width);
1.1       kristaps 1061:        }
                   1062:
1.70      kristaps 1063:        if (MDOC_HEAD == n->type)
                   1064:                return(mdoc_it_head_pre(m, n, h, type, &width));
                   1065:        else if (MDOC_BODY == n->type)
                   1066:                return(mdoc_it_body_pre(m, n, h, type, &width));
                   1067:
                   1068:        return(mdoc_it_block_pre(m, n, h, type, comp, &offs, &width));
1.1       kristaps 1069: }
                   1070:
                   1071:
                   1072: /* ARGSUSED */
                   1073: static int
                   1074: mdoc_bl_pre(MDOC_ARGS)
                   1075: {
                   1076:        struct ord      *ord;
                   1077:
1.59      kristaps 1078:        if (MDOC_HEAD == n->type)
                   1079:                return(0);
1.1       kristaps 1080:        if (MDOC_BLOCK != n->type)
                   1081:                return(1);
1.67      kristaps 1082:        if (LIST_enum != n->data.list)
1.1       kristaps 1083:                return(1);
                   1084:
                   1085:        ord = malloc(sizeof(struct ord));
1.43      kristaps 1086:        if (NULL == ord) {
1.44      kristaps 1087:                perror(NULL);
1.43      kristaps 1088:                exit(EXIT_FAILURE);
                   1089:        }
1.1       kristaps 1090:        ord->cookie = n;
                   1091:        ord->pos = 1;
1.39      kristaps 1092:        ord->next = h->ords.head;
                   1093:        h->ords.head = ord;
1.1       kristaps 1094:        return(1);
                   1095: }
                   1096:
                   1097:
                   1098: /* ARGSUSED */
                   1099: static void
                   1100: mdoc_bl_post(MDOC_ARGS)
                   1101: {
                   1102:        struct ord      *ord;
                   1103:
                   1104:        if (MDOC_BLOCK != n->type)
                   1105:                return;
1.67      kristaps 1106:        if (LIST_enum != n->data.list)
1.1       kristaps 1107:                return;
                   1108:
1.39      kristaps 1109:        ord = h->ords.head;
1.1       kristaps 1110:        assert(ord);
1.39      kristaps 1111:        h->ords.head = ord->next;
1.1       kristaps 1112:        free(ord);
                   1113: }
                   1114:
                   1115:
                   1116: /* ARGSUSED */
                   1117: static int
                   1118: mdoc_ex_pre(MDOC_ARGS)
                   1119: {
                   1120:        const struct mdoc_node  *nn;
                   1121:        struct tag              *t;
                   1122:        struct htmlpair          tag;
                   1123:
1.23      kristaps 1124:        PAIR_CLASS_INIT(&tag, "utility");
                   1125:
1.1       kristaps 1126:        print_text(h, "The");
                   1127:        for (nn = n->child; nn; nn = nn->next) {
                   1128:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1129:                print_text(h, nn->string);
                   1130:                print_tagq(h, t);
                   1131:
                   1132:                h->flags |= HTML_NOSPACE;
                   1133:
                   1134:                if (nn->next && NULL == nn->next->next)
                   1135:                        print_text(h, ", and");
                   1136:                else if (nn->next)
                   1137:                        print_text(h, ",");
                   1138:                else
                   1139:                        h->flags &= ~HTML_NOSPACE;
                   1140:        }
                   1141:
1.65      kristaps 1142:        if (n->child && n->child->next)
1.1       kristaps 1143:                print_text(h, "utilities exit");
                   1144:        else
                   1145:                print_text(h, "utility exits");
                   1146:
                   1147:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1148:        return(0);
                   1149: }
                   1150:
                   1151:
                   1152: /* ARGSUSED */
                   1153: static int
                   1154: mdoc_dq_pre(MDOC_ARGS)
                   1155: {
                   1156:
                   1157:        if (MDOC_BODY != n->type)
                   1158:                return(1);
                   1159:        print_text(h, "\\(lq");
                   1160:        h->flags |= HTML_NOSPACE;
                   1161:        return(1);
                   1162: }
                   1163:
                   1164:
                   1165: /* ARGSUSED */
                   1166: static void
                   1167: mdoc_dq_post(MDOC_ARGS)
                   1168: {
                   1169:
                   1170:        if (MDOC_BODY != n->type)
                   1171:                return;
                   1172:        h->flags |= HTML_NOSPACE;
                   1173:        print_text(h, "\\(rq");
                   1174: }
                   1175:
                   1176:
                   1177: /* ARGSUSED */
                   1178: static int
                   1179: mdoc_pq_pre(MDOC_ARGS)
                   1180: {
                   1181:
                   1182:        if (MDOC_BODY != n->type)
                   1183:                return(1);
                   1184:        print_text(h, "\\&(");
                   1185:        h->flags |= HTML_NOSPACE;
                   1186:        return(1);
                   1187: }
                   1188:
                   1189:
                   1190: /* ARGSUSED */
                   1191: static void
                   1192: mdoc_pq_post(MDOC_ARGS)
                   1193: {
                   1194:
                   1195:        if (MDOC_BODY != n->type)
                   1196:                return;
                   1197:        print_text(h, ")");
                   1198: }
                   1199:
                   1200:
                   1201: /* ARGSUSED */
                   1202: static int
                   1203: mdoc_sq_pre(MDOC_ARGS)
                   1204: {
                   1205:
                   1206:        if (MDOC_BODY != n->type)
                   1207:                return(1);
                   1208:        print_text(h, "\\(oq");
                   1209:        h->flags |= HTML_NOSPACE;
                   1210:        return(1);
                   1211: }
                   1212:
                   1213:
                   1214: /* ARGSUSED */
                   1215: static void
                   1216: mdoc_sq_post(MDOC_ARGS)
                   1217: {
                   1218:
                   1219:        if (MDOC_BODY != n->type)
                   1220:                return;
                   1221:        h->flags |= HTML_NOSPACE;
                   1222:        print_text(h, "\\(aq");
                   1223: }
                   1224:
                   1225:
                   1226: /* ARGSUSED */
                   1227: static int
                   1228: mdoc_em_pre(MDOC_ARGS)
                   1229: {
                   1230:        struct htmlpair tag;
                   1231:
1.23      kristaps 1232:        PAIR_CLASS_INIT(&tag, "emph");
1.1       kristaps 1233:        print_otag(h, TAG_SPAN, 1, &tag);
                   1234:        return(1);
                   1235: }
                   1236:
                   1237:
                   1238: /* ARGSUSED */
                   1239: static int
                   1240: mdoc_d1_pre(MDOC_ARGS)
                   1241: {
1.23      kristaps 1242:        struct htmlpair  tag[2];
                   1243:        struct roffsu    su;
1.1       kristaps 1244:
                   1245:        if (MDOC_BLOCK != n->type)
                   1246:                return(1);
                   1247:
1.35      kristaps 1248:        /* FIXME: D1 shouldn't be literal. */
                   1249:
1.64      kristaps 1250:        SCALE_VS_INIT(&su, INDENT - 1);
1.23      kristaps 1251:        bufcat_su(h, "margin-left", &su);
                   1252:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1253:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1254:        print_otag(h, TAG_DIV, 2, tag);
                   1255:        return(1);
                   1256: }
                   1257:
                   1258:
                   1259: /* ARGSUSED */
                   1260: static int
                   1261: mdoc_sx_pre(MDOC_ARGS)
                   1262: {
1.18      kristaps 1263:        struct htmlpair          tag[2];
1.1       kristaps 1264:        const struct mdoc_node  *nn;
1.35      kristaps 1265:        char                     buf[BUFSIZ];
1.1       kristaps 1266:
1.41      kristaps 1267:        strlcpy(buf, "#", BUFSIZ);
1.1       kristaps 1268:        for (nn = n->child; nn; nn = nn->next) {
1.41      kristaps 1269:                html_idcat(buf, nn->string, BUFSIZ);
1.1       kristaps 1270:                if (nn->next)
1.42      kristaps 1271:                        html_idcat(buf, " ", BUFSIZ);
1.1       kristaps 1272:        }
                   1273:
1.23      kristaps 1274:        PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57      kristaps 1275:        PAIR_HREF_INIT(&tag[1], buf);
1.1       kristaps 1276:
1.18      kristaps 1277:        print_otag(h, TAG_A, 2, tag);
1.1       kristaps 1278:        return(1);
                   1279: }
                   1280:
                   1281:
                   1282: /* ARGSUSED */
                   1283: static int
                   1284: mdoc_aq_pre(MDOC_ARGS)
                   1285: {
                   1286:
                   1287:        if (MDOC_BODY != n->type)
                   1288:                return(1);
                   1289:        print_text(h, "\\(la");
                   1290:        h->flags |= HTML_NOSPACE;
                   1291:        return(1);
                   1292: }
                   1293:
                   1294:
                   1295: /* ARGSUSED */
                   1296: static void
                   1297: mdoc_aq_post(MDOC_ARGS)
                   1298: {
                   1299:
                   1300:        if (MDOC_BODY != n->type)
                   1301:                return;
                   1302:        h->flags |= HTML_NOSPACE;
                   1303:        print_text(h, "\\(ra");
                   1304: }
                   1305:
                   1306:
                   1307: /* ARGSUSED */
                   1308: static int
                   1309: mdoc_bd_pre(MDOC_ARGS)
                   1310: {
                   1311:        struct htmlpair          tag[2];
1.23      kristaps 1312:        int                      type, comp, i;
1.14      kristaps 1313:        const struct mdoc_node  *bl, *nn;
1.23      kristaps 1314:        struct roffsu            su;
1.1       kristaps 1315:
                   1316:        if (MDOC_BLOCK == n->type)
                   1317:                bl = n;
                   1318:        else if (MDOC_HEAD == n->type)
                   1319:                return(0);
                   1320:        else
                   1321:                bl = n->parent;
                   1322:
1.24      kristaps 1323:        SCALE_VS_INIT(&su, 0);
                   1324:
1.23      kristaps 1325:        type = comp = 0;
1.72      kristaps 1326:        for (i = 0; bl->args && i < (int)bl->args->argc; i++)
1.1       kristaps 1327:                switch (bl->args->argv[i].arg) {
                   1328:                case (MDOC_Offset):
1.23      kristaps 1329:                        a2offs(bl->args->argv[i].value[0], &su);
1.1       kristaps 1330:                        break;
                   1331:                case (MDOC_Compact):
1.23      kristaps 1332:                        comp = 1;
1.1       kristaps 1333:                        break;
1.30      kristaps 1334:                case (MDOC_Centred):
                   1335:                        /* FALLTHROUGH */
1.1       kristaps 1336:                case (MDOC_Ragged):
                   1337:                        /* FALLTHROUGH */
                   1338:                case (MDOC_Filled):
                   1339:                        /* FALLTHROUGH */
                   1340:                case (MDOC_Unfilled):
                   1341:                        /* FALLTHROUGH */
                   1342:                case (MDOC_Literal):
1.23      kristaps 1343:                        type = bl->args->argv[i].arg;
1.1       kristaps 1344:                        break;
1.30      kristaps 1345:                default:
                   1346:                        break;
1.1       kristaps 1347:                }
                   1348:
1.31      kristaps 1349:        /* FIXME: -centered, etc. formatting. */
1.60      kristaps 1350:        /* FIXME: does not respect -offset ??? */
1.31      kristaps 1351:
1.1       kristaps 1352:        if (MDOC_BLOCK == n->type) {
1.24      kristaps 1353:                bufcat_su(h, "margin-left", &su);
1.23      kristaps 1354:                for (nn = n; nn && ! comp; nn = nn->parent) {
                   1355:                        if (MDOC_BLOCK != nn->type)
                   1356:                                continue;
                   1357:                        if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                   1358:                                comp = 1;
                   1359:                        if (nn->prev)
                   1360:                                break;
                   1361:                }
                   1362:                if (comp) {
1.64      kristaps 1363:                        PAIR_STYLE_INIT(&tag[0], h);
                   1364:                        print_otag(h, TAG_DIV, 1, tag);
1.23      kristaps 1365:                        return(1);
1.14      kristaps 1366:                }
1.23      kristaps 1367:                SCALE_VS_INIT(&su, 1);
                   1368:                bufcat_su(h, "margin-top", &su);
                   1369:                PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps 1370:                print_otag(h, TAG_DIV, 1, tag);
                   1371:                return(1);
                   1372:        }
                   1373:
1.23      kristaps 1374:        if (MDOC_Unfilled != type && MDOC_Literal != type)
1.1       kristaps 1375:                return(1);
                   1376:
1.23      kristaps 1377:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1378:        bufcat_style(h, "white-space", "pre");
                   1379:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1380:        print_otag(h, TAG_DIV, 2, tag);
                   1381:
1.14      kristaps 1382:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1383:                h->flags |= HTML_NOSPACE;
1.14      kristaps 1384:                print_mdoc_node(m, nn, h);
                   1385:                if (NULL == nn->next)
                   1386:                        continue;
                   1387:                if (nn->prev && nn->prev->line < nn->line)
1.1       kristaps 1388:                        print_text(h, "\n");
1.23      kristaps 1389:                else if (NULL == nn->prev)
                   1390:                        print_text(h, "\n");
1.1       kristaps 1391:        }
                   1392:
                   1393:        return(0);
                   1394: }
                   1395:
                   1396:
                   1397: /* ARGSUSED */
                   1398: static int
                   1399: mdoc_pa_pre(MDOC_ARGS)
                   1400: {
                   1401:        struct htmlpair tag;
                   1402:
1.23      kristaps 1403:        PAIR_CLASS_INIT(&tag, "file");
1.1       kristaps 1404:        print_otag(h, TAG_SPAN, 1, &tag);
                   1405:        return(1);
                   1406: }
                   1407:
                   1408:
                   1409: /* ARGSUSED */
                   1410: static int
                   1411: mdoc_ad_pre(MDOC_ARGS)
                   1412: {
                   1413:        struct htmlpair tag;
                   1414:
1.23      kristaps 1415:        PAIR_CLASS_INIT(&tag, "addr");
1.1       kristaps 1416:        print_otag(h, TAG_SPAN, 1, &tag);
                   1417:        return(1);
                   1418: }
                   1419:
                   1420:
                   1421: /* ARGSUSED */
                   1422: static int
                   1423: mdoc_an_pre(MDOC_ARGS)
                   1424: {
                   1425:        struct htmlpair tag;
                   1426:
1.19      kristaps 1427:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1428:
1.23      kristaps 1429:        PAIR_CLASS_INIT(&tag, "author");
1.1       kristaps 1430:        print_otag(h, TAG_SPAN, 1, &tag);
                   1431:        return(1);
                   1432: }
                   1433:
                   1434:
                   1435: /* ARGSUSED */
                   1436: static int
                   1437: mdoc_cd_pre(MDOC_ARGS)
                   1438: {
                   1439:        struct htmlpair tag;
                   1440:
1.28      kristaps 1441:        print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 1442:        PAIR_CLASS_INIT(&tag, "config");
1.1       kristaps 1443:        print_otag(h, TAG_SPAN, 1, &tag);
                   1444:        return(1);
                   1445: }
                   1446:
                   1447:
                   1448: /* ARGSUSED */
                   1449: static int
                   1450: mdoc_dv_pre(MDOC_ARGS)
                   1451: {
                   1452:        struct htmlpair tag;
                   1453:
1.23      kristaps 1454:        PAIR_CLASS_INIT(&tag, "define");
1.1       kristaps 1455:        print_otag(h, TAG_SPAN, 1, &tag);
                   1456:        return(1);
                   1457: }
                   1458:
                   1459:
                   1460: /* ARGSUSED */
                   1461: static int
                   1462: mdoc_ev_pre(MDOC_ARGS)
                   1463: {
                   1464:        struct htmlpair tag;
                   1465:
1.23      kristaps 1466:        PAIR_CLASS_INIT(&tag, "env");
1.1       kristaps 1467:        print_otag(h, TAG_SPAN, 1, &tag);
                   1468:        return(1);
                   1469: }
                   1470:
                   1471:
                   1472: /* ARGSUSED */
                   1473: static int
                   1474: mdoc_er_pre(MDOC_ARGS)
                   1475: {
                   1476:        struct htmlpair tag;
                   1477:
1.23      kristaps 1478:        PAIR_CLASS_INIT(&tag, "errno");
1.1       kristaps 1479:        print_otag(h, TAG_SPAN, 1, &tag);
                   1480:        return(1);
                   1481: }
                   1482:
                   1483:
                   1484: /* ARGSUSED */
                   1485: static int
                   1486: mdoc_fa_pre(MDOC_ARGS)
                   1487: {
                   1488:        const struct mdoc_node  *nn;
                   1489:        struct htmlpair          tag;
                   1490:        struct tag              *t;
                   1491:
1.23      kristaps 1492:        PAIR_CLASS_INIT(&tag, "farg");
1.1       kristaps 1493:        if (n->parent->tok != MDOC_Fo) {
                   1494:                print_otag(h, TAG_SPAN, 1, &tag);
                   1495:                return(1);
                   1496:        }
                   1497:
                   1498:        for (nn = n->child; nn; nn = nn->next) {
                   1499:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1500:                print_text(h, nn->string);
                   1501:                print_tagq(h, t);
                   1502:                if (nn->next)
                   1503:                        print_text(h, ",");
                   1504:        }
                   1505:
                   1506:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1507:                print_text(h, ",");
                   1508:
                   1509:        return(0);
                   1510: }
                   1511:
                   1512:
                   1513: /* ARGSUSED */
1.73      kristaps 1514: static void
                   1515: mdoc_fd_post(MDOC_ARGS)
                   1516: {
                   1517:
                   1518:        print_otag(h, TAG_BR, 0, NULL);
                   1519: }
                   1520:
                   1521:
                   1522: /* ARGSUSED */
1.1       kristaps 1523: static int
                   1524: mdoc_fd_pre(MDOC_ARGS)
                   1525: {
1.23      kristaps 1526:        struct htmlpair  tag;
1.1       kristaps 1527:
1.23      kristaps 1528:        PAIR_CLASS_INIT(&tag, "macro");
1.1       kristaps 1529:        print_otag(h, TAG_SPAN, 1, &tag);
                   1530:        return(1);
                   1531: }
                   1532:
                   1533:
                   1534: /* ARGSUSED */
                   1535: static int
                   1536: mdoc_vt_pre(MDOC_ARGS)
                   1537: {
1.23      kristaps 1538:        struct htmlpair  tag;
                   1539:        struct roffsu    su;
1.1       kristaps 1540:
1.57      kristaps 1541:        if (SEC_SYNOPSIS == n->sec && MDOC_BLOCK == n->type) {
                   1542:                if (n->next && MDOC_Vt != n->next->tok) {
1.23      kristaps 1543:                        SCALE_VS_INIT(&su, 1);
1.57      kristaps 1544:                        bufcat_su(h, "margin-bottom", &su);
1.23      kristaps 1545:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1546:                        print_otag(h, TAG_DIV, 1, &tag);
                   1547:                } else
                   1548:                        print_otag(h, TAG_DIV, 0, NULL);
1.57      kristaps 1549:
1.54      kristaps 1550:                return(1);
                   1551:        } else if (MDOC_HEAD == n->type)
                   1552:                return(0);
1.1       kristaps 1553:
1.23      kristaps 1554:        PAIR_CLASS_INIT(&tag, "type");
1.1       kristaps 1555:        print_otag(h, TAG_SPAN, 1, &tag);
                   1556:        return(1);
                   1557: }
                   1558:
1.2       kristaps 1559:
1.1       kristaps 1560: /* ARGSUSED */
                   1561: static int
                   1562: mdoc_ft_pre(MDOC_ARGS)
                   1563: {
1.23      kristaps 1564:        struct htmlpair  tag;
1.1       kristaps 1565:
1.62      kristaps 1566:        if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
1.57      kristaps 1567:                print_otag(h, TAG_DIV, 0, NULL);
1.1       kristaps 1568:
1.23      kristaps 1569:        PAIR_CLASS_INIT(&tag, "ftype");
1.1       kristaps 1570:        print_otag(h, TAG_SPAN, 1, &tag);
                   1571:        return(1);
                   1572: }
                   1573:
                   1574:
                   1575: /* ARGSUSED */
                   1576: static int
                   1577: mdoc_fn_pre(MDOC_ARGS)
                   1578: {
                   1579:        struct tag              *t;
1.15      kristaps 1580:        struct htmlpair          tag[2];
1.1       kristaps 1581:        const struct mdoc_node  *nn;
1.7       kristaps 1582:        char                     nbuf[BUFSIZ];
                   1583:        const char              *sp, *ep;
1.15      kristaps 1584:        int                      sz, i;
1.23      kristaps 1585:        struct roffsu            su;
1.1       kristaps 1586:
1.75      kristaps 1587:        /* NB: MDOC_LINE has no effect on this macro! */
                   1588:        if (SEC_SYNOPSIS == n->sec) {
1.23      kristaps 1589:                SCALE_HS_INIT(&su, INDENT);
                   1590:                bufcat_su(h, "margin-left", &su);
                   1591:                su.scale = -su.scale;
                   1592:                bufcat_su(h, "text-indent", &su);
1.76    ! kristaps 1593:                if (n->prev && MDOC_Ft != n->prev->tok) {
        !          1594:                        SCALE_VS_INIT(&su, 1);
        !          1595:                        bufcat_su(h, "margin-top", &su);
        !          1596:                }
1.23      kristaps 1597:                if (n->next) {
                   1598:                        SCALE_VS_INIT(&su, 1);
                   1599:                        bufcat_su(h, "margin-bottom", &su);
                   1600:                }
                   1601:                PAIR_STYLE_INIT(&tag[0], h);
1.15      kristaps 1602:                print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps 1603:        }
                   1604:
1.7       kristaps 1605:        /* Split apart into type and name. */
                   1606:        assert(n->child->string);
                   1607:        sp = n->child->string;
1.19      kristaps 1608:
1.26      kristaps 1609:        ep = strchr(sp, ' ');
                   1610:        if (NULL != ep) {
1.23      kristaps 1611:                PAIR_CLASS_INIT(&tag[0], "ftype");
1.19      kristaps 1612:                t = print_otag(h, TAG_SPAN, 1, tag);
                   1613:
                   1614:                while (ep) {
                   1615:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1616:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1617:                        nbuf[sz] = '\0';
                   1618:                        print_text(h, nbuf);
                   1619:                        sp = ++ep;
                   1620:                        ep = strchr(sp, ' ');
                   1621:                }
                   1622:                print_tagq(h, t);
1.7       kristaps 1623:        }
1.1       kristaps 1624:
1.23      kristaps 1625:        PAIR_CLASS_INIT(&tag[0], "fname");
1.57      kristaps 1626:
                   1627:        /*
                   1628:         * FIXME: only refer to IDs that we know exist.
                   1629:         */
                   1630:
                   1631: #if 0
                   1632:        if (SEC_SYNOPSIS == n->sec) {
                   1633:                nbuf[0] = '\0';
                   1634:                html_idcat(nbuf, sp, BUFSIZ);
                   1635:                PAIR_ID_INIT(&tag[1], nbuf);
                   1636:        } else {
                   1637:                strlcpy(nbuf, "#", BUFSIZ);
                   1638:                html_idcat(nbuf, sp, BUFSIZ);
                   1639:                PAIR_HREF_INIT(&tag[1], nbuf);
                   1640:        }
                   1641: #endif
                   1642:
1.15      kristaps 1643:        t = print_otag(h, TAG_SPAN, 1, tag);
1.7       kristaps 1644:
                   1645:        if (sp) {
1.57      kristaps 1646:                strlcpy(nbuf, sp, BUFSIZ);
1.7       kristaps 1647:                print_text(h, nbuf);
                   1648:        }
                   1649:
1.1       kristaps 1650:        print_tagq(h, t);
                   1651:
                   1652:        h->flags |= HTML_NOSPACE;
                   1653:        print_text(h, "(");
                   1654:
1.23      kristaps 1655:        bufinit(h);
                   1656:        PAIR_CLASS_INIT(&tag[0], "farg");
                   1657:        bufcat_style(h, "white-space", "nowrap");
                   1658:        PAIR_STYLE_INIT(&tag[1], h);
                   1659:
1.1       kristaps 1660:        for (nn = n->child->next; nn; nn = nn->next) {
1.23      kristaps 1661:                i = 1;
                   1662:                if (SEC_SYNOPSIS == n->sec)
                   1663:                        i = 2;
1.15      kristaps 1664:                t = print_otag(h, TAG_SPAN, i, tag);
1.1       kristaps 1665:                print_text(h, nn->string);
                   1666:                print_tagq(h, t);
                   1667:                if (nn->next)
                   1668:                        print_text(h, ",");
                   1669:        }
                   1670:
                   1671:        print_text(h, ")");
                   1672:        if (SEC_SYNOPSIS == n->sec)
                   1673:                print_text(h, ";");
                   1674:
                   1675:        return(0);
                   1676: }
                   1677:
                   1678:
                   1679: /* ARGSUSED */
                   1680: static int
                   1681: mdoc_sp_pre(MDOC_ARGS)
                   1682: {
1.23      kristaps 1683:        int              len;
                   1684:        struct htmlpair  tag;
                   1685:        struct roffsu    su;
1.1       kristaps 1686:
                   1687:        switch (n->tok) {
                   1688:        case (MDOC_sp):
1.23      kristaps 1689:                /* FIXME: can this have a scaling indicator? */
1.1       kristaps 1690:                len = n->child ? atoi(n->child->string) : 1;
                   1691:                break;
                   1692:        case (MDOC_br):
                   1693:                len = 0;
                   1694:                break;
                   1695:        default:
                   1696:                len = 1;
                   1697:                break;
                   1698:        }
                   1699:
1.23      kristaps 1700:        SCALE_VS_INIT(&su, len);
                   1701:        bufcat_su(h, "height", &su);
                   1702:        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1703:        print_otag(h, TAG_DIV, 1, &tag);
1.42      kristaps 1704:        /* So the div isn't empty: */
                   1705:        print_text(h, "\\~");
                   1706:
                   1707:        return(0);
1.1       kristaps 1708:
                   1709: }
1.2       kristaps 1710:
                   1711:
                   1712: /* ARGSUSED */
                   1713: static int
                   1714: mdoc_brq_pre(MDOC_ARGS)
                   1715: {
                   1716:
                   1717:        if (MDOC_BODY != n->type)
                   1718:                return(1);
                   1719:        print_text(h, "\\(lC");
                   1720:        h->flags |= HTML_NOSPACE;
                   1721:        return(1);
                   1722: }
                   1723:
                   1724:
                   1725: /* ARGSUSED */
                   1726: static void
                   1727: mdoc_brq_post(MDOC_ARGS)
                   1728: {
                   1729:
                   1730:        if (MDOC_BODY != n->type)
                   1731:                return;
                   1732:        h->flags |= HTML_NOSPACE;
                   1733:        print_text(h, "\\(rC");
                   1734: }
                   1735:
                   1736:
                   1737: /* ARGSUSED */
                   1738: static int
                   1739: mdoc_lk_pre(MDOC_ARGS)
                   1740: {
                   1741:        const struct mdoc_node  *nn;
                   1742:        struct htmlpair          tag[2];
                   1743:
                   1744:        nn = n->child;
                   1745:
1.23      kristaps 1746:        PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57      kristaps 1747:        PAIR_HREF_INIT(&tag[1], nn->string);
1.2       kristaps 1748:        print_otag(h, TAG_A, 2, tag);
                   1749:
1.38      kristaps 1750:        if (NULL == nn->next)
                   1751:                return(1);
                   1752:
1.2       kristaps 1753:        for (nn = nn->next; nn; nn = nn->next)
                   1754:                print_text(h, nn->string);
                   1755:
                   1756:        return(0);
                   1757: }
                   1758:
                   1759:
                   1760: /* ARGSUSED */
                   1761: static int
                   1762: mdoc_mt_pre(MDOC_ARGS)
                   1763: {
                   1764:        struct htmlpair          tag[2];
                   1765:        struct tag              *t;
                   1766:        const struct mdoc_node  *nn;
                   1767:
1.23      kristaps 1768:        PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2       kristaps 1769:
                   1770:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps 1771:                bufinit(h);
                   1772:                bufcat(h, "mailto:");
                   1773:                bufcat(h, nn->string);
1.57      kristaps 1774:                PAIR_HREF_INIT(&tag[1], h->buf);
1.2       kristaps 1775:                t = print_otag(h, TAG_A, 2, tag);
                   1776:                print_text(h, nn->string);
                   1777:                print_tagq(h, t);
                   1778:        }
                   1779:
                   1780:        return(0);
                   1781: }
1.4       kristaps 1782:
                   1783:
                   1784: /* ARGSUSED */
                   1785: static int
                   1786: mdoc_fo_pre(MDOC_ARGS)
                   1787: {
                   1788:        struct htmlpair tag;
1.57      kristaps 1789:        struct roffsu   su;
1.4       kristaps 1790:
                   1791:        if (MDOC_BODY == n->type) {
                   1792:                h->flags |= HTML_NOSPACE;
                   1793:                print_text(h, "(");
                   1794:                h->flags |= HTML_NOSPACE;
                   1795:                return(1);
1.57      kristaps 1796:        } else if (MDOC_BLOCK == n->type && n->next) {
                   1797:                SCALE_VS_INIT(&su, 1);
                   1798:                bufcat_su(h, "margin-bottom", &su);
                   1799:                PAIR_STYLE_INIT(&tag, h);
                   1800:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps 1801:                return(1);
1.57      kristaps 1802:        }
1.4       kristaps 1803:
1.23      kristaps 1804:        PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1805:        print_otag(h, TAG_SPAN, 1, &tag);
                   1806:        return(1);
                   1807: }
                   1808:
                   1809:
                   1810: /* ARGSUSED */
                   1811: static void
                   1812: mdoc_fo_post(MDOC_ARGS)
                   1813: {
                   1814:        if (MDOC_BODY != n->type)
                   1815:                return;
                   1816:        h->flags |= HTML_NOSPACE;
                   1817:        print_text(h, ")");
                   1818:        h->flags |= HTML_NOSPACE;
                   1819:        print_text(h, ";");
                   1820: }
                   1821:
                   1822:
                   1823: /* ARGSUSED */
                   1824: static int
                   1825: mdoc_in_pre(MDOC_ARGS)
                   1826: {
                   1827:        const struct mdoc_node  *nn;
1.23      kristaps 1828:        struct tag              *t;
1.17      kristaps 1829:        struct htmlpair          tag[2];
                   1830:        int                      i;
1.34      kristaps 1831:
1.23      kristaps 1832:        PAIR_CLASS_INIT(&tag[0], "includes");
1.17      kristaps 1833:        print_otag(h, TAG_SPAN, 1, tag);
1.4       kristaps 1834:
1.74      kristaps 1835:        if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
1.4       kristaps 1836:                print_text(h, "#include");
                   1837:
                   1838:        print_text(h, "<");
                   1839:        h->flags |= HTML_NOSPACE;
                   1840:
1.17      kristaps 1841:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1842:                PAIR_CLASS_INIT(&tag[0], "link-includes");
                   1843:                i = 1;
1.41      kristaps 1844:                bufinit(h);
1.17      kristaps 1845:                if (h->base_includes) {
                   1846:                        buffmt_includes(h, nn->string);
1.57      kristaps 1847:                        PAIR_HREF_INIT(&tag[i], h->buf);
                   1848:                        i++;
1.17      kristaps 1849:                }
                   1850:                t = print_otag(h, TAG_A, i, tag);
1.4       kristaps 1851:                print_mdoc_node(m, nn, h);
1.17      kristaps 1852:                print_tagq(h, t);
                   1853:        }
1.4       kristaps 1854:
                   1855:        h->flags |= HTML_NOSPACE;
                   1856:        print_text(h, ">");
1.74      kristaps 1857:
                   1858:        if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
                   1859:                print_otag(h, TAG_BR, 0, NULL);
1.4       kristaps 1860:
                   1861:        return(0);
                   1862: }
                   1863:
                   1864:
                   1865: /* ARGSUSED */
                   1866: static int
                   1867: mdoc_ic_pre(MDOC_ARGS)
                   1868: {
                   1869:        struct htmlpair tag;
                   1870:
1.23      kristaps 1871:        PAIR_CLASS_INIT(&tag, "cmd");
1.4       kristaps 1872:        print_otag(h, TAG_SPAN, 1, &tag);
                   1873:        return(1);
                   1874: }
                   1875:
                   1876:
                   1877: /* ARGSUSED */
                   1878: static int
                   1879: mdoc_rv_pre(MDOC_ARGS)
                   1880: {
                   1881:        const struct mdoc_node  *nn;
                   1882:        struct htmlpair          tag;
                   1883:        struct tag              *t;
                   1884:
                   1885:        print_otag(h, TAG_DIV, 0, NULL);
                   1886:        print_text(h, "The");
                   1887:
                   1888:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1889:                PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1890:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1891:                print_text(h, nn->string);
                   1892:                print_tagq(h, t);
                   1893:
                   1894:                h->flags |= HTML_NOSPACE;
                   1895:                if (nn->next && NULL == nn->next->next)
                   1896:                        print_text(h, "(), and");
                   1897:                else if (nn->next)
                   1898:                        print_text(h, "(),");
                   1899:                else
                   1900:                        print_text(h, "()");
                   1901:        }
                   1902:
1.65      kristaps 1903:        if (n->child && n->child->next)
1.4       kristaps 1904:                print_text(h, "functions return");
                   1905:        else
                   1906:                print_text(h, "function returns");
                   1907:
                   1908:                print_text(h, "the value 0 if successful; otherwise the value "
                   1909:                        "-1 is returned and the global variable");
                   1910:
1.23      kristaps 1911:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1912:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1913:        print_text(h, "errno");
                   1914:        print_tagq(h, t);
                   1915:                print_text(h, "is set to indicate the error.");
                   1916:        return(0);
                   1917: }
                   1918:
                   1919:
                   1920: /* ARGSUSED */
                   1921: static int
                   1922: mdoc_va_pre(MDOC_ARGS)
                   1923: {
                   1924:        struct htmlpair tag;
                   1925:
1.23      kristaps 1926:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1927:        print_otag(h, TAG_SPAN, 1, &tag);
                   1928:        return(1);
                   1929: }
                   1930:
                   1931:
                   1932: /* ARGSUSED */
                   1933: static int
                   1934: mdoc_bq_pre(MDOC_ARGS)
                   1935: {
                   1936:
                   1937:        if (MDOC_BODY != n->type)
                   1938:                return(1);
                   1939:        print_text(h, "\\(lB");
                   1940:        h->flags |= HTML_NOSPACE;
                   1941:        return(1);
                   1942: }
                   1943:
                   1944:
                   1945: /* ARGSUSED */
                   1946: static void
                   1947: mdoc_bq_post(MDOC_ARGS)
                   1948: {
                   1949:
                   1950:        if (MDOC_BODY != n->type)
                   1951:                return;
                   1952:        h->flags |= HTML_NOSPACE;
                   1953:        print_text(h, "\\(rB");
                   1954: }
1.5       kristaps 1955:
                   1956:
                   1957: /* ARGSUSED */
                   1958: static int
                   1959: mdoc_ap_pre(MDOC_ARGS)
                   1960: {
                   1961:
                   1962:        h->flags |= HTML_NOSPACE;
                   1963:        print_text(h, "\\(aq");
                   1964:        h->flags |= HTML_NOSPACE;
                   1965:        return(1);
                   1966: }
                   1967:
                   1968:
                   1969: /* ARGSUSED */
                   1970: static int
                   1971: mdoc_bf_pre(MDOC_ARGS)
                   1972: {
1.23      kristaps 1973:        int              i;
                   1974:        struct htmlpair  tag[2];
                   1975:        struct roffsu    su;
1.5       kristaps 1976:
                   1977:        if (MDOC_HEAD == n->type)
                   1978:                return(0);
                   1979:        else if (MDOC_BLOCK != n->type)
                   1980:                return(1);
                   1981:
1.23      kristaps 1982:        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 1983:
                   1984:        if (n->head->child) {
                   1985:                if ( ! strcmp("Em", n->head->child->string))
1.23      kristaps 1986:                        PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 1987:                else if ( ! strcmp("Sy", n->head->child->string))
1.23      kristaps 1988:                        PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 1989:                else if ( ! strcmp("Li", n->head->child->string))
1.23      kristaps 1990:                        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 1991:        } else {
1.72      kristaps 1992:                for (i = 0; n->args && i < (int)n->args->argc; i++)
1.5       kristaps 1993:                        switch (n->args->argv[i].arg) {
                   1994:                        case (MDOC_Symbolic):
1.23      kristaps 1995:                                PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 1996:                                break;
                   1997:                        case (MDOC_Literal):
1.23      kristaps 1998:                                PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 1999:                                break;
                   2000:                        case (MDOC_Emphasis):
1.23      kristaps 2001:                                PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 2002:                                break;
                   2003:                        default:
                   2004:                                break;
                   2005:                        }
                   2006:        }
                   2007:
                   2008:        /* FIXME: div's have spaces stripped--we want them. */
                   2009:
1.23      kristaps 2010:        bufcat_style(h, "display", "inline");
                   2011:        SCALE_HS_INIT(&su, 1);
                   2012:        bufcat_su(h, "margin-right", &su);
                   2013:        PAIR_STYLE_INIT(&tag[1], h);
1.5       kristaps 2014:        print_otag(h, TAG_DIV, 2, tag);
                   2015:        return(1);
                   2016: }
                   2017:
                   2018:
                   2019: /* ARGSUSED */
                   2020: static int
                   2021: mdoc_ms_pre(MDOC_ARGS)
                   2022: {
                   2023:        struct htmlpair tag;
                   2024:
1.23      kristaps 2025:        PAIR_CLASS_INIT(&tag, "symb");
1.5       kristaps 2026:        print_otag(h, TAG_SPAN, 1, &tag);
                   2027:        return(1);
                   2028: }
                   2029:
                   2030:
                   2031: /* ARGSUSED */
                   2032: static int
                   2033: mdoc_pf_pre(MDOC_ARGS)
                   2034: {
                   2035:
                   2036:        h->flags |= HTML_IGNDELIM;
                   2037:        return(1);
                   2038: }
                   2039:
                   2040:
                   2041: /* ARGSUSED */
                   2042: static void
                   2043: mdoc_pf_post(MDOC_ARGS)
                   2044: {
                   2045:
                   2046:        h->flags &= ~HTML_IGNDELIM;
                   2047:        h->flags |= HTML_NOSPACE;
                   2048: }
                   2049:
                   2050:
                   2051: /* ARGSUSED */
                   2052: static int
                   2053: mdoc_rs_pre(MDOC_ARGS)
                   2054: {
1.23      kristaps 2055:        struct htmlpair  tag;
                   2056:        struct roffsu    su;
1.5       kristaps 2057:
                   2058:        if (MDOC_BLOCK != n->type)
                   2059:                return(1);
                   2060:
1.8       kristaps 2061:        if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23      kristaps 2062:                SCALE_VS_INIT(&su, 1);
                   2063:                bufcat_su(h, "margin-top", &su);
                   2064:                PAIR_STYLE_INIT(&tag, h);
1.8       kristaps 2065:                print_otag(h, TAG_DIV, 1, &tag);
1.5       kristaps 2066:        }
                   2067:
1.23      kristaps 2068:        PAIR_CLASS_INIT(&tag, "ref");
1.8       kristaps 2069:        print_otag(h, TAG_SPAN, 1, &tag);
1.5       kristaps 2070:        return(1);
                   2071: }
1.6       kristaps 2072:
                   2073:
                   2074:
                   2075: /* ARGSUSED */
                   2076: static int
                   2077: mdoc_li_pre(MDOC_ARGS)
                   2078: {
                   2079:        struct htmlpair tag;
                   2080:
1.23      kristaps 2081:        PAIR_CLASS_INIT(&tag, "lit");
1.6       kristaps 2082:        print_otag(h, TAG_SPAN, 1, &tag);
                   2083:        return(1);
                   2084: }
                   2085:
                   2086:
                   2087: /* ARGSUSED */
                   2088: static int
                   2089: mdoc_sy_pre(MDOC_ARGS)
                   2090: {
                   2091:        struct htmlpair tag;
                   2092:
1.23      kristaps 2093:        PAIR_CLASS_INIT(&tag, "symb");
1.6       kristaps 2094:        print_otag(h, TAG_SPAN, 1, &tag);
                   2095:        return(1);
                   2096: }
                   2097:
                   2098:
                   2099: /* ARGSUSED */
                   2100: static int
                   2101: mdoc_bt_pre(MDOC_ARGS)
                   2102: {
                   2103:
                   2104:        print_text(h, "is currently in beta test.");
                   2105:        return(0);
                   2106: }
                   2107:
                   2108:
                   2109: /* ARGSUSED */
                   2110: static int
                   2111: mdoc_ud_pre(MDOC_ARGS)
                   2112: {
                   2113:
                   2114:        print_text(h, "currently under development.");
                   2115:        return(0);
                   2116: }
                   2117:
                   2118:
                   2119: /* ARGSUSED */
                   2120: static int
                   2121: mdoc_lb_pre(MDOC_ARGS)
                   2122: {
                   2123:        struct htmlpair tag;
                   2124:
1.62      kristaps 2125:        if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.6       kristaps 2126:                print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 2127:        PAIR_CLASS_INIT(&tag, "lib");
1.6       kristaps 2128:        print_otag(h, TAG_SPAN, 1, &tag);
                   2129:        return(1);
                   2130: }
1.10      kristaps 2131:
                   2132:
                   2133: /* ARGSUSED */
                   2134: static int
                   2135: mdoc__x_pre(MDOC_ARGS)
                   2136: {
1.38      kristaps 2137:        struct htmlpair tag[2];
1.37      kristaps 2138:
1.10      kristaps 2139:        switch (n->tok) {
                   2140:        case(MDOC__A):
1.38      kristaps 2141:                PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.10      kristaps 2142:                break;
                   2143:        case(MDOC__B):
1.38      kristaps 2144:                PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10      kristaps 2145:                break;
                   2146:        case(MDOC__C):
1.38      kristaps 2147:                PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10      kristaps 2148:                break;
                   2149:        case(MDOC__D):
1.38      kristaps 2150:                PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10      kristaps 2151:                break;
                   2152:        case(MDOC__I):
1.38      kristaps 2153:                PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10      kristaps 2154:                break;
                   2155:        case(MDOC__J):
1.38      kristaps 2156:                PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10      kristaps 2157:                break;
                   2158:        case(MDOC__N):
1.38      kristaps 2159:                PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10      kristaps 2160:                break;
                   2161:        case(MDOC__O):
1.38      kristaps 2162:                PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10      kristaps 2163:                break;
                   2164:        case(MDOC__P):
1.38      kristaps 2165:                PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10      kristaps 2166:                break;
                   2167:        case(MDOC__Q):
1.38      kristaps 2168:                PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10      kristaps 2169:                break;
                   2170:        case(MDOC__R):
1.38      kristaps 2171:                PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10      kristaps 2172:                break;
                   2173:        case(MDOC__T):
1.38      kristaps 2174:                PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10      kristaps 2175:                break;
1.38      kristaps 2176:        case(MDOC__U):
                   2177:                PAIR_CLASS_INIT(&tag[0], "link-ref");
                   2178:                break;
1.10      kristaps 2179:        case(MDOC__V):
1.38      kristaps 2180:                PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10      kristaps 2181:                break;
                   2182:        default:
                   2183:                abort();
                   2184:                /* NOTREACHED */
                   2185:        }
                   2186:
1.38      kristaps 2187:        if (MDOC__U != n->tok) {
                   2188:                print_otag(h, TAG_SPAN, 1, tag);
                   2189:                return(1);
                   2190:        }
                   2191:
                   2192:        PAIR_HREF_INIT(&tag[1], n->child->string);
                   2193:        print_otag(h, TAG_A, 2, tag);
1.10      kristaps 2194:        return(1);
                   2195: }
                   2196:
                   2197:
                   2198: /* ARGSUSED */
                   2199: static void
                   2200: mdoc__x_post(MDOC_ARGS)
                   2201: {
                   2202:
1.61      kristaps 2203:        /* TODO: %U */
                   2204:
1.10      kristaps 2205:        h->flags |= HTML_NOSPACE;
                   2206:        print_text(h, n->next ? "," : ".");
                   2207: }

CVSweb