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

Annotation of mandoc/mdoc_html.c, Revision 1.174

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

CVSweb