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

Annotation of mandoc/mdoc_html.c, Revision 1.41

1.41    ! kristaps    1: /*     $Id: mdoc_html.c,v 1.40 2009/10/27 04:50:15 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.41    ! kristaps  586:        html_idcpy(buf, "id_", BUFSIZ);
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.41    ! 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.41    ! kristaps  639:        html_idcpy(buf, "id_", BUFSIZ);
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.41    ! 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):
                    957:                print_otag(h, TAG_DIV, 0, NULL);
                    958:                break;
                    959:        case (MDOC_Column):
1.23      kristaps  960:                bufcat_su(h, "min-width", width);
                    961:                bufcat_style(h, "clear", "none");
1.1       kristaps  962:                if (n->next && MDOC_HEAD == n->next->type)
1.23      kristaps  963:                        bufcat_style(h, "float", "left");
                    964:                PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  965:                print_otag(h, TAG_DIV, 1, &tag);
                    966:                break;
                    967:        default:
1.23      kristaps  968:                bufcat_su(h, "min-width", width);
                    969:                SCALE_INVERT(width);
                    970:                bufcat_su(h, "margin-left", width);
1.2       kristaps  971:                if (n->next && n->next->child)
1.23      kristaps  972:                        bufcat_style(h, "float", "left");
1.24      kristaps  973:
                    974:                /* XXX: buffer if we run into body. */
1.23      kristaps  975:                SCALE_HS_INIT(width, 1);
                    976:                bufcat_su(h, "margin-right", width);
                    977:                PAIR_STYLE_INIT(&tag, h);
1.1       kristaps  978:                print_otag(h, TAG_DIV, 1, &tag);
                    979:                break;
                    980:        }
                    981:
1.23      kristaps  982:        switch (type) {
1.1       kristaps  983:        case (MDOC_Diag):
1.23      kristaps  984:                PAIR_CLASS_INIT(&tag, "diag");
1.1       kristaps  985:                print_otag(h, TAG_SPAN, 1, &tag);
                    986:                break;
                    987:        case (MDOC_Enum):
1.39      kristaps  988:                ord = h->ords.head;
1.1       kristaps  989:                assert(ord);
                    990:                nbuf[BUFSIZ - 1] = 0;
                    991:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    992:                print_text(h, nbuf);
                    993:                return(0);
                    994:        case (MDOC_Dash):
                    995:                print_text(h, "\\(en");
                    996:                return(0);
                    997:        case (MDOC_Hyphen):
1.4       kristaps  998:                print_text(h, "\\(hy");
1.1       kristaps  999:                return(0);
                   1000:        case (MDOC_Bullet):
                   1001:                print_text(h, "\\(bu");
                   1002:                return(0);
                   1003:        default:
                   1004:                break;
                   1005:        }
                   1006:
                   1007:        return(1);
                   1008: }
                   1009:
                   1010:
                   1011: static int
1.23      kristaps 1012: mdoc_it_pre(MDOC_ARGS)
1.1       kristaps 1013: {
1.23      kristaps 1014:        int                      i, type, wp, comp;
1.1       kristaps 1015:        const struct mdoc_node  *bl, *nn;
1.23      kristaps 1016:        struct roffsu            width, offs;
                   1017:
1.24      kristaps 1018:        /*
                   1019:         * XXX: be very careful in changing anything, here.  Lists in
                   1020:         * mandoc have many peculiarities; furthermore, they don't
                   1021:         * translate well into HTML and require a bit of mangling.
                   1022:         */
1.1       kristaps 1023:
                   1024:        bl = n->parent->parent;
1.23      kristaps 1025:        if (MDOC_BLOCK != n->type)
1.1       kristaps 1026:                bl = bl->parent;
                   1027:
1.23      kristaps 1028:        type = a2list(bl);
1.1       kristaps 1029:
1.23      kristaps 1030:        /* Set default width and offset. */
1.1       kristaps 1031:
1.24      kristaps 1032:        SCALE_HS_INIT(&offs, 0);
                   1033:
1.1       kristaps 1034:        switch (type) {
                   1035:        case (MDOC_Enum):
                   1036:                /* FALLTHROUGH */
                   1037:        case (MDOC_Dash):
                   1038:                /* FALLTHROUGH */
                   1039:        case (MDOC_Hyphen):
                   1040:                /* FALLTHROUGH */
                   1041:        case (MDOC_Bullet):
1.23      kristaps 1042:                SCALE_HS_INIT(&width, 2);
1.1       kristaps 1043:                break;
1.23      kristaps 1044:        default:
                   1045:                SCALE_HS_INIT(&width, INDENT);
                   1046:                break;
                   1047:        }
                   1048:
                   1049:        /* Get width, offset, and compact arguments. */
                   1050:
                   1051:        for (wp = -1, comp = i = 0; i < (int)bl->args->argc; i++)
                   1052:                switch (bl->args->argv[i].arg) {
1.24      kristaps 1053:                case (MDOC_Column):
                   1054:                        wp = i; /* Save for later. */
                   1055:                        break;
1.23      kristaps 1056:                case (MDOC_Width):
                   1057:                        a2width(bl->args->argv[i].value[0], &width);
                   1058:                        break;
                   1059:                case (MDOC_Offset):
                   1060:                        a2offs(bl->args->argv[i].value[0], &offs);
                   1061:                        break;
                   1062:                case (MDOC_Compact):
                   1063:                        comp = 1;
                   1064:                        break;
                   1065:                default:
                   1066:                        break;
                   1067:                }
                   1068:
                   1069:        /* Override width in some cases. */
                   1070:
                   1071:        switch (type) {
1.33      kristaps 1072:        case (MDOC_Item):
                   1073:                /* FALLTHROUGH */
1.1       kristaps 1074:        case (MDOC_Inset):
                   1075:                /* FALLTHROUGH */
                   1076:        case (MDOC_Diag):
1.23      kristaps 1077:                SCALE_HS_INIT(&width, 0);
1.1       kristaps 1078:                break;
                   1079:        default:
1.23      kristaps 1080:                if (0 == width.scale)
                   1081:                        SCALE_HS_INIT(&width, INDENT);
1.1       kristaps 1082:                break;
                   1083:        }
                   1084:
1.23      kristaps 1085:        /* Flip to body/block processing. */
                   1086:
                   1087:        if (MDOC_BODY == n->type)
                   1088:                return(mdoc_it_body_pre(m, n, h, type));
                   1089:        if (MDOC_BLOCK == n->type)
1.27      kristaps 1090:                return(mdoc_it_block_pre(m, n, h, type, comp,
                   1091:                                        &offs, &width));
1.23      kristaps 1092:
                   1093:        /* Override column widths. */
                   1094:
                   1095:        if (MDOC_Column == type) {
                   1096:                nn = n->parent->child;
                   1097:                for (i = 0; nn && nn != n; nn = nn->next, i++)
                   1098:                        /* Counter... */ ;
1.24      kristaps 1099:                if (i < (int)bl->args->argv[wp].sz)
1.23      kristaps 1100:                        a2width(bl->args->argv[wp].value[i], &width);
1.1       kristaps 1101:        }
                   1102:
1.23      kristaps 1103:        return(mdoc_it_head_pre(m, n, h, type, &width));
1.1       kristaps 1104: }
                   1105:
                   1106:
                   1107: /* ARGSUSED */
                   1108: static int
                   1109: mdoc_bl_pre(MDOC_ARGS)
                   1110: {
                   1111:        struct ord      *ord;
                   1112:
                   1113:        if (MDOC_BLOCK != n->type)
                   1114:                return(1);
                   1115:        if (MDOC_Enum != a2list(n))
                   1116:                return(1);
                   1117:
                   1118:        ord = malloc(sizeof(struct ord));
                   1119:        if (NULL == ord)
                   1120:                err(EXIT_FAILURE, "malloc");
                   1121:        ord->cookie = n;
                   1122:        ord->pos = 1;
1.39      kristaps 1123:        ord->next = h->ords.head;
                   1124:        h->ords.head = ord;
1.1       kristaps 1125:        return(1);
                   1126: }
                   1127:
                   1128:
                   1129: /* ARGSUSED */
                   1130: static void
                   1131: mdoc_bl_post(MDOC_ARGS)
                   1132: {
                   1133:        struct ord      *ord;
                   1134:
                   1135:        if (MDOC_BLOCK != n->type)
                   1136:                return;
                   1137:        if (MDOC_Enum != a2list(n))
                   1138:                return;
                   1139:
1.39      kristaps 1140:        ord = h->ords.head;
1.1       kristaps 1141:        assert(ord);
1.39      kristaps 1142:        h->ords.head = ord->next;
1.1       kristaps 1143:        free(ord);
                   1144: }
                   1145:
                   1146:
                   1147: /* ARGSUSED */
                   1148: static int
                   1149: mdoc_ex_pre(MDOC_ARGS)
                   1150: {
                   1151:        const struct mdoc_node  *nn;
                   1152:        struct tag              *t;
                   1153:        struct htmlpair          tag;
                   1154:
1.23      kristaps 1155:        PAIR_CLASS_INIT(&tag, "utility");
                   1156:
1.1       kristaps 1157:        print_text(h, "The");
                   1158:        for (nn = n->child; nn; nn = nn->next) {
                   1159:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1160:                print_text(h, nn->string);
                   1161:                print_tagq(h, t);
                   1162:
                   1163:                h->flags |= HTML_NOSPACE;
                   1164:
                   1165:                if (nn->next && NULL == nn->next->next)
                   1166:                        print_text(h, ", and");
                   1167:                else if (nn->next)
                   1168:                        print_text(h, ",");
                   1169:                else
                   1170:                        h->flags &= ~HTML_NOSPACE;
                   1171:        }
                   1172:
                   1173:        if (n->child->next)
                   1174:                print_text(h, "utilities exit");
                   1175:        else
                   1176:                print_text(h, "utility exits");
                   1177:
                   1178:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1179:        return(0);
                   1180: }
                   1181:
                   1182:
                   1183: /* ARGSUSED */
                   1184: static int
                   1185: mdoc_dq_pre(MDOC_ARGS)
                   1186: {
                   1187:
                   1188:        if (MDOC_BODY != n->type)
                   1189:                return(1);
                   1190:        print_text(h, "\\(lq");
                   1191:        h->flags |= HTML_NOSPACE;
                   1192:        return(1);
                   1193: }
                   1194:
                   1195:
                   1196: /* ARGSUSED */
                   1197: static void
                   1198: mdoc_dq_post(MDOC_ARGS)
                   1199: {
                   1200:
                   1201:        if (MDOC_BODY != n->type)
                   1202:                return;
                   1203:        h->flags |= HTML_NOSPACE;
                   1204:        print_text(h, "\\(rq");
                   1205: }
                   1206:
                   1207:
                   1208: /* ARGSUSED */
                   1209: static int
                   1210: mdoc_pq_pre(MDOC_ARGS)
                   1211: {
                   1212:
                   1213:        if (MDOC_BODY != n->type)
                   1214:                return(1);
                   1215:        print_text(h, "\\&(");
                   1216:        h->flags |= HTML_NOSPACE;
                   1217:        return(1);
                   1218: }
                   1219:
                   1220:
                   1221: /* ARGSUSED */
                   1222: static void
                   1223: mdoc_pq_post(MDOC_ARGS)
                   1224: {
                   1225:
                   1226:        if (MDOC_BODY != n->type)
                   1227:                return;
                   1228:        print_text(h, ")");
                   1229: }
                   1230:
                   1231:
                   1232: /* ARGSUSED */
                   1233: static int
                   1234: mdoc_sq_pre(MDOC_ARGS)
                   1235: {
                   1236:
                   1237:        if (MDOC_BODY != n->type)
                   1238:                return(1);
                   1239:        print_text(h, "\\(oq");
                   1240:        h->flags |= HTML_NOSPACE;
                   1241:        return(1);
                   1242: }
                   1243:
                   1244:
                   1245: /* ARGSUSED */
                   1246: static void
                   1247: mdoc_sq_post(MDOC_ARGS)
                   1248: {
                   1249:
                   1250:        if (MDOC_BODY != n->type)
                   1251:                return;
                   1252:        h->flags |= HTML_NOSPACE;
                   1253:        print_text(h, "\\(aq");
                   1254: }
                   1255:
                   1256:
                   1257: /* ARGSUSED */
                   1258: static int
                   1259: mdoc_em_pre(MDOC_ARGS)
                   1260: {
                   1261:        struct htmlpair tag;
                   1262:
1.23      kristaps 1263:        PAIR_CLASS_INIT(&tag, "emph");
1.1       kristaps 1264:        print_otag(h, TAG_SPAN, 1, &tag);
                   1265:        return(1);
                   1266: }
                   1267:
                   1268:
                   1269: /* ARGSUSED */
                   1270: static int
                   1271: mdoc_d1_pre(MDOC_ARGS)
                   1272: {
1.23      kristaps 1273:        struct htmlpair  tag[2];
                   1274:        struct roffsu    su;
1.1       kristaps 1275:
                   1276:        if (MDOC_BLOCK != n->type)
                   1277:                return(1);
                   1278:
1.35      kristaps 1279:        /* FIXME: D1 shouldn't be literal. */
                   1280:
1.23      kristaps 1281:        SCALE_VS_INIT(&su, INDENT - 2);
                   1282:        bufcat_su(h, "margin-left", &su);
                   1283:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1284:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1285:        print_otag(h, TAG_DIV, 2, tag);
                   1286:        return(1);
                   1287: }
                   1288:
                   1289:
                   1290: /* ARGSUSED */
                   1291: static int
                   1292: mdoc_sx_pre(MDOC_ARGS)
                   1293: {
1.18      kristaps 1294:        struct htmlpair          tag[2];
1.1       kristaps 1295:        const struct mdoc_node  *nn;
1.35      kristaps 1296:        char                     buf[BUFSIZ];
1.1       kristaps 1297:
1.23      kristaps 1298:        /* FIXME: duplicates? */
                   1299:
1.41    ! kristaps 1300:        strlcpy(buf, "#", BUFSIZ);
        !          1301:        html_idcat(buf, "id_", BUFSIZ);
1.1       kristaps 1302:        for (nn = n->child; nn; nn = nn->next) {
1.41    ! kristaps 1303:                html_idcat(buf, nn->string, BUFSIZ);
1.1       kristaps 1304:                if (nn->next)
1.41    ! kristaps 1305:                        html_idcat(buf, "_", BUFSIZ);
1.1       kristaps 1306:        }
                   1307:
1.23      kristaps 1308:        PAIR_CLASS_INIT(&tag[0], "link-sec");
1.21      kristaps 1309:        tag[1].key = ATTR_HREF;
1.35      kristaps 1310:        tag[1].val = buf;
1.1       kristaps 1311:
1.18      kristaps 1312:        print_otag(h, TAG_A, 2, tag);
1.1       kristaps 1313:        return(1);
                   1314: }
                   1315:
                   1316:
                   1317: /* ARGSUSED */
                   1318: static int
                   1319: mdoc_aq_pre(MDOC_ARGS)
                   1320: {
                   1321:
                   1322:        if (MDOC_BODY != n->type)
                   1323:                return(1);
                   1324:        print_text(h, "\\(la");
                   1325:        h->flags |= HTML_NOSPACE;
                   1326:        return(1);
                   1327: }
                   1328:
                   1329:
                   1330: /* ARGSUSED */
                   1331: static void
                   1332: mdoc_aq_post(MDOC_ARGS)
                   1333: {
                   1334:
                   1335:        if (MDOC_BODY != n->type)
                   1336:                return;
                   1337:        h->flags |= HTML_NOSPACE;
                   1338:        print_text(h, "\\(ra");
                   1339: }
                   1340:
                   1341:
                   1342: /* ARGSUSED */
                   1343: static int
                   1344: mdoc_bd_pre(MDOC_ARGS)
                   1345: {
                   1346:        struct htmlpair          tag[2];
1.23      kristaps 1347:        int                      type, comp, i;
1.14      kristaps 1348:        const struct mdoc_node  *bl, *nn;
1.23      kristaps 1349:        struct roffsu            su;
1.1       kristaps 1350:
                   1351:        if (MDOC_BLOCK == n->type)
                   1352:                bl = n;
                   1353:        else if (MDOC_HEAD == n->type)
                   1354:                return(0);
                   1355:        else
                   1356:                bl = n->parent;
                   1357:
1.24      kristaps 1358:        SCALE_VS_INIT(&su, 0);
                   1359:
1.23      kristaps 1360:        type = comp = 0;
1.1       kristaps 1361:        for (i = 0; i < (int)bl->args->argc; i++)
                   1362:                switch (bl->args->argv[i].arg) {
                   1363:                case (MDOC_Offset):
1.23      kristaps 1364:                        a2offs(bl->args->argv[i].value[0], &su);
1.1       kristaps 1365:                        break;
                   1366:                case (MDOC_Compact):
1.23      kristaps 1367:                        comp = 1;
1.1       kristaps 1368:                        break;
1.30      kristaps 1369:                case (MDOC_Centred):
                   1370:                        /* FALLTHROUGH */
1.1       kristaps 1371:                case (MDOC_Ragged):
                   1372:                        /* FALLTHROUGH */
                   1373:                case (MDOC_Filled):
                   1374:                        /* FALLTHROUGH */
                   1375:                case (MDOC_Unfilled):
                   1376:                        /* FALLTHROUGH */
                   1377:                case (MDOC_Literal):
1.23      kristaps 1378:                        type = bl->args->argv[i].arg;
1.1       kristaps 1379:                        break;
1.30      kristaps 1380:                default:
                   1381:                        break;
1.1       kristaps 1382:                }
                   1383:
1.31      kristaps 1384:        /* FIXME: -centered, etc. formatting. */
                   1385:
1.1       kristaps 1386:        if (MDOC_BLOCK == n->type) {
1.24      kristaps 1387:                bufcat_su(h, "margin-left", &su);
1.23      kristaps 1388:                for (nn = n; nn && ! comp; nn = nn->parent) {
                   1389:                        if (MDOC_BLOCK != nn->type)
                   1390:                                continue;
                   1391:                        if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                   1392:                                comp = 1;
                   1393:                        if (nn->prev)
                   1394:                                break;
                   1395:                }
                   1396:                if (comp) {
                   1397:                        print_otag(h, TAG_DIV, 0, tag);
                   1398:                        return(1);
1.14      kristaps 1399:                }
1.23      kristaps 1400:                SCALE_VS_INIT(&su, 1);
                   1401:                bufcat_su(h, "margin-top", &su);
                   1402:                PAIR_STYLE_INIT(&tag[0], h);
1.1       kristaps 1403:                print_otag(h, TAG_DIV, 1, tag);
                   1404:                return(1);
                   1405:        }
                   1406:
1.23      kristaps 1407:        if (MDOC_Unfilled != type && MDOC_Literal != type)
1.1       kristaps 1408:                return(1);
                   1409:
1.23      kristaps 1410:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1411:        bufcat_style(h, "white-space", "pre");
                   1412:        PAIR_STYLE_INIT(&tag[1], h);
1.1       kristaps 1413:        print_otag(h, TAG_DIV, 2, tag);
                   1414:
1.14      kristaps 1415:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1416:                h->flags |= HTML_NOSPACE;
1.14      kristaps 1417:                print_mdoc_node(m, nn, h);
                   1418:                if (NULL == nn->next)
                   1419:                        continue;
                   1420:                if (nn->prev && nn->prev->line < nn->line)
1.1       kristaps 1421:                        print_text(h, "\n");
1.23      kristaps 1422:                else if (NULL == nn->prev)
                   1423:                        print_text(h, "\n");
1.1       kristaps 1424:        }
                   1425:
                   1426:        return(0);
                   1427: }
                   1428:
                   1429:
                   1430: /* ARGSUSED */
                   1431: static int
                   1432: mdoc_pa_pre(MDOC_ARGS)
                   1433: {
                   1434:        struct htmlpair tag;
                   1435:
1.23      kristaps 1436:        PAIR_CLASS_INIT(&tag, "file");
1.1       kristaps 1437:        print_otag(h, TAG_SPAN, 1, &tag);
                   1438:        return(1);
                   1439: }
                   1440:
                   1441:
                   1442: /* ARGSUSED */
                   1443: static int
                   1444: mdoc_ad_pre(MDOC_ARGS)
                   1445: {
                   1446:        struct htmlpair tag;
                   1447:
1.23      kristaps 1448:        PAIR_CLASS_INIT(&tag, "addr");
1.1       kristaps 1449:        print_otag(h, TAG_SPAN, 1, &tag);
                   1450:        return(1);
                   1451: }
                   1452:
                   1453:
                   1454: /* ARGSUSED */
                   1455: static int
                   1456: mdoc_an_pre(MDOC_ARGS)
                   1457: {
                   1458:        struct htmlpair tag;
                   1459:
1.19      kristaps 1460:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1461:
1.23      kristaps 1462:        PAIR_CLASS_INIT(&tag, "author");
1.1       kristaps 1463:        print_otag(h, TAG_SPAN, 1, &tag);
                   1464:        return(1);
                   1465: }
                   1466:
                   1467:
                   1468: /* ARGSUSED */
                   1469: static int
                   1470: mdoc_cd_pre(MDOC_ARGS)
                   1471: {
                   1472:        struct htmlpair tag;
                   1473:
1.28      kristaps 1474:        print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 1475:        PAIR_CLASS_INIT(&tag, "config");
1.1       kristaps 1476:        print_otag(h, TAG_SPAN, 1, &tag);
                   1477:        return(1);
                   1478: }
                   1479:
                   1480:
                   1481: /* ARGSUSED */
                   1482: static int
                   1483: mdoc_dv_pre(MDOC_ARGS)
                   1484: {
                   1485:        struct htmlpair tag;
                   1486:
1.23      kristaps 1487:        PAIR_CLASS_INIT(&tag, "define");
1.1       kristaps 1488:        print_otag(h, TAG_SPAN, 1, &tag);
                   1489:        return(1);
                   1490: }
                   1491:
                   1492:
                   1493: /* ARGSUSED */
                   1494: static int
                   1495: mdoc_ev_pre(MDOC_ARGS)
                   1496: {
                   1497:        struct htmlpair tag;
                   1498:
1.23      kristaps 1499:        PAIR_CLASS_INIT(&tag, "env");
1.1       kristaps 1500:        print_otag(h, TAG_SPAN, 1, &tag);
                   1501:        return(1);
                   1502: }
                   1503:
                   1504:
                   1505: /* ARGSUSED */
                   1506: static int
                   1507: mdoc_er_pre(MDOC_ARGS)
                   1508: {
                   1509:        struct htmlpair tag;
                   1510:
1.23      kristaps 1511:        PAIR_CLASS_INIT(&tag, "errno");
1.1       kristaps 1512:        print_otag(h, TAG_SPAN, 1, &tag);
                   1513:        return(1);
                   1514: }
                   1515:
                   1516:
                   1517: /* ARGSUSED */
                   1518: static int
                   1519: mdoc_fa_pre(MDOC_ARGS)
                   1520: {
                   1521:        const struct mdoc_node  *nn;
                   1522:        struct htmlpair          tag;
                   1523:        struct tag              *t;
                   1524:
1.23      kristaps 1525:        PAIR_CLASS_INIT(&tag, "farg");
1.1       kristaps 1526:        if (n->parent->tok != MDOC_Fo) {
                   1527:                print_otag(h, TAG_SPAN, 1, &tag);
                   1528:                return(1);
                   1529:        }
                   1530:
                   1531:        for (nn = n->child; nn; nn = nn->next) {
                   1532:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1533:                print_text(h, nn->string);
                   1534:                print_tagq(h, t);
                   1535:                if (nn->next)
                   1536:                        print_text(h, ",");
                   1537:        }
                   1538:
                   1539:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1540:                print_text(h, ",");
                   1541:
                   1542:        return(0);
                   1543: }
                   1544:
                   1545:
                   1546: /* ARGSUSED */
                   1547: static int
                   1548: mdoc_fd_pre(MDOC_ARGS)
                   1549: {
1.23      kristaps 1550:        struct htmlpair  tag;
                   1551:        struct roffsu    su;
1.1       kristaps 1552:
                   1553:        if (SEC_SYNOPSIS == n->sec) {
                   1554:                if (n->next && MDOC_Fd != n->next->tok) {
1.23      kristaps 1555:                        SCALE_VS_INIT(&su, 1);
                   1556:                        bufcat_su(h, "margin-bottom", &su);
                   1557:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1558:                        print_otag(h, TAG_DIV, 1, &tag);
                   1559:                } else
                   1560:                        print_otag(h, TAG_DIV, 0, NULL);
                   1561:        }
                   1562:
1.23      kristaps 1563:        PAIR_CLASS_INIT(&tag, "macro");
1.1       kristaps 1564:        print_otag(h, TAG_SPAN, 1, &tag);
                   1565:        return(1);
                   1566: }
                   1567:
                   1568:
                   1569: /* ARGSUSED */
                   1570: static int
                   1571: mdoc_vt_pre(MDOC_ARGS)
                   1572: {
1.23      kristaps 1573:        struct htmlpair  tag;
                   1574:        struct roffsu    su;
1.1       kristaps 1575:
                   1576:        if (SEC_SYNOPSIS == n->sec) {
                   1577:                if (n->next && MDOC_Vt != n->next->tok) {
1.23      kristaps 1578:                        SCALE_VS_INIT(&su, 1);
                   1579:                        bufcat_su(h, "margin-bottom", &su);
                   1580:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1581:                        print_otag(h, TAG_DIV, 1, &tag);
                   1582:                } else
                   1583:                        print_otag(h, TAG_DIV, 0, NULL);
                   1584:        }
                   1585:
1.23      kristaps 1586:        PAIR_CLASS_INIT(&tag, "type");
1.1       kristaps 1587:        print_otag(h, TAG_SPAN, 1, &tag);
                   1588:        return(1);
                   1589: }
                   1590:
1.2       kristaps 1591:
1.1       kristaps 1592: /* ARGSUSED */
                   1593: static int
                   1594: mdoc_ft_pre(MDOC_ARGS)
                   1595: {
1.23      kristaps 1596:        struct htmlpair  tag;
                   1597:        struct roffsu    su;
1.1       kristaps 1598:
                   1599:        if (SEC_SYNOPSIS == n->sec) {
                   1600:                if (n->prev && MDOC_Fo == n->prev->tok) {
1.23      kristaps 1601:                        SCALE_VS_INIT(&su, 1);
                   1602:                        bufcat_su(h, "margin-top", &su);
                   1603:                        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1604:                        print_otag(h, TAG_DIV, 1, &tag);
                   1605:                } else
                   1606:                        print_otag(h, TAG_DIV, 0, NULL);
                   1607:        }
                   1608:
1.23      kristaps 1609:        PAIR_CLASS_INIT(&tag, "ftype");
1.1       kristaps 1610:        print_otag(h, TAG_SPAN, 1, &tag);
                   1611:        return(1);
                   1612: }
                   1613:
                   1614:
                   1615: /* ARGSUSED */
                   1616: static int
                   1617: mdoc_fn_pre(MDOC_ARGS)
                   1618: {
                   1619:        struct tag              *t;
1.15      kristaps 1620:        struct htmlpair          tag[2];
1.1       kristaps 1621:        const struct mdoc_node  *nn;
1.7       kristaps 1622:        char                     nbuf[BUFSIZ];
                   1623:        const char              *sp, *ep;
1.15      kristaps 1624:        int                      sz, i;
1.23      kristaps 1625:        struct roffsu            su;
1.1       kristaps 1626:
                   1627:        if (SEC_SYNOPSIS == n->sec) {
1.23      kristaps 1628:                SCALE_HS_INIT(&su, INDENT);
                   1629:                bufcat_su(h, "margin-left", &su);
                   1630:                su.scale = -su.scale;
                   1631:                bufcat_su(h, "text-indent", &su);
                   1632:                if (n->next) {
                   1633:                        SCALE_VS_INIT(&su, 1);
                   1634:                        bufcat_su(h, "margin-bottom", &su);
                   1635:                }
                   1636:                PAIR_STYLE_INIT(&tag[0], h);
1.15      kristaps 1637:                print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps 1638:        }
                   1639:
1.7       kristaps 1640:        /* Split apart into type and name. */
                   1641:        assert(n->child->string);
                   1642:        sp = n->child->string;
1.19      kristaps 1643:
1.26      kristaps 1644:        ep = strchr(sp, ' ');
                   1645:        if (NULL != ep) {
1.23      kristaps 1646:                PAIR_CLASS_INIT(&tag[0], "ftype");
1.19      kristaps 1647:                t = print_otag(h, TAG_SPAN, 1, tag);
                   1648:
                   1649:                while (ep) {
                   1650:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1651:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1652:                        nbuf[sz] = '\0';
                   1653:                        print_text(h, nbuf);
                   1654:                        sp = ++ep;
                   1655:                        ep = strchr(sp, ' ');
                   1656:                }
                   1657:                print_tagq(h, t);
1.7       kristaps 1658:        }
1.1       kristaps 1659:
1.23      kristaps 1660:        PAIR_CLASS_INIT(&tag[0], "fname");
1.15      kristaps 1661:        t = print_otag(h, TAG_SPAN, 1, tag);
1.7       kristaps 1662:
                   1663:        if (sp) {
                   1664:                (void)strlcpy(nbuf, sp, BUFSIZ);
                   1665:                print_text(h, nbuf);
                   1666:        }
                   1667:
1.1       kristaps 1668:        print_tagq(h, t);
                   1669:
                   1670:        h->flags |= HTML_NOSPACE;
                   1671:        print_text(h, "(");
                   1672:
1.23      kristaps 1673:        bufinit(h);
                   1674:        PAIR_CLASS_INIT(&tag[0], "farg");
                   1675:        bufcat_style(h, "white-space", "nowrap");
                   1676:        PAIR_STYLE_INIT(&tag[1], h);
                   1677:
1.1       kristaps 1678:        for (nn = n->child->next; nn; nn = nn->next) {
1.23      kristaps 1679:                i = 1;
                   1680:                if (SEC_SYNOPSIS == n->sec)
                   1681:                        i = 2;
1.15      kristaps 1682:                t = print_otag(h, TAG_SPAN, i, tag);
1.1       kristaps 1683:                print_text(h, nn->string);
                   1684:                print_tagq(h, t);
                   1685:                if (nn->next)
                   1686:                        print_text(h, ",");
                   1687:        }
                   1688:
                   1689:        print_text(h, ")");
                   1690:        if (SEC_SYNOPSIS == n->sec)
                   1691:                print_text(h, ";");
                   1692:
                   1693:        return(0);
                   1694: }
                   1695:
                   1696:
                   1697: /* ARGSUSED */
                   1698: static int
                   1699: mdoc_sp_pre(MDOC_ARGS)
                   1700: {
1.23      kristaps 1701:        int              len;
                   1702:        struct htmlpair  tag;
                   1703:        struct roffsu    su;
1.1       kristaps 1704:
                   1705:        switch (n->tok) {
                   1706:        case (MDOC_sp):
1.23      kristaps 1707:                /* FIXME: can this have a scaling indicator? */
1.1       kristaps 1708:                len = n->child ? atoi(n->child->string) : 1;
                   1709:                break;
                   1710:        case (MDOC_br):
                   1711:                len = 0;
                   1712:                break;
                   1713:        default:
                   1714:                len = 1;
                   1715:                break;
                   1716:        }
                   1717:
1.23      kristaps 1718:        SCALE_VS_INIT(&su, len);
                   1719:        bufcat_su(h, "height", &su);
                   1720:        PAIR_STYLE_INIT(&tag, h);
1.1       kristaps 1721:        print_otag(h, TAG_DIV, 1, &tag);
                   1722:        return(1);
                   1723:
                   1724: }
1.2       kristaps 1725:
                   1726:
                   1727: /* ARGSUSED */
                   1728: static int
                   1729: mdoc_brq_pre(MDOC_ARGS)
                   1730: {
                   1731:
                   1732:        if (MDOC_BODY != n->type)
                   1733:                return(1);
                   1734:        print_text(h, "\\(lC");
                   1735:        h->flags |= HTML_NOSPACE;
                   1736:        return(1);
                   1737: }
                   1738:
                   1739:
                   1740: /* ARGSUSED */
                   1741: static void
                   1742: mdoc_brq_post(MDOC_ARGS)
                   1743: {
                   1744:
                   1745:        if (MDOC_BODY != n->type)
                   1746:                return;
                   1747:        h->flags |= HTML_NOSPACE;
                   1748:        print_text(h, "\\(rC");
                   1749: }
                   1750:
                   1751:
                   1752: /* ARGSUSED */
                   1753: static int
                   1754: mdoc_lk_pre(MDOC_ARGS)
                   1755: {
                   1756:        const struct mdoc_node  *nn;
                   1757:        struct htmlpair          tag[2];
                   1758:
                   1759:        nn = n->child;
                   1760:
1.23      kristaps 1761:        PAIR_CLASS_INIT(&tag[0], "link-ext");
1.2       kristaps 1762:        tag[1].key = ATTR_HREF;
                   1763:        tag[1].val = nn->string;
                   1764:        print_otag(h, TAG_A, 2, tag);
                   1765:
1.38      kristaps 1766:        if (NULL == nn->next)
                   1767:                return(1);
                   1768:
1.2       kristaps 1769:        for (nn = nn->next; nn; nn = nn->next)
                   1770:                print_text(h, nn->string);
                   1771:
                   1772:        return(0);
                   1773: }
                   1774:
                   1775:
                   1776: /* ARGSUSED */
                   1777: static int
                   1778: mdoc_mt_pre(MDOC_ARGS)
                   1779: {
                   1780:        struct htmlpair          tag[2];
                   1781:        struct tag              *t;
                   1782:        const struct mdoc_node  *nn;
                   1783:
1.23      kristaps 1784:        PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2       kristaps 1785:
                   1786:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps 1787:                bufinit(h);
                   1788:                bufcat(h, "mailto:");
                   1789:                bufcat(h, nn->string);
1.23      kristaps 1790:                PAIR_STYLE_INIT(&tag[1], h);
1.2       kristaps 1791:                t = print_otag(h, TAG_A, 2, tag);
                   1792:                print_text(h, nn->string);
                   1793:                print_tagq(h, t);
                   1794:        }
                   1795:
                   1796:        return(0);
                   1797: }
1.4       kristaps 1798:
                   1799:
                   1800: /* ARGSUSED */
                   1801: static int
                   1802: mdoc_fo_pre(MDOC_ARGS)
                   1803: {
                   1804:        struct htmlpair tag;
                   1805:
                   1806:        if (MDOC_BODY == n->type) {
                   1807:                h->flags |= HTML_NOSPACE;
                   1808:                print_text(h, "(");
                   1809:                h->flags |= HTML_NOSPACE;
                   1810:                return(1);
                   1811:        } else if (MDOC_BLOCK == n->type)
                   1812:                return(1);
                   1813:
1.23      kristaps 1814:        PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1815:        print_otag(h, TAG_SPAN, 1, &tag);
                   1816:        return(1);
                   1817: }
                   1818:
                   1819:
                   1820: /* ARGSUSED */
                   1821: static void
                   1822: mdoc_fo_post(MDOC_ARGS)
                   1823: {
                   1824:        if (MDOC_BODY != n->type)
                   1825:                return;
                   1826:        h->flags |= HTML_NOSPACE;
                   1827:        print_text(h, ")");
                   1828:        h->flags |= HTML_NOSPACE;
                   1829:        print_text(h, ";");
                   1830: }
                   1831:
                   1832:
                   1833: /* ARGSUSED */
                   1834: static int
                   1835: mdoc_in_pre(MDOC_ARGS)
                   1836: {
                   1837:        const struct mdoc_node  *nn;
1.23      kristaps 1838:        struct tag              *t;
1.17      kristaps 1839:        struct htmlpair          tag[2];
                   1840:        int                      i;
1.23      kristaps 1841:        struct roffsu            su;
1.4       kristaps 1842:
                   1843:        if (SEC_SYNOPSIS == n->sec) {
                   1844:                if (n->next && MDOC_In != n->next->tok) {
1.23      kristaps 1845:                        SCALE_VS_INIT(&su, 1);
                   1846:                        bufcat_su(h, "margin-bottom", &su);
                   1847:                        PAIR_STYLE_INIT(&tag[0], h);
1.17      kristaps 1848:                        print_otag(h, TAG_DIV, 1, tag);
1.4       kristaps 1849:                } else
                   1850:                        print_otag(h, TAG_DIV, 0, NULL);
                   1851:        }
                   1852:
1.34      kristaps 1853:        /* FIXME: there's a buffer bug in here somewhere. */
                   1854:
1.23      kristaps 1855:        PAIR_CLASS_INIT(&tag[0], "includes");
1.17      kristaps 1856:        print_otag(h, TAG_SPAN, 1, tag);
1.4       kristaps 1857:
                   1858:        if (SEC_SYNOPSIS == n->sec)
                   1859:                print_text(h, "#include");
                   1860:
                   1861:        print_text(h, "<");
                   1862:        h->flags |= HTML_NOSPACE;
                   1863:
                   1864:        /* XXX -- see warning in termp_in_post(). */
                   1865:
1.17      kristaps 1866:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1867:                PAIR_CLASS_INIT(&tag[0], "link-includes");
                   1868:                i = 1;
1.41    ! kristaps 1869:                bufinit(h);
1.17      kristaps 1870:                if (h->base_includes) {
                   1871:                        buffmt_includes(h, nn->string);
                   1872:                        tag[i].key = ATTR_HREF;
                   1873:                        tag[i++].val = h->buf;
                   1874:                }
                   1875:                t = print_otag(h, TAG_A, i, tag);
1.4       kristaps 1876:                print_mdoc_node(m, nn, h);
1.17      kristaps 1877:                print_tagq(h, t);
                   1878:        }
1.4       kristaps 1879:
                   1880:        h->flags |= HTML_NOSPACE;
                   1881:        print_text(h, ">");
                   1882:
                   1883:        return(0);
                   1884: }
                   1885:
                   1886:
                   1887: /* ARGSUSED */
                   1888: static int
                   1889: mdoc_ic_pre(MDOC_ARGS)
                   1890: {
                   1891:        struct htmlpair tag;
                   1892:
1.23      kristaps 1893:        PAIR_CLASS_INIT(&tag, "cmd");
1.4       kristaps 1894:        print_otag(h, TAG_SPAN, 1, &tag);
                   1895:        return(1);
                   1896: }
                   1897:
                   1898:
                   1899: /* ARGSUSED */
                   1900: static int
                   1901: mdoc_rv_pre(MDOC_ARGS)
                   1902: {
                   1903:        const struct mdoc_node  *nn;
                   1904:        struct htmlpair          tag;
                   1905:        struct tag              *t;
                   1906:
                   1907:        print_otag(h, TAG_DIV, 0, NULL);
                   1908:        print_text(h, "The");
                   1909:
                   1910:        for (nn = n->child; nn; nn = nn->next) {
1.23      kristaps 1911:                PAIR_CLASS_INIT(&tag, "fname");
1.4       kristaps 1912:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1913:                print_text(h, nn->string);
                   1914:                print_tagq(h, t);
                   1915:
                   1916:                h->flags |= HTML_NOSPACE;
                   1917:                if (nn->next && NULL == nn->next->next)
                   1918:                        print_text(h, "(), and");
                   1919:                else if (nn->next)
                   1920:                        print_text(h, "(),");
                   1921:                else
                   1922:                        print_text(h, "()");
                   1923:        }
                   1924:
                   1925:        if (n->child->next)
                   1926:                print_text(h, "functions return");
                   1927:        else
                   1928:                print_text(h, "function returns");
                   1929:
                   1930:                print_text(h, "the value 0 if successful; otherwise the value "
                   1931:                        "-1 is returned and the global variable");
                   1932:
1.23      kristaps 1933:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1934:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1935:        print_text(h, "errno");
                   1936:        print_tagq(h, t);
                   1937:                print_text(h, "is set to indicate the error.");
                   1938:        return(0);
                   1939: }
                   1940:
                   1941:
                   1942: /* ARGSUSED */
                   1943: static int
                   1944: mdoc_va_pre(MDOC_ARGS)
                   1945: {
                   1946:        struct htmlpair tag;
                   1947:
1.23      kristaps 1948:        PAIR_CLASS_INIT(&tag, "var");
1.4       kristaps 1949:        print_otag(h, TAG_SPAN, 1, &tag);
                   1950:        return(1);
                   1951: }
                   1952:
                   1953:
                   1954: /* ARGSUSED */
                   1955: static int
                   1956: mdoc_bq_pre(MDOC_ARGS)
                   1957: {
                   1958:
                   1959:        if (MDOC_BODY != n->type)
                   1960:                return(1);
                   1961:        print_text(h, "\\(lB");
                   1962:        h->flags |= HTML_NOSPACE;
                   1963:        return(1);
                   1964: }
                   1965:
                   1966:
                   1967: /* ARGSUSED */
                   1968: static void
                   1969: mdoc_bq_post(MDOC_ARGS)
                   1970: {
                   1971:
                   1972:        if (MDOC_BODY != n->type)
                   1973:                return;
                   1974:        h->flags |= HTML_NOSPACE;
                   1975:        print_text(h, "\\(rB");
                   1976: }
1.5       kristaps 1977:
                   1978:
                   1979: /* ARGSUSED */
                   1980: static int
                   1981: mdoc_ap_pre(MDOC_ARGS)
                   1982: {
                   1983:
                   1984:        h->flags |= HTML_NOSPACE;
                   1985:        print_text(h, "\\(aq");
                   1986:        h->flags |= HTML_NOSPACE;
                   1987:        return(1);
                   1988: }
                   1989:
                   1990:
                   1991: /* ARGSUSED */
                   1992: static int
                   1993: mdoc_bf_pre(MDOC_ARGS)
                   1994: {
1.23      kristaps 1995:        int              i;
                   1996:        struct htmlpair  tag[2];
                   1997:        struct roffsu    su;
1.5       kristaps 1998:
                   1999:        if (MDOC_HEAD == n->type)
                   2000:                return(0);
                   2001:        else if (MDOC_BLOCK != n->type)
                   2002:                return(1);
                   2003:
1.23      kristaps 2004:        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2005:
                   2006:        if (n->head->child) {
                   2007:                if ( ! strcmp("Em", n->head->child->string))
1.23      kristaps 2008:                        PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 2009:                else if ( ! strcmp("Sy", n->head->child->string))
1.23      kristaps 2010:                        PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 2011:                else if ( ! strcmp("Li", n->head->child->string))
1.23      kristaps 2012:                        PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2013:        } else {
                   2014:                assert(n->args);
                   2015:                for (i = 0; i < (int)n->args->argc; i++)
                   2016:                        switch (n->args->argv[i].arg) {
                   2017:                        case (MDOC_Symbolic):
1.23      kristaps 2018:                                PAIR_CLASS_INIT(&tag[0], "symb");
1.5       kristaps 2019:                                break;
                   2020:                        case (MDOC_Literal):
1.23      kristaps 2021:                                PAIR_CLASS_INIT(&tag[0], "lit");
1.5       kristaps 2022:                                break;
                   2023:                        case (MDOC_Emphasis):
1.23      kristaps 2024:                                PAIR_CLASS_INIT(&tag[0], "emph");
1.5       kristaps 2025:                                break;
                   2026:                        default:
                   2027:                                break;
                   2028:                        }
                   2029:        }
                   2030:
                   2031:        /* FIXME: div's have spaces stripped--we want them. */
                   2032:
1.23      kristaps 2033:        bufcat_style(h, "display", "inline");
                   2034:        SCALE_HS_INIT(&su, 1);
                   2035:        bufcat_su(h, "margin-right", &su);
                   2036:        PAIR_STYLE_INIT(&tag[1], h);
1.5       kristaps 2037:        print_otag(h, TAG_DIV, 2, tag);
                   2038:        return(1);
                   2039: }
                   2040:
                   2041:
                   2042: /* ARGSUSED */
                   2043: static int
                   2044: mdoc_ms_pre(MDOC_ARGS)
                   2045: {
                   2046:        struct htmlpair tag;
                   2047:
1.23      kristaps 2048:        PAIR_CLASS_INIT(&tag, "symb");
1.5       kristaps 2049:        print_otag(h, TAG_SPAN, 1, &tag);
                   2050:        return(1);
                   2051: }
                   2052:
                   2053:
                   2054: /* ARGSUSED */
                   2055: static int
                   2056: mdoc_pf_pre(MDOC_ARGS)
                   2057: {
                   2058:
                   2059:        h->flags |= HTML_IGNDELIM;
                   2060:        return(1);
                   2061: }
                   2062:
                   2063:
                   2064: /* ARGSUSED */
                   2065: static void
                   2066: mdoc_pf_post(MDOC_ARGS)
                   2067: {
                   2068:
                   2069:        h->flags &= ~HTML_IGNDELIM;
                   2070:        h->flags |= HTML_NOSPACE;
                   2071: }
                   2072:
                   2073:
                   2074: /* ARGSUSED */
                   2075: static int
                   2076: mdoc_rs_pre(MDOC_ARGS)
                   2077: {
1.23      kristaps 2078:        struct htmlpair  tag;
                   2079:        struct roffsu    su;
1.5       kristaps 2080:
                   2081:        if (MDOC_BLOCK != n->type)
                   2082:                return(1);
                   2083:
1.8       kristaps 2084:        if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23      kristaps 2085:                SCALE_VS_INIT(&su, 1);
                   2086:                bufcat_su(h, "margin-top", &su);
                   2087:                PAIR_STYLE_INIT(&tag, h);
1.8       kristaps 2088:                print_otag(h, TAG_DIV, 1, &tag);
1.5       kristaps 2089:        }
                   2090:
1.23      kristaps 2091:        PAIR_CLASS_INIT(&tag, "ref");
1.8       kristaps 2092:        print_otag(h, TAG_SPAN, 1, &tag);
1.5       kristaps 2093:        return(1);
                   2094: }
1.6       kristaps 2095:
                   2096:
                   2097:
                   2098: /* ARGSUSED */
                   2099: static int
                   2100: mdoc_li_pre(MDOC_ARGS)
                   2101: {
                   2102:        struct htmlpair tag;
                   2103:
1.23      kristaps 2104:        PAIR_CLASS_INIT(&tag, "lit");
1.6       kristaps 2105:        print_otag(h, TAG_SPAN, 1, &tag);
                   2106:        return(1);
                   2107: }
                   2108:
                   2109:
                   2110: /* ARGSUSED */
                   2111: static int
                   2112: mdoc_sy_pre(MDOC_ARGS)
                   2113: {
                   2114:        struct htmlpair tag;
                   2115:
1.23      kristaps 2116:        PAIR_CLASS_INIT(&tag, "symb");
1.6       kristaps 2117:        print_otag(h, TAG_SPAN, 1, &tag);
                   2118:        return(1);
                   2119: }
                   2120:
                   2121:
                   2122: /* ARGSUSED */
                   2123: static int
                   2124: mdoc_bt_pre(MDOC_ARGS)
                   2125: {
                   2126:
                   2127:        print_text(h, "is currently in beta test.");
                   2128:        return(0);
                   2129: }
                   2130:
                   2131:
                   2132: /* ARGSUSED */
                   2133: static int
                   2134: mdoc_ud_pre(MDOC_ARGS)
                   2135: {
                   2136:
                   2137:        print_text(h, "currently under development.");
                   2138:        return(0);
                   2139: }
                   2140:
                   2141:
                   2142: /* ARGSUSED */
                   2143: static int
                   2144: mdoc_lb_pre(MDOC_ARGS)
                   2145: {
                   2146:        struct htmlpair tag;
                   2147:
                   2148:        if (SEC_SYNOPSIS == n->sec)
                   2149:                print_otag(h, TAG_DIV, 0, NULL);
1.23      kristaps 2150:        PAIR_CLASS_INIT(&tag, "lib");
1.6       kristaps 2151:        print_otag(h, TAG_SPAN, 1, &tag);
                   2152:        return(1);
                   2153: }
1.10      kristaps 2154:
                   2155:
                   2156: /* ARGSUSED */
                   2157: static int
                   2158: mdoc__x_pre(MDOC_ARGS)
                   2159: {
1.38      kristaps 2160:        struct htmlpair tag[2];
1.37      kristaps 2161:
1.10      kristaps 2162:        switch (n->tok) {
                   2163:        case(MDOC__A):
1.38      kristaps 2164:                PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.10      kristaps 2165:                break;
                   2166:        case(MDOC__B):
1.38      kristaps 2167:                PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10      kristaps 2168:                break;
                   2169:        case(MDOC__C):
1.38      kristaps 2170:                PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10      kristaps 2171:                break;
                   2172:        case(MDOC__D):
1.38      kristaps 2173:                PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10      kristaps 2174:                break;
                   2175:        case(MDOC__I):
1.38      kristaps 2176:                PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10      kristaps 2177:                break;
                   2178:        case(MDOC__J):
1.38      kristaps 2179:                PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10      kristaps 2180:                break;
                   2181:        case(MDOC__N):
1.38      kristaps 2182:                PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10      kristaps 2183:                break;
                   2184:        case(MDOC__O):
1.38      kristaps 2185:                PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10      kristaps 2186:                break;
                   2187:        case(MDOC__P):
1.38      kristaps 2188:                PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10      kristaps 2189:                break;
                   2190:        case(MDOC__Q):
1.38      kristaps 2191:                PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10      kristaps 2192:                break;
                   2193:        case(MDOC__R):
1.38      kristaps 2194:                PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10      kristaps 2195:                break;
                   2196:        case(MDOC__T):
1.38      kristaps 2197:                PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10      kristaps 2198:                print_text(h, "\\(lq");
                   2199:                h->flags |= HTML_NOSPACE;
                   2200:                break;
1.38      kristaps 2201:        case(MDOC__U):
                   2202:                PAIR_CLASS_INIT(&tag[0], "link-ref");
                   2203:                break;
1.10      kristaps 2204:        case(MDOC__V):
1.38      kristaps 2205:                PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10      kristaps 2206:                break;
                   2207:        default:
                   2208:                abort();
                   2209:                /* NOTREACHED */
                   2210:        }
                   2211:
1.38      kristaps 2212:        if (MDOC__U != n->tok) {
                   2213:                print_otag(h, TAG_SPAN, 1, tag);
                   2214:                return(1);
                   2215:        }
                   2216:
                   2217:        PAIR_HREF_INIT(&tag[1], n->child->string);
                   2218:        print_otag(h, TAG_A, 2, tag);
1.10      kristaps 2219:        return(1);
                   2220: }
                   2221:
                   2222:
                   2223: /* ARGSUSED */
                   2224: static void
                   2225: mdoc__x_post(MDOC_ARGS)
                   2226: {
                   2227:
                   2228:        h->flags |= HTML_NOSPACE;
                   2229:        switch (n->tok) {
                   2230:        case (MDOC__T):
                   2231:                print_text(h, "\\(rq");
                   2232:                h->flags |= HTML_NOSPACE;
                   2233:                break;
                   2234:        default:
                   2235:                break;
                   2236:        }
                   2237:        print_text(h, n->next ? "," : ".");
                   2238: }

CVSweb