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

Annotation of mandoc/mdoc_html.c, Revision 1.217

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

CVSweb