[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.48

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