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

Annotation of mandoc/mdoc_html.c, Revision 1.206

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

CVSweb