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

Annotation of mandoc/mdoc_html.c, Revision 1.209

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

CVSweb