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

Annotation of mandoc/mdoc_html.c, Revision 1.51

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

CVSweb