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

Annotation of mandoc/mdoc_html.c, Revision 1.187

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

CVSweb