[BACK]Return to mdoc_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.35

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