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

Annotation of mandoc/mdoc_html.c, Revision 1.191

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

CVSweb