[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.33

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