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

Annotation of mandoc/man_html.c, Revision 1.35

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

CVSweb