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

Annotation of mandoc/mdoc_html.c, Revision 1.203

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

CVSweb