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

Annotation of mandoc/mdoc_html.c, Revision 1.238

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

CVSweb