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

Annotation of mandoc/man_html.c, Revision 1.89

1.89    ! schwarze    1: /*     $Id: man_html.c,v 1.88 2012/06/02 20:16:23 schwarze Exp $ */
1.1       kristaps    2: /*
1.87      schwarze    3:  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
1.25      kristaps   17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
1.1       kristaps   21: #include <sys/types.h>
                     22:
1.5       kristaps   23: #include <assert.h>
                     24: #include <ctype.h>
1.2       kristaps   25: #include <stdio.h>
1.1       kristaps   26: #include <stdlib.h>
1.4       kristaps   27: #include <string.h>
1.1       kristaps   28:
1.35      kristaps   29: #include "mandoc.h"
1.7       kristaps   30: #include "out.h"
1.1       kristaps   31: #include "html.h"
                     32: #include "man.h"
1.10      kristaps   33: #include "main.h"
1.1       kristaps   34:
1.6       kristaps   35: /* TODO: preserve ident widths. */
1.13      kristaps   36: /* FIXME: have PD set the default vspace width. */
1.6       kristaps   37:
                     38: #define        INDENT            5
1.4       kristaps   39:
1.89    ! schwarze   40: #define        MAN_ARGS          const struct man_meta *man, \
1.3       kristaps   41:                          const struct man_node *n, \
1.45      kristaps   42:                          struct mhtml *mh, \
1.3       kristaps   43:                          struct html *h
                     44:
1.45      kristaps   45: struct mhtml {
                     46:        int               fl;
                     47: #define        MANH_LITERAL     (1 << 0) /* literal context */
                     48: };
                     49:
1.3       kristaps   50: struct htmlman {
                     51:        int             (*pre)(MAN_ARGS);
                     52:        int             (*post)(MAN_ARGS);
                     53: };
                     54:
1.74      kristaps   55: static void              print_bvspace(struct html *,
                     56:                                const struct man_node *);
1.3       kristaps   57: static void              print_man(MAN_ARGS);
                     58: static void              print_man_head(MAN_ARGS);
1.4       kristaps   59: static void              print_man_nodelist(MAN_ARGS);
                     60: static void              print_man_node(MAN_ARGS);
1.7       kristaps   61: static int               a2width(const struct man_node *,
                     62:                                struct roffsu *);
1.8       kristaps   63: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   64: static int               man_HP_pre(MAN_ARGS);
1.86      kristaps   65: static int               man_IP_pre(MAN_ARGS);
1.8       kristaps   66: static int               man_I_pre(MAN_ARGS);
1.86      kristaps   67: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   68: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   69: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   70: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   71: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   72: static int               man_SS_pre(MAN_ARGS);
1.86      kristaps   73: static int               man_alt_pre(MAN_ARGS);
                     74: static int               man_br_pre(MAN_ARGS);
                     75: static int               man_ign_pre(MAN_ARGS);
                     76: static int               man_in_pre(MAN_ARGS);
                     77: static int               man_literal_pre(MAN_ARGS);
                     78: static void              man_root_post(MAN_ARGS);
                     79: static void              man_root_pre(MAN_ARGS);
1.4       kristaps   80:
1.3       kristaps   81: static const struct htmlman mans[MAN_MAX] = {
1.4       kristaps   82:        { man_br_pre, NULL }, /* br */
1.3       kristaps   83:        { NULL, NULL }, /* TH */
1.4       kristaps   84:        { man_SH_pre, NULL }, /* SH */
                     85:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   86:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   87:        { man_PP_pre, NULL }, /* LP */
                     88:        { man_PP_pre, NULL }, /* PP */
                     89:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   90:        { man_IP_pre, NULL }, /* IP */
1.6       kristaps   91:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   92:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   93:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   94:        { man_alt_pre, NULL }, /* BI */
                     95:        { man_alt_pre, NULL }, /* IB */
                     96:        { man_alt_pre, NULL }, /* BR */
                     97:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   98:        { NULL, NULL }, /* R */
1.8       kristaps   99:        { man_B_pre, NULL }, /* B */
                    100:        { man_I_pre, NULL }, /* I */
                    101:        { man_alt_pre, NULL }, /* IR */
                    102:        { man_alt_pre, NULL }, /* RI */
1.67      schwarze  103:        { man_ign_pre, NULL }, /* na */
1.4       kristaps  104:        { man_br_pre, NULL }, /* sp */
1.45      kristaps  105:        { man_literal_pre, NULL }, /* nf */
                    106:        { man_literal_pre, NULL }, /* fi */
1.3       kristaps  107:        { NULL, NULL }, /* RE */
1.9       kristaps  108:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  109:        { man_ign_pre, NULL }, /* DT */
                    110:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  111:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     112:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  113:        { man_in_pre, NULL }, /* in */
1.51      kristaps  114:        { man_ign_pre, NULL }, /* ft */
1.86      kristaps  115:        { man_OP_pre, NULL }, /* OP */
1.88      schwarze  116:        { man_literal_pre, NULL }, /* EX */
                    117:        { man_literal_pre, NULL }, /* EE */
1.3       kristaps  118: };
                    119:
1.74      kristaps  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       kristaps  142:
                    143: void
1.89    ! schwarze  144: html_man(void *arg, const struct man *man)
1.1       kristaps  145: {
1.45      kristaps  146:        struct mhtml     mh;
1.3       kristaps  147:
1.45      kristaps  148:        memset(&mh, 0, sizeof(struct mhtml));
1.89    ! schwarze  149:        print_man(man_meta(man), man_node(man), &mh, (struct html *)arg);
1.82      kristaps  150:        putchar('\n');
1.3       kristaps  151: }
                    152:
                    153: static void
                    154: print_man(MAN_ARGS)
                    155: {
1.82      kristaps  156:        struct tag      *t, *tt;
                    157:        struct htmlpair  tag;
                    158:
                    159:        PAIR_CLASS_INIT(&tag, "mandoc");
1.3       kristaps  160:
1.82      kristaps  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.89    ! schwarze  165:                print_man_head(man, n, mh, h);
1.82      kristaps  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.53      kristaps  171:
1.89    ! schwarze  172:        print_man_nodelist(man, n, mh, h);
1.3       kristaps  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.89    ! schwarze  183:        assert(man->title);
        !           184:        assert(man->msec);
        !           185:        bufcat_fmt(h, "%s(%s)", man->title, man->msec);
1.3       kristaps  186:        print_otag(h, TAG_TITLE, 0, NULL);
                    187:        print_text(h, h->buf);
1.1       kristaps  188: }
1.4       kristaps  189:
                    190:
                    191: static void
                    192: print_man_nodelist(MAN_ARGS)
                    193: {
                    194:
1.89    ! schwarze  195:        print_man_node(man, n, mh, h);
1.4       kristaps  196:        if (n->next)
1.89    ! schwarze  197:                print_man_nodelist(man, n->next, mh, h);
1.4       kristaps  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.14      kristaps  208:        t = h->tags.head;
1.4       kristaps  209:
                    210:        switch (n->type) {
                    211:        case (MAN_ROOT):
1.89    ! schwarze  212:                man_root_pre(man, n, mh, h);
1.4       kristaps  213:                break;
                    214:        case (MAN_TEXT):
1.65      kristaps  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.63      kristaps  220:                if ('\0' == *n->string) {
                    221:                        print_otag(h, TAG_P, 0, NULL);
                    222:                        return;
1.78      kristaps  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.63      kristaps  228:                        print_otag(h, TAG_BR, 0, NULL);
                    229:
1.4       kristaps  230:                print_text(h, n->string);
1.68      kristaps  231:                return;
                    232:        case (MAN_EQN):
1.80      kristaps  233:                print_eqn(h, n->eqn);
1.69      kristaps  234:                break;
1.58      kristaps  235:        case (MAN_TBL):
1.66      kristaps  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.60      kristaps  241:                print_tbl(h, n->span);
1.64      kristaps  242:                return;
1.4       kristaps  243:        default:
1.21      kristaps  244:                /*
                    245:                 * Close out scope of font prior to opening a macro
1.66      kristaps  246:                 * scope.
1.21      kristaps  247:                 */
1.57      kristaps  248:                if (HTMLFONT_NONE != h->metac) {
                    249:                        h->metal = h->metac;
                    250:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  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.20      kristaps  261:                }
1.4       kristaps  262:                if (mans[n->tok].pre)
1.89    ! schwarze  263:                        child = (*mans[n->tok].pre)(man, n, mh, h);
1.4       kristaps  264:                break;
                    265:        }
                    266:
1.21      kristaps  267:        if (child && n->child)
1.89    ! schwarze  268:                print_man_nodelist(man, n->child, mh, h);
1.21      kristaps  269:
1.24      kristaps  270:        /* This will automatically close out any font scope. */
1.4       kristaps  271:        print_stagq(h, t);
                    272:
1.61      kristaps  273:        switch (n->type) {
                    274:        case (MAN_ROOT):
1.89    ! schwarze  275:                man_root_post(man, n, mh, h);
1.69      kristaps  276:                break;
                    277:        case (MAN_EQN):
1.61      kristaps  278:                break;
                    279:        default:
                    280:                if (mans[n->tok].post)
1.89    ! schwarze  281:                        (*mans[n->tok].post)(man, n, mh, h);
1.61      kristaps  282:                break;
                    283:        }
1.4       kristaps  284: }
                    285:
                    286:
1.5       kristaps  287: static int
1.7       kristaps  288: a2width(const struct man_node *n, struct roffsu *su)
1.5       kristaps  289: {
                    290:
1.6       kristaps  291:        if (MAN_TEXT != n->type)
1.7       kristaps  292:                return(0);
1.11      kristaps  293:        if (a2roffsu(n->string, su, SCALE_BU))
1.7       kristaps  294:                return(1);
1.5       kristaps  295:
1.7       kristaps  296:        return(0);
1.5       kristaps  297: }
                    298:
                    299:
1.40      kristaps  300: /* ARGSUSED */
1.65      kristaps  301: static void
1.4       kristaps  302: man_root_pre(MAN_ARGS)
                    303: {
1.56      kristaps  304:        struct htmlpair  tag[3];
1.4       kristaps  305:        struct tag      *t, *tt;
                    306:        char             b[BUFSIZ], title[BUFSIZ];
                    307:
                    308:        b[0] = 0;
1.89    ! schwarze  309:        if (man->vol)
        !           310:                (void)strlcat(b, man->vol, BUFSIZ);
1.4       kristaps  311:
1.89    ! schwarze  312:        assert(man->title);
        !           313:        assert(man->msec);
        !           314:        snprintf(title, BUFSIZ - 1, "%s(%s)", man->title, man->msec);
1.4       kristaps  315:
1.56      kristaps  316:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    317:        PAIR_CLASS_INIT(&tag[1], "head");
1.83      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.56      kristaps  324:
                    325:        print_otag(h, TAG_TBODY, 0, NULL);
1.15      kristaps  326:
1.4       kristaps  327:        tt = print_otag(h, TAG_TR, 0, NULL);
                    328:
1.55      kristaps  329:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.4       kristaps  330:        print_otag(h, TAG_TD, 1, tag);
                    331:        print_text(h, title);
                    332:        print_stagq(h, tt);
                    333:
1.55      kristaps  334:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.83      schwarze  335:        PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    336:        print_otag(h, TAG_TD, 2, tag);
1.4       kristaps  337:        print_text(h, b);
                    338:        print_stagq(h, tt);
                    339:
1.55      kristaps  340:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.83      schwarze  341:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    342:        print_otag(h, TAG_TD, 2, tag);
1.4       kristaps  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.56      kristaps  352:        struct htmlpair  tag[3];
1.4       kristaps  353:        struct tag      *t, *tt;
                    354:
1.56      kristaps  355:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    356:        PAIR_CLASS_INIT(&tag[1], "foot");
1.83      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.15      kristaps  362:
1.4       kristaps  363:        tt = print_otag(h, TAG_TR, 0, NULL);
                    364:
1.55      kristaps  365:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.4       kristaps  366:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  367:
1.89    ! schwarze  368:        assert(man->date);
        !           369:        print_text(h, man->date);
1.4       kristaps  370:        print_stagq(h, tt);
                    371:
1.55      kristaps  372:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.83      schwarze  373:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    374:        print_otag(h, TAG_TD, 2, tag);
1.55      kristaps  375:
1.89    ! schwarze  376:        if (man->source)
        !           377:                print_text(h, man->source);
1.4       kristaps  378:        print_tagq(h, t);
                    379: }
                    380:
                    381:
                    382: /* ARGSUSED */
                    383: static int
                    384: man_br_pre(MAN_ARGS)
                    385: {
1.7       kristaps  386:        struct roffsu    su;
                    387:        struct htmlpair  tag;
1.4       kristaps  388:
1.7       kristaps  389:        SCALE_VS_INIT(&su, 1);
                    390:
1.49      kristaps  391:        if (MAN_sp == n->tok) {
1.75      kristaps  392:                if (NULL != (n = n->child))
                    393:                        if ( ! a2roffsu(n->string, &su, SCALE_VS))
                    394:                                SCALE_VS_INIT(&su, atoi(n->string));
1.49      kristaps  395:        } else
1.7       kristaps  396:                su.scale = 0;
1.4       kristaps  397:
1.72      kristaps  398:        bufinit(h);
1.7       kristaps  399:        bufcat_su(h, "height", &su);
                    400:        PAIR_STYLE_INIT(&tag, h);
1.4       kristaps  401:        print_otag(h, TAG_DIV, 1, &tag);
1.24      kristaps  402:
1.16      kristaps  403:        /* So the div isn't empty: */
                    404:        print_text(h, "\\~");
                    405:
1.7       kristaps  406:        return(0);
1.4       kristaps  407: }
                    408:
                    409: /* ARGSUSED */
                    410: static int
                    411: man_SH_pre(MAN_ARGS)
                    412: {
1.54      kristaps  413:        struct htmlpair  tag;
1.4       kristaps  414:
1.54      kristaps  415:        if (MAN_BLOCK == n->type) {
1.76      kristaps  416:                mh->fl &= ~MANH_LITERAL;
1.54      kristaps  417:                PAIR_CLASS_INIT(&tag, "section");
                    418:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  419:                return(1);
1.54      kristaps  420:        } else if (MAN_BODY == n->type)
1.4       kristaps  421:                return(1);
                    422:
1.54      kristaps  423:        print_otag(h, TAG_H1, 0, NULL);
1.4       kristaps  424:        return(1);
                    425: }
                    426:
                    427: /* ARGSUSED */
                    428: static int
1.8       kristaps  429: man_alt_pre(MAN_ARGS)
                    430: {
                    431:        const struct man_node   *nn;
1.78      kristaps  432:        int              i, savelit;
1.57      kristaps  433:        enum htmltag     fp;
                    434:        struct tag      *t;
1.8       kristaps  435:
1.78      kristaps  436:        if ((savelit = mh->fl & MANH_LITERAL))
                    437:                print_otag(h, TAG_BR, 0, NULL);
                    438:
                    439:        mh->fl &= ~MANH_LITERAL;
                    440:
1.8       kristaps  441:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.57      kristaps  442:                t = NULL;
1.8       kristaps  443:                switch (n->tok) {
                    444:                case (MAN_BI):
1.57      kristaps  445:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  446:                        break;
                    447:                case (MAN_IB):
1.57      kristaps  448:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  449:                        break;
                    450:                case (MAN_RI):
1.57      kristaps  451:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  452:                        break;
                    453:                case (MAN_IR):
1.57      kristaps  454:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  455:                        break;
                    456:                case (MAN_BR):
1.57      kristaps  457:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  458:                        break;
                    459:                case (MAN_RB):
1.57      kristaps  460:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  461:                        break;
                    462:                default:
                    463:                        abort();
                    464:                        /* NOTREACHED */
                    465:                }
                    466:
                    467:                if (i)
                    468:                        h->flags |= HTML_NOSPACE;
                    469:
1.57      kristaps  470:                if (TAG_MAX != fp)
                    471:                        t = print_otag(h, fp, 0, NULL);
                    472:
1.89    ! schwarze  473:                print_man_node(man, nn, mh, h);
1.57      kristaps  474:
                    475:                if (t)
                    476:                        print_tagq(h, t);
1.8       kristaps  477:        }
                    478:
1.78      kristaps  479:        if (savelit)
                    480:                mh->fl |= MANH_LITERAL;
                    481:
1.8       kristaps  482:        return(0);
                    483: }
                    484:
                    485: /* ARGSUSED */
                    486: static int
1.56      kristaps  487: man_SM_pre(MAN_ARGS)
1.8       kristaps  488: {
                    489:
1.57      kristaps  490:        print_otag(h, TAG_SMALL, 0, NULL);
1.56      kristaps  491:        if (MAN_SB == n->tok)
1.57      kristaps  492:                print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  493:        return(1);
                    494: }
                    495:
                    496: /* ARGSUSED */
                    497: static int
1.4       kristaps  498: man_SS_pre(MAN_ARGS)
                    499: {
1.54      kristaps  500:        struct htmlpair  tag;
1.4       kristaps  501:
1.54      kristaps  502:        if (MAN_BLOCK == n->type) {
1.76      kristaps  503:                mh->fl &= ~MANH_LITERAL;
1.54      kristaps  504:                PAIR_CLASS_INIT(&tag, "subsection");
                    505:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  506:                return(1);
1.54      kristaps  507:        } else if (MAN_BODY == n->type)
1.4       kristaps  508:                return(1);
                    509:
1.54      kristaps  510:        print_otag(h, TAG_H2, 0, NULL);
1.4       kristaps  511:        return(1);
                    512: }
                    513:
                    514: /* ARGSUSED */
                    515: static int
                    516: man_PP_pre(MAN_ARGS)
                    517: {
                    518:
1.47      kristaps  519:        if (MAN_HEAD == n->type)
                    520:                return(0);
1.74      kristaps  521:        else if (MAN_BLOCK == n->type)
                    522:                print_bvspace(h, n);
1.47      kristaps  523:
1.5       kristaps  524:        return(1);
                    525: }
                    526:
                    527: /* ARGSUSED */
                    528: static int
                    529: man_IP_pre(MAN_ARGS)
                    530: {
                    531:        const struct man_node   *nn;
                    532:
1.7       kristaps  533:        if (MAN_BODY == n->type) {
1.77      kristaps  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.6       kristaps  538:                return(1);
                    539:        }
                    540:
1.78      kristaps  541:        /* FIXME: width specification. */
                    542:
1.77      kristaps  543:        print_otag(h, TAG_DT, 0, NULL);
1.6       kristaps  544:
1.59      schwarze  545:        /* For IP, only print the first header element. */
1.7       kristaps  546:
1.59      schwarze  547:        if (MAN_IP == n->tok && n->child)
1.89    ! schwarze  548:                print_man_node(man, n->child, mh, h);
1.27      kristaps  549:
1.59      schwarze  550:        /* For TP, only print next-line header elements. */
1.6       kristaps  551:
1.7       kristaps  552:        if (MAN_TP == n->tok)
1.59      schwarze  553:                for (nn = n->child; nn; nn = nn->next)
                    554:                        if (nn->line > n->line)
1.89    ! schwarze  555:                                print_man_node(man, nn, mh, h);
1.6       kristaps  556:
                    557:        return(0);
                    558: }
                    559:
                    560: /* ARGSUSED */
                    561: static int
                    562: man_HP_pre(MAN_ARGS)
                    563: {
1.56      kristaps  564:        struct htmlpair  tag;
                    565:        struct roffsu    su;
                    566:        const struct man_node *np;
1.6       kristaps  567:
1.77      kristaps  568:        if (MAN_HEAD == n->type)
                    569:                return(0);
                    570:        else if (MAN_BLOCK != n->type)
                    571:                return(1);
1.72      kristaps  572:
1.77      kristaps  573:        np = n->head->child;
1.6       kristaps  574:
1.56      kristaps  575:        if (NULL == np || ! a2width(np, &su))
                    576:                SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  577:
1.77      kristaps  578:        bufinit(h);
1.5       kristaps  579:
1.77      kristaps  580:        print_bvspace(h, n);
                    581:        bufcat_su(h, "margin-left", &su);
1.56      kristaps  582:        su.scale = -su.scale;
1.7       kristaps  583:        bufcat_su(h, "text-indent", &su);
                    584:        PAIR_STYLE_INIT(&tag, h);
1.77      kristaps  585:        print_otag(h, TAG_P, 1, &tag);
1.4       kristaps  586:        return(1);
                    587: }
1.86      kristaps  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.6       kristaps  619:
1.8       kristaps  620: /* ARGSUSED */
                    621: static int
                    622: man_B_pre(MAN_ARGS)
                    623: {
                    624:
1.57      kristaps  625:        print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  626:        return(1);
                    627: }
                    628:
                    629: /* ARGSUSED */
                    630: static int
                    631: man_I_pre(MAN_ARGS)
                    632: {
1.23      kristaps  633:
1.57      kristaps  634:        print_otag(h, TAG_I, 0, NULL);
1.8       kristaps  635:        return(1);
1.45      kristaps  636: }
                    637:
                    638: /* ARGSUSED */
                    639: static int
                    640: man_literal_pre(MAN_ARGS)
                    641: {
                    642:
1.88      schwarze  643:        if (MAN_fi == n->tok || MAN_EE == n->tok) {
1.45      kristaps  644:                print_otag(h, TAG_BR, 0, NULL);
1.78      kristaps  645:                mh->fl &= ~MANH_LITERAL;
                    646:        } else
1.45      kristaps  647:                mh->fl |= MANH_LITERAL;
                    648:
1.67      schwarze  649:        return(0);
1.45      kristaps  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.8       kristaps  659: }
                    660:
                    661: /* ARGSUSED */
                    662: static int
                    663: man_ign_pre(MAN_ARGS)
                    664: {
                    665:
                    666:        return(0);
                    667: }
1.9       kristaps  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.56      kristaps  682:        if (n->head->child)
1.9       kristaps  683:                a2width(n->head->child, &su);
                    684:
1.72      kristaps  685:        bufinit(h);
1.56      kristaps  686:        bufcat_su(h, "margin-left", &su);
1.9       kristaps  687:        PAIR_STYLE_INIT(&tag, h);
                    688:        print_otag(h, TAG_DIV, 1, &tag);
                    689:        return(1);
                    690: }

CVSweb