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

Annotation of mandoc/mdoc_html.c, Revision 1.42

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

CVSweb