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

Annotation of mandoc/mdoc_html.c, Revision 1.189

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

CVSweb