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

Annotation of mandoc/mdoc_html.c, Revision 1.224

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

CVSweb