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

Annotation of mandoc/mdoc_html.c, Revision 1.243

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

CVSweb