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

Annotation of mandoc/man_html.c, Revision 1.10

1.10    ! kristaps    1: /*     $Id: man_html.c,v 1.9 2009/10/09 07:10:37 kristaps 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:  */
                     17: #include <sys/types.h>
                     18: #include <sys/queue.h>
                     19:
1.5       kristaps   20: #include <assert.h>
                     21: #include <ctype.h>
1.4       kristaps   22: #include <err.h>
1.2       kristaps   23: #include <stdio.h>
1.1       kristaps   24: #include <stdlib.h>
1.4       kristaps   25: #include <string.h>
1.1       kristaps   26:
1.7       kristaps   27: #include "out.h"
1.1       kristaps   28: #include "html.h"
                     29: #include "man.h"
1.10    ! kristaps   30: #include "main.h"
1.1       kristaps   31:
1.6       kristaps   32: /* TODO: preserve ident widths. */
                     33:
                     34: #define        INDENT            5
1.4       kristaps   35: #define        HALFINDENT        3
                     36:
1.3       kristaps   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);
1.4       kristaps   48: static void              print_man_nodelist(MAN_ARGS);
                     49: static void              print_man_node(MAN_ARGS);
1.3       kristaps   50:
1.7       kristaps   51: static int               a2width(const struct man_node *,
                     52:                                struct roffsu *);
1.5       kristaps   53:
1.8       kristaps   54: static int               man_alt_pre(MAN_ARGS);
1.4       kristaps   55: static int               man_br_pre(MAN_ARGS);
1.8       kristaps   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);
1.6       kristaps   60: static int               man_HP_pre(MAN_ARGS);
1.8       kristaps   61: static int               man_I_pre(MAN_ARGS);
1.5       kristaps   62: static int               man_IP_pre(MAN_ARGS);
1.4       kristaps   63: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   64: static int               man_RS_pre(MAN_ARGS);
1.8       kristaps   65: static int               man_SB_pre(MAN_ARGS);
1.4       kristaps   66: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   67: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   68: static int               man_SS_pre(MAN_ARGS);
                     69:
                     70: #ifdef __linux__
                     71: extern size_t            strlcpy(char *, const char *, size_t);
                     72: extern size_t            strlcat(char *, const char *, size_t);
                     73: #endif
1.3       kristaps   74:
                     75: static const struct htmlman mans[MAN_MAX] = {
1.4       kristaps   76:        { man_br_pre, NULL }, /* br */
1.3       kristaps   77:        { NULL, NULL }, /* TH */
1.4       kristaps   78:        { man_SH_pre, NULL }, /* SH */
                     79:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   80:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   81:        { man_PP_pre, NULL }, /* LP */
                     82:        { man_PP_pre, NULL }, /* PP */
                     83:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   84:        { man_IP_pre, NULL }, /* IP */
1.6       kristaps   85:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   86:        { man_SM_pre, NULL }, /* SM */
                     87:        { man_SB_pre, NULL }, /* SB */
                     88:        { man_alt_pre, NULL }, /* BI */
                     89:        { man_alt_pre, NULL }, /* IB */
                     90:        { man_alt_pre, NULL }, /* BR */
                     91:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   92:        { NULL, NULL }, /* R */
1.8       kristaps   93:        { man_B_pre, NULL }, /* B */
                     94:        { man_I_pre, NULL }, /* I */
                     95:        { man_alt_pre, NULL }, /* IR */
                     96:        { man_alt_pre, NULL }, /* RI */
1.3       kristaps   97:        { NULL, NULL }, /* na */
                     98:        { NULL, NULL }, /* i */
1.4       kristaps   99:        { man_br_pre, NULL }, /* sp */
1.3       kristaps  100:        { NULL, NULL }, /* nf */
                    101:        { NULL, NULL }, /* fi */
                    102:        { NULL, NULL }, /* r */
                    103:        { NULL, NULL }, /* RE */
1.9       kristaps  104:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  105:        { man_ign_pre, NULL }, /* DT */
                    106:        { man_ign_pre, NULL }, /* UC */
1.3       kristaps  107: };
                    108:
1.1       kristaps  109:
                    110: void
                    111: html_man(void *arg, const struct man *m)
                    112: {
1.3       kristaps  113:        struct html     *h;
                    114:        struct tag      *t;
                    115:
                    116:        h = (struct html *)arg;
                    117:
                    118:        print_gen_doctype(h);
                    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:
1.4       kristaps  144:        print_man_nodelist(m, n, h);
1.3       kristaps  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);
                    157:        buffmt(h, "%s(%d)", m->title, m->msec);
                    158:
                    159:        print_otag(h, TAG_TITLE, 0, NULL);
                    160:        print_text(h, h->buf);
1.1       kristaps  161: }
1.4       kristaps  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;
                    181:        t = SLIST_FIRST(&h->tags);
                    182:
                    183:        bufinit(h);
                    184:
                    185:        switch (n->type) {
                    186:        case (MAN_ROOT):
                    187:                child = man_root_pre(m, n, h);
                    188:                break;
                    189:        case (MAN_TEXT):
                    190:                print_text(h, n->string);
                    191:                break;
                    192:        default:
                    193:                if (mans[n->tok].pre)
                    194:                        child = (*mans[n->tok].pre)(m, n, h);
                    195:                break;
                    196:        }
                    197:
                    198:        if (child && n->child)
                    199:                print_man_nodelist(m, n->child, h);
                    200:
                    201:        print_stagq(h, t);
                    202:
                    203:        bufinit(h);
                    204:
                    205:        switch (n->type) {
                    206:        case (MAN_ROOT):
                    207:                man_root_post(m, n, h);
                    208:                break;
                    209:        case (MAN_TEXT):
                    210:                break;
                    211:        default:
                    212:                if (mans[n->tok].post)
                    213:                        (*mans[n->tok].post)(m, n, h);
                    214:                break;
                    215:        }
                    216: }
                    217:
                    218:
1.5       kristaps  219: static int
1.7       kristaps  220: a2width(const struct man_node *n, struct roffsu *su)
1.5       kristaps  221: {
                    222:
1.6       kristaps  223:        if (MAN_TEXT != n->type)
1.7       kristaps  224:                return(0);
                    225:        if (a2roffsu(n->string, su))
                    226:                return(1);
1.5       kristaps  227:
1.7       kristaps  228:        return(0);
1.5       kristaps  229: }
                    230:
                    231:
1.4       kristaps  232: /* ARGSUSED */
                    233: static int
                    234: man_root_pre(MAN_ARGS)
                    235: {
                    236:        struct htmlpair  tag[2];
                    237:        struct tag      *t, *tt;
                    238:        char             b[BUFSIZ], title[BUFSIZ];
                    239:
                    240:        b[0] = 0;
                    241:        if (m->vol)
                    242:                (void)strlcat(b, m->vol, BUFSIZ);
                    243:
                    244:        (void)snprintf(title, BUFSIZ - 1,
                    245:                        "%s(%d)", m->title, m->msec);
                    246:
1.7       kristaps  247:        PAIR_CLASS_INIT(&tag[0], "header");
                    248:        bufcat_style(h, "width", "100%");
                    249:        PAIR_STYLE_INIT(&tag[1], h);
1.4       kristaps  250:        t = print_otag(h, TAG_TABLE, 2, tag);
                    251:        tt = print_otag(h, TAG_TR, 0, NULL);
                    252:
1.7       kristaps  253:        bufinit(h);
                    254:        bufcat_style(h, "width", "10%");
                    255:        PAIR_STYLE_INIT(&tag[0], h);
1.4       kristaps  256:        print_otag(h, TAG_TD, 1, tag);
                    257:        print_text(h, title);
                    258:        print_stagq(h, tt);
                    259:
1.7       kristaps  260:        bufinit(h);
                    261:        bufcat_style(h, "width", "80%");
                    262:        bufcat_style(h, "white-space", "nowrap");
                    263:        bufcat_style(h, "text-align", "center");
                    264:        PAIR_STYLE_INIT(&tag[0], h);
1.4       kristaps  265:        print_otag(h, TAG_TD, 1, tag);
                    266:        print_text(h, b);
                    267:        print_stagq(h, tt);
                    268:
1.7       kristaps  269:        bufinit(h);
                    270:        bufcat_style(h, "width", "10%");
                    271:        bufcat_style(h, "text-align", "right");
                    272:        PAIR_STYLE_INIT(&tag[0], h);
1.4       kristaps  273:        print_otag(h, TAG_TD, 1, tag);
                    274:        print_text(h, title);
                    275:        print_tagq(h, t);
                    276:        return(1);
                    277: }
                    278:
                    279:
                    280: /* ARGSUSED */
                    281: static void
                    282: man_root_post(MAN_ARGS)
                    283: {
                    284:        struct tm        tm;
                    285:        struct htmlpair  tag[2];
                    286:        struct tag      *t, *tt;
                    287:        char             b[BUFSIZ];
                    288:
                    289:        (void)localtime_r(&m->date, &tm);
                    290:
                    291:        if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm))
                    292:                err(EXIT_FAILURE, "strftime");
                    293:
1.7       kristaps  294:        PAIR_CLASS_INIT(&tag[0], "footer");
                    295:        bufcat_style(h, "width", "100%");
                    296:        PAIR_STYLE_INIT(&tag[1], h);
1.4       kristaps  297:        t = print_otag(h, TAG_TABLE, 2, tag);
                    298:        tt = print_otag(h, TAG_TR, 0, NULL);
                    299:
1.7       kristaps  300:        bufinit(h);
                    301:        bufcat_style(h, "width", "50%");
                    302:        PAIR_STYLE_INIT(&tag[0], h);
1.4       kristaps  303:        print_otag(h, TAG_TD, 1, tag);
                    304:        print_text(h, b);
                    305:        print_stagq(h, tt);
                    306:
1.7       kristaps  307:        bufinit(h);
                    308:        bufcat_style(h, "width", "50%");
                    309:        bufcat_style(h, "text-align", "right");
                    310:        PAIR_STYLE_INIT(&tag[0], h);
1.4       kristaps  311:        print_otag(h, TAG_TD, 1, tag);
                    312:        if (m->source)
                    313:                print_text(h, m->source);
                    314:        print_tagq(h, t);
                    315: }
                    316:
                    317:
                    318:
                    319: /* ARGSUSED */
                    320: static int
                    321: man_br_pre(MAN_ARGS)
                    322: {
1.7       kristaps  323:        struct roffsu    su;
                    324:        struct htmlpair  tag;
1.4       kristaps  325:
1.7       kristaps  326:        SCALE_VS_INIT(&su, 1);
                    327:
                    328:        if (MAN_sp == n->tok) {
                    329:                su.scale = 1;
                    330:                if (n->child)
                    331:                        a2roffsu(n->child->string, &su);
                    332:        } else if (MAN_br == n->tok)
                    333:                su.scale = 0;
1.4       kristaps  334:
1.7       kristaps  335:        bufcat_su(h, "height", &su);
                    336:        PAIR_STYLE_INIT(&tag, h);
1.4       kristaps  337:        print_otag(h, TAG_DIV, 1, &tag);
1.7       kristaps  338:        return(0);
1.4       kristaps  339: }
                    340:
                    341:
                    342: /* ARGSUSED */
                    343: static int
                    344: man_SH_pre(MAN_ARGS)
                    345: {
1.7       kristaps  346:        struct htmlpair  tag[2];
                    347:        struct roffsu    su;
1.4       kristaps  348:
                    349:        if (MAN_BODY == n->type) {
1.7       kristaps  350:                SCALE_HS_INIT(&su, INDENT);
                    351:                bufcat_su(h, "margin-left", &su);
                    352:                PAIR_CLASS_INIT(&tag[0], "sec-body");
                    353:                PAIR_STYLE_INIT(&tag[1], h);
1.4       kristaps  354:                print_otag(h, TAG_DIV, 2, tag);
                    355:                return(1);
                    356:        } else if (MAN_BLOCK == n->type) {
1.7       kristaps  357:                PAIR_CLASS_INIT(&tag[0], "sec-block");
1.4       kristaps  358:                if (n->prev && MAN_SH == n->prev->tok)
                    359:                        if (NULL == n->prev->body->child) {
                    360:                                print_otag(h, TAG_DIV, 1, tag);
                    361:                                return(1);
                    362:                        }
                    363:
1.7       kristaps  364:                SCALE_VS_INIT(&su, 1);
                    365:                bufcat_su(h, "margin-top", &su);
1.4       kristaps  366:                if (NULL == n->next)
1.7       kristaps  367:                        bufcat_su(h, "margin-bottom", &su);
                    368:                PAIR_STYLE_INIT(&tag[1], h);
1.4       kristaps  369:                print_otag(h, TAG_DIV, 2, tag);
                    370:                return(1);
                    371:        }
                    372:
1.7       kristaps  373:        PAIR_CLASS_INIT(&tag[0], "sec-head");
1.4       kristaps  374:        print_otag(h, TAG_DIV, 1, tag);
                    375:        return(1);
                    376: }
                    377:
                    378:
                    379: /* ARGSUSED */
                    380: static int
1.8       kristaps  381: man_alt_pre(MAN_ARGS)
                    382: {
                    383:        const struct man_node   *nn;
                    384:        struct tag              *t;
                    385:        int                      i;
                    386:        struct htmlpair          tagi, tagb, *tagp;
                    387:
                    388:        PAIR_CLASS_INIT(&tagi, "italic");
                    389:        PAIR_CLASS_INIT(&tagb, "bold");
                    390:
                    391:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    392:                switch (n->tok) {
                    393:                case (MAN_BI):
                    394:                        tagp = i % 2 ? &tagi : &tagb;
                    395:                        break;
                    396:                case (MAN_IB):
                    397:                        tagp = i % 2 ? &tagb : &tagi;
                    398:                        break;
                    399:                case (MAN_RI):
                    400:                        tagp = i % 2 ? &tagi : NULL;
                    401:                        break;
                    402:                case (MAN_IR):
                    403:                        tagp = i % 2 ? NULL : &tagi;
                    404:                        break;
                    405:                case (MAN_BR):
                    406:                        tagp = i % 2 ? NULL : &tagb;
                    407:                        break;
                    408:                case (MAN_RB):
                    409:                        tagp = i % 2 ? &tagb : NULL;
                    410:                        break;
                    411:                default:
                    412:                        abort();
                    413:                        /* NOTREACHED */
                    414:                }
                    415:
                    416:                if (i)
                    417:                        h->flags |= HTML_NOSPACE;
                    418:
                    419:                if (tagp) {
                    420:                        t = print_otag(h, TAG_SPAN, 1, tagp);
                    421:                        print_man_node(m, nn, h);
                    422:                        print_tagq(h, t);
                    423:                } else
                    424:                        print_man_node(m, nn, h);
                    425:        }
                    426:
                    427:        return(0);
                    428: }
                    429:
                    430:
                    431: /* ARGSUSED */
                    432: static int
                    433: man_SB_pre(MAN_ARGS)
                    434: {
                    435:        struct htmlpair  tag;
                    436:
                    437:        PAIR_CLASS_INIT(&tag, "small bold");
                    438:        print_otag(h, TAG_SPAN, 1, &tag);
                    439:        return(1);
                    440: }
                    441:
                    442:
                    443: /* ARGSUSED */
                    444: static int
                    445: man_SM_pre(MAN_ARGS)
                    446: {
                    447:        struct htmlpair  tag;
                    448:
                    449:        PAIR_CLASS_INIT(&tag, "small");
                    450:        print_otag(h, TAG_SPAN, 1, &tag);
                    451:        return(1);
                    452: }
                    453:
                    454:
                    455: /* ARGSUSED */
                    456: static int
1.4       kristaps  457: man_SS_pre(MAN_ARGS)
                    458: {
                    459:        struct htmlpair  tag[3];
1.7       kristaps  460:        struct roffsu    su;
1.4       kristaps  461:
1.7       kristaps  462:        SCALE_VS_INIT(&su, 1);
1.4       kristaps  463:
                    464:        if (MAN_BODY == n->type) {
1.7       kristaps  465:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.4       kristaps  466:                if (n->parent->next && n->child) {
1.7       kristaps  467:                        bufcat_su(h, "margin-bottom", &su);
                    468:                        PAIR_STYLE_INIT(&tag[1], h);
                    469:                        print_otag(h, TAG_DIV, 2, tag);
                    470:                        return(1);
1.4       kristaps  471:                }
                    472:
1.7       kristaps  473:                print_otag(h, TAG_DIV, 1, tag);
1.4       kristaps  474:                return(1);
                    475:        } else if (MAN_BLOCK == n->type) {
1.7       kristaps  476:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.4       kristaps  477:                if (n->prev && MAN_SS == n->prev->tok)
                    478:                        if (n->prev->body->child) {
1.7       kristaps  479:                                bufcat_su(h, "margin-top", &su);
                    480:                                PAIR_STYLE_INIT(&tag[1], h);
                    481:                                print_otag(h, TAG_DIV, 2, tag);
                    482:                                return(1);
1.4       kristaps  483:                        }
                    484:
1.7       kristaps  485:                print_otag(h, TAG_DIV, 1, tag);
1.4       kristaps  486:                return(1);
                    487:        }
                    488:
1.7       kristaps  489:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    490:        bufcat_su(h, "margin-left", &su);
                    491:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    492:        PAIR_STYLE_INIT(&tag[1], h);
1.4       kristaps  493:        print_otag(h, TAG_DIV, 2, tag);
                    494:        return(1);
                    495: }
                    496:
                    497:
                    498: /* ARGSUSED */
                    499: static int
                    500: man_PP_pre(MAN_ARGS)
                    501: {
1.5       kristaps  502:        struct htmlpair  tag;
1.7       kristaps  503:        struct roffsu    su;
1.5       kristaps  504:        int              i;
1.4       kristaps  505:
                    506:        if (MAN_BLOCK != n->type)
                    507:                return(1);
                    508:
1.5       kristaps  509:        i = 0;
                    510:
                    511:        if (MAN_ROOT == n->parent->tok) {
1.7       kristaps  512:                SCALE_HS_INIT(&su, INDENT);
                    513:                bufcat_su(h, "margin-left", &su);
                    514:                i++;
1.5       kristaps  515:        }
                    516:        if (n->next && n->next->child) {
1.7       kristaps  517:                SCALE_VS_INIT(&su, 1);
                    518:                bufcat_su(h, "margin-bottom", &su);
                    519:                i++;
1.5       kristaps  520:        }
1.4       kristaps  521:
1.7       kristaps  522:        PAIR_STYLE_INIT(&tag, h);
                    523:        print_otag(h, TAG_DIV, i ? 1 : 0, &tag);
1.5       kristaps  524:        return(1);
                    525: }
                    526:
                    527:
                    528: /* ARGSUSED */
                    529: static int
                    530: man_IP_pre(MAN_ARGS)
                    531: {
1.7       kristaps  532:        struct roffsu            su;
1.5       kristaps  533:        struct htmlpair          tag;
                    534:        const struct man_node   *nn;
1.7       kristaps  535:        int                      width;
1.5       kristaps  536:
1.7       kristaps  537:        /*
                    538:         * This scattering of 1-BU margins and pads is to make sure that
                    539:         * when text overruns its box, the subsequent text isn't flush
                    540:         * up against it.  However, the rest of the right-hand box must
                    541:         * also be adjusted in consideration of this 1-BU space.
                    542:         */
                    543:
                    544:        if (MAN_BODY == n->type) {
                    545:                SCALE_HS_INIT(&su, INDENT);
                    546:                bufcat_su(h, "margin-left", &su);
                    547:                PAIR_STYLE_INIT(&tag, h);
                    548:                print_otag(h, TAG_DIV, 1, &tag);
1.6       kristaps  549:                return(1);
                    550:        }
                    551:
                    552:        nn = MAN_BLOCK == n->type ?
                    553:                n->head->child : n->parent->head->child;
                    554:
1.7       kristaps  555:        SCALE_HS_INIT(&su, INDENT);
                    556:        width = 0;
1.6       kristaps  557:
1.7       kristaps  558:        if (MAN_IP == n->tok && NULL != nn)
1.5       kristaps  559:                if (NULL != (nn = nn->next)) {
                    560:                        for ( ; nn->next; nn = nn->next)
                    561:                                /* Do nothing. */ ;
1.7       kristaps  562:                        width = a2width(nn, &su);
1.5       kristaps  563:                }
                    564:
1.7       kristaps  565:        if (MAN_TP == n->tok && NULL != nn)
                    566:                width = a2width(nn, &su);
                    567:
1.5       kristaps  568:        if (MAN_BLOCK == n->type) {
1.7       kristaps  569:                bufcat_su(h, "margin-left", &su);
1.9       kristaps  570:                SCALE_VS_INIT(&su, 1);
                    571:                bufcat_su(h, "margin-top", &su);
1.7       kristaps  572:                bufcat_style(h, "clear", "both");
                    573:                PAIR_STYLE_INIT(&tag, h);
1.5       kristaps  574:                print_otag(h, TAG_DIV, 1, &tag);
                    575:                return(1);
1.6       kristaps  576:        }
                    577:
1.7       kristaps  578:        bufcat_su(h, "min-width", &su);
                    579:        SCALE_INVERT(&su);
                    580:        bufcat_su(h, "margin-left", &su);
                    581:        SCALE_HS_INIT(&su, 1);
                    582:        bufcat_su(h, "margin-right", &su);
                    583:        bufcat_style(h, "clear", "left");
1.6       kristaps  584:
                    585:        if (n->next && n->next->child)
1.7       kristaps  586:                bufcat_style(h, "float", "left");
1.6       kristaps  587:
1.7       kristaps  588:        PAIR_STYLE_INIT(&tag, h);
1.6       kristaps  589:        print_otag(h, TAG_DIV, 1, &tag);
                    590:
1.7       kristaps  591:        /* With a length string, manually omit the last child. */
                    592:
                    593:        if ( ! width)
1.6       kristaps  594:                return(1);
                    595:
1.7       kristaps  596:        if (MAN_IP == n->tok)
                    597:                for (nn = n->child; nn->next; nn = nn->next)
                    598:                        print_man_node(m, nn, h);
                    599:        if (MAN_TP == n->tok)
                    600:                for (nn = n->child->next; nn; nn = nn->next)
                    601:                        print_man_node(m, nn, h);
1.6       kristaps  602:
                    603:        return(0);
                    604: }
                    605:
                    606:
                    607: /* ARGSUSED */
                    608: static int
                    609: man_HP_pre(MAN_ARGS)
                    610: {
                    611:        const struct man_node   *nn;
                    612:        struct htmlpair          tag;
1.7       kristaps  613:        struct roffsu            su;
1.6       kristaps  614:
                    615:        if (MAN_HEAD == n->type)
                    616:                return(0);
                    617:
                    618:        nn = MAN_BLOCK == n->type ?
                    619:                n->head->child : n->parent->head->child;
                    620:
1.7       kristaps  621:        SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  622:
                    623:        if (NULL != nn)
1.7       kristaps  624:                (void)a2width(nn, &su);
1.6       kristaps  625:
                    626:        if (MAN_BLOCK == n->type) {
1.7       kristaps  627:                bufcat_su(h, "margin-left", &su);
1.9       kristaps  628:                SCALE_VS_INIT(&su, 1);
                    629:                bufcat_su(h, "margin-top", &su);
1.7       kristaps  630:                bufcat_style(h, "clear", "both");
                    631:                PAIR_STYLE_INIT(&tag, h);
1.5       kristaps  632:                print_otag(h, TAG_DIV, 1, &tag);
1.6       kristaps  633:                return(1);
                    634:        }
1.5       kristaps  635:
1.7       kristaps  636:        bufcat_su(h, "margin-left", &su);
                    637:        SCALE_INVERT(&su);
                    638:        bufcat_su(h, "text-indent", &su);
1.5       kristaps  639:
1.7       kristaps  640:        PAIR_STYLE_INIT(&tag, h);
1.6       kristaps  641:        print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  642:        return(1);
                    643: }
1.6       kristaps  644:
1.8       kristaps  645:
                    646: /* ARGSUSED */
                    647: static int
                    648: man_B_pre(MAN_ARGS)
                    649: {
                    650:        struct htmlpair  tag;
                    651:
                    652:        PAIR_CLASS_INIT(&tag, "bold");
                    653:        print_otag(h, TAG_SPAN, 1, &tag);
                    654:        return(1);
                    655: }
                    656:
                    657:
                    658: /* ARGSUSED */
                    659: static int
                    660: man_I_pre(MAN_ARGS)
                    661: {
                    662:        struct htmlpair  tag;
                    663:
                    664:        PAIR_CLASS_INIT(&tag, "italic");
                    665:        print_otag(h, TAG_SPAN, 1, &tag);
                    666:        return(1);
                    667: }
                    668:
                    669:
                    670: /* ARGSUSED */
                    671: static int
                    672: man_ign_pre(MAN_ARGS)
                    673: {
                    674:
                    675:        return(0);
                    676: }
1.9       kristaps  677:
                    678:
                    679: /* ARGSUSED */
                    680: static int
                    681: man_RS_pre(MAN_ARGS)
                    682: {
                    683:        struct htmlpair  tag;
                    684:        struct roffsu    su;
                    685:
                    686:        if (MAN_HEAD == n->type)
                    687:                return(0);
                    688:        else if (MAN_BODY == n->type)
                    689:                return(1);
                    690:
                    691:        SCALE_HS_INIT(&su, INDENT);
                    692:        bufcat_su(h, "margin-left", &su);
                    693:
                    694:        if (n->head->child) {
                    695:                SCALE_VS_INIT(&su, 1);
                    696:                a2width(n->head->child, &su);
                    697:                bufcat_su(h, "margin-top", &su);
                    698:        }
                    699:
                    700:        PAIR_STYLE_INIT(&tag, h);
                    701:        print_otag(h, TAG_DIV, 1, &tag);
                    702:        return(1);
                    703: }

CVSweb