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

1.11    ! schwarze    1: /*     $Id: man_html.c,v 1.10 2010/05/15 18:06:02 schwarze Exp $ */
1.1       schwarze    2: /*
                      3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
                      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:
                     25: #include "out.h"
                     26: #include "html.h"
                     27: #include "man.h"
                     28: #include "main.h"
                     29:
                     30: /* TODO: preserve ident widths. */
1.2       schwarze   31: /* FIXME: have PD set the default vspace width. */
1.1       schwarze   32:
                     33: #define        INDENT            5
                     34: #define        HALFINDENT        3
                     35:
                     36: #define        MAN_ARGS          const struct man_meta *m, \
                     37:                          const struct man_node *n, \
                     38:                          struct html *h
                     39:
                     40: struct htmlman {
                     41:        int             (*pre)(MAN_ARGS);
                     42:        int             (*post)(MAN_ARGS);
                     43: };
                     44:
                     45: static void              print_man(MAN_ARGS);
                     46: static void              print_man_head(MAN_ARGS);
                     47: static void              print_man_nodelist(MAN_ARGS);
                     48: static void              print_man_node(MAN_ARGS);
                     49:
                     50: static int               a2width(const struct man_node *,
                     51:                                struct roffsu *);
                     52:
                     53: static int               man_alt_pre(MAN_ARGS);
                     54: static int               man_br_pre(MAN_ARGS);
                     55: static int               man_ign_pre(MAN_ARGS);
                     56: static void              man_root_post(MAN_ARGS);
                     57: static int               man_root_pre(MAN_ARGS);
                     58: static int               man_B_pre(MAN_ARGS);
                     59: static int               man_HP_pre(MAN_ARGS);
                     60: static int               man_I_pre(MAN_ARGS);
                     61: static int               man_IP_pre(MAN_ARGS);
                     62: static int               man_PP_pre(MAN_ARGS);
                     63: static int               man_RS_pre(MAN_ARGS);
                     64: static int               man_SB_pre(MAN_ARGS);
                     65: static int               man_SH_pre(MAN_ARGS);
                     66: static int               man_SM_pre(MAN_ARGS);
                     67: static int               man_SS_pre(MAN_ARGS);
                     68:
                     69: static const struct htmlman mans[MAN_MAX] = {
                     70:        { man_br_pre, NULL }, /* br */
                     71:        { NULL, NULL }, /* TH */
                     72:        { man_SH_pre, NULL }, /* SH */
                     73:        { man_SS_pre, NULL }, /* SS */
                     74:        { man_IP_pre, NULL }, /* TP */
                     75:        { man_PP_pre, NULL }, /* LP */
                     76:        { man_PP_pre, NULL }, /* PP */
                     77:        { man_PP_pre, NULL }, /* P */
                     78:        { man_IP_pre, NULL }, /* IP */
                     79:        { man_HP_pre, NULL }, /* HP */
                     80:        { man_SM_pre, NULL }, /* SM */
                     81:        { man_SB_pre, NULL }, /* SB */
                     82:        { man_alt_pre, NULL }, /* BI */
                     83:        { man_alt_pre, NULL }, /* IB */
                     84:        { man_alt_pre, NULL }, /* BR */
                     85:        { man_alt_pre, NULL }, /* RB */
                     86:        { NULL, NULL }, /* R */
                     87:        { man_B_pre, NULL }, /* B */
                     88:        { man_I_pre, NULL }, /* I */
                     89:        { man_alt_pre, NULL }, /* IR */
                     90:        { man_alt_pre, NULL }, /* RI */
                     91:        { NULL, NULL }, /* na */
                     92:        { NULL, NULL }, /* i */
                     93:        { man_br_pre, NULL }, /* sp */
                     94:        { NULL, NULL }, /* nf */
                     95:        { NULL, NULL }, /* fi */
                     96:        { NULL, NULL }, /* r */
                     97:        { NULL, NULL }, /* RE */
                     98:        { man_RS_pre, NULL }, /* RS */
                     99:        { man_ign_pre, NULL }, /* DT */
                    100:        { man_ign_pre, NULL }, /* UC */
1.2       schwarze  101:        { man_ign_pre, NULL }, /* PD */
1.6       schwarze  102:        { man_br_pre, NULL }, /* Sp */
1.8       schwarze  103:        { man_ign_pre, NULL }, /* Vb */
                    104:        { NULL, NULL }, /* Ve */
1.9       schwarze  105:        { NULL, NULL }, /* if */
                    106:        { NULL, NULL }, /* ie */
                    107:        { NULL, NULL }, /* el */
1.1       schwarze  108: };
                    109:
                    110:
                    111: void
                    112: html_man(void *arg, const struct man *m)
                    113: {
                    114:        struct html     *h;
                    115:        struct tag      *t;
                    116:
                    117:        h = (struct html *)arg;
                    118:
1.5       schwarze  119:        print_gen_decls(h);
1.1       schwarze  120:
                    121:        t = print_otag(h, TAG_HTML, 0, NULL);
                    122:        print_man(man_meta(m), man_node(m), h);
                    123:        print_tagq(h, t);
                    124:
                    125:        printf("\n");
                    126: }
                    127:
                    128:
                    129: static void
                    130: print_man(MAN_ARGS)
                    131: {
                    132:        struct tag      *t;
                    133:        struct htmlpair  tag;
                    134:
                    135:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    136:
                    137:        print_man_head(m, n, h);
                    138:        print_tagq(h, t);
                    139:        t = print_otag(h, TAG_BODY, 0, NULL);
                    140:
                    141:        tag.key = ATTR_CLASS;
                    142:        tag.val = "body";
                    143:        print_otag(h, TAG_DIV, 1, &tag);
                    144:
                    145:        print_man_nodelist(m, n, h);
                    146:
                    147:        print_tagq(h, t);
                    148: }
                    149:
                    150:
                    151: /* ARGSUSED */
                    152: static void
                    153: print_man_head(MAN_ARGS)
                    154: {
                    155:
                    156:        print_gen_head(h);
                    157:        bufinit(h);
1.10      schwarze  158:        buffmt(h, "%s(%s)", m->title, m->msec);
1.1       schwarze  159:
                    160:        print_otag(h, TAG_TITLE, 0, NULL);
                    161:        print_text(h, h->buf);
                    162: }
                    163:
                    164:
                    165: static void
                    166: print_man_nodelist(MAN_ARGS)
                    167: {
                    168:
                    169:        print_man_node(m, n, h);
                    170:        if (n->next)
                    171:                print_man_nodelist(m, n->next, h);
                    172: }
                    173:
                    174:
                    175: static void
                    176: print_man_node(MAN_ARGS)
                    177: {
                    178:        int              child;
                    179:        struct tag      *t;
                    180:
                    181:        child = 1;
1.2       schwarze  182:        t = h->tags.head;
1.1       schwarze  183:
                    184:        bufinit(h);
                    185:
1.7       schwarze  186:        /*
                    187:         * FIXME: embedded elements within next-line scopes (e.g., `br'
                    188:         * within an empty `B') will cause formatting to be forgotten
                    189:         * due to scope closing out.
                    190:         */
                    191:
1.1       schwarze  192:        switch (n->type) {
                    193:        case (MAN_ROOT):
                    194:                child = man_root_pre(m, n, h);
                    195:                break;
                    196:        case (MAN_TEXT):
                    197:                print_text(h, n->string);
1.4       schwarze  198:                return;
1.1       schwarze  199:        default:
1.4       schwarze  200:                /*
                    201:                 * Close out scope of font prior to opening a macro
                    202:                 * scope.  Assert that the metafont is on the top of the
                    203:                 * stack (it's never nested).
                    204:                 */
                    205:                if (h->metaf) {
                    206:                        assert(h->metaf == t);
                    207:                        print_tagq(h, h->metaf);
                    208:                        assert(NULL == h->metaf);
                    209:                        t = h->tags.head;
                    210:                }
1.1       schwarze  211:                if (mans[n->tok].pre)
                    212:                        child = (*mans[n->tok].pre)(m, n, h);
                    213:                break;
                    214:        }
                    215:
                    216:        if (child && n->child)
                    217:                print_man_nodelist(m, n->child, h);
                    218:
1.4       schwarze  219:        /* This will automatically close out any font scope. */
1.1       schwarze  220:        print_stagq(h, t);
                    221:
                    222:        bufinit(h);
                    223:
                    224:        switch (n->type) {
                    225:        case (MAN_ROOT):
                    226:                man_root_post(m, n, h);
                    227:                break;
                    228:        case (MAN_TEXT):
                    229:                break;
                    230:        default:
                    231:                if (mans[n->tok].post)
                    232:                        (*mans[n->tok].post)(m, n, h);
                    233:                break;
                    234:        }
                    235: }
                    236:
                    237:
                    238: static int
                    239: a2width(const struct man_node *n, struct roffsu *su)
                    240: {
                    241:
                    242:        if (MAN_TEXT != n->type)
                    243:                return(0);
                    244:        if (a2roffsu(n->string, su, SCALE_BU))
                    245:                return(1);
                    246:
                    247:        return(0);
                    248: }
                    249:
                    250:
                    251: /* ARGSUSED */
                    252: static int
                    253: man_root_pre(MAN_ARGS)
                    254: {
1.3       schwarze  255:        struct htmlpair  tag[3];
1.1       schwarze  256:        struct tag      *t, *tt;
                    257:        char             b[BUFSIZ], title[BUFSIZ];
                    258:
                    259:        b[0] = 0;
                    260:        if (m->vol)
                    261:                (void)strlcat(b, m->vol, BUFSIZ);
                    262:
1.10      schwarze  263:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.1       schwarze  264:
                    265:        PAIR_CLASS_INIT(&tag[0], "header");
                    266:        bufcat_style(h, "width", "100%");
                    267:        PAIR_STYLE_INIT(&tag[1], h);
1.3       schwarze  268:        PAIR_SUMMARY_INIT(&tag[2], "header");
                    269:
                    270:        t = print_otag(h, TAG_TABLE, 3, tag);
1.1       schwarze  271:        tt = print_otag(h, TAG_TR, 0, NULL);
                    272:
                    273:        bufinit(h);
                    274:        bufcat_style(h, "width", "10%");
                    275:        PAIR_STYLE_INIT(&tag[0], h);
                    276:        print_otag(h, TAG_TD, 1, tag);
                    277:        print_text(h, title);
                    278:        print_stagq(h, tt);
                    279:
                    280:        bufinit(h);
                    281:        bufcat_style(h, "width", "80%");
                    282:        bufcat_style(h, "white-space", "nowrap");
                    283:        bufcat_style(h, "text-align", "center");
                    284:        PAIR_STYLE_INIT(&tag[0], h);
                    285:        print_otag(h, TAG_TD, 1, tag);
                    286:        print_text(h, b);
                    287:        print_stagq(h, tt);
                    288:
                    289:        bufinit(h);
                    290:        bufcat_style(h, "width", "10%");
                    291:        bufcat_style(h, "text-align", "right");
                    292:        PAIR_STYLE_INIT(&tag[0], h);
                    293:        print_otag(h, TAG_TD, 1, tag);
                    294:        print_text(h, title);
                    295:        print_tagq(h, t);
                    296:        return(1);
                    297: }
                    298:
                    299:
                    300: /* ARGSUSED */
                    301: static void
                    302: man_root_post(MAN_ARGS)
                    303: {
1.3       schwarze  304:        struct htmlpair  tag[3];
1.1       schwarze  305:        struct tag      *t, *tt;
1.2       schwarze  306:        char             b[DATESIZ];
1.1       schwarze  307:
1.2       schwarze  308:        time2a(m->date, b, DATESIZ);
1.1       schwarze  309:
                    310:        PAIR_CLASS_INIT(&tag[0], "footer");
                    311:        bufcat_style(h, "width", "100%");
                    312:        PAIR_STYLE_INIT(&tag[1], h);
1.3       schwarze  313:        PAIR_SUMMARY_INIT(&tag[2], "footer");
                    314:
                    315:        t = print_otag(h, TAG_TABLE, 3, tag);
1.1       schwarze  316:        tt = print_otag(h, TAG_TR, 0, NULL);
                    317:
                    318:        bufinit(h);
                    319:        bufcat_style(h, "width", "50%");
                    320:        PAIR_STYLE_INIT(&tag[0], h);
                    321:        print_otag(h, TAG_TD, 1, tag);
                    322:        print_text(h, b);
                    323:        print_stagq(h, tt);
                    324:
                    325:        bufinit(h);
                    326:        bufcat_style(h, "width", "50%");
                    327:        bufcat_style(h, "text-align", "right");
                    328:        PAIR_STYLE_INIT(&tag[0], h);
                    329:        print_otag(h, TAG_TD, 1, tag);
                    330:        if (m->source)
                    331:                print_text(h, m->source);
                    332:        print_tagq(h, t);
                    333: }
                    334:
                    335:
                    336:
                    337: /* ARGSUSED */
                    338: static int
                    339: man_br_pre(MAN_ARGS)
                    340: {
                    341:        struct roffsu    su;
                    342:        struct htmlpair  tag;
                    343:
                    344:        SCALE_VS_INIT(&su, 1);
                    345:
1.8       schwarze  346:        switch (n->tok) {
                    347:        case (MAN_Sp):
                    348:                SCALE_VS_INIT(&su, 0.5);
                    349:                break;
                    350:        case (MAN_sp):
                    351:                if (n->child)
                    352:                        a2roffsu(n->child->string, &su, SCALE_VS);
                    353:                break;
                    354:        default:
1.1       schwarze  355:                su.scale = 0;
1.8       schwarze  356:                break;
                    357:        }
1.1       schwarze  358:
                    359:        bufcat_su(h, "height", &su);
                    360:        PAIR_STYLE_INIT(&tag, h);
                    361:        print_otag(h, TAG_DIV, 1, &tag);
1.4       schwarze  362:
1.3       schwarze  363:        /* So the div isn't empty: */
                    364:        print_text(h, "\\~");
                    365:
1.1       schwarze  366:        return(0);
                    367: }
                    368:
                    369:
                    370: /* ARGSUSED */
                    371: static int
                    372: man_SH_pre(MAN_ARGS)
                    373: {
                    374:        struct htmlpair  tag[2];
                    375:        struct roffsu    su;
                    376:
                    377:        if (MAN_BODY == n->type) {
                    378:                SCALE_HS_INIT(&su, INDENT);
                    379:                bufcat_su(h, "margin-left", &su);
                    380:                PAIR_CLASS_INIT(&tag[0], "sec-body");
                    381:                PAIR_STYLE_INIT(&tag[1], h);
                    382:                print_otag(h, TAG_DIV, 2, tag);
                    383:                return(1);
                    384:        } else if (MAN_BLOCK == n->type) {
                    385:                PAIR_CLASS_INIT(&tag[0], "sec-block");
                    386:                if (n->prev && MAN_SH == n->prev->tok)
                    387:                        if (NULL == n->prev->body->child) {
                    388:                                print_otag(h, TAG_DIV, 1, tag);
                    389:                                return(1);
                    390:                        }
                    391:
                    392:                SCALE_VS_INIT(&su, 1);
                    393:                bufcat_su(h, "margin-top", &su);
                    394:                if (NULL == n->next)
                    395:                        bufcat_su(h, "margin-bottom", &su);
                    396:                PAIR_STYLE_INIT(&tag[1], h);
                    397:                print_otag(h, TAG_DIV, 2, tag);
                    398:                return(1);
                    399:        }
                    400:
                    401:        PAIR_CLASS_INIT(&tag[0], "sec-head");
                    402:        print_otag(h, TAG_DIV, 1, tag);
                    403:        return(1);
                    404: }
                    405:
                    406:
                    407: /* ARGSUSED */
                    408: static int
                    409: man_alt_pre(MAN_ARGS)
                    410: {
                    411:        const struct man_node   *nn;
                    412:        struct tag              *t;
                    413:        int                      i;
1.4       schwarze  414:        enum htmlfont            fp;
1.1       schwarze  415:
                    416:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    417:                switch (n->tok) {
                    418:                case (MAN_BI):
1.4       schwarze  419:                        fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_BOLD;
1.1       schwarze  420:                        break;
                    421:                case (MAN_IB):
1.4       schwarze  422:                        fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_ITALIC;
1.1       schwarze  423:                        break;
                    424:                case (MAN_RI):
1.4       schwarze  425:                        fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_NONE;
1.1       schwarze  426:                        break;
                    427:                case (MAN_IR):
1.4       schwarze  428:                        fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_ITALIC;
1.1       schwarze  429:                        break;
                    430:                case (MAN_BR):
1.4       schwarze  431:                        fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_BOLD;
1.1       schwarze  432:                        break;
                    433:                case (MAN_RB):
1.4       schwarze  434:                        fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_NONE;
1.1       schwarze  435:                        break;
                    436:                default:
                    437:                        abort();
                    438:                        /* NOTREACHED */
                    439:                }
                    440:
                    441:                if (i)
                    442:                        h->flags |= HTML_NOSPACE;
                    443:
1.4       schwarze  444:                /*
                    445:                 * Open and close the scope with each argument, so that
                    446:                 * internal \f escapes, which are common, are also
                    447:                 * closed out with the scope.
                    448:                 */
                    449:                t = print_ofont(h, fp);
                    450:                print_man_node(m, nn, h);
                    451:                print_tagq(h, t);
1.1       schwarze  452:        }
                    453:
                    454:        return(0);
                    455: }
                    456:
                    457:
                    458: /* ARGSUSED */
                    459: static int
                    460: man_SB_pre(MAN_ARGS)
                    461: {
                    462:        struct htmlpair  tag;
                    463:
1.4       schwarze  464:        /* FIXME: print_ofont(). */
1.1       schwarze  465:        PAIR_CLASS_INIT(&tag, "small bold");
                    466:        print_otag(h, TAG_SPAN, 1, &tag);
                    467:        return(1);
                    468: }
                    469:
                    470:
                    471: /* ARGSUSED */
                    472: static int
                    473: man_SM_pre(MAN_ARGS)
                    474: {
                    475:        struct htmlpair  tag;
                    476:
                    477:        PAIR_CLASS_INIT(&tag, "small");
                    478:        print_otag(h, TAG_SPAN, 1, &tag);
                    479:        return(1);
                    480: }
                    481:
                    482:
                    483: /* ARGSUSED */
                    484: static int
                    485: man_SS_pre(MAN_ARGS)
                    486: {
                    487:        struct htmlpair  tag[3];
                    488:        struct roffsu    su;
                    489:
                    490:        SCALE_VS_INIT(&su, 1);
                    491:
                    492:        if (MAN_BODY == n->type) {
                    493:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
                    494:                if (n->parent->next && n->child) {
                    495:                        bufcat_su(h, "margin-bottom", &su);
                    496:                        PAIR_STYLE_INIT(&tag[1], h);
                    497:                        print_otag(h, TAG_DIV, 2, tag);
                    498:                        return(1);
                    499:                }
                    500:
                    501:                print_otag(h, TAG_DIV, 1, tag);
                    502:                return(1);
                    503:        } else if (MAN_BLOCK == n->type) {
                    504:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
                    505:                if (n->prev && MAN_SS == n->prev->tok)
                    506:                        if (n->prev->body->child) {
                    507:                                bufcat_su(h, "margin-top", &su);
                    508:                                PAIR_STYLE_INIT(&tag[1], h);
                    509:                                print_otag(h, TAG_DIV, 2, tag);
                    510:                                return(1);
                    511:                        }
                    512:
                    513:                print_otag(h, TAG_DIV, 1, tag);
                    514:                return(1);
                    515:        }
                    516:
                    517:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    518:        bufcat_su(h, "margin-left", &su);
                    519:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    520:        PAIR_STYLE_INIT(&tag[1], h);
                    521:        print_otag(h, TAG_DIV, 2, tag);
                    522:        return(1);
                    523: }
                    524:
                    525:
                    526: /* ARGSUSED */
                    527: static int
                    528: man_PP_pre(MAN_ARGS)
                    529: {
                    530:        struct htmlpair  tag;
                    531:        struct roffsu    su;
                    532:        int              i;
                    533:
                    534:        if (MAN_BLOCK != n->type)
                    535:                return(1);
                    536:
                    537:        i = 0;
                    538:
1.4       schwarze  539:        if (MAN_ROOT == n->parent->type) {
1.1       schwarze  540:                SCALE_HS_INIT(&su, INDENT);
                    541:                bufcat_su(h, "margin-left", &su);
1.4       schwarze  542:                i = 1;
1.1       schwarze  543:        }
1.4       schwarze  544:        if (n->prev) {
1.1       schwarze  545:                SCALE_VS_INIT(&su, 1);
1.4       schwarze  546:                bufcat_su(h, "margin-top", &su);
                    547:                i = 1;
1.1       schwarze  548:        }
                    549:
                    550:        PAIR_STYLE_INIT(&tag, h);
1.4       schwarze  551:        print_otag(h, TAG_DIV, i, &tag);
1.1       schwarze  552:        return(1);
                    553: }
                    554:
                    555:
                    556: /* ARGSUSED */
                    557: static int
                    558: man_IP_pre(MAN_ARGS)
                    559: {
                    560:        struct roffsu            su;
                    561:        struct htmlpair          tag;
                    562:        const struct man_node   *nn;
                    563:        int                      width;
                    564:
                    565:        /*
                    566:         * This scattering of 1-BU margins and pads is to make sure that
                    567:         * when text overruns its box, the subsequent text isn't flush
                    568:         * up against it.  However, the rest of the right-hand box must
                    569:         * also be adjusted in consideration of this 1-BU space.
                    570:         */
                    571:
                    572:        if (MAN_BODY == n->type) {
                    573:                SCALE_HS_INIT(&su, INDENT);
                    574:                bufcat_su(h, "margin-left", &su);
                    575:                PAIR_STYLE_INIT(&tag, h);
                    576:                print_otag(h, TAG_DIV, 1, &tag);
                    577:                return(1);
                    578:        }
                    579:
                    580:        nn = MAN_BLOCK == n->type ?
                    581:                n->head->child : n->parent->head->child;
                    582:
                    583:        SCALE_HS_INIT(&su, INDENT);
                    584:        width = 0;
                    585:
1.7       schwarze  586:        /* Width is the last token. */
                    587:
1.1       schwarze  588:        if (MAN_IP == n->tok && NULL != nn)
                    589:                if (NULL != (nn = nn->next)) {
                    590:                        for ( ; nn->next; nn = nn->next)
                    591:                                /* Do nothing. */ ;
                    592:                        width = a2width(nn, &su);
                    593:                }
                    594:
1.7       schwarze  595:        /* Width is the first token. */
                    596:
                    597:        if (MAN_TP == n->tok && NULL != nn) {
                    598:                /* Skip past non-text children. */
                    599:                while (nn && MAN_TEXT != nn->type)
                    600:                        nn = nn->next;
                    601:                if (nn)
                    602:                        width = a2width(nn, &su);
                    603:        }
1.1       schwarze  604:
                    605:        if (MAN_BLOCK == n->type) {
                    606:                bufcat_su(h, "margin-left", &su);
                    607:                SCALE_VS_INIT(&su, 1);
                    608:                bufcat_su(h, "margin-top", &su);
                    609:                bufcat_style(h, "clear", "both");
                    610:                PAIR_STYLE_INIT(&tag, h);
                    611:                print_otag(h, TAG_DIV, 1, &tag);
                    612:                return(1);
                    613:        }
                    614:
                    615:        bufcat_su(h, "min-width", &su);
                    616:        SCALE_INVERT(&su);
                    617:        bufcat_su(h, "margin-left", &su);
                    618:        SCALE_HS_INIT(&su, 1);
                    619:        bufcat_su(h, "margin-right", &su);
                    620:        bufcat_style(h, "clear", "left");
                    621:
                    622:        if (n->next && n->next->child)
                    623:                bufcat_style(h, "float", "left");
                    624:
                    625:        PAIR_STYLE_INIT(&tag, h);
                    626:        print_otag(h, TAG_DIV, 1, &tag);
                    627:
1.7       schwarze  628:        /*
                    629:         * Without a length string, we can print all of our children.
                    630:         */
1.1       schwarze  631:
                    632:        if ( ! width)
                    633:                return(1);
1.7       schwarze  634:
                    635:        /*
                    636:         * When a length has been specified, we need to carefully print
                    637:         * our child context:  IP gets all children printed but the last
                    638:         * (the width), while TP gets all children printed but the first
                    639:         * (the width).
                    640:         */
1.1       schwarze  641:
                    642:        if (MAN_IP == n->tok)
                    643:                for (nn = n->child; nn->next; nn = nn->next)
                    644:                        print_man_node(m, nn, h);
                    645:        if (MAN_TP == n->tok)
                    646:                for (nn = n->child->next; nn; nn = nn->next)
                    647:                        print_man_node(m, nn, h);
                    648:
                    649:        return(0);
                    650: }
                    651:
                    652:
                    653: /* ARGSUSED */
                    654: static int
                    655: man_HP_pre(MAN_ARGS)
                    656: {
                    657:        const struct man_node   *nn;
                    658:        struct htmlpair          tag;
                    659:        struct roffsu            su;
                    660:
                    661:        if (MAN_HEAD == n->type)
                    662:                return(0);
                    663:
                    664:        nn = MAN_BLOCK == n->type ?
                    665:                n->head->child : n->parent->head->child;
                    666:
                    667:        SCALE_HS_INIT(&su, INDENT);
                    668:
                    669:        if (NULL != nn)
                    670:                (void)a2width(nn, &su);
                    671:
                    672:        if (MAN_BLOCK == n->type) {
                    673:                bufcat_su(h, "margin-left", &su);
                    674:                SCALE_VS_INIT(&su, 1);
                    675:                bufcat_su(h, "margin-top", &su);
                    676:                bufcat_style(h, "clear", "both");
                    677:                PAIR_STYLE_INIT(&tag, h);
                    678:                print_otag(h, TAG_DIV, 1, &tag);
                    679:                return(1);
                    680:        }
                    681:
                    682:        bufcat_su(h, "margin-left", &su);
                    683:        SCALE_INVERT(&su);
                    684:        bufcat_su(h, "text-indent", &su);
                    685:
                    686:        PAIR_STYLE_INIT(&tag, h);
                    687:        print_otag(h, TAG_DIV, 1, &tag);
                    688:        return(1);
                    689: }
                    690:
                    691:
                    692: /* ARGSUSED */
                    693: static int
                    694: man_B_pre(MAN_ARGS)
                    695: {
                    696:
1.4       schwarze  697:        print_ofont(h, HTMLFONT_BOLD);
1.1       schwarze  698:        return(1);
                    699: }
                    700:
                    701:
                    702: /* ARGSUSED */
                    703: static int
                    704: man_I_pre(MAN_ARGS)
                    705: {
1.4       schwarze  706:
                    707:        print_ofont(h, HTMLFONT_ITALIC);
1.1       schwarze  708:        return(1);
                    709: }
                    710:
                    711:
                    712: /* ARGSUSED */
                    713: static int
                    714: man_ign_pre(MAN_ARGS)
                    715: {
                    716:
                    717:        return(0);
                    718: }
                    719:
                    720:
                    721: /* ARGSUSED */
                    722: static int
                    723: man_RS_pre(MAN_ARGS)
                    724: {
                    725:        struct htmlpair  tag;
                    726:        struct roffsu    su;
                    727:
                    728:        if (MAN_HEAD == n->type)
                    729:                return(0);
                    730:        else if (MAN_BODY == n->type)
                    731:                return(1);
                    732:
                    733:        SCALE_HS_INIT(&su, INDENT);
                    734:        bufcat_su(h, "margin-left", &su);
                    735:
                    736:        if (n->head->child) {
                    737:                SCALE_VS_INIT(&su, 1);
                    738:                a2width(n->head->child, &su);
                    739:                bufcat_su(h, "margin-top", &su);
                    740:        }
                    741:
                    742:        PAIR_STYLE_INIT(&tag, h);
                    743:        print_otag(h, TAG_DIV, 1, &tag);
                    744:        return(1);
                    745: }