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

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