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

Annotation of mandoc/man_html.c, Revision 1.9

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

CVSweb