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

Annotation of mandoc/mdoc_html.c, Revision 1.233

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

CVSweb