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

Annotation of mandoc/mdoc_html.c, Revision 1.154

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

CVSweb