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

Annotation of mandoc/mdoc_html.c, Revision 1.204

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

CVSweb