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

Annotation of mandoc/mdoc_html.c, Revision 1.201

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

CVSweb