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

Annotation of mandoc/mdoc_html.c, Revision 1.59

1.59    ! kristaps    1: /*     $Id: mdoc_html.c,v 1.58 2010/04/06 07:27:42 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.57      kristaps  592:        PAIR_CLASS_INIT(&tag[0], "sec-head");
                    593:        PAIR_ID_INIT(&tag[1], buf);
1.22      kristaps  594:
1.1       kristaps  595:        print_otag(h, TAG_DIV, 2, tag);
                    596:        return(1);
                    597: }
                    598:
                    599:
                    600: /* ARGSUSED */
                    601: static int
                    602: mdoc_ss_pre(MDOC_ARGS)
                    603: {
1.21      kristaps  604:        struct htmlpair          tag[3];
1.1       kristaps  605:        const struct mdoc_node  *nn;
1.41      kristaps  606:        char                     buf[BUFSIZ];
1.23      kristaps  607:        struct roffsu            su;
1.1       kristaps  608:
1.23      kristaps  609:        SCALE_VS_INIT(&su, 1);
1.1       kristaps  610:
                    611:        if (MDOC_BODY == n->type) {
1.23      kristaps  612:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.1       kristaps  613:                if (n->parent->next && n->child) {
1.23      kristaps  614:                        bufcat_su(h, "margin-bottom", &su);
                    615:                        PAIR_STYLE_INIT(&tag[1], h);
                    616:                        print_otag(h, TAG_DIV, 2, tag);
                    617:                } else
                    618:                        print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps  619:                return(1);
                    620:        } else if (MDOC_BLOCK == n->type) {
1.23      kristaps  621:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.1       kristaps  622:                if (n->prev) {
1.23      kristaps  623:                        bufcat_su(h, "margin-top", &su);
                    624:                        PAIR_STYLE_INIT(&tag[1], h);
                    625:                        print_otag(h, TAG_DIV, 2, tag);
                    626:                } else
                    627:                        print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps  628:                return(1);
                    629:        }
                    630:
1.23      kristaps  631:        /* TODO: see note in mdoc_sh_pre() about duplicates. */
                    632:
1.42      kristaps  633:        buf[0] = '\0';
1.21      kristaps  634:        for (nn = n->child; nn; nn = nn->next) {
1.41      kristaps  635:                html_idcat(buf, nn->string, BUFSIZ);
1.21      kristaps  636:                if (nn->next)
1.42      kristaps  637:                        html_idcat(buf, " ", BUFSIZ);
1.21      kristaps  638:        }
                    639:
1.23      kristaps  640:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    641:        su.scale = -su.scale;
                    642:        bufcat_su(h, "margin-left", &su);
1.22      kristaps  643:
1.23      kristaps  644:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    645:        PAIR_STYLE_INIT(&tag[1], h);
1.57      kristaps  646:        PAIR_ID_INIT(&tag[2], buf);
                    647:
1.21      kristaps  648:        print_otag(h, TAG_DIV, 3, tag);
1.1       kristaps  649:        return(1);
                    650: }
                    651:
                    652:
                    653: /* ARGSUSED */
                    654: static int
                    655: mdoc_fl_pre(MDOC_ARGS)
                    656: {
                    657:        struct htmlpair  tag;
                    658:
1.51      kristaps  659:        PAIR_CLASS_INIT(&tag, "flag");
                    660:        print_otag(h, TAG_SPAN, 1, &tag);
                    661:
1.50      kristaps  662:        /* `Cm' has no leading hyphen. */
                    663:
1.51      kristaps  664:        if (MDOC_Cm == n->tok)
1.50      kristaps  665:                return(1);
                    666:
                    667:        print_text(h, "\\-");
                    668:
                    669:        if (n->child)
1.58      kristaps  670:                h->flags |= HTML_NOSPACE;
                    671:        else if (n->next && n->next->line == n->line)
1.1       kristaps  672:                h->flags |= HTML_NOSPACE;
1.50      kristaps  673:
1.1       kristaps  674:        return(1);
                    675: }
                    676:
                    677:
                    678: /* ARGSUSED */
                    679: static int
                    680: mdoc_nd_pre(MDOC_ARGS)
                    681: {
                    682:        struct htmlpair  tag;
                    683:
                    684:        if (MDOC_BODY != n->type)
                    685:                return(1);
                    686:
1.24      kristaps  687:        /* XXX: this tag in theory can contain block elements. */
                    688:
1.1       kristaps  689:        print_text(h, "\\(em");
1.23      kristaps  690:        PAIR_CLASS_INIT(&tag, "desc-body");
1.1       kristaps  691:        print_otag(h, TAG_SPAN, 1, &tag);
                    692:        return(1);
                    693: }
                    694:
                    695:
                    696: /* ARGSUSED */
                    697: static int
                    698: mdoc_op_pre(MDOC_ARGS)
                    699: {
                    700:        struct htmlpair  tag;
                    701:
                    702:        if (MDOC_BODY != n->type)
                    703:                return(1);
                    704:
1.24      kristaps  705:        /* XXX: this tag in theory can contain block elements. */
                    706:
1.1       kristaps  707:        print_text(h, "\\(lB");
                    708:        h->flags |= HTML_NOSPACE;
1.23      kristaps  709:        PAIR_CLASS_INIT(&tag, "opt");
1.1       kristaps  710:        print_otag(h, TAG_SPAN, 1, &tag);
                    711:        return(1);
                    712: }
                    713:
                    714:
                    715: /* ARGSUSED */
                    716: static void
                    717: mdoc_op_post(MDOC_ARGS)
                    718: {
                    719:
                    720:        if (MDOC_BODY != n->type)
                    721:                return;
                    722:        h->flags |= HTML_NOSPACE;
                    723:        print_text(h, "\\(rB");
                    724: }
                    725:
                    726:
                    727: static int
                    728: mdoc_nm_pre(MDOC_ARGS)
                    729: {
                    730:        struct htmlpair tag;
                    731:
1.47      kristaps  732:        if (SEC_SYNOPSIS == n->sec && n->prev) {
                    733:                bufcat_style(h, "clear", "both");
                    734:                PAIR_STYLE_INIT(&tag, h);
                    735:                print_otag(h, TAG_BR, 1, &tag);
                    736:        }
1.1       kristaps  737:
1.23      kristaps  738:        PAIR_CLASS_INIT(&tag, "name");
1.1       kristaps  739:        print_otag(h, TAG_SPAN, 1, &tag);
                    740:        if (NULL == n->child)
                    741:                print_text(h, m->name);
                    742:
                    743:        return(1);
                    744: }
                    745:
                    746:
                    747: /* ARGSUSED */
                    748: static int
                    749: mdoc_xr_pre(MDOC_ARGS)
                    750: {
                    751:        struct htmlpair          tag[2];
                    752:        const struct mdoc_node  *nn;
1.56      kristaps  753:
                    754:        if (NULL == n->child)
                    755:                return(0);
1.17      kristaps  756:
1.23      kristaps  757:        PAIR_CLASS_INIT(&tag[0], "link-man");
1.1       kristaps  758:
1.17      kristaps  759:        if (h->base_man) {
1.23      kristaps  760:                buffmt_man(h, n->child->string,
                    761:                                n->child->next ?
1.17      kristaps  762:                                n->child->next->string : NULL);
1.57      kristaps  763:                PAIR_HREF_INIT(&tag[1], h->buf);
1.23      kristaps  764:                print_otag(h, TAG_A, 2, tag);
                    765:        } else
                    766:                print_otag(h, TAG_A, 1, tag);
1.1       kristaps  767:
                    768:        nn = n->child;
                    769:        print_text(h, nn->string);
1.16      kristaps  770:
1.1       kristaps  771:        if (NULL == (nn = nn->next))
                    772:                return(0);
                    773:
                    774:        h->flags |= HTML_NOSPACE;
                    775:        print_text(h, "(");
                    776:        h->flags |= HTML_NOSPACE;
                    777:        print_text(h, nn->string);
                    778:        h->flags |= HTML_NOSPACE;
                    779:        print_text(h, ")");
                    780:        return(0);
                    781: }
                    782:
                    783:
                    784: /* ARGSUSED */
                    785: static int
                    786: mdoc_ns_pre(MDOC_ARGS)
                    787: {
                    788:
                    789:        h->flags |= HTML_NOSPACE;
                    790:        return(1);
                    791: }
                    792:
                    793:
                    794: /* ARGSUSED */
                    795: static int
                    796: mdoc_ar_pre(MDOC_ARGS)
                    797: {
                    798:        struct htmlpair tag;
                    799:
1.23      kristaps  800:        PAIR_CLASS_INIT(&tag, "arg");
1.1       kristaps  801:        print_otag(h, TAG_SPAN, 1, &tag);
                    802:        return(1);
                    803: }
                    804:
                    805:
                    806: /* ARGSUSED */
                    807: static int
                    808: mdoc_xx_pre(MDOC_ARGS)
                    809: {
                    810:        const char      *pp;
                    811:        struct htmlpair  tag;
                    812:
                    813:        switch (n->tok) {
                    814:        case (MDOC_Bsx):
                    815:                pp = "BSDI BSD/OS";
                    816:                break;
                    817:        case (MDOC_Dx):
1.45      kristaps  818:                pp = "DragonFly";
1.1       kristaps  819:                break;
                    820:        case (MDOC_Fx):
                    821:                pp = "FreeBSD";
                    822:                break;
                    823:        case (MDOC_Nx):
                    824:                pp = "NetBSD";
                    825:                break;
                    826:        case (MDOC_Ox):
                    827:                pp = "OpenBSD";
                    828:                break;
                    829:        case (MDOC_Ux):
                    830:                pp = "UNIX";
                    831:                break;
                    832:        default:
                    833:                return(1);
                    834:        }
                    835:
1.23      kristaps  836:        PAIR_CLASS_INIT(&tag, "unix");
1.1       kristaps  837:        print_otag(h, TAG_SPAN, 1, &tag);
                    838:        print_text(h, pp);
                    839:        return(1);
                    840: }
                    841:
                    842:
                    843: /* ARGSUSED */
                    844: static int
1.4       kristaps  845: mdoc_bx_pre(MDOC_ARGS)
                    846: {
                    847:        const struct mdoc_node  *nn;
                    848:        struct htmlpair          tag;
                    849:
1.23      kristaps  850:        PAIR_CLASS_INIT(&tag, "unix");
1.4       kristaps  851:        print_otag(h, TAG_SPAN, 1, &tag);
                    852:
                    853:        for (nn = n->child; nn; nn = nn->next)
                    854:                print_mdoc_node(m, nn, h);
                    855:
                    856:        if (n->child)
                    857:                h->flags |= HTML_NOSPACE;
                    858:
                    859:        print_text(h, "BSD");
                    860:        return(0);
                    861: }
                    862:
                    863:
                    864: /* ARGSUSED */
                    865: static int
1.27      kristaps  866: mdoc_it_block_pre(MDOC_ARGS, int type, int comp,
                    867:                struct roffsu *offs, struct roffsu *width)
1.1       kristaps  868: {
1.14      kristaps  869:        struct htmlpair          tag;
                    870:        const struct mdoc_node  *nn;
1.23      kristaps  871:        struct roffsu            su;
                    872:
                    873:        nn = n->parent->parent;
                    874:        assert(nn->args);
                    875:
1.24      kristaps  876:        /* XXX: see notes in mdoc_it_pre(). */
                    877:
                    878:        if (MDOC_Column == type) {
                    879:                /* Don't width-pad on the left. */
                    880:                SCALE_HS_INIT(width, 0);
                    881:                /* Also disallow non-compact. */
                    882:                comp = 1;
                    883:        }
1.23      kristaps  884:        if (MDOC_Diag == type)
1.24      kristaps  885:                /* Mandate non-compact with empty prior. */
1.23      kristaps  886:                if (n->prev && NULL == n->prev->body->child)
                    887:                        comp = 1;
                    888:
1.24      kristaps  889:        bufcat_style(h, "clear", "both");
1.23      kristaps  890:        if (offs->scale > 0)
                    891:                bufcat_su(h, "margin-left", offs);
                    892:        if (width->scale > 0)
                    893:                bufcat_su(h, "padding-left", width);
1.1       kristaps  894:
1.23      kristaps  895:        PAIR_STYLE_INIT(&tag, h);
                    896:
1.24      kristaps  897:        /* Mandate compact following `Ss' and `Sh' starts. */
                    898:
1.23      kristaps  899:        for (nn = n; nn && ! comp; nn = nn->parent) {
                    900:                if (MDOC_BLOCK != nn->type)
                    901:                        continue;
                    902:                if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                    903:                        comp = 1;
                    904:                if (nn->prev)
                    905:                        break;
1.1       kristaps  906:        }
                    907:
1.23      kristaps  908:        if ( ! comp) {
                    909:                SCALE_VS_INIT(&su, 1);
                    910:                bufcat_su(h, "padding-top", &su);
1.1       kristaps  911:        }
                    912:
1.23      kristaps  913:        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  914:        print_otag(h, TAG_DIV, 1, &tag);
                    915:        return(1);
                    916: }
                    917:
                    918:
1.25      kristaps  919: /* ARGSUSED */
1.1       kristaps  920: static int
1.23      kristaps  921: mdoc_it_body_pre(MDOC_ARGS, int type)
1.1       kristaps  922: {
1.23      kristaps  923:        struct htmlpair  tag;
                    924:        struct roffsu    su;
                    925:
                    926:        switch (type) {
                    927:        case (MDOC_Item):
                    928:                /* FALLTHROUGH */
                    929:        case (MDOC_Ohang):
                    930:                /* FALLTHROUGH */
                    931:        case (MDOC_Column):
                    932:                break;
                    933:        default:
1.24      kristaps  934:                /*
                    935:                 * XXX: this tricks CSS into aligning the bodies with
                    936:                 * the right-padding in the head.
                    937:                 */
1.23      kristaps  938:                SCALE_HS_INIT(&su, 2);
                    939:                bufcat_su(h, "margin-left", &su);
                    940:                PAIR_STYLE_INIT(&tag, h);
                    941:                print_otag(h, TAG_DIV, 1, &tag);
                    942:                break;
                    943:        }
1.1       kristaps  944:
                    945:        return(1);
                    946: }
                    947:
                    948:
1.25      kristaps  949: /* ARGSUSED */
1.1       kristaps  950: static int
1.23      kristaps  951: mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *width)
1.1       kristaps  952: {
                    953:        struct htmlpair  tag;
                    954:        struct ord      *ord;
                    955:        char             nbuf[BUFSIZ];
                    956:
1.23      kristaps  957:        switch (type) {
1.1       kristaps  958:        case (MDOC_Item):
1.46      kristaps  959:                return(0);
1.1       kristaps  960:        case (MDOC_Ohang):
1.46      kristaps  961:                print_otag(h, TAG_DIV, 0, &tag);
                    962:                return(1);
1.1       kristaps  963:        case (MDOC_Column):
1.23      kristaps  964:                bufcat_su(h, "min-width", width);
                    965:                bufcat_style(h, "clear", "none");
1.1       kristaps  966:                if (n->next && MDOC_HEAD == n->next->type)
1.23      kristaps  967:                        bufcat_style(h, "float", "left");
                    968:                PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  969:                print_otag(h, TAG_DIV, 1, &tag);
                    970:                break;
                    971:        default:
1.23      kristaps  972:                bufcat_su(h, "min-width", width);
                    973:                SCALE_INVERT(width);
                    974:                bufcat_su(h, "margin-left", width);
1.2       kristaps  975:                if (n->next && n->next->child)
1.23      kristaps  976:                        bufcat_style(h, "float", "left");
1.24      kristaps  977:
                    978:                /* XXX: buffer if we run into body. */
1.23      kristaps  979:                SCALE_HS_INIT(width, 1);
                    980:                bufcat_su(h, "margin-right", width);
                    981:                PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  982:                print_otag(h, TAG_DIV, 1, &tag);
                    983:                break;
                    984:        }
                    985:
1.23      kristaps  986:        switch (type) {
1.1       kristaps  987:        case (MDOC_Diag):
1.23      kristaps  988:                PAIR_CLASS_INIT(&tag, "diag");
1.1       kristaps  989:                print_otag(h, TAG_SPAN, 1, &tag);
                    990:                break;
                    991:        case (MDOC_Enum):
1.39      kristaps  992:                ord = h->ords.head;
1.1       kristaps  993:                assert(ord);
                    994:                nbuf[BUFSIZ - 1] = 0;
                    995:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    996:                print_text(h, nbuf);
                    997:                return(0);
                    998:        case (MDOC_Dash):
                    999:                print_text(h, "\\(en");
                   1000:                return(0);
                   1001:        case (MDOC_Hyphen):
1.4       kristaps 1002:                print_text(h, "\\(hy");
1.1       kristaps 1003:                return(0);
                   1004:        case (MDOC_Bullet):
                   1005:                print_text(h, "\\(bu");
                   1006:                return(0);
                   1007:        default:
                   1008:                break;
                   1009:        }
                   1010:
                   1011:        return(1);
                   1012: }
                   1013:
                   1014:
                   1015: static int
1.23      kristaps 1016: mdoc_it_pre(MDOC_ARGS)
1.1       kristaps 1017: {
1.23      kristaps 1018:        int                      i, type, wp, comp;
1.1       kristaps 1019:        const struct mdoc_node  *bl, *nn;
1.23      kristaps 1020:        struct roffsu            width, offs;
                   1021:
1.24      kristaps 1022:        /*
                   1023:         * XXX: be very careful in changing anything, here.  Lists in
                   1024:         * mandoc have many peculiarities; furthermore, they don't
                   1025:         * translate well into HTML and require a bit of mangling.
                   1026:         */
1.1       kristaps 1027:
                   1028:        bl = n->parent->parent;
1.23      kristaps 1029:        if (MDOC_BLOCK != n->type)
1.1       kristaps 1030:                bl = bl->parent;
                   1031:
1.23      kristaps 1032:        type = a2list(bl);
1.1       kristaps 1033:
1.23      kristaps 1034:        /* Set default width and offset. */
1.1       kristaps 1035:
1.24      kristaps 1036:        SCALE_HS_INIT(&offs, 0);
                   1037:
1.1       kristaps 1038:        switch (type) {
                   1039:        case (MDOC_Enum):
                   1040:                /* FALLTHROUGH */
                   1041:        case (MDOC_Dash):
                   1042:                /* FALLTHROUGH */
                   1043:        case (MDOC_Hyphen):
                   1044:                /* FALLTHROUGH */
                   1045:        case (MDOC_Bullet):
1.23      kristaps 1046:                SCALE_HS_INIT(&width, 2);
1.1       kristaps 1047:                break;
1.23      kristaps 1048:        default:
                   1049:                SCALE_HS_INIT(&width, INDENT);
                   1050:                break;
                   1051:        }
                   1052:
                   1053:        /* Get width, offset, and compact arguments. */
                   1054:
                   1055:        for (wp = -1, comp = i = 0; i < (int)bl->args->argc; i++)
                   1056:                switch (bl->args->argv[i].arg) {
1.24      kristaps 1057:                case (MDOC_Column):
                   1058:                        wp = i; /* Save for later. */
                   1059:                        break;
1.23      kristaps 1060:                case (MDOC_Width):
                   1061:                        a2width(bl->args->argv[i].value[0], &width);
                   1062:                        break;
                   1063:                case (MDOC_Offset):
                   1064:                        a2offs(bl->args->argv[i].value[0], &offs);
                   1065:                        break;
                   1066:                case (MDOC_Compact):
                   1067:                        comp = 1;
                   1068:                        break;
                   1069:                default:
                   1070:                        break;
                   1071:                }
                   1072:
                   1073:        /* Override width in some cases. */
                   1074:
                   1075:        switch (type) {
1.46      kristaps 1076:        case (MDOC_Ohang):
                   1077:                /* FALLTHROUGH */
1.33      kristaps 1078:        case (MDOC_Item):
                   1079:                /* FALLTHROUGH */
1.1       kristaps 1080:        case (MDOC_Inset):
                   1081:                /* FALLTHROUGH */
                   1082:        case (MDOC_Diag):
1.23      kristaps 1083:                SCALE_HS_INIT(&width, 0);
1.1       kristaps 1084:                break;
                   1085:        default:
1.23      kristaps 1086:                if (0 == width.scale)
                   1087:                        SCALE_HS_INIT(&width, INDENT);
1.1       kristaps 1088:                break;
                   1089:        }
                   1090:
1.23      kristaps 1091:        /* Flip to body/block processing. */
                   1092:
                   1093:        if (MDOC_BODY == n->type)
                   1094:                return(mdoc_it_body_pre(m, n, h, type));
                   1095:        if (MDOC_BLOCK == n->type)
1.27      kristaps 1096:                return(mdoc_it_block_pre(m, n, h, type, comp,
                   1097:                                        &offs, &width));
1.23      kristaps 1098:
                   1099:        /* Override column widths. */
                   1100:
                   1101:        if (MDOC_Column == type) {
                   1102:                nn = n->parent->child;
                   1103:                for (i = 0; nn && nn != n; nn = nn->next, i++)
                   1104:                        /* Counter... */ ;
1.24      kristaps 1105:                if (i < (int)bl->args->argv[wp].sz)
1.23      kristaps 1106:                        a2width(bl->args->argv[wp].value[i], &width);
1.1       kristaps 1107:        }
                   1108:
1.23      kristaps 1109:        return(mdoc_it_head_pre(m, n, h, type, &width));
1.1       kristaps 1110: }
                   1111:
                   1112:
                   1113: /* ARGSUSED */
                   1114: static int
                   1115: mdoc_bl_pre(MDOC_ARGS)
                   1116: {
                   1117:        struct ord      *ord;
                   1118:
1.59    ! kristaps 1119:        if (MDOC_HEAD == n->type)
        !          1120:                return(0);
1.1       kristaps 1121:        if (MDOC_BLOCK != n->type)
                   1122:                return(1);
                   1123:        if (MDOC_Enum != a2list(n))
                   1124:                return(1);
                   1125:
                   1126:        ord = malloc(sizeof(struct ord));
1.43      kristaps 1127:        if (NULL == ord) {
1.44      kristaps 1128:                perror(NULL);
1.43      kristaps 1129:                exit(EXIT_FAILURE);
                   1130:        }
1.1       kristaps 1131:        ord->cookie = n;
                   1132:        ord->pos = 1;
1.39      kristaps 1133:        ord->next = h->ords.head;
                   1134:        h->ords.head = ord;
1.1       kristaps 1135:        return(1);
                   1136: }
                   1137:
                   1138:
                   1139: /* ARGSUSED */
                   1140: static void
                   1141: mdoc_bl_post(MDOC_ARGS)
                   1142: {
                   1143:        struct ord      *ord;
                   1144:
                   1145:        if (MDOC_BLOCK != n->type)
                   1146:                return;
                   1147:        if (MDOC_Enum != a2list(n))
                   1148:                return;
                   1149:
1.39      kristaps 1150:        ord = h->ords.head;
1.1       kristaps 1151:        assert(ord);
1.39      kristaps 1152:        h->ords.head = ord->next;
1.1       kristaps 1153:        free(ord);
                   1154: }
                   1155:
                   1156:
                   1157: /* ARGSUSED */
                   1158: static int
                   1159: mdoc_ex_pre(MDOC_ARGS)
                   1160: {
                   1161:        const struct mdoc_node  *nn;
                   1162:        struct tag              *t;
                   1163:        struct htmlpair          tag;
                   1164:
1.23      kristaps 1165:        PAIR_CLASS_INIT(&tag, "utility");
                   1166:
1.1       kristaps 1167:        print_text(h, "The");
                   1168:        for (nn = n->child; nn; nn = nn->next) {
                   1169:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1170:                print_text(h, nn->string);
                   1171:                print_tagq(h, t);
                   1172:
                   1173:                h->flags |= HTML_NOSPACE;
                   1174:
                   1175:                if (nn->next && NULL == nn->next->next)
                   1176:                        print_text(h, ", and");
                   1177:                else if (nn->next)
                   1178:                        print_text(h, ",");
                   1179:                else
                   1180:                        h->flags &= ~HTML_NOSPACE;
                   1181:        }
                   1182:
                   1183:        if (n->child->next)
                   1184:                print_text(h, "utilities exit");
                   1185:        else
                   1186:                print_text(h, "utility exits");
                   1187:
                   1188:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1189:        return(0);
                   1190: }
                   1191:
                   1192:
                   1193: /* ARGSUSED */
                   1194: static int
                   1195: mdoc_dq_pre(MDOC_ARGS)
                   1196: {
                   1197:
                   1198:        if (MDOC_BODY != n->type)
                   1199:                return(1);
                   1200:        print_text(h, "\\(lq");
                   1201:        h->flags |= HTML_NOSPACE;
                   1202:        return(1);
                   1203: }
                   1204:
                   1205:
                   1206: /* ARGSUSED */
                   1207: static void
                   1208: mdoc_dq_post(MDOC_ARGS)
                   1209: {
                   1210:
                   1211:        if (MDOC_BODY != n->type)
                   1212:                return;
                   1213:        h->flags |= HTML_NOSPACE;
                   1214:        print_text(h, "\\(rq");
                   1215: }
                   1216:
                   1217:
                   1218: /* ARGSUSED */
                   1219: static int
                   1220: mdoc_pq_pre(MDOC_ARGS)
                   1221: {
                   1222:
                   1223:        if (MDOC_BODY != n->type)
                   1224:                return(1);
                   1225:        print_text(h, "\\&(");
                   1226:        h->flags |= HTML_NOSPACE;
                   1227:        return(1);
                   1228: }
                   1229:
                   1230:
                   1231: /* ARGSUSED */
                   1232: static void
                   1233: mdoc_pq_post(MDOC_ARGS)
                   1234: {
                   1235:
                   1236:        if (MDOC_BODY != n->type)
                   1237:                return;
                   1238:        print_text(h, ")");
                   1239: }
                   1240:
                   1241:
                   1242: /* ARGSUSED */
                   1243: static int
                   1244: mdoc_sq_pre(MDOC_ARGS)
                   1245: {
                   1246:
                   1247:        if (MDOC_BODY != n->type)
                   1248:                return(1);
                   1249:        print_text(h, "\\(oq");
                   1250:        h->flags |= HTML_NOSPACE;
                   1251:        return(1);
                   1252: }
                   1253:
                   1254:
                   1255: /* ARGSUSED */
                   1256: static void
                   1257: mdoc_sq_post(MDOC_ARGS)
                   1258: {
                   1259:
                   1260:        if (MDOC_BODY != n->type)
                   1261:                return;
                   1262:        h->flags |= HTML_NOSPACE;
                   1263:        print_text(h, "\\(aq");
                   1264: }
                   1265:
                   1266:
                   1267: /* ARGSUSED */
                   1268: static int
                   1269: mdoc_em_pre(MDOC_ARGS)
                   1270: {
                   1271:        struct htmlpair tag;
                   1272:
1.23      kristaps 1273:        PAIR_CLASS_INIT(&tag, "emph");
1.1       kristaps 1274:        print_otag(h, TAG_SPAN, 1, &tag);
                   1275:        return(1);
                   1276: }
                   1277:
                   1278:
                   1279: /* ARGSUSED */
                   1280: static int
                   1281: mdoc_d1_pre(MDOC_ARGS)
                   1282: {
1.23      kristaps 1283:        struct htmlpair  tag[2];
                   1284:        struct roffsu    su;
1.1       kristaps 1285:
                   1286:        if (MDOC_BLOCK != n->type)
                   1287:                return(1);
                   1288:
1.35      kristaps 1289:        /* FIXME: D1 shouldn't be literal. */
                   1290:
1.23      kristaps 1291:        SCALE_VS_INIT(&su, INDENT - 2);
                   1292:        bufcat_su(h, "margin-left", &su);
                   1293:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1294:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1295:        print_otag(h, TAG_DIV, 2, tag);
                   1296:        return(1);
                   1297: }
                   1298:
                   1299:
                   1300: /* ARGSUSED */
                   1301: static int
                   1302: mdoc_sx_pre(MDOC_ARGS)
                   1303: {
1.18      kristaps 1304:        struct htmlpair          tag[2];
1.1       kristaps 1305:        const struct mdoc_node  *nn;
1.35      kristaps 1306:        char                     buf[BUFSIZ];
1.1       kristaps 1307:
1.41      kristaps 1308:        strlcpy(buf, "#", BUFSIZ);
1.1       kristaps 1309:        for (nn = n->child; nn; nn = nn->next) {
1.41      kristaps 1310:                html_idcat(buf, nn->string, BUFSIZ);
1.1       kristaps 1311:                if (nn->next)
1.42      kristaps 1312:                        html_idcat(buf, " ", BUFSIZ);
1.1       kristaps 1313:        }
                   1314:
1.23      kristaps 1315:        PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57      kristaps 1316:        PAIR_HREF_INIT(&tag[1], buf);
1.1       kristaps 1317:
1.18      kristaps 1318:        print_otag(h, TAG_A, 2, tag);
1.1       kristaps 1319:        return(1);
                   1320: }
                   1321:
                   1322:
                   1323: /* ARGSUSED */
                   1324: static int
                   1325: mdoc_aq_pre(MDOC_ARGS)
                   1326: {
                   1327:
                   1328:        if (MDOC_BODY != n->type)
                   1329:                return(1);
                   1330:        print_text(h, "\\(la");
                   1331:        h->flags |= HTML_NOSPACE;
                   1332:        return(1);
                   1333: }
                   1334:
                   1335:
                   1336: /* ARGSUSED */
                   1337: static void
                   1338: mdoc_aq_post(MDOC_ARGS)
                   1339: {
                   1340:
                   1341:        if (MDOC_BODY != n->type)
                   1342:                return;
                   1343:        h->flags |= HTML_NOSPACE;
                   1344:        print_text(h, "\\(ra");
                   1345: }
                   1346:
                   1347:
                   1348: /* ARGSUSED */
                   1349: static int
                   1350: mdoc_bd_pre(MDOC_ARGS)
                   1351: {
                   1352:        struct htmlpair          tag[2];
1.23      kristaps 1353:        int                      type, comp, i;
1.14      kristaps 1354:        const struct mdoc_node  *bl, *nn;
1.23      kristaps 1355:        struct roffsu            su;
1.1       kristaps 1356:
                   1357:        if (MDOC_BLOCK == n->type)
                   1358:                bl = n;
                   1359:        else if (MDOC_HEAD == n->type)
                   1360:                return(0);
                   1361:        else
                   1362:                bl = n->parent;
                   1363:
1.24      kristaps 1364:        SCALE_VS_INIT(&su, 0);
                   1365:
1.23      kristaps 1366:        type = comp = 0;
1.1       kristaps 1367:        for (i = 0; i < (int)bl->args->argc; i++)
                   1368:                switch (bl->args->argv[i].arg) {
                   1369:                case (MDOC_Offset):
1.23      kristaps 1370:                        a2offs(bl->args->argv[i].value[0], &su);
1.1       kristaps 1371:                        break;
                   1372:                case (MDOC_Compact):
1.23      kristaps 1373:                        comp = 1;
1.1       kristaps 1374:                        break;
1.30      kristaps 1375:                case (MDOC_Centred):
                   1376:                        /* FALLTHROUGH */
1.1       kristaps 1377:                case (MDOC_Ragged):
                   1378:                        /* FALLTHROUGH */
                   1379:                case (MDOC_Filled):
                   1380:                        /* FALLTHROUGH */
                   1381:                case (MDOC_Unfilled):
                   1382:                        /* FALLTHROUGH */
                   1383:                case (MDOC_Literal):
1.23      kristaps 1384:                        type = bl->args->argv[i].arg;
1.1       kristaps 1385:                        break;
1.30      kristaps 1386:                default:
                   1387:                        break;
1.1       kristaps 1388:                }
                   1389:
1.31      kristaps 1390:        /* FIXME: -centered, etc. formatting. */
                   1391:
1.1       kristaps 1392:        if (MDOC_BLOCK == n->type) {
1.24      kristaps 1393:                bufcat_su(h, "margin-left", &su);
1.23      kristaps 1394:                for (nn = n; nn && ! comp; nn = nn->parent) {
                   1395:                        if (MDOC_BLOCK != nn->type)
                   1396:                                continue;
                   1397:                        if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                   1398:                                comp = 1;
                   1399:                        if (nn->prev)
                   1400:                                break;
                   1401:                }
                   1402:                if (comp) {
                   1403:                        print_otag(h, TAG_DIV, 0, tag);
                   1404:                        return(1);
1.14      kristaps 1405:                }
1.23      kristaps 1406:                SCALE_VS_INIT(&su, 1);
                   1407:                bufcat_su(h, "margin-top", &su);
                   1408:                PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps 1409:                print_otag(h, TAG_DIV, 1, tag);
                   1410:                return(1);
                   1411:        }
                   1412:
1.23      kristaps 1413:        if (MDOC_Unfilled != type && MDOC_Literal != type)
1.1       kristaps 1414:                return(1);
                   1415:
1.23      kristaps 1416:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1417:        bufcat_style(h, "white-space", "pre");
                   1418:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1419:        print_otag(h, TAG_DIV, 2, tag);
                   1420:
1.14      kristaps 1421:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1422:                h->flags |= HTML_NOSPACE;
1.14      kristaps 1423:                print_mdoc_node(m, nn, h);
                   1424:                if (NULL == nn->next)
                   1425:                        continue;
                   1426:                if (nn->prev && nn->prev->line < nn->line)
1.1       kristaps 1427:                        print_text(h, "\n");
1.23      kristaps 1428:                else if (NULL == nn->prev)
                   1429:                        print_text(h, "\n");
1.1       kristaps 1430:        }
                   1431:
                   1432:        return(0);
                   1433: }
                   1434:
                   1435:
                   1436: /* ARGSUSED */
                   1437: static int
                   1438: mdoc_pa_pre(MDOC_ARGS)
                   1439: {
                   1440:        struct htmlpair tag;
                   1441:
1.23      kristaps 1442:        PAIR_CLASS_INIT(&tag, "file");
1.1       kristaps 1443:        print_otag(h, TAG_SPAN, 1, &tag);
                   1444:        return(1);
                   1445: }
                   1446:
                   1447:
                   1448: /* ARGSUSED */
                   1449: static int
                   1450: mdoc_ad_pre(MDOC_ARGS)
                   1451: {
                   1452:        struct htmlpair tag;
                   1453:
1.23      kristaps 1454:        PAIR_CLASS_INIT(&tag, "addr");
1.1       kristaps 1455:        print_otag(h, TAG_SPAN, 1, &tag);
                   1456:        return(1);
                   1457: }
                   1458:
                   1459:
                   1460: /* ARGSUSED */
                   1461: static int
                   1462: mdoc_an_pre(MDOC_ARGS)
                   1463: {
                   1464:        struct htmlpair tag;
                   1465:
1.19      kristaps 1466:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1467:
1.23      kristaps 1468:        PAIR_CLASS_INIT(&tag, "author");
1.1       kristaps 1469:        print_otag(h, TAG_SPAN, 1, &tag);
                   1470:        return(1);
                   1471: }
                   1472:
                   1473:
                   1474: /* ARGSUSED */
                   1475: static int
                   1476: mdoc_cd_pre(MDOC_ARGS)
                   1477: {
                   1478:        struct htmlpair tag;
                   1479:
1.28      kristaps 1480:        print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 1481:        PAIR_CLASS_INIT(&tag, "config");
1.1       kristaps 1482:        print_otag(h, TAG_SPAN, 1, &tag);
                   1483:        return(1);
                   1484: }
                   1485:
                   1486:
                   1487: /* ARGSUSED */
                   1488: static int
                   1489: mdoc_dv_pre(MDOC_ARGS)
                   1490: {
                   1491:        struct htmlpair tag;
                   1492:
1.23      kristaps 1493:        PAIR_CLASS_INIT(&tag, "define");
1.1       kristaps 1494:        print_otag(h, TAG_SPAN, 1, &tag);
                   1495:        return(1);
                   1496: }
                   1497:
                   1498:
                   1499: /* ARGSUSED */
                   1500: static int
                   1501: mdoc_ev_pre(MDOC_ARGS)
                   1502: {
                   1503:        struct htmlpair tag;
                   1504:
1.23      kristaps 1505:        PAIR_CLASS_INIT(&tag, "env");
1.1       kristaps 1506:        print_otag(h, TAG_SPAN, 1, &tag);
                   1507:        return(1);
                   1508: }
                   1509:
                   1510:
                   1511: /* ARGSUSED */
                   1512: static int
                   1513: mdoc_er_pre(MDOC_ARGS)
                   1514: {
                   1515:        struct htmlpair tag;
                   1516:
1.23      kristaps 1517:        PAIR_CLASS_INIT(&tag, "errno");
1.1       kristaps 1518:        print_otag(h, TAG_SPAN, 1, &tag);
                   1519:        return(1);
                   1520: }
                   1521:
                   1522:
                   1523: /* ARGSUSED */
                   1524: static int
                   1525: mdoc_fa_pre(MDOC_ARGS)
                   1526: {
                   1527:        const struct mdoc_node  *nn;
                   1528:        struct htmlpair          tag;
                   1529:        struct tag              *t;
                   1530:
1.23      kristaps 1531:        PAIR_CLASS_INIT(&tag, "farg");
1.1       kristaps 1532:        if (n->parent->tok != MDOC_Fo) {
                   1533:                print_otag(h, TAG_SPAN, 1, &tag);
                   1534:                return(1);
                   1535:        }
                   1536:
                   1537:        for (nn = n->child; nn; nn = nn->next) {
                   1538:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1539:                print_text(h, nn->string);
                   1540:                print_tagq(h, t);
                   1541:                if (nn->next)
                   1542:                        print_text(h, ",");
                   1543:        }
                   1544:
                   1545:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1546:                print_text(h, ",");
                   1547:
                   1548:        return(0);
                   1549: }
                   1550:
                   1551:
                   1552: /* ARGSUSED */
                   1553: static int
                   1554: mdoc_fd_pre(MDOC_ARGS)
                   1555: {
1.23      kristaps 1556:        struct htmlpair  tag;
                   1557:        struct roffsu    su;
1.1       kristaps 1558:
                   1559:        if (SEC_SYNOPSIS == n->sec) {
                   1560:                if (n->next && MDOC_Fd != n->next->tok) {
1.23      kristaps 1561:                        SCALE_VS_INIT(&su, 1);
                   1562:                        bufcat_su(h, "margin-bottom", &su);
                   1563:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1564:                        print_otag(h, TAG_DIV, 1, &tag);
                   1565:                } else
                   1566:                        print_otag(h, TAG_DIV, 0, NULL);
                   1567:        }
                   1568:
1.23      kristaps 1569:        PAIR_CLASS_INIT(&tag, "macro");
1.1       kristaps 1570:        print_otag(h, TAG_SPAN, 1, &tag);
                   1571:        return(1);
                   1572: }
                   1573:
                   1574:
                   1575: /* ARGSUSED */
                   1576: static int
                   1577: mdoc_vt_pre(MDOC_ARGS)
                   1578: {
1.23      kristaps 1579:        struct htmlpair  tag;
                   1580:        struct roffsu    su;
1.1       kristaps 1581:
1.57      kristaps 1582:        if (SEC_SYNOPSIS == n->sec && MDOC_BLOCK == n->type) {
                   1583:                if (n->next && MDOC_Vt != n->next->tok) {
1.23      kristaps 1584:                        SCALE_VS_INIT(&su, 1);
1.57      kristaps 1585:                        bufcat_su(h, "margin-bottom", &su);
1.23      kristaps 1586:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1587:                        print_otag(h, TAG_DIV, 1, &tag);
                   1588:                } else
                   1589:                        print_otag(h, TAG_DIV, 0, NULL);
1.57      kristaps 1590:
1.54      kristaps 1591:                return(1);
                   1592:        } else if (MDOC_HEAD == n->type)
                   1593:                return(0);
1.1       kristaps 1594:
1.23      kristaps 1595:        PAIR_CLASS_INIT(&tag, "type");
1.1       kristaps 1596:        print_otag(h, TAG_SPAN, 1, &tag);
                   1597:        return(1);
                   1598: }
                   1599:
1.2       kristaps 1600:
1.1       kristaps 1601: /* ARGSUSED */
                   1602: static int
                   1603: mdoc_ft_pre(MDOC_ARGS)
                   1604: {
1.23      kristaps 1605:        struct htmlpair  tag;
1.1       kristaps 1606:
1.57      kristaps 1607:        if (SEC_SYNOPSIS == n->sec)
                   1608:                print_otag(h, TAG_DIV, 0, NULL);
1.1       kristaps 1609:
1.23      kristaps 1610:        PAIR_CLASS_INIT(&tag, "ftype");
1.1       kristaps 1611:        print_otag(h, TAG_SPAN, 1, &tag);
                   1612:        return(1);
                   1613: }
                   1614:
                   1615:
                   1616: /* ARGSUSED */
                   1617: static int
                   1618: mdoc_fn_pre(MDOC_ARGS)
                   1619: {
                   1620:        struct tag              *t;
1.15      kristaps 1621:        struct htmlpair          tag[2];
1.1       kristaps 1622:        const struct mdoc_node  *nn;
1.7       kristaps 1623:        char                     nbuf[BUFSIZ];
                   1624:        const char              *sp, *ep;
1.15      kristaps 1625:        int                      sz, i;
1.23      kristaps 1626:        struct roffsu            su;
1.1       kristaps 1627:
                   1628:        if (SEC_SYNOPSIS == n->sec) {
1.23      kristaps 1629:                SCALE_HS_INIT(&su, INDENT);
                   1630:                bufcat_su(h, "margin-left", &su);
                   1631:                su.scale = -su.scale;
                   1632:                bufcat_su(h, "text-indent", &su);
                   1633:                if (n->next) {
                   1634:                        SCALE_VS_INIT(&su, 1);
                   1635:                        bufcat_su(h, "margin-bottom", &su);
                   1636:                }
                   1637:                PAIR_STYLE_INIT(&tag[0], h);
1.15      kristaps 1638:                print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps 1639:        }
                   1640:
1.7       kristaps 1641:        /* Split apart into type and name. */
                   1642:        assert(n->child->string);
                   1643:        sp = n->child->string;
1.19      kristaps 1644:
1.26      kristaps 1645:        ep = strchr(sp, ' ');
                   1646:        if (NULL != ep) {
1.23      kristaps 1647:                PAIR_CLASS_INIT(&tag[0], "ftype");
1.19      kristaps 1648:                t = print_otag(h, TAG_SPAN, 1, tag);
                   1649:
                   1650:                while (ep) {
                   1651:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1652:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1653:                        nbuf[sz] = '\0';
                   1654:                        print_text(h, nbuf);
                   1655:                        sp = ++ep;
                   1656:                        ep = strchr(sp, ' ');
                   1657:                }
                   1658:                print_tagq(h, t);
1.7       kristaps 1659:        }
1.1       kristaps 1660:
1.23      kristaps 1661:        PAIR_CLASS_INIT(&tag[0], "fname");
1.57      kristaps 1662:
                   1663:        /*
                   1664:         * FIXME: only refer to IDs that we know exist.
                   1665:         */
                   1666:
                   1667: #if 0
                   1668:        if (SEC_SYNOPSIS == n->sec) {
                   1669:                nbuf[0] = '\0';
                   1670:                html_idcat(nbuf, sp, BUFSIZ);
                   1671:                PAIR_ID_INIT(&tag[1], nbuf);
                   1672:        } else {
                   1673:                strlcpy(nbuf, "#", BUFSIZ);
                   1674:                html_idcat(nbuf, sp, BUFSIZ);
                   1675:                PAIR_HREF_INIT(&tag[1], nbuf);
                   1676:        }
                   1677: #endif
                   1678:
1.15      kristaps 1679:        t = print_otag(h, TAG_SPAN, 1, tag);
1.7       kristaps 1680:
                   1681:        if (sp) {
1.57      kristaps 1682:                strlcpy(nbuf, sp, BUFSIZ);
1.7       kristaps 1683:                print_text(h, nbuf);
                   1684:        }
                   1685:
1.1       kristaps 1686:        print_tagq(h, t);
                   1687:
                   1688:        h->flags |= HTML_NOSPACE;
                   1689:        print_text(h, "(");
                   1690:
1.23      kristaps 1691:        bufinit(h);
                   1692:        PAIR_CLASS_INIT(&tag[0], "farg");
                   1693:        bufcat_style(h, "white-space", "nowrap");
                   1694:        PAIR_STYLE_INIT(&tag[1], h);
                   1695:
1.1       kristaps 1696:        for (nn = n->child->next; nn; nn = nn->next) {
1.23      kristaps 1697:                i = 1;
                   1698:                if (SEC_SYNOPSIS == n->sec)
                   1699:                        i = 2;
1.15      kristaps 1700:                t = print_otag(h, TAG_SPAN, i, tag);
1.1       kristaps 1701:                print_text(h, nn->string);
                   1702:                print_tagq(h, t);
                   1703:                if (nn->next)
                   1704:                        print_text(h, ",");
                   1705:        }
                   1706:
                   1707:        print_text(h, ")");
                   1708:        if (SEC_SYNOPSIS == n->sec)
                   1709:                print_text(h, ";");
                   1710:
                   1711:        return(0);
                   1712: }
                   1713:
                   1714:
                   1715: /* ARGSUSED */
                   1716: static int
                   1717: mdoc_sp_pre(MDOC_ARGS)
                   1718: {
1.23      kristaps 1719:        int              len;
                   1720:        struct htmlpair  tag;
                   1721:        struct roffsu    su;
1.1       kristaps 1722:
                   1723:        switch (n->tok) {
                   1724:        case (MDOC_sp):
1.23      kristaps 1725:                /* FIXME: can this have a scaling indicator? */
1.1       kristaps 1726:                len = n->child ? atoi(n->child->string) : 1;
                   1727:                break;
                   1728:        case (MDOC_br):
                   1729:                len = 0;
                   1730:                break;
                   1731:        default:
                   1732:                len = 1;
                   1733:                break;
                   1734:        }
                   1735:
1.23      kristaps 1736:        SCALE_VS_INIT(&su, len);
                   1737:        bufcat_su(h, "height", &su);
                   1738:        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1739:        print_otag(h, TAG_DIV, 1, &tag);
1.42      kristaps 1740:        /* So the div isn't empty: */
                   1741:        print_text(h, "\\~");
                   1742:
                   1743:        return(0);
1.1       kristaps 1744:
                   1745: }
1.2       kristaps 1746:
                   1747:
                   1748: /* ARGSUSED */
                   1749: static int
                   1750: mdoc_brq_pre(MDOC_ARGS)
                   1751: {
                   1752:
                   1753:        if (MDOC_BODY != n->type)
                   1754:                return(1);
                   1755:        print_text(h, "\\(lC");
                   1756:        h->flags |= HTML_NOSPACE;
                   1757:        return(1);
                   1758: }
                   1759:
                   1760:
                   1761: /* ARGSUSED */
                   1762: static void
                   1763: mdoc_brq_post(MDOC_ARGS)
                   1764: {
                   1765:
                   1766:        if (MDOC_BODY != n->type)
                   1767:                return;
                   1768:        h->flags |= HTML_NOSPACE;
                   1769:        print_text(h, "\\(rC");
                   1770: }
                   1771:
                   1772:
                   1773: /* ARGSUSED */
                   1774: static int
                   1775: mdoc_lk_pre(MDOC_ARGS)
                   1776: {
                   1777:        const struct mdoc_node  *nn;
                   1778:        struct htmlpair          tag[2];
                   1779:
                   1780:        nn = n->child;
                   1781:
1.23      kristaps 1782:        PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57      kristaps 1783:        PAIR_HREF_INIT(&tag[1], nn->string);
1.2       kristaps 1784:        print_otag(h, TAG_A, 2, tag);
                   1785:
1.38      kristaps 1786:        if (NULL == nn->next)
                   1787:                return(1);
                   1788:
1.2       kristaps 1789:        for (nn = nn->next; nn; nn = nn->next)
                   1790:                print_text(h, nn->string);
                   1791:
                   1792:        return(0);
                   1793: }
                   1794:
                   1795:
                   1796: /* ARGSUSED */
                   1797: static int
                   1798: mdoc_mt_pre(MDOC_ARGS)
                   1799: {
                   1800:        struct htmlpair          tag[2];
                   1801:        struct tag              *t;
                   1802:        const struct mdoc_node  *nn;
                   1803:
1.23      kristaps 1804:        PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2       kristaps 1805:
                   1806:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps 1807:                bufinit(h);
                   1808:                bufcat(h, "mailto:");
                   1809:                bufcat(h, nn->string);
1.57      kristaps 1810:                PAIR_HREF_INIT(&tag[1], h->buf);
1.2       kristaps 1811:                t = print_otag(h, TAG_A, 2, tag);
                   1812:                print_text(h, nn->string);
                   1813:                print_tagq(h, t);
                   1814:        }
                   1815:
                   1816:        return(0);
                   1817: }
1.4       kristaps 1818:
                   1819:
                   1820: /* ARGSUSED */
                   1821: static int
                   1822: mdoc_fo_pre(MDOC_ARGS)
                   1823: {
                   1824:        struct htmlpair tag;
1.57      kristaps 1825:        struct roffsu   su;
1.4       kristaps 1826:
                   1827:        if (MDOC_BODY == n->type) {
                   1828:                h->flags |= HTML_NOSPACE;
                   1829:                print_text(h, "(");
                   1830:                h->flags |= HTML_NOSPACE;
                   1831:                return(1);
1.57      kristaps 1832:        } else if (MDOC_BLOCK == n->type && n->next) {
                   1833:                SCALE_VS_INIT(&su, 1);
                   1834:                bufcat_su(h, "margin-bottom", &su);
                   1835:                PAIR_STYLE_INIT(&tag, h);
                   1836:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps 1837:                return(1);
1.57      kristaps 1838:        }
1.4       kristaps 1839:
1.23      kristaps 1840:        PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1841:        print_otag(h, TAG_SPAN, 1, &tag);
                   1842:        return(1);
                   1843: }
                   1844:
                   1845:
                   1846: /* ARGSUSED */
                   1847: static void
                   1848: mdoc_fo_post(MDOC_ARGS)
                   1849: {
                   1850:        if (MDOC_BODY != n->type)
                   1851:                return;
                   1852:        h->flags |= HTML_NOSPACE;
                   1853:        print_text(h, ")");
                   1854:        h->flags |= HTML_NOSPACE;
                   1855:        print_text(h, ";");
                   1856: }
                   1857:
                   1858:
                   1859: /* ARGSUSED */
                   1860: static int
                   1861: mdoc_in_pre(MDOC_ARGS)
                   1862: {
                   1863:        const struct mdoc_node  *nn;
1.23      kristaps 1864:        struct tag              *t;
1.17      kristaps 1865:        struct htmlpair          tag[2];
                   1866:        int                      i;
1.23      kristaps 1867:        struct roffsu            su;
1.4       kristaps 1868:
                   1869:        if (SEC_SYNOPSIS == n->sec) {
                   1870:                if (n->next && MDOC_In != n->next->tok) {
1.23      kristaps 1871:                        SCALE_VS_INIT(&su, 1);
                   1872:                        bufcat_su(h, "margin-bottom", &su);
                   1873:                        PAIR_STYLE_INIT(&tag[0], h);
1.17      kristaps 1874:                        print_otag(h, TAG_DIV, 1, tag);
1.4       kristaps 1875:                } else
                   1876:                        print_otag(h, TAG_DIV, 0, NULL);
                   1877:        }
                   1878:
1.34      kristaps 1879:        /* FIXME: there's a buffer bug in here somewhere. */
                   1880:
1.23      kristaps 1881:        PAIR_CLASS_INIT(&tag[0], "includes");
1.17      kristaps 1882:        print_otag(h, TAG_SPAN, 1, tag);
1.4       kristaps 1883:
                   1884:        if (SEC_SYNOPSIS == n->sec)
                   1885:                print_text(h, "#include");
                   1886:
                   1887:        print_text(h, "<");
                   1888:        h->flags |= HTML_NOSPACE;
                   1889:
                   1890:        /* XXX -- see warning in termp_in_post(). */
                   1891:
1.17      kristaps 1892:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1893:                PAIR_CLASS_INIT(&tag[0], "link-includes");
                   1894:                i = 1;
1.41      kristaps 1895:                bufinit(h);
1.17      kristaps 1896:                if (h->base_includes) {
                   1897:                        buffmt_includes(h, nn->string);
1.57      kristaps 1898:                        PAIR_HREF_INIT(&tag[i], h->buf);
                   1899:                        i++;
1.17      kristaps 1900:                }
                   1901:                t = print_otag(h, TAG_A, i, tag);
1.4       kristaps 1902:                print_mdoc_node(m, nn, h);
1.17      kristaps 1903:                print_tagq(h, t);
                   1904:        }
1.4       kristaps 1905:
                   1906:        h->flags |= HTML_NOSPACE;
                   1907:        print_text(h, ">");
                   1908:
                   1909:        return(0);
                   1910: }
                   1911:
                   1912:
                   1913: /* ARGSUSED */
                   1914: static int
                   1915: mdoc_ic_pre(MDOC_ARGS)
                   1916: {
                   1917:        struct htmlpair tag;
                   1918:
1.23      kristaps 1919:        PAIR_CLASS_INIT(&tag, "cmd");
1.4       kristaps 1920:        print_otag(h, TAG_SPAN, 1, &tag);
                   1921:        return(1);
                   1922: }
                   1923:
                   1924:
                   1925: /* ARGSUSED */
                   1926: static int
                   1927: mdoc_rv_pre(MDOC_ARGS)
                   1928: {
                   1929:        const struct mdoc_node  *nn;
                   1930:        struct htmlpair          tag;
                   1931:        struct tag              *t;
                   1932:
                   1933:        print_otag(h, TAG_DIV, 0, NULL);
                   1934:        print_text(h, "The");
                   1935:
                   1936:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1937:                PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1938:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1939:                print_text(h, nn->string);
                   1940:                print_tagq(h, t);
                   1941:
                   1942:                h->flags |= HTML_NOSPACE;
                   1943:                if (nn->next && NULL == nn->next->next)
                   1944:                        print_text(h, "(), and");
                   1945:                else if (nn->next)
                   1946:                        print_text(h, "(),");
                   1947:                else
                   1948:                        print_text(h, "()");
                   1949:        }
                   1950:
                   1951:        if (n->child->next)
                   1952:                print_text(h, "functions return");
                   1953:        else
                   1954:                print_text(h, "function returns");
                   1955:
                   1956:                print_text(h, "the value 0 if successful; otherwise the value "
                   1957:                        "-1 is returned and the global variable");
                   1958:
1.23      kristaps 1959:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1960:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1961:        print_text(h, "errno");
                   1962:        print_tagq(h, t);
                   1963:                print_text(h, "is set to indicate the error.");
                   1964:        return(0);
                   1965: }
                   1966:
                   1967:
                   1968: /* ARGSUSED */
                   1969: static int
                   1970: mdoc_va_pre(MDOC_ARGS)
                   1971: {
                   1972:        struct htmlpair tag;
                   1973:
1.23      kristaps 1974:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1975:        print_otag(h, TAG_SPAN, 1, &tag);
                   1976:        return(1);
                   1977: }
                   1978:
                   1979:
                   1980: /* ARGSUSED */
                   1981: static int
                   1982: mdoc_bq_pre(MDOC_ARGS)
                   1983: {
                   1984:
                   1985:        if (MDOC_BODY != n->type)
                   1986:                return(1);
                   1987:        print_text(h, "\\(lB");
                   1988:        h->flags |= HTML_NOSPACE;
                   1989:        return(1);
                   1990: }
                   1991:
                   1992:
                   1993: /* ARGSUSED */
                   1994: static void
                   1995: mdoc_bq_post(MDOC_ARGS)
                   1996: {
                   1997:
                   1998:        if (MDOC_BODY != n->type)
                   1999:                return;
                   2000:        h->flags |= HTML_NOSPACE;
                   2001:        print_text(h, "\\(rB");
                   2002: }
1.5       kristaps 2003:
                   2004:
                   2005: /* ARGSUSED */
                   2006: static int
                   2007: mdoc_ap_pre(MDOC_ARGS)
                   2008: {
                   2009:
                   2010:        h->flags |= HTML_NOSPACE;
                   2011:        print_text(h, "\\(aq");
                   2012:        h->flags |= HTML_NOSPACE;
                   2013:        return(1);
                   2014: }
                   2015:
                   2016:
                   2017: /* ARGSUSED */
                   2018: static int
                   2019: mdoc_bf_pre(MDOC_ARGS)
                   2020: {
1.23      kristaps 2021:        int              i;
                   2022:        struct htmlpair  tag[2];
                   2023:        struct roffsu    su;
1.5       kristaps 2024:
                   2025:        if (MDOC_HEAD == n->type)
                   2026:                return(0);
                   2027:        else if (MDOC_BLOCK != n->type)
                   2028:                return(1);
                   2029:
1.23      kristaps 2030:        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2031:
                   2032:        if (n->head->child) {
                   2033:                if ( ! strcmp("Em", n->head->child->string))
1.23      kristaps 2034:                        PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 2035:                else if ( ! strcmp("Sy", n->head->child->string))
1.23      kristaps 2036:                        PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 2037:                else if ( ! strcmp("Li", n->head->child->string))
1.23      kristaps 2038:                        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2039:        } else {
                   2040:                assert(n->args);
                   2041:                for (i = 0; i < (int)n->args->argc; i++)
                   2042:                        switch (n->args->argv[i].arg) {
                   2043:                        case (MDOC_Symbolic):
1.23      kristaps 2044:                                PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 2045:                                break;
                   2046:                        case (MDOC_Literal):
1.23      kristaps 2047:                                PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2048:                                break;
                   2049:                        case (MDOC_Emphasis):
1.23      kristaps 2050:                                PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 2051:                                break;
                   2052:                        default:
                   2053:                                break;
                   2054:                        }
                   2055:        }
                   2056:
                   2057:        /* FIXME: div's have spaces stripped--we want them. */
                   2058:
1.23      kristaps 2059:        bufcat_style(h, "display", "inline");
                   2060:        SCALE_HS_INIT(&su, 1);
                   2061:        bufcat_su(h, "margin-right", &su);
                   2062:        PAIR_STYLE_INIT(&tag[1], h);
1.5       kristaps 2063:        print_otag(h, TAG_DIV, 2, tag);
                   2064:        return(1);
                   2065: }
                   2066:
                   2067:
                   2068: /* ARGSUSED */
                   2069: static int
                   2070: mdoc_ms_pre(MDOC_ARGS)
                   2071: {
                   2072:        struct htmlpair tag;
                   2073:
1.23      kristaps 2074:        PAIR_CLASS_INIT(&tag, "symb");
1.5       kristaps 2075:        print_otag(h, TAG_SPAN, 1, &tag);
                   2076:        return(1);
                   2077: }
                   2078:
                   2079:
                   2080: /* ARGSUSED */
                   2081: static int
                   2082: mdoc_pf_pre(MDOC_ARGS)
                   2083: {
                   2084:
                   2085:        h->flags |= HTML_IGNDELIM;
                   2086:        return(1);
                   2087: }
                   2088:
                   2089:
                   2090: /* ARGSUSED */
                   2091: static void
                   2092: mdoc_pf_post(MDOC_ARGS)
                   2093: {
                   2094:
                   2095:        h->flags &= ~HTML_IGNDELIM;
                   2096:        h->flags |= HTML_NOSPACE;
                   2097: }
                   2098:
                   2099:
                   2100: /* ARGSUSED */
                   2101: static int
                   2102: mdoc_rs_pre(MDOC_ARGS)
                   2103: {
1.23      kristaps 2104:        struct htmlpair  tag;
                   2105:        struct roffsu    su;
1.5       kristaps 2106:
                   2107:        if (MDOC_BLOCK != n->type)
                   2108:                return(1);
                   2109:
1.8       kristaps 2110:        if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23      kristaps 2111:                SCALE_VS_INIT(&su, 1);
                   2112:                bufcat_su(h, "margin-top", &su);
                   2113:                PAIR_STYLE_INIT(&tag, h);
1.8       kristaps 2114:                print_otag(h, TAG_DIV, 1, &tag);
1.5       kristaps 2115:        }
                   2116:
1.23      kristaps 2117:        PAIR_CLASS_INIT(&tag, "ref");
1.8       kristaps 2118:        print_otag(h, TAG_SPAN, 1, &tag);
1.5       kristaps 2119:        return(1);
                   2120: }
1.6       kristaps 2121:
                   2122:
                   2123:
                   2124: /* ARGSUSED */
                   2125: static int
                   2126: mdoc_li_pre(MDOC_ARGS)
                   2127: {
                   2128:        struct htmlpair tag;
                   2129:
1.23      kristaps 2130:        PAIR_CLASS_INIT(&tag, "lit");
1.6       kristaps 2131:        print_otag(h, TAG_SPAN, 1, &tag);
                   2132:        return(1);
                   2133: }
                   2134:
                   2135:
                   2136: /* ARGSUSED */
                   2137: static int
                   2138: mdoc_sy_pre(MDOC_ARGS)
                   2139: {
                   2140:        struct htmlpair tag;
                   2141:
1.23      kristaps 2142:        PAIR_CLASS_INIT(&tag, "symb");
1.6       kristaps 2143:        print_otag(h, TAG_SPAN, 1, &tag);
                   2144:        return(1);
                   2145: }
                   2146:
                   2147:
                   2148: /* ARGSUSED */
                   2149: static int
                   2150: mdoc_bt_pre(MDOC_ARGS)
                   2151: {
                   2152:
                   2153:        print_text(h, "is currently in beta test.");
                   2154:        return(0);
                   2155: }
                   2156:
                   2157:
                   2158: /* ARGSUSED */
                   2159: static int
                   2160: mdoc_ud_pre(MDOC_ARGS)
                   2161: {
                   2162:
                   2163:        print_text(h, "currently under development.");
                   2164:        return(0);
                   2165: }
                   2166:
                   2167:
                   2168: /* ARGSUSED */
                   2169: static int
                   2170: mdoc_lb_pre(MDOC_ARGS)
                   2171: {
                   2172:        struct htmlpair tag;
                   2173:
                   2174:        if (SEC_SYNOPSIS == n->sec)
                   2175:                print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 2176:        PAIR_CLASS_INIT(&tag, "lib");
1.6       kristaps 2177:        print_otag(h, TAG_SPAN, 1, &tag);
                   2178:        return(1);
                   2179: }
1.10      kristaps 2180:
                   2181:
                   2182: /* ARGSUSED */
                   2183: static int
                   2184: mdoc__x_pre(MDOC_ARGS)
                   2185: {
1.38      kristaps 2186:        struct htmlpair tag[2];
1.37      kristaps 2187:
1.10      kristaps 2188:        switch (n->tok) {
                   2189:        case(MDOC__A):
1.38      kristaps 2190:                PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.10      kristaps 2191:                break;
                   2192:        case(MDOC__B):
1.38      kristaps 2193:                PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10      kristaps 2194:                break;
                   2195:        case(MDOC__C):
1.38      kristaps 2196:                PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10      kristaps 2197:                break;
                   2198:        case(MDOC__D):
1.38      kristaps 2199:                PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10      kristaps 2200:                break;
                   2201:        case(MDOC__I):
1.38      kristaps 2202:                PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10      kristaps 2203:                break;
                   2204:        case(MDOC__J):
1.38      kristaps 2205:                PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10      kristaps 2206:                break;
                   2207:        case(MDOC__N):
1.38      kristaps 2208:                PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10      kristaps 2209:                break;
                   2210:        case(MDOC__O):
1.38      kristaps 2211:                PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10      kristaps 2212:                break;
                   2213:        case(MDOC__P):
1.38      kristaps 2214:                PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10      kristaps 2215:                break;
                   2216:        case(MDOC__Q):
1.38      kristaps 2217:                PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10      kristaps 2218:                break;
                   2219:        case(MDOC__R):
1.38      kristaps 2220:                PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10      kristaps 2221:                break;
                   2222:        case(MDOC__T):
1.38      kristaps 2223:                PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10      kristaps 2224:                print_text(h, "\\(lq");
                   2225:                h->flags |= HTML_NOSPACE;
                   2226:                break;
1.38      kristaps 2227:        case(MDOC__U):
                   2228:                PAIR_CLASS_INIT(&tag[0], "link-ref");
                   2229:                break;
1.10      kristaps 2230:        case(MDOC__V):
1.38      kristaps 2231:                PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10      kristaps 2232:                break;
                   2233:        default:
                   2234:                abort();
                   2235:                /* NOTREACHED */
                   2236:        }
                   2237:
1.38      kristaps 2238:        if (MDOC__U != n->tok) {
                   2239:                print_otag(h, TAG_SPAN, 1, tag);
                   2240:                return(1);
                   2241:        }
                   2242:
                   2243:        PAIR_HREF_INIT(&tag[1], n->child->string);
                   2244:        print_otag(h, TAG_A, 2, tag);
1.10      kristaps 2245:        return(1);
                   2246: }
                   2247:
                   2248:
                   2249: /* ARGSUSED */
                   2250: static void
                   2251: mdoc__x_post(MDOC_ARGS)
                   2252: {
                   2253:
                   2254:        h->flags |= HTML_NOSPACE;
                   2255:        switch (n->tok) {
                   2256:        case (MDOC__T):
                   2257:                print_text(h, "\\(rq");
                   2258:                h->flags |= HTML_NOSPACE;
                   2259:                break;
                   2260:        default:
                   2261:                break;
                   2262:        }
                   2263:        print_text(h, n->next ? "," : ".");
                   2264: }

CVSweb