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

Annotation of mandoc/mdoc_html.c, Revision 1.151

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

CVSweb