[BACK]Return to man_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/man_html.c, Revision 1.49

1.49    ! schwarze    1: /*     $Id: man_html.c,v 1.48 2012/11/17 00:25:20 schwarze Exp $ */
1.1       schwarze    2: /*
1.49    ! schwarze    3:  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
        !             4:  * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
1.1       schwarze    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:  */
                     18: #include <sys/types.h>
                     19:
                     20: #include <assert.h>
                     21: #include <ctype.h>
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24: #include <string.h>
                     25:
1.14      schwarze   26: #include "mandoc.h"
1.1       schwarze   27: #include "out.h"
                     28: #include "html.h"
                     29: #include "man.h"
                     30: #include "main.h"
                     31:
                     32: /* TODO: preserve ident widths. */
1.2       schwarze   33: /* FIXME: have PD set the default vspace width. */
1.1       schwarze   34:
                     35: #define        INDENT            5
                     36:
1.48      schwarze   37: #define        MAN_ARGS          const struct man_meta *man, \
1.1       schwarze   38:                          const struct man_node *n, \
1.18      schwarze   39:                          struct mhtml *mh, \
1.1       schwarze   40:                          struct html *h
                     41:
1.18      schwarze   42: struct mhtml {
                     43:        int               fl;
                     44: #define        MANH_LITERAL     (1 << 0) /* literal context */
                     45: };
                     46:
1.1       schwarze   47: struct htmlman {
                     48:        int             (*pre)(MAN_ARGS);
                     49:        int             (*post)(MAN_ARGS);
                     50: };
                     51:
1.39      schwarze   52: static void              print_bvspace(struct html *,
                     53:                                const struct man_node *);
1.1       schwarze   54: static void              print_man(MAN_ARGS);
                     55: static void              print_man_head(MAN_ARGS);
                     56: static void              print_man_nodelist(MAN_ARGS);
                     57: static void              print_man_node(MAN_ARGS);
                     58: static int               a2width(const struct man_node *,
                     59:                                struct roffsu *);
                     60: static int               man_B_pre(MAN_ARGS);
                     61: static int               man_HP_pre(MAN_ARGS);
1.46      schwarze   62: static int               man_IP_pre(MAN_ARGS);
1.1       schwarze   63: static int               man_I_pre(MAN_ARGS);
1.46      schwarze   64: static int               man_OP_pre(MAN_ARGS);
1.1       schwarze   65: static int               man_PP_pre(MAN_ARGS);
                     66: static int               man_RS_pre(MAN_ARGS);
                     67: static int               man_SH_pre(MAN_ARGS);
                     68: static int               man_SM_pre(MAN_ARGS);
                     69: static int               man_SS_pre(MAN_ARGS);
1.49    ! schwarze   70: static int               man_UR_pre(MAN_ARGS);
1.46      schwarze   71: static int               man_alt_pre(MAN_ARGS);
                     72: static int               man_br_pre(MAN_ARGS);
                     73: static int               man_ign_pre(MAN_ARGS);
                     74: static int               man_in_pre(MAN_ARGS);
                     75: static int               man_literal_pre(MAN_ARGS);
                     76: static void              man_root_post(MAN_ARGS);
                     77: static void              man_root_pre(MAN_ARGS);
1.1       schwarze   78:
                     79: static const struct htmlman mans[MAN_MAX] = {
                     80:        { man_br_pre, NULL }, /* br */
                     81:        { NULL, NULL }, /* TH */
                     82:        { man_SH_pre, NULL }, /* SH */
                     83:        { man_SS_pre, NULL }, /* SS */
                     84:        { man_IP_pre, NULL }, /* TP */
                     85:        { man_PP_pre, NULL }, /* LP */
                     86:        { man_PP_pre, NULL }, /* PP */
                     87:        { man_PP_pre, NULL }, /* P */
                     88:        { man_IP_pre, NULL }, /* IP */
                     89:        { man_HP_pre, NULL }, /* HP */
                     90:        { man_SM_pre, NULL }, /* SM */
1.26      schwarze   91:        { man_SM_pre, NULL }, /* SB */
1.1       schwarze   92:        { man_alt_pre, NULL }, /* BI */
                     93:        { man_alt_pre, NULL }, /* IB */
                     94:        { man_alt_pre, NULL }, /* BR */
                     95:        { man_alt_pre, NULL }, /* RB */
                     96:        { NULL, NULL }, /* R */
                     97:        { man_B_pre, NULL }, /* B */
                     98:        { man_I_pre, NULL }, /* I */
                     99:        { man_alt_pre, NULL }, /* IR */
                    100:        { man_alt_pre, NULL }, /* RI */
1.34      schwarze  101:        { man_ign_pre, NULL }, /* na */
1.1       schwarze  102:        { man_br_pre, NULL }, /* sp */
1.18      schwarze  103:        { man_literal_pre, NULL }, /* nf */
                    104:        { man_literal_pre, NULL }, /* fi */
1.1       schwarze  105:        { NULL, NULL }, /* RE */
                    106:        { man_RS_pre, NULL }, /* RS */
                    107:        { man_ign_pre, NULL }, /* DT */
                    108:        { man_ign_pre, NULL }, /* UC */
1.2       schwarze  109:        { man_ign_pre, NULL }, /* PD */
1.13      schwarze  110:        { man_ign_pre, NULL }, /* AT */
1.18      schwarze  111:        { man_in_pre, NULL }, /* in */
1.23      schwarze  112:        { man_ign_pre, NULL }, /* ft */
1.46      schwarze  113:        { man_OP_pre, NULL }, /* OP */
1.47      schwarze  114:        { man_literal_pre, NULL }, /* EX */
                    115:        { man_literal_pre, NULL }, /* EE */
1.49    ! schwarze  116:        { man_UR_pre, NULL }, /* UR */
        !           117:        { NULL, NULL }, /* UE */
1.1       schwarze  118: };
                    119:
1.39      schwarze  120: /*
                    121:  * Printing leading vertical space before a block.
                    122:  * This is used for the paragraph macros.
                    123:  * The rules are pretty simple, since there's very little nesting going
                    124:  * on here.  Basically, if we're the first within another block (SS/SH),
                    125:  * then don't emit vertical space.  If we are (RS), then do.  If not the
                    126:  * first, print it.
                    127:  */
                    128: static void
                    129: print_bvspace(struct html *h, const struct man_node *n)
                    130: {
                    131:
                    132:        if (n->body && n->body->child)
                    133:                if (MAN_TBL == n->body->child->type)
                    134:                        return;
                    135:
                    136:        if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
                    137:                if (NULL == n->prev)
                    138:                        return;
                    139:
                    140:        print_otag(h, TAG_P, 0, NULL);
                    141: }
1.1       schwarze  142:
                    143: void
1.48      schwarze  144: html_man(void *arg, const struct man *man)
1.1       schwarze  145: {
1.18      schwarze  146:        struct mhtml     mh;
1.1       schwarze  147:
1.18      schwarze  148:        memset(&mh, 0, sizeof(struct mhtml));
1.48      schwarze  149:        print_man(man_meta(man), man_node(man), &mh, (struct html *)arg);
1.43      schwarze  150:        putchar('\n');
1.1       schwarze  151: }
                    152:
                    153: static void
                    154: print_man(MAN_ARGS)
                    155: {
1.43      schwarze  156:        struct tag      *t, *tt;
                    157:        struct htmlpair  tag;
                    158:
                    159:        PAIR_CLASS_INIT(&tag, "mandoc");
1.1       schwarze  160:
1.43      schwarze  161:        if ( ! (HTML_FRAGMENT & h->oflags)) {
                    162:                print_gen_decls(h);
                    163:                t = print_otag(h, TAG_HTML, 0, NULL);
                    164:                tt = print_otag(h, TAG_HEAD, 0, NULL);
1.48      schwarze  165:                print_man_head(man, n, mh, h);
1.43      schwarze  166:                print_tagq(h, tt);
                    167:                print_otag(h, TAG_BODY, 0, NULL);
                    168:                print_otag(h, TAG_DIV, 1, &tag);
                    169:        } else
                    170:                t = print_otag(h, TAG_DIV, 1, &tag);
1.25      schwarze  171:
1.48      schwarze  172:        print_man_nodelist(man, n, mh, h);
1.1       schwarze  173:        print_tagq(h, t);
                    174: }
                    175:
                    176:
                    177: /* ARGSUSED */
                    178: static void
                    179: print_man_head(MAN_ARGS)
                    180: {
                    181:
                    182:        print_gen_head(h);
1.48      schwarze  183:        assert(man->title);
                    184:        assert(man->msec);
                    185:        bufcat_fmt(h, "%s(%s)", man->title, man->msec);
1.1       schwarze  186:        print_otag(h, TAG_TITLE, 0, NULL);
                    187:        print_text(h, h->buf);
                    188: }
                    189:
                    190:
                    191: static void
                    192: print_man_nodelist(MAN_ARGS)
                    193: {
                    194:
1.48      schwarze  195:        print_man_node(man, n, mh, h);
1.1       schwarze  196:        if (n->next)
1.48      schwarze  197:                print_man_nodelist(man, n->next, mh, h);
1.1       schwarze  198: }
                    199:
                    200:
                    201: static void
                    202: print_man_node(MAN_ARGS)
                    203: {
                    204:        int              child;
                    205:        struct tag      *t;
                    206:
                    207:        child = 1;
1.2       schwarze  208:        t = h->tags.head;
1.1       schwarze  209:
                    210:        switch (n->type) {
                    211:        case (MAN_ROOT):
1.48      schwarze  212:                man_root_pre(man, n, mh, h);
1.1       schwarze  213:                break;
                    214:        case (MAN_TEXT):
1.38      schwarze  215:                /*
                    216:                 * If we have a blank line, output a vertical space.
                    217:                 * If we have a space as the first character, break
                    218:                 * before printing the line's data.
                    219:                 */
1.31      schwarze  220:                if ('\0' == *n->string) {
                    221:                        print_otag(h, TAG_P, 0, NULL);
                    222:                        return;
1.40      schwarze  223:                }
                    224:
                    225:                if (' ' == *n->string && MAN_LINE & n->flags)
                    226:                        print_otag(h, TAG_BR, 0, NULL);
                    227:                else if (MANH_LITERAL & mh->fl && n->prev)
1.31      schwarze  228:                        print_otag(h, TAG_BR, 0, NULL);
                    229:
1.1       schwarze  230:                print_text(h, n->string);
1.36      schwarze  231:                return;
                    232:        case (MAN_EQN):
1.41      schwarze  233:                print_eqn(h, n->eqn);
1.37      schwarze  234:                break;
1.29      schwarze  235:        case (MAN_TBL):
1.33      schwarze  236:                /*
                    237:                 * This will take care of initialising all of the table
                    238:                 * state data for the first table, then tearing it down
                    239:                 * for the last one.
                    240:                 */
1.29      schwarze  241:                print_tbl(h, n->span);
1.32      schwarze  242:                return;
1.1       schwarze  243:        default:
1.4       schwarze  244:                /*
                    245:                 * Close out scope of font prior to opening a macro
1.33      schwarze  246:                 * scope.
1.4       schwarze  247:                 */
1.27      schwarze  248:                if (HTMLFONT_NONE != h->metac) {
                    249:                        h->metal = h->metac;
                    250:                        h->metac = HTMLFONT_NONE;
1.33      schwarze  251:                }
                    252:
                    253:                /*
                    254:                 * Close out the current table, if it's open, and unset
                    255:                 * the "meta" table state.  This will be reopened on the
                    256:                 * next table element.
                    257:                 */
                    258:                if (h->tblt) {
                    259:                        print_tblclose(h);
                    260:                        t = h->tags.head;
1.4       schwarze  261:                }
1.1       schwarze  262:                if (mans[n->tok].pre)
1.48      schwarze  263:                        child = (*mans[n->tok].pre)(man, n, mh, h);
1.1       schwarze  264:                break;
                    265:        }
                    266:
                    267:        if (child && n->child)
1.48      schwarze  268:                print_man_nodelist(man, n->child, mh, h);
1.1       schwarze  269:
1.4       schwarze  270:        /* This will automatically close out any font scope. */
1.1       schwarze  271:        print_stagq(h, t);
                    272:
                    273:        switch (n->type) {
                    274:        case (MAN_ROOT):
1.48      schwarze  275:                man_root_post(man, n, mh, h);
1.37      schwarze  276:                break;
                    277:        case (MAN_EQN):
1.1       schwarze  278:                break;
                    279:        default:
                    280:                if (mans[n->tok].post)
1.48      schwarze  281:                        (*mans[n->tok].post)(man, n, mh, h);
1.1       schwarze  282:                break;
                    283:        }
                    284: }
                    285:
                    286:
                    287: static int
                    288: a2width(const struct man_node *n, struct roffsu *su)
                    289: {
                    290:
                    291:        if (MAN_TEXT != n->type)
                    292:                return(0);
                    293:        if (a2roffsu(n->string, su, SCALE_BU))
                    294:                return(1);
                    295:
                    296:        return(0);
                    297: }
                    298:
                    299:
                    300: /* ARGSUSED */
1.38      schwarze  301: static void
1.1       schwarze  302: man_root_pre(MAN_ARGS)
                    303: {
1.26      schwarze  304:        struct htmlpair  tag[3];
1.1       schwarze  305:        struct tag      *t, *tt;
                    306:        char             b[BUFSIZ], title[BUFSIZ];
                    307:
                    308:        b[0] = 0;
1.48      schwarze  309:        if (man->vol)
                    310:                (void)strlcat(b, man->vol, BUFSIZ);
1.1       schwarze  311:
1.48      schwarze  312:        assert(man->title);
                    313:        assert(man->msec);
                    314:        snprintf(title, BUFSIZ - 1, "%s(%s)", man->title, man->msec);
1.1       schwarze  315:
1.26      schwarze  316:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    317:        PAIR_CLASS_INIT(&tag[1], "head");
1.44      schwarze  318:        PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    319:        t = print_otag(h, TAG_TABLE, 3, tag);
                    320:        PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    321:        print_otag(h, TAG_COL, 1, tag);
                    322:        print_otag(h, TAG_COL, 1, tag);
                    323:        print_otag(h, TAG_COL, 1, tag);
1.26      schwarze  324:
                    325:        print_otag(h, TAG_TBODY, 0, NULL);
1.3       schwarze  326:
1.1       schwarze  327:        tt = print_otag(h, TAG_TR, 0, NULL);
                    328:
1.25      schwarze  329:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1       schwarze  330:        print_otag(h, TAG_TD, 1, tag);
                    331:        print_text(h, title);
                    332:        print_stagq(h, tt);
                    333:
1.25      schwarze  334:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.44      schwarze  335:        PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    336:        print_otag(h, TAG_TD, 2, tag);
1.1       schwarze  337:        print_text(h, b);
                    338:        print_stagq(h, tt);
                    339:
1.25      schwarze  340:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.44      schwarze  341:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    342:        print_otag(h, TAG_TD, 2, tag);
1.1       schwarze  343:        print_text(h, title);
                    344:        print_tagq(h, t);
                    345: }
                    346:
                    347:
                    348: /* ARGSUSED */
                    349: static void
                    350: man_root_post(MAN_ARGS)
                    351: {
1.26      schwarze  352:        struct htmlpair  tag[3];
1.1       schwarze  353:        struct tag      *t, *tt;
                    354:
1.26      schwarze  355:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    356:        PAIR_CLASS_INIT(&tag[1], "foot");
1.44      schwarze  357:        PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    358:        t = print_otag(h, TAG_TABLE, 3, tag);
                    359:        PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    360:        print_otag(h, TAG_COL, 1, tag);
                    361:        print_otag(h, TAG_COL, 1, tag);
1.3       schwarze  362:
1.1       schwarze  363:        tt = print_otag(h, TAG_TR, 0, NULL);
                    364:
1.25      schwarze  365:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1       schwarze  366:        print_otag(h, TAG_TD, 1, tag);
1.25      schwarze  367:
1.48      schwarze  368:        assert(man->date);
                    369:        print_text(h, man->date);
1.1       schwarze  370:        print_stagq(h, tt);
                    371:
1.25      schwarze  372:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.44      schwarze  373:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    374:        print_otag(h, TAG_TD, 2, tag);
1.25      schwarze  375:
1.48      schwarze  376:        if (man->source)
                    377:                print_text(h, man->source);
1.1       schwarze  378:        print_tagq(h, t);
                    379: }
                    380:
                    381:
                    382: /* ARGSUSED */
                    383: static int
                    384: man_br_pre(MAN_ARGS)
                    385: {
                    386:        struct roffsu    su;
                    387:        struct htmlpair  tag;
                    388:
                    389:        SCALE_VS_INIT(&su, 1);
                    390:
1.21      schwarze  391:        if (MAN_sp == n->tok) {
1.39      schwarze  392:                if (NULL != (n = n->child))
                    393:                        if ( ! a2roffsu(n->string, &su, SCALE_VS))
                    394:                                SCALE_VS_INIT(&su, atoi(n->string));
1.21      schwarze  395:        } else
1.1       schwarze  396:                su.scale = 0;
                    397:
1.38      schwarze  398:        bufinit(h);
1.1       schwarze  399:        bufcat_su(h, "height", &su);
                    400:        PAIR_STYLE_INIT(&tag, h);
                    401:        print_otag(h, TAG_DIV, 1, &tag);
1.4       schwarze  402:
1.3       schwarze  403:        /* So the div isn't empty: */
                    404:        print_text(h, "\\~");
                    405:
1.1       schwarze  406:        return(0);
                    407: }
                    408:
                    409: /* ARGSUSED */
                    410: static int
                    411: man_SH_pre(MAN_ARGS)
                    412: {
1.25      schwarze  413:        struct htmlpair  tag;
1.1       schwarze  414:
1.25      schwarze  415:        if (MAN_BLOCK == n->type) {
1.39      schwarze  416:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  417:                PAIR_CLASS_INIT(&tag, "section");
                    418:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  419:                return(1);
1.25      schwarze  420:        } else if (MAN_BODY == n->type)
1.1       schwarze  421:                return(1);
                    422:
1.25      schwarze  423:        print_otag(h, TAG_H1, 0, NULL);
1.1       schwarze  424:        return(1);
                    425: }
                    426:
                    427: /* ARGSUSED */
                    428: static int
                    429: man_alt_pre(MAN_ARGS)
                    430: {
                    431:        const struct man_node   *nn;
1.40      schwarze  432:        int              i, savelit;
1.27      schwarze  433:        enum htmltag     fp;
                    434:        struct tag      *t;
1.1       schwarze  435:
1.40      schwarze  436:        if ((savelit = mh->fl & MANH_LITERAL))
                    437:                print_otag(h, TAG_BR, 0, NULL);
                    438:
                    439:        mh->fl &= ~MANH_LITERAL;
                    440:
1.1       schwarze  441:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.27      schwarze  442:                t = NULL;
1.1       schwarze  443:                switch (n->tok) {
                    444:                case (MAN_BI):
1.27      schwarze  445:                        fp = i % 2 ? TAG_I : TAG_B;
1.1       schwarze  446:                        break;
                    447:                case (MAN_IB):
1.27      schwarze  448:                        fp = i % 2 ? TAG_B : TAG_I;
1.1       schwarze  449:                        break;
                    450:                case (MAN_RI):
1.27      schwarze  451:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.1       schwarze  452:                        break;
                    453:                case (MAN_IR):
1.27      schwarze  454:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.1       schwarze  455:                        break;
                    456:                case (MAN_BR):
1.27      schwarze  457:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.1       schwarze  458:                        break;
                    459:                case (MAN_RB):
1.27      schwarze  460:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.1       schwarze  461:                        break;
                    462:                default:
                    463:                        abort();
                    464:                        /* NOTREACHED */
                    465:                }
                    466:
                    467:                if (i)
                    468:                        h->flags |= HTML_NOSPACE;
                    469:
1.27      schwarze  470:                if (TAG_MAX != fp)
                    471:                        t = print_otag(h, fp, 0, NULL);
                    472:
1.48      schwarze  473:                print_man_node(man, nn, mh, h);
1.27      schwarze  474:
                    475:                if (t)
                    476:                        print_tagq(h, t);
1.1       schwarze  477:        }
                    478:
1.40      schwarze  479:        if (savelit)
                    480:                mh->fl |= MANH_LITERAL;
                    481:
1.1       schwarze  482:        return(0);
                    483: }
                    484:
                    485: /* ARGSUSED */
                    486: static int
1.26      schwarze  487: man_SM_pre(MAN_ARGS)
1.1       schwarze  488: {
                    489:
1.27      schwarze  490:        print_otag(h, TAG_SMALL, 0, NULL);
1.26      schwarze  491:        if (MAN_SB == n->tok)
1.27      schwarze  492:                print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  493:        return(1);
                    494: }
                    495:
                    496: /* ARGSUSED */
                    497: static int
                    498: man_SS_pre(MAN_ARGS)
                    499: {
1.25      schwarze  500:        struct htmlpair  tag;
1.1       schwarze  501:
1.25      schwarze  502:        if (MAN_BLOCK == n->type) {
1.39      schwarze  503:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  504:                PAIR_CLASS_INIT(&tag, "subsection");
                    505:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  506:                return(1);
1.25      schwarze  507:        } else if (MAN_BODY == n->type)
1.1       schwarze  508:                return(1);
                    509:
1.25      schwarze  510:        print_otag(h, TAG_H2, 0, NULL);
1.1       schwarze  511:        return(1);
                    512: }
                    513:
                    514: /* ARGSUSED */
                    515: static int
                    516: man_PP_pre(MAN_ARGS)
                    517: {
                    518:
1.22      schwarze  519:        if (MAN_HEAD == n->type)
                    520:                return(0);
1.39      schwarze  521:        else if (MAN_BLOCK == n->type)
                    522:                print_bvspace(h, n);
1.22      schwarze  523:
1.1       schwarze  524:        return(1);
                    525: }
                    526:
                    527: /* ARGSUSED */
                    528: static int
                    529: man_IP_pre(MAN_ARGS)
                    530: {
                    531:        const struct man_node   *nn;
                    532:
                    533:        if (MAN_BODY == n->type) {
1.40      schwarze  534:                print_otag(h, TAG_DD, 0, NULL);
                    535:                return(1);
                    536:        } else if (MAN_HEAD != n->type) {
                    537:                print_otag(h, TAG_DL, 0, NULL);
1.1       schwarze  538:                return(1);
                    539:        }
                    540:
1.40      schwarze  541:        /* FIXME: width specification. */
1.7       schwarze  542:
1.40      schwarze  543:        print_otag(h, TAG_DT, 0, NULL);
1.1       schwarze  544:
1.28      schwarze  545:        /* For IP, only print the first header element. */
1.1       schwarze  546:
1.28      schwarze  547:        if (MAN_IP == n->tok && n->child)
1.48      schwarze  548:                print_man_node(man, n->child, mh, h);
1.7       schwarze  549:
1.28      schwarze  550:        /* For TP, only print next-line header elements. */
1.1       schwarze  551:
                    552:        if (MAN_TP == n->tok)
1.28      schwarze  553:                for (nn = n->child; nn; nn = nn->next)
                    554:                        if (nn->line > n->line)
1.48      schwarze  555:                                print_man_node(man, nn, mh, h);
1.1       schwarze  556:
                    557:        return(0);
                    558: }
                    559:
                    560: /* ARGSUSED */
                    561: static int
                    562: man_HP_pre(MAN_ARGS)
                    563: {
1.26      schwarze  564:        struct htmlpair  tag;
                    565:        struct roffsu    su;
                    566:        const struct man_node *np;
1.1       schwarze  567:
1.40      schwarze  568:        if (MAN_HEAD == n->type)
                    569:                return(0);
                    570:        else if (MAN_BLOCK != n->type)
                    571:                return(1);
1.38      schwarze  572:
1.40      schwarze  573:        np = n->head->child;
1.1       schwarze  574:
1.26      schwarze  575:        if (NULL == np || ! a2width(np, &su))
                    576:                SCALE_HS_INIT(&su, INDENT);
1.1       schwarze  577:
1.40      schwarze  578:        bufinit(h);
1.1       schwarze  579:
1.40      schwarze  580:        print_bvspace(h, n);
                    581:        bufcat_su(h, "margin-left", &su);
1.26      schwarze  582:        su.scale = -su.scale;
1.1       schwarze  583:        bufcat_su(h, "text-indent", &su);
                    584:        PAIR_STYLE_INIT(&tag, h);
1.40      schwarze  585:        print_otag(h, TAG_P, 1, &tag);
1.1       schwarze  586:        return(1);
                    587: }
1.46      schwarze  588:
                    589: /* ARGSUSED */
                    590: static int
                    591: man_OP_pre(MAN_ARGS)
                    592: {
                    593:        struct tag      *tt;
                    594:        struct htmlpair  tag;
                    595:
                    596:        print_text(h, "[");
                    597:        h->flags |= HTML_NOSPACE;
                    598:        PAIR_CLASS_INIT(&tag, "opt");
                    599:        tt = print_otag(h, TAG_SPAN, 1, &tag);
                    600:
                    601:        if (NULL != (n = n->child)) {
                    602:                print_otag(h, TAG_B, 0, NULL);
                    603:                print_text(h, n->string);
                    604:        }
                    605:
                    606:        print_stagq(h, tt);
                    607:
                    608:        if (NULL != n && NULL != n->next) {
                    609:                print_otag(h, TAG_I, 0, NULL);
                    610:                print_text(h, n->next->string);
                    611:        }
                    612:
                    613:        print_stagq(h, tt);
                    614:        h->flags |= HTML_NOSPACE;
                    615:        print_text(h, "]");
                    616:        return(0);
                    617: }
                    618:
1.1       schwarze  619:
                    620: /* ARGSUSED */
                    621: static int
                    622: man_B_pre(MAN_ARGS)
                    623: {
                    624:
1.27      schwarze  625:        print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  626:        return(1);
                    627: }
                    628:
                    629: /* ARGSUSED */
                    630: static int
                    631: man_I_pre(MAN_ARGS)
                    632: {
1.4       schwarze  633:
1.27      schwarze  634:        print_otag(h, TAG_I, 0, NULL);
1.1       schwarze  635:        return(1);
1.18      schwarze  636: }
                    637:
                    638: /* ARGSUSED */
                    639: static int
                    640: man_literal_pre(MAN_ARGS)
                    641: {
                    642:
1.47      schwarze  643:        if (MAN_fi == n->tok || MAN_EE == n->tok) {
1.18      schwarze  644:                print_otag(h, TAG_BR, 0, NULL);
1.40      schwarze  645:                mh->fl &= ~MANH_LITERAL;
                    646:        } else
1.18      schwarze  647:                mh->fl |= MANH_LITERAL;
                    648:
1.34      schwarze  649:        return(0);
1.18      schwarze  650: }
                    651:
                    652: /* ARGSUSED */
                    653: static int
                    654: man_in_pre(MAN_ARGS)
                    655: {
                    656:
                    657:        print_otag(h, TAG_BR, 0, NULL);
                    658:        return(0);
1.1       schwarze  659: }
                    660:
                    661: /* ARGSUSED */
                    662: static int
                    663: man_ign_pre(MAN_ARGS)
                    664: {
                    665:
                    666:        return(0);
                    667: }
                    668:
                    669: /* ARGSUSED */
                    670: static int
                    671: man_RS_pre(MAN_ARGS)
                    672: {
                    673:        struct htmlpair  tag;
                    674:        struct roffsu    su;
                    675:
                    676:        if (MAN_HEAD == n->type)
                    677:                return(0);
                    678:        else if (MAN_BODY == n->type)
                    679:                return(1);
                    680:
                    681:        SCALE_HS_INIT(&su, INDENT);
1.26      schwarze  682:        if (n->head->child)
1.1       schwarze  683:                a2width(n->head->child, &su);
                    684:
1.38      schwarze  685:        bufinit(h);
1.26      schwarze  686:        bufcat_su(h, "margin-left", &su);
1.1       schwarze  687:        PAIR_STYLE_INIT(&tag, h);
                    688:        print_otag(h, TAG_DIV, 1, &tag);
                    689:        return(1);
1.49    ! schwarze  690: }
        !           691:
        !           692: /* ARGSUSED */
        !           693: static int
        !           694: man_UR_pre(MAN_ARGS)
        !           695: {
        !           696:        struct htmlpair          tag[2];
        !           697:
        !           698:        n = n->child;
        !           699:        assert(MAN_HEAD == n->type);
        !           700:        if (n->nchild) {
        !           701:                assert(MAN_TEXT == n->child->type);
        !           702:                PAIR_CLASS_INIT(&tag[0], "link-ext");
        !           703:                PAIR_HREF_INIT(&tag[1], n->child->string);
        !           704:                print_otag(h, TAG_A, 2, tag);
        !           705:        }
        !           706:
        !           707:        assert(MAN_BODY == n->next->type);
        !           708:        if (n->next->nchild)
        !           709:                n = n->next;
        !           710:
        !           711:        print_man_nodelist(man, n->child, mh, h);
        !           712:
        !           713:        return(0);
1.1       schwarze  714: }