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

Annotation of mandoc/mdoc_html.c, Revision 1.175

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

CVSweb