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

Annotation of mandoc/mdoc_html.c, Revision 1.247

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

CVSweb