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

Annotation of mandoc/mdoc_html.c, Revision 1.125

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

CVSweb