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

Annotation of mandoc/mdoc_html.c, Revision 1.246

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

CVSweb