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

Annotation of mandoc/man_html.c, Revision 1.63

1.63    ! kristaps    1: /*     $Id: man_html.c,v 1.62 2011/01/07 13:20:58 kristaps Exp $ */
1.1       kristaps    2: /*
1.42      schwarze    3:  * Copyright (c) 2008, 2009, 2010 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: #define        HALFINDENT        3
                     40:
1.3       kristaps   41: #define        MAN_ARGS          const struct man_meta *m, \
                     42:                          const struct man_node *n, \
1.45      kristaps   43:                          struct mhtml *mh, \
1.3       kristaps   44:                          struct html *h
                     45:
1.45      kristaps   46: struct mhtml {
                     47:        int               fl;
                     48: #define        MANH_LITERAL     (1 << 0) /* literal context */
                     49: };
                     50:
1.3       kristaps   51: struct htmlman {
                     52:        int             (*pre)(MAN_ARGS);
                     53:        int             (*post)(MAN_ARGS);
                     54: };
                     55:
                     56: static void              print_man(MAN_ARGS);
                     57: static void              print_man_head(MAN_ARGS);
1.4       kristaps   58: static void              print_man_nodelist(MAN_ARGS);
                     59: static void              print_man_node(MAN_ARGS);
1.3       kristaps   60:
1.7       kristaps   61: static int               a2width(const struct man_node *,
                     62:                                struct roffsu *);
1.5       kristaps   63:
1.8       kristaps   64: static int               man_alt_pre(MAN_ARGS);
1.4       kristaps   65: static int               man_br_pre(MAN_ARGS);
1.8       kristaps   66: static int               man_ign_pre(MAN_ARGS);
1.45      kristaps   67: static int               man_in_pre(MAN_ARGS);
                     68: static int               man_literal_pre(MAN_ARGS);
1.8       kristaps   69: static void              man_root_post(MAN_ARGS);
                     70: static int               man_root_pre(MAN_ARGS);
                     71: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   72: static int               man_HP_pre(MAN_ARGS);
1.8       kristaps   73: static int               man_I_pre(MAN_ARGS);
1.5       kristaps   74: static int               man_IP_pre(MAN_ARGS);
1.4       kristaps   75: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   76: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   77: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   78: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   79: static int               man_SS_pre(MAN_ARGS);
                     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.3       kristaps  103:        { NULL, 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.3       kristaps  115: };
                    116:
1.1       kristaps  117:
                    118: void
                    119: html_man(void *arg, const struct man *m)
                    120: {
1.3       kristaps  121:        struct html     *h;
                    122:        struct tag      *t;
1.45      kristaps  123:        struct mhtml     mh;
1.3       kristaps  124:
                    125:        h = (struct html *)arg;
                    126:
1.26      kristaps  127:        print_gen_decls(h);
1.3       kristaps  128:
1.45      kristaps  129:        memset(&mh, 0, sizeof(struct mhtml));
                    130:
1.3       kristaps  131:        t = print_otag(h, TAG_HTML, 0, NULL);
1.45      kristaps  132:        print_man(man_meta(m), man_node(m), &mh, h);
1.3       kristaps  133:        print_tagq(h, t);
                    134:
                    135:        printf("\n");
                    136: }
                    137:
                    138:
                    139: static void
                    140: print_man(MAN_ARGS)
                    141: {
                    142:        struct tag      *t;
                    143:
                    144:        t = print_otag(h, TAG_HEAD, 0, NULL);
1.45      kristaps  145:        print_man_head(m, n, mh, h);
1.3       kristaps  146:        print_tagq(h, t);
1.53      kristaps  147:
1.3       kristaps  148:        t = print_otag(h, TAG_BODY, 0, NULL);
1.45      kristaps  149:        print_man_nodelist(m, n, mh, h);
1.3       kristaps  150:        print_tagq(h, t);
                    151: }
                    152:
                    153:
                    154: /* ARGSUSED */
                    155: static void
                    156: print_man_head(MAN_ARGS)
                    157: {
                    158:
                    159:        print_gen_head(h);
                    160:        bufinit(h);
1.31      kristaps  161:        buffmt(h, "%s(%s)", m->title, m->msec);
1.3       kristaps  162:
                    163:        print_otag(h, TAG_TITLE, 0, NULL);
                    164:        print_text(h, h->buf);
1.1       kristaps  165: }
1.4       kristaps  166:
                    167:
                    168: static void
                    169: print_man_nodelist(MAN_ARGS)
                    170: {
                    171:
1.45      kristaps  172:        print_man_node(m, n, mh, h);
1.4       kristaps  173:        if (n->next)
1.45      kristaps  174:                print_man_nodelist(m, n->next, mh, h);
1.4       kristaps  175: }
                    176:
                    177:
                    178: static void
                    179: print_man_node(MAN_ARGS)
                    180: {
                    181:        int              child;
                    182:        struct tag      *t;
                    183:
                    184:        child = 1;
1.14      kristaps  185:        t = h->tags.head;
1.4       kristaps  186:
                    187:        bufinit(h);
                    188:
1.28      kristaps  189:        /*
                    190:         * FIXME: embedded elements within next-line scopes (e.g., `br'
                    191:         * within an empty `B') will cause formatting to be forgotten
                    192:         * due to scope closing out.
                    193:         */
                    194:
1.4       kristaps  195:        switch (n->type) {
                    196:        case (MAN_ROOT):
1.45      kristaps  197:                child = man_root_pre(m, n, mh, h);
1.4       kristaps  198:                break;
                    199:        case (MAN_TEXT):
1.63    ! kristaps  200:                if ('\0' == *n->string) {
        !           201:                        print_otag(h, TAG_P, 0, NULL);
        !           202:                        return;
        !           203:                }
        !           204:
        !           205:                if (' ' == *n->string && MAN_LINE & n->flags)
        !           206:                        print_otag(h, TAG_BR, 0, NULL);
        !           207:
1.4       kristaps  208:                print_text(h, n->string);
1.63    ! kristaps  209:
1.45      kristaps  210:                if (MANH_LITERAL & mh->fl)
                    211:                        print_otag(h, TAG_BR, 0, NULL);
1.58      kristaps  212:                return;
                    213:        case (MAN_TBL):
1.60      kristaps  214:                print_tbl(h, n->span);
                    215:                break;
1.4       kristaps  216:        default:
1.21      kristaps  217:                /*
                    218:                 * Close out scope of font prior to opening a macro
                    219:                 * scope.  Assert that the metafont is on the top of the
                    220:                 * stack (it's never nested).
                    221:                 */
1.57      kristaps  222:                if (HTMLFONT_NONE != h->metac) {
                    223:                        h->metal = h->metac;
                    224:                        h->metac = HTMLFONT_NONE;
1.20      kristaps  225:                }
1.4       kristaps  226:                if (mans[n->tok].pre)
1.45      kristaps  227:                        child = (*mans[n->tok].pre)(m, n, mh, h);
1.4       kristaps  228:                break;
                    229:        }
                    230:
1.21      kristaps  231:        if (child && n->child)
1.45      kristaps  232:                print_man_nodelist(m, n->child, mh, h);
1.21      kristaps  233:
1.24      kristaps  234:        /* This will automatically close out any font scope. */
1.4       kristaps  235:        print_stagq(h, t);
                    236:
                    237:        bufinit(h);
                    238:
1.61      kristaps  239:        switch (n->type) {
                    240:        case (MAN_ROOT):
1.45      kristaps  241:                man_root_post(m, n, mh, h);
1.61      kristaps  242:                break;
                    243:        case (MAN_TBL):
                    244:                break;
                    245:        default:
                    246:                if (mans[n->tok].post)
                    247:                        (*mans[n->tok].post)(m, n, mh, h);
                    248:                break;
                    249:        }
1.4       kristaps  250: }
                    251:
                    252:
1.5       kristaps  253: static int
1.7       kristaps  254: a2width(const struct man_node *n, struct roffsu *su)
1.5       kristaps  255: {
                    256:
1.6       kristaps  257:        if (MAN_TEXT != n->type)
1.7       kristaps  258:                return(0);
1.11      kristaps  259:        if (a2roffsu(n->string, su, SCALE_BU))
1.7       kristaps  260:                return(1);
1.5       kristaps  261:
1.7       kristaps  262:        return(0);
1.5       kristaps  263: }
                    264:
                    265:
1.40      kristaps  266: /* ARGSUSED */
1.4       kristaps  267: static int
                    268: man_root_pre(MAN_ARGS)
                    269: {
1.56      kristaps  270:        struct htmlpair  tag[3];
1.4       kristaps  271:        struct tag      *t, *tt;
                    272:        char             b[BUFSIZ], title[BUFSIZ];
                    273:
                    274:        b[0] = 0;
                    275:        if (m->vol)
                    276:                (void)strlcat(b, m->vol, BUFSIZ);
                    277:
1.31      kristaps  278:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.4       kristaps  279:
1.56      kristaps  280:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    281:        PAIR_CLASS_INIT(&tag[1], "head");
                    282:        if (NULL == h->style) {
                    283:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    284:                t = print_otag(h, TAG_TABLE, 3, tag);
                    285:                PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    286:                print_otag(h, TAG_COL, 1, tag);
                    287:                print_otag(h, TAG_COL, 1, tag);
                    288:                print_otag(h, TAG_COL, 1, tag);
                    289:        } else
                    290:                t = print_otag(h, TAG_TABLE, 2, tag);
                    291:
                    292:        print_otag(h, TAG_TBODY, 0, NULL);
1.15      kristaps  293:
1.4       kristaps  294:        tt = print_otag(h, TAG_TR, 0, NULL);
                    295:
1.55      kristaps  296:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.4       kristaps  297:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  298:
1.4       kristaps  299:        print_text(h, title);
                    300:        print_stagq(h, tt);
                    301:
1.55      kristaps  302:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.56      kristaps  303:        if (NULL == h->style) {
                    304:                PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    305:                print_otag(h, TAG_TD, 2, tag);
                    306:        } else
                    307:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  308:
1.4       kristaps  309:        print_text(h, b);
                    310:        print_stagq(h, tt);
                    311:
1.55      kristaps  312:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.56      kristaps  313:        if (NULL == h->style) {
                    314:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    315:                print_otag(h, TAG_TD, 2, tag);
                    316:        } else
                    317:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  318:
1.4       kristaps  319:        print_text(h, title);
                    320:        print_tagq(h, t);
                    321:        return(1);
                    322: }
                    323:
                    324:
                    325: /* ARGSUSED */
                    326: static void
                    327: man_root_post(MAN_ARGS)
                    328: {
1.56      kristaps  329:        struct htmlpair  tag[3];
1.4       kristaps  330:        struct tag      *t, *tt;
1.12      kristaps  331:        char             b[DATESIZ];
1.4       kristaps  332:
1.36      kristaps  333:        if (m->rawdate)
                    334:                strlcpy(b, m->rawdate, DATESIZ);
                    335:        else
                    336:                time2a(m->date, b, DATESIZ);
1.4       kristaps  337:
1.56      kristaps  338:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    339:        PAIR_CLASS_INIT(&tag[1], "foot");
                    340:        if (NULL == h->style) {
                    341:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    342:                t = print_otag(h, TAG_TABLE, 3, tag);
                    343:                PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    344:                print_otag(h, TAG_COL, 1, tag);
                    345:                print_otag(h, TAG_COL, 1, tag);
                    346:        } else
                    347:                t = print_otag(h, TAG_TABLE, 2, tag);
1.15      kristaps  348:
1.4       kristaps  349:        tt = print_otag(h, TAG_TR, 0, NULL);
                    350:
1.55      kristaps  351:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.4       kristaps  352:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  353:
1.4       kristaps  354:        print_text(h, b);
                    355:        print_stagq(h, tt);
                    356:
1.55      kristaps  357:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.56      kristaps  358:        if (NULL == h->style) {
                    359:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    360:                print_otag(h, TAG_TD, 2, tag);
                    361:        } else
                    362:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  363:
1.4       kristaps  364:        if (m->source)
                    365:                print_text(h, m->source);
                    366:        print_tagq(h, t);
                    367: }
                    368:
                    369:
                    370:
                    371: /* ARGSUSED */
                    372: static int
                    373: man_br_pre(MAN_ARGS)
                    374: {
1.7       kristaps  375:        struct roffsu    su;
                    376:        struct htmlpair  tag;
1.4       kristaps  377:
1.7       kristaps  378:        SCALE_VS_INIT(&su, 1);
                    379:
1.49      kristaps  380:        if (MAN_sp == n->tok) {
1.29      kristaps  381:                if (n->child)
                    382:                        a2roffsu(n->child->string, &su, SCALE_VS);
1.49      kristaps  383:        } else
1.7       kristaps  384:                su.scale = 0;
1.4       kristaps  385:
1.7       kristaps  386:        bufcat_su(h, "height", &su);
                    387:        PAIR_STYLE_INIT(&tag, h);
1.4       kristaps  388:        print_otag(h, TAG_DIV, 1, &tag);
1.24      kristaps  389:
1.16      kristaps  390:        /* So the div isn't empty: */
                    391:        print_text(h, "\\~");
                    392:
1.7       kristaps  393:        return(0);
1.4       kristaps  394: }
                    395:
                    396:
                    397: /* ARGSUSED */
                    398: static int
                    399: man_SH_pre(MAN_ARGS)
                    400: {
1.54      kristaps  401:        struct htmlpair  tag;
1.4       kristaps  402:
1.54      kristaps  403:        if (MAN_BLOCK == n->type) {
                    404:                PAIR_CLASS_INIT(&tag, "section");
                    405:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  406:                return(1);
1.54      kristaps  407:        } else if (MAN_BODY == n->type)
1.4       kristaps  408:                return(1);
                    409:
1.54      kristaps  410:        print_otag(h, TAG_H1, 0, NULL);
1.4       kristaps  411:        return(1);
                    412: }
                    413:
                    414:
                    415: /* ARGSUSED */
                    416: static int
1.8       kristaps  417: man_alt_pre(MAN_ARGS)
                    418: {
                    419:        const struct man_node   *nn;
1.57      kristaps  420:        int              i;
                    421:        enum htmltag     fp;
                    422:        struct tag      *t;
1.8       kristaps  423:
                    424:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.57      kristaps  425:                t = NULL;
1.8       kristaps  426:                switch (n->tok) {
                    427:                case (MAN_BI):
1.57      kristaps  428:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  429:                        break;
                    430:                case (MAN_IB):
1.57      kristaps  431:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  432:                        break;
                    433:                case (MAN_RI):
1.57      kristaps  434:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  435:                        break;
                    436:                case (MAN_IR):
1.57      kristaps  437:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  438:                        break;
                    439:                case (MAN_BR):
1.57      kristaps  440:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  441:                        break;
                    442:                case (MAN_RB):
1.57      kristaps  443:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  444:                        break;
                    445:                default:
                    446:                        abort();
                    447:                        /* NOTREACHED */
                    448:                }
                    449:
                    450:                if (i)
                    451:                        h->flags |= HTML_NOSPACE;
                    452:
1.57      kristaps  453:                if (TAG_MAX != fp)
                    454:                        t = print_otag(h, fp, 0, NULL);
                    455:
1.45      kristaps  456:                print_man_node(m, nn, mh, h);
1.57      kristaps  457:
                    458:                if (t)
                    459:                        print_tagq(h, t);
1.8       kristaps  460:        }
                    461:
                    462:        return(0);
                    463: }
                    464:
                    465:
                    466: /* ARGSUSED */
                    467: static int
1.56      kristaps  468: man_SM_pre(MAN_ARGS)
1.8       kristaps  469: {
                    470:
1.57      kristaps  471:        print_otag(h, TAG_SMALL, 0, NULL);
1.56      kristaps  472:        if (MAN_SB == n->tok)
1.57      kristaps  473:                print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  474:        return(1);
                    475: }
                    476:
                    477:
                    478: /* ARGSUSED */
                    479: static int
1.4       kristaps  480: man_SS_pre(MAN_ARGS)
                    481: {
1.54      kristaps  482:        struct htmlpair  tag;
1.4       kristaps  483:
1.54      kristaps  484:        if (MAN_BLOCK == n->type) {
                    485:                PAIR_CLASS_INIT(&tag, "subsection");
                    486:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  487:                return(1);
1.54      kristaps  488:        } else if (MAN_BODY == n->type)
1.4       kristaps  489:                return(1);
                    490:
1.54      kristaps  491:        print_otag(h, TAG_H2, 0, NULL);
1.4       kristaps  492:        return(1);
                    493: }
                    494:
                    495:
                    496: /* ARGSUSED */
                    497: static int
                    498: man_PP_pre(MAN_ARGS)
                    499: {
                    500:
1.47      kristaps  501:        if (MAN_HEAD == n->type)
                    502:                return(0);
1.56      kristaps  503:        else if (MAN_BODY == n->type && n->prev)
                    504:                print_otag(h, TAG_P, 0, NULL);
1.47      kristaps  505:
1.5       kristaps  506:        return(1);
                    507: }
                    508:
                    509:
                    510: /* ARGSUSED */
                    511: static int
                    512: man_IP_pre(MAN_ARGS)
                    513: {
1.7       kristaps  514:        struct roffsu            su;
1.5       kristaps  515:        struct htmlpair          tag;
                    516:        const struct man_node   *nn;
                    517:
1.7       kristaps  518:        /*
                    519:         * This scattering of 1-BU margins and pads is to make sure that
                    520:         * when text overruns its box, the subsequent text isn't flush
                    521:         * up against it.  However, the rest of the right-hand box must
                    522:         * also be adjusted in consideration of this 1-BU space.
                    523:         */
                    524:
                    525:        if (MAN_BODY == n->type) {
1.56      kristaps  526:                print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  527:                return(1);
                    528:        }
                    529:
                    530:        nn = MAN_BLOCK == n->type ?
                    531:                n->head->child : n->parent->head->child;
                    532:
1.7       kristaps  533:        SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  534:
1.59      schwarze  535:        /* Width is the second token. */
1.28      kristaps  536:
1.7       kristaps  537:        if (MAN_IP == n->tok && NULL != nn)
1.59      schwarze  538:                if (NULL != (nn = nn->next))
1.62      kristaps  539:                        a2width(nn, &su);
1.5       kristaps  540:
1.28      kristaps  541:        /* Width is the first token. */
                    542:
1.27      kristaps  543:        if (MAN_TP == n->tok && NULL != nn) {
1.28      kristaps  544:                /* Skip past non-text children. */
1.27      kristaps  545:                while (nn && MAN_TEXT != nn->type)
                    546:                        nn = nn->next;
1.28      kristaps  547:                if (nn)
1.62      kristaps  548:                        a2width(nn, &su);
1.27      kristaps  549:        }
1.7       kristaps  550:
1.5       kristaps  551:        if (MAN_BLOCK == n->type) {
1.56      kristaps  552:                print_otag(h, TAG_P, 0, NULL);
                    553:                print_otag(h, TAG_TABLE, 0, NULL);
                    554:                bufcat_su(h, "width", &su);
1.7       kristaps  555:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  556:                print_otag(h, TAG_COL, 1, &tag);
                    557:                print_otag(h, TAG_COL, 0, NULL);
                    558:                print_otag(h, TAG_TBODY, 0, NULL);
                    559:                print_otag(h, TAG_TR, 0, NULL);
1.5       kristaps  560:                return(1);
1.6       kristaps  561:        }
                    562:
1.56      kristaps  563:        print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  564:
1.59      schwarze  565:        /* For IP, only print the first header element. */
1.7       kristaps  566:
1.59      schwarze  567:        if (MAN_IP == n->tok && n->child)
                    568:                print_man_node(m, n->child, mh, h);
1.27      kristaps  569:
1.59      schwarze  570:        /* For TP, only print next-line header elements. */
1.6       kristaps  571:
1.7       kristaps  572:        if (MAN_TP == n->tok)
1.59      schwarze  573:                for (nn = n->child; nn; nn = nn->next)
                    574:                        if (nn->line > n->line)
                    575:                                print_man_node(m, nn, mh, h);
1.6       kristaps  576:
                    577:        return(0);
                    578: }
                    579:
                    580:
                    581: /* ARGSUSED */
                    582: static int
                    583: man_HP_pre(MAN_ARGS)
                    584: {
1.56      kristaps  585:        struct htmlpair  tag;
                    586:        struct roffsu    su;
                    587:        const struct man_node *np;
1.6       kristaps  588:
1.56      kristaps  589:        np = MAN_BLOCK == n->type ?
                    590:                n->head->child :
                    591:                n->parent->head->child;
1.6       kristaps  592:
1.56      kristaps  593:        if (NULL == np || ! a2width(np, &su))
                    594:                SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  595:
1.56      kristaps  596:        if (MAN_HEAD == n->type) {
                    597:                print_otag(h, TAG_TD, 0, NULL);
                    598:                return(0);
                    599:        } else if (MAN_BLOCK == n->type) {
                    600:                print_otag(h, TAG_P, 0, NULL);
                    601:                print_otag(h, TAG_TABLE, 0, NULL);
                    602:                bufcat_su(h, "width", &su);
1.7       kristaps  603:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  604:                print_otag(h, TAG_COL, 1, &tag);
                    605:                print_otag(h, TAG_COL, 0, NULL);
                    606:                print_otag(h, TAG_TBODY, 0, NULL);
                    607:                print_otag(h, TAG_TR, 0, NULL);
1.6       kristaps  608:                return(1);
                    609:        }
1.5       kristaps  610:
1.56      kristaps  611:        su.scale = -su.scale;
1.7       kristaps  612:        bufcat_su(h, "text-indent", &su);
                    613:        PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  614:        print_otag(h, TAG_TD, 1, &tag);
1.4       kristaps  615:        return(1);
                    616: }
1.6       kristaps  617:
1.8       kristaps  618:
                    619: /* ARGSUSED */
                    620: static int
                    621: man_B_pre(MAN_ARGS)
                    622: {
                    623:
1.57      kristaps  624:        print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  625:        return(1);
                    626: }
                    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:
                    639: /* ARGSUSED */
                    640: static int
                    641: man_literal_pre(MAN_ARGS)
                    642: {
                    643:
1.48      kristaps  644:        if (MAN_nf == n->tok) {
1.45      kristaps  645:                print_otag(h, TAG_BR, 0, NULL);
                    646:                mh->fl |= MANH_LITERAL;
1.48      kristaps  647:        } else
1.45      kristaps  648:                mh->fl &= ~MANH_LITERAL;
                    649:
                    650:        return(1);
                    651: }
                    652:
                    653:
                    654: /* ARGSUSED */
                    655: static int
                    656: man_in_pre(MAN_ARGS)
                    657: {
                    658:
                    659:        print_otag(h, TAG_BR, 0, NULL);
                    660:        return(0);
1.8       kristaps  661: }
                    662:
                    663:
                    664: /* ARGSUSED */
                    665: static int
                    666: man_ign_pre(MAN_ARGS)
                    667: {
                    668:
                    669:        return(0);
                    670: }
1.9       kristaps  671:
                    672:
                    673: /* ARGSUSED */
                    674: static int
                    675: man_RS_pre(MAN_ARGS)
                    676: {
                    677:        struct htmlpair  tag;
                    678:        struct roffsu    su;
                    679:
                    680:        if (MAN_HEAD == n->type)
                    681:                return(0);
                    682:        else if (MAN_BODY == n->type)
                    683:                return(1);
                    684:
                    685:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  686:        if (n->head->child)
1.9       kristaps  687:                a2width(n->head->child, &su);
                    688:
1.56      kristaps  689:        bufcat_su(h, "margin-left", &su);
1.9       kristaps  690:        PAIR_STYLE_INIT(&tag, h);
                    691:        print_otag(h, TAG_DIV, 1, &tag);
                    692:        return(1);
                    693: }

CVSweb