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

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