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

Annotation of mandoc/mdoc_html.c, Revision 1.153

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

CVSweb