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

Annotation of mandoc/mdoc_html.c, Revision 1.96

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

CVSweb