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

Annotation of mandoc/mdoc_html.c, Revision 1.248

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

CVSweb