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

Annotation of mandoc/mdoc_html.c, Revision 1.188

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

CVSweb