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

Annotation of mandoc/mdoc_html.c, Revision 1.56

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

CVSweb