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

Annotation of mandoc/mdoc_html.c, Revision 1.29

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

CVSweb