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

Annotation of mandoc/man_html.c, Revision 1.74

1.74    ! kristaps    1: /*     $Id: man_html.c,v 1.73 2011/06/18 17:58:48 kristaps Exp $ */
1.1       kristaps    2: /*
1.70      schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    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, \
1.45      kristaps   43:                          struct mhtml *mh, \
1.3       kristaps   44:                          struct html *h
                     45:
1.45      kristaps   46: struct mhtml {
                     47:        int               fl;
                     48: #define        MANH_LITERAL     (1 << 0) /* literal context */
                     49: };
                     50:
1.3       kristaps   51: struct htmlman {
                     52:        int             (*pre)(MAN_ARGS);
                     53:        int             (*post)(MAN_ARGS);
                     54: };
                     55:
1.74    ! kristaps   56: static void              print_bvspace(struct html *,
        !            57:                                const struct man_node *);
1.3       kristaps   58: static void              print_man(MAN_ARGS);
                     59: static void              print_man_head(MAN_ARGS);
1.4       kristaps   60: static void              print_man_nodelist(MAN_ARGS);
                     61: static void              print_man_node(MAN_ARGS);
1.3       kristaps   62:
1.7       kristaps   63: static int               a2width(const struct man_node *,
                     64:                                struct roffsu *);
1.5       kristaps   65:
1.8       kristaps   66: static int               man_alt_pre(MAN_ARGS);
1.4       kristaps   67: static int               man_br_pre(MAN_ARGS);
1.8       kristaps   68: static int               man_ign_pre(MAN_ARGS);
1.45      kristaps   69: static int               man_in_pre(MAN_ARGS);
                     70: static int               man_literal_pre(MAN_ARGS);
1.8       kristaps   71: static void              man_root_post(MAN_ARGS);
1.65      kristaps   72: static void              man_root_pre(MAN_ARGS);
1.8       kristaps   73: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   74: static int               man_HP_pre(MAN_ARGS);
1.8       kristaps   75: static int               man_I_pre(MAN_ARGS);
1.5       kristaps   76: static int               man_IP_pre(MAN_ARGS);
1.4       kristaps   77: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   78: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   79: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   80: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   81: static int               man_SS_pre(MAN_ARGS);
                     82:
1.3       kristaps   83: static const struct htmlman mans[MAN_MAX] = {
1.4       kristaps   84:        { man_br_pre, NULL }, /* br */
1.3       kristaps   85:        { NULL, NULL }, /* TH */
1.4       kristaps   86:        { man_SH_pre, NULL }, /* SH */
                     87:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   88:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   89:        { man_PP_pre, NULL }, /* LP */
                     90:        { man_PP_pre, NULL }, /* PP */
                     91:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   92:        { man_IP_pre, NULL }, /* IP */
1.6       kristaps   93:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   94:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   95:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   96:        { man_alt_pre, NULL }, /* BI */
                     97:        { man_alt_pre, NULL }, /* IB */
                     98:        { man_alt_pre, NULL }, /* BR */
                     99:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps  100:        { NULL, NULL }, /* R */
1.8       kristaps  101:        { man_B_pre, NULL }, /* B */
                    102:        { man_I_pre, NULL }, /* I */
                    103:        { man_alt_pre, NULL }, /* IR */
                    104:        { man_alt_pre, NULL }, /* RI */
1.67      schwarze  105:        { man_ign_pre, NULL }, /* na */
1.4       kristaps  106:        { man_br_pre, NULL }, /* sp */
1.45      kristaps  107:        { man_literal_pre, NULL }, /* nf */
                    108:        { man_literal_pre, NULL }, /* fi */
1.3       kristaps  109:        { NULL, NULL }, /* RE */
1.9       kristaps  110:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  111:        { man_ign_pre, NULL }, /* DT */
                    112:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  113:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     114:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  115:        { man_in_pre, NULL }, /* in */
1.51      kristaps  116:        { man_ign_pre, NULL }, /* ft */
1.3       kristaps  117: };
                    118:
1.74    ! kristaps  119: /*
        !           120:  * Printing leading vertical space before a block.
        !           121:  * This is used for the paragraph macros.
        !           122:  * The rules are pretty simple, since there's very little nesting going
        !           123:  * on here.  Basically, if we're the first within another block (SS/SH),
        !           124:  * then don't emit vertical space.  If we are (RS), then do.  If not the
        !           125:  * first, print it.
        !           126:  */
        !           127: static void
        !           128: print_bvspace(struct html *h, const struct man_node *n)
        !           129: {
        !           130:
        !           131:        if (n->body && n->body->child)
        !           132:                if (MAN_TBL == n->body->child->type)
        !           133:                        return;
        !           134:
        !           135:        if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
        !           136:                if (NULL == n->prev)
        !           137:                        return;
        !           138:
        !           139:        print_otag(h, TAG_P, 0, NULL);
        !           140: }
1.1       kristaps  141:
                    142: void
                    143: html_man(void *arg, const struct man *m)
                    144: {
1.3       kristaps  145:        struct html     *h;
                    146:        struct tag      *t;
1.45      kristaps  147:        struct mhtml     mh;
1.3       kristaps  148:
                    149:        h = (struct html *)arg;
                    150:
1.26      kristaps  151:        print_gen_decls(h);
1.3       kristaps  152:
1.45      kristaps  153:        memset(&mh, 0, sizeof(struct mhtml));
                    154:
1.3       kristaps  155:        t = print_otag(h, TAG_HTML, 0, NULL);
1.45      kristaps  156:        print_man(man_meta(m), man_node(m), &mh, h);
1.3       kristaps  157:        print_tagq(h, t);
                    158:
                    159:        printf("\n");
                    160: }
                    161:
                    162: static void
                    163: print_man(MAN_ARGS)
                    164: {
                    165:        struct tag      *t;
                    166:
                    167:        t = print_otag(h, TAG_HEAD, 0, NULL);
1.45      kristaps  168:        print_man_head(m, n, mh, h);
1.3       kristaps  169:        print_tagq(h, t);
1.53      kristaps  170:
1.3       kristaps  171:        t = print_otag(h, TAG_BODY, 0, NULL);
1.45      kristaps  172:        print_man_nodelist(m, n, mh, h);
1.3       kristaps  173:        print_tagq(h, t);
                    174: }
                    175:
                    176:
                    177: /* ARGSUSED */
                    178: static void
                    179: print_man_head(MAN_ARGS)
                    180: {
                    181:
                    182:        print_gen_head(h);
1.71      kristaps  183:        bufcat_fmt(h, "%s(%s)", m->title, m->msec);
1.3       kristaps  184:        print_otag(h, TAG_TITLE, 0, NULL);
                    185:        print_text(h, h->buf);
1.1       kristaps  186: }
1.4       kristaps  187:
                    188:
                    189: static void
                    190: print_man_nodelist(MAN_ARGS)
                    191: {
                    192:
1.45      kristaps  193:        print_man_node(m, n, mh, h);
1.4       kristaps  194:        if (n->next)
1.45      kristaps  195:                print_man_nodelist(m, n->next, mh, h);
1.4       kristaps  196: }
                    197:
                    198:
                    199: static void
                    200: print_man_node(MAN_ARGS)
                    201: {
                    202:        int              child;
                    203:        struct tag      *t;
1.69      kristaps  204:        struct htmlpair  tag;
1.4       kristaps  205:
                    206:        child = 1;
1.14      kristaps  207:        t = h->tags.head;
1.4       kristaps  208:
                    209:        switch (n->type) {
                    210:        case (MAN_ROOT):
1.65      kristaps  211:                man_root_pre(m, n, mh, h);
1.4       kristaps  212:                break;
                    213:        case (MAN_TEXT):
1.65      kristaps  214:                /*
                    215:                 * If we have a blank line, output a vertical space.
                    216:                 * If we have a space as the first character, break
                    217:                 * before printing the line's data.
                    218:                 */
1.63      kristaps  219:                if ('\0' == *n->string) {
                    220:                        print_otag(h, TAG_P, 0, NULL);
                    221:                        return;
1.64      kristaps  222:                } else if (' ' == *n->string && MAN_LINE & n->flags)
1.63      kristaps  223:                        print_otag(h, TAG_BR, 0, NULL);
                    224:
1.4       kristaps  225:                print_text(h, n->string);
1.63      kristaps  226:
1.65      kristaps  227:                /*
                    228:                 * If we're in a literal context, make sure that words
                    229:                 * togehter on the same line stay together.  This is a
                    230:                 * POST-printing call, so we check the NEXT word.  Since
                    231:                 * -man doesn't have nested macros, we don't need to be
                    232:                 * more specific than this.
                    233:                 */
1.64      kristaps  234:                if (MANH_LITERAL & mh->fl &&
                    235:                                (NULL == n->next ||
                    236:                                 n->next->line > n->line))
1.45      kristaps  237:                        print_otag(h, TAG_BR, 0, NULL);
1.68      kristaps  238:                return;
                    239:        case (MAN_EQN):
1.69      kristaps  240:                PAIR_CLASS_INIT(&tag, "eqn");
                    241:                print_otag(h, TAG_SPAN, 1, &tag);
                    242:                print_text(h, n->eqn->data);
                    243:                break;
1.58      kristaps  244:        case (MAN_TBL):
1.66      kristaps  245:                /*
                    246:                 * This will take care of initialising all of the table
                    247:                 * state data for the first table, then tearing it down
                    248:                 * for the last one.
                    249:                 */
1.60      kristaps  250:                print_tbl(h, n->span);
1.64      kristaps  251:                return;
1.4       kristaps  252:        default:
1.21      kristaps  253:                /*
                    254:                 * Close out scope of font prior to opening a macro
1.66      kristaps  255:                 * scope.
1.21      kristaps  256:                 */
1.57      kristaps  257:                if (HTMLFONT_NONE != h->metac) {
                    258:                        h->metal = h->metac;
                    259:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  260:                }
                    261:
                    262:                /*
                    263:                 * Close out the current table, if it's open, and unset
                    264:                 * the "meta" table state.  This will be reopened on the
                    265:                 * next table element.
                    266:                 */
                    267:                if (h->tblt) {
                    268:                        print_tblclose(h);
                    269:                        t = h->tags.head;
1.20      kristaps  270:                }
1.4       kristaps  271:                if (mans[n->tok].pre)
1.45      kristaps  272:                        child = (*mans[n->tok].pre)(m, n, mh, h);
1.4       kristaps  273:                break;
                    274:        }
                    275:
1.21      kristaps  276:        if (child && n->child)
1.45      kristaps  277:                print_man_nodelist(m, n->child, mh, h);
1.21      kristaps  278:
1.24      kristaps  279:        /* This will automatically close out any font scope. */
1.4       kristaps  280:        print_stagq(h, t);
                    281:
1.61      kristaps  282:        switch (n->type) {
                    283:        case (MAN_ROOT):
1.45      kristaps  284:                man_root_post(m, n, mh, h);
1.69      kristaps  285:                break;
                    286:        case (MAN_EQN):
1.61      kristaps  287:                break;
                    288:        default:
                    289:                if (mans[n->tok].post)
                    290:                        (*mans[n->tok].post)(m, n, mh, h);
                    291:                break;
                    292:        }
1.4       kristaps  293: }
                    294:
                    295:
1.5       kristaps  296: static int
1.7       kristaps  297: a2width(const struct man_node *n, struct roffsu *su)
1.5       kristaps  298: {
                    299:
1.6       kristaps  300:        if (MAN_TEXT != n->type)
1.7       kristaps  301:                return(0);
1.11      kristaps  302:        if (a2roffsu(n->string, su, SCALE_BU))
1.7       kristaps  303:                return(1);
1.5       kristaps  304:
1.7       kristaps  305:        return(0);
1.5       kristaps  306: }
                    307:
                    308:
1.40      kristaps  309: /* ARGSUSED */
1.65      kristaps  310: static void
1.4       kristaps  311: man_root_pre(MAN_ARGS)
                    312: {
1.56      kristaps  313:        struct htmlpair  tag[3];
1.4       kristaps  314:        struct tag      *t, *tt;
                    315:        char             b[BUFSIZ], title[BUFSIZ];
                    316:
                    317:        b[0] = 0;
                    318:        if (m->vol)
                    319:                (void)strlcat(b, m->vol, BUFSIZ);
                    320:
1.31      kristaps  321:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.4       kristaps  322:
1.56      kristaps  323:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    324:        PAIR_CLASS_INIT(&tag[1], "head");
                    325:        if (NULL == h->style) {
                    326:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    327:                t = print_otag(h, TAG_TABLE, 3, tag);
                    328:                PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    329:                print_otag(h, TAG_COL, 1, tag);
                    330:                print_otag(h, TAG_COL, 1, tag);
                    331:                print_otag(h, TAG_COL, 1, tag);
                    332:        } else
                    333:                t = print_otag(h, TAG_TABLE, 2, tag);
                    334:
                    335:        print_otag(h, TAG_TBODY, 0, NULL);
1.15      kristaps  336:
1.4       kristaps  337:        tt = print_otag(h, TAG_TR, 0, NULL);
                    338:
1.55      kristaps  339:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.4       kristaps  340:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  341:
1.4       kristaps  342:        print_text(h, title);
                    343:        print_stagq(h, tt);
                    344:
1.55      kristaps  345:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.56      kristaps  346:        if (NULL == h->style) {
                    347:                PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    348:                print_otag(h, TAG_TD, 2, tag);
                    349:        } else
                    350:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  351:
1.4       kristaps  352:        print_text(h, b);
                    353:        print_stagq(h, tt);
                    354:
1.55      kristaps  355:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.56      kristaps  356:        if (NULL == h->style) {
                    357:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    358:                print_otag(h, TAG_TD, 2, tag);
                    359:        } else
                    360:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  361:
1.4       kristaps  362:        print_text(h, title);
                    363:        print_tagq(h, t);
                    364: }
                    365:
                    366:
                    367: /* ARGSUSED */
                    368: static void
                    369: man_root_post(MAN_ARGS)
                    370: {
1.56      kristaps  371:        struct htmlpair  tag[3];
1.4       kristaps  372:        struct tag      *t, *tt;
                    373:
1.56      kristaps  374:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    375:        PAIR_CLASS_INIT(&tag[1], "foot");
                    376:        if (NULL == h->style) {
                    377:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    378:                t = print_otag(h, TAG_TABLE, 3, tag);
                    379:                PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    380:                print_otag(h, TAG_COL, 1, tag);
                    381:                print_otag(h, TAG_COL, 1, tag);
                    382:        } else
                    383:                t = print_otag(h, TAG_TABLE, 2, tag);
1.15      kristaps  384:
1.4       kristaps  385:        tt = print_otag(h, TAG_TR, 0, NULL);
                    386:
1.55      kristaps  387:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.4       kristaps  388:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  389:
1.70      schwarze  390:        print_text(h, m->date);
1.4       kristaps  391:        print_stagq(h, tt);
                    392:
1.55      kristaps  393:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.56      kristaps  394:        if (NULL == h->style) {
                    395:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    396:                print_otag(h, TAG_TD, 2, tag);
                    397:        } else
                    398:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  399:
1.4       kristaps  400:        if (m->source)
                    401:                print_text(h, m->source);
                    402:        print_tagq(h, t);
                    403: }
                    404:
                    405:
                    406:
                    407: /* ARGSUSED */
                    408: static int
                    409: man_br_pre(MAN_ARGS)
                    410: {
1.7       kristaps  411:        struct roffsu    su;
                    412:        struct htmlpair  tag;
1.4       kristaps  413:
1.7       kristaps  414:        SCALE_VS_INIT(&su, 1);
                    415:
1.49      kristaps  416:        if (MAN_sp == n->tok) {
1.29      kristaps  417:                if (n->child)
                    418:                        a2roffsu(n->child->string, &su, SCALE_VS);
1.49      kristaps  419:        } else
1.7       kristaps  420:                su.scale = 0;
1.4       kristaps  421:
1.72      kristaps  422:        bufinit(h);
1.7       kristaps  423:        bufcat_su(h, "height", &su);
                    424:        PAIR_STYLE_INIT(&tag, h);
1.4       kristaps  425:        print_otag(h, TAG_DIV, 1, &tag);
1.24      kristaps  426:
1.16      kristaps  427:        /* So the div isn't empty: */
                    428:        print_text(h, "\\~");
                    429:
1.7       kristaps  430:        return(0);
1.4       kristaps  431: }
                    432:
                    433:
                    434: /* ARGSUSED */
                    435: static int
                    436: man_SH_pre(MAN_ARGS)
                    437: {
1.54      kristaps  438:        struct htmlpair  tag;
1.4       kristaps  439:
1.54      kristaps  440:        if (MAN_BLOCK == n->type) {
                    441:                PAIR_CLASS_INIT(&tag, "section");
                    442:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  443:                return(1);
1.54      kristaps  444:        } else if (MAN_BODY == n->type)
1.4       kristaps  445:                return(1);
                    446:
1.54      kristaps  447:        print_otag(h, TAG_H1, 0, NULL);
1.4       kristaps  448:        return(1);
                    449: }
                    450:
                    451:
                    452: /* ARGSUSED */
                    453: static int
1.8       kristaps  454: man_alt_pre(MAN_ARGS)
                    455: {
                    456:        const struct man_node   *nn;
1.57      kristaps  457:        int              i;
                    458:        enum htmltag     fp;
                    459:        struct tag      *t;
1.8       kristaps  460:
                    461:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.57      kristaps  462:                t = NULL;
1.8       kristaps  463:                switch (n->tok) {
                    464:                case (MAN_BI):
1.57      kristaps  465:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  466:                        break;
                    467:                case (MAN_IB):
1.57      kristaps  468:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  469:                        break;
                    470:                case (MAN_RI):
1.57      kristaps  471:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  472:                        break;
                    473:                case (MAN_IR):
1.57      kristaps  474:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  475:                        break;
                    476:                case (MAN_BR):
1.57      kristaps  477:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  478:                        break;
                    479:                case (MAN_RB):
1.57      kristaps  480:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  481:                        break;
                    482:                default:
                    483:                        abort();
                    484:                        /* NOTREACHED */
                    485:                }
                    486:
                    487:                if (i)
                    488:                        h->flags |= HTML_NOSPACE;
                    489:
1.57      kristaps  490:                if (TAG_MAX != fp)
                    491:                        t = print_otag(h, fp, 0, NULL);
                    492:
1.45      kristaps  493:                print_man_node(m, nn, mh, h);
1.57      kristaps  494:
                    495:                if (t)
                    496:                        print_tagq(h, t);
1.8       kristaps  497:        }
                    498:
                    499:        return(0);
                    500: }
                    501:
                    502:
                    503: /* ARGSUSED */
                    504: static int
1.56      kristaps  505: man_SM_pre(MAN_ARGS)
1.8       kristaps  506: {
                    507:
1.57      kristaps  508:        print_otag(h, TAG_SMALL, 0, NULL);
1.56      kristaps  509:        if (MAN_SB == n->tok)
1.57      kristaps  510:                print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  511:        return(1);
                    512: }
                    513:
                    514:
                    515: /* ARGSUSED */
                    516: static int
1.4       kristaps  517: man_SS_pre(MAN_ARGS)
                    518: {
1.54      kristaps  519:        struct htmlpair  tag;
1.4       kristaps  520:
1.54      kristaps  521:        if (MAN_BLOCK == n->type) {
                    522:                PAIR_CLASS_INIT(&tag, "subsection");
                    523:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  524:                return(1);
1.54      kristaps  525:        } else if (MAN_BODY == n->type)
1.4       kristaps  526:                return(1);
                    527:
1.54      kristaps  528:        print_otag(h, TAG_H2, 0, NULL);
1.4       kristaps  529:        return(1);
                    530: }
                    531:
                    532:
                    533: /* ARGSUSED */
                    534: static int
                    535: man_PP_pre(MAN_ARGS)
                    536: {
                    537:
1.47      kristaps  538:        if (MAN_HEAD == n->type)
                    539:                return(0);
1.74    ! kristaps  540:        else if (MAN_BLOCK == n->type)
        !           541:                print_bvspace(h, n);
1.47      kristaps  542:
1.5       kristaps  543:        return(1);
                    544: }
                    545:
                    546:
                    547: /* ARGSUSED */
                    548: static int
                    549: man_IP_pre(MAN_ARGS)
                    550: {
1.7       kristaps  551:        struct roffsu            su;
1.5       kristaps  552:        struct htmlpair          tag;
                    553:        const struct man_node   *nn;
                    554:
1.7       kristaps  555:        /*
                    556:         * This scattering of 1-BU margins and pads is to make sure that
                    557:         * when text overruns its box, the subsequent text isn't flush
                    558:         * up against it.  However, the rest of the right-hand box must
                    559:         * also be adjusted in consideration of this 1-BU space.
                    560:         */
                    561:
                    562:        if (MAN_BODY == n->type) {
1.56      kristaps  563:                print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  564:                return(1);
                    565:        }
                    566:
                    567:        nn = MAN_BLOCK == n->type ?
                    568:                n->head->child : n->parent->head->child;
                    569:
1.7       kristaps  570:        SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  571:
1.59      schwarze  572:        /* Width is the second token. */
1.28      kristaps  573:
1.7       kristaps  574:        if (MAN_IP == n->tok && NULL != nn)
1.59      schwarze  575:                if (NULL != (nn = nn->next))
1.62      kristaps  576:                        a2width(nn, &su);
1.5       kristaps  577:
1.28      kristaps  578:        /* Width is the first token. */
                    579:
1.27      kristaps  580:        if (MAN_TP == n->tok && NULL != nn) {
1.28      kristaps  581:                /* Skip past non-text children. */
1.27      kristaps  582:                while (nn && MAN_TEXT != nn->type)
                    583:                        nn = nn->next;
1.28      kristaps  584:                if (nn)
1.62      kristaps  585:                        a2width(nn, &su);
1.27      kristaps  586:        }
1.7       kristaps  587:
1.5       kristaps  588:        if (MAN_BLOCK == n->type) {
1.74    ! kristaps  589:                print_bvspace(h, n);
1.56      kristaps  590:                print_otag(h, TAG_TABLE, 0, NULL);
1.72      kristaps  591:                bufinit(h);
1.56      kristaps  592:                bufcat_su(h, "width", &su);
1.7       kristaps  593:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  594:                print_otag(h, TAG_COL, 1, &tag);
                    595:                print_otag(h, TAG_COL, 0, NULL);
                    596:                print_otag(h, TAG_TBODY, 0, NULL);
                    597:                print_otag(h, TAG_TR, 0, NULL);
1.5       kristaps  598:                return(1);
1.6       kristaps  599:        }
                    600:
1.56      kristaps  601:        print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  602:
1.59      schwarze  603:        /* For IP, only print the first header element. */
1.7       kristaps  604:
1.59      schwarze  605:        if (MAN_IP == n->tok && n->child)
                    606:                print_man_node(m, n->child, mh, h);
1.27      kristaps  607:
1.59      schwarze  608:        /* For TP, only print next-line header elements. */
1.6       kristaps  609:
1.7       kristaps  610:        if (MAN_TP == n->tok)
1.59      schwarze  611:                for (nn = n->child; nn; nn = nn->next)
                    612:                        if (nn->line > n->line)
                    613:                                print_man_node(m, nn, mh, h);
1.6       kristaps  614:
                    615:        return(0);
                    616: }
                    617:
                    618:
                    619: /* ARGSUSED */
                    620: static int
                    621: man_HP_pre(MAN_ARGS)
                    622: {
1.56      kristaps  623:        struct htmlpair  tag;
                    624:        struct roffsu    su;
                    625:        const struct man_node *np;
1.6       kristaps  626:
1.72      kristaps  627:        bufinit(h);
                    628:
1.56      kristaps  629:        np = MAN_BLOCK == n->type ?
                    630:                n->head->child :
                    631:                n->parent->head->child;
1.6       kristaps  632:
1.56      kristaps  633:        if (NULL == np || ! a2width(np, &su))
                    634:                SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  635:
1.56      kristaps  636:        if (MAN_HEAD == n->type) {
                    637:                print_otag(h, TAG_TD, 0, NULL);
                    638:                return(0);
                    639:        } else if (MAN_BLOCK == n->type) {
1.74    ! kristaps  640:                print_bvspace(h, n);
1.56      kristaps  641:                print_otag(h, TAG_TABLE, 0, NULL);
                    642:                bufcat_su(h, "width", &su);
1.7       kristaps  643:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  644:                print_otag(h, TAG_COL, 1, &tag);
                    645:                print_otag(h, TAG_COL, 0, NULL);
                    646:                print_otag(h, TAG_TBODY, 0, NULL);
                    647:                print_otag(h, TAG_TR, 0, NULL);
1.6       kristaps  648:                return(1);
                    649:        }
1.5       kristaps  650:
1.56      kristaps  651:        su.scale = -su.scale;
1.7       kristaps  652:        bufcat_su(h, "text-indent", &su);
                    653:        PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  654:        print_otag(h, TAG_TD, 1, &tag);
1.4       kristaps  655:        return(1);
                    656: }
1.6       kristaps  657:
1.8       kristaps  658:
                    659: /* ARGSUSED */
                    660: static int
                    661: man_B_pre(MAN_ARGS)
                    662: {
                    663:
1.57      kristaps  664:        print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  665:        return(1);
                    666: }
                    667:
                    668:
                    669: /* ARGSUSED */
                    670: static int
                    671: man_I_pre(MAN_ARGS)
                    672: {
1.23      kristaps  673:
1.57      kristaps  674:        print_otag(h, TAG_I, 0, NULL);
1.8       kristaps  675:        return(1);
1.45      kristaps  676: }
                    677:
                    678:
                    679: /* ARGSUSED */
                    680: static int
                    681: man_literal_pre(MAN_ARGS)
                    682: {
                    683:
1.48      kristaps  684:        if (MAN_nf == n->tok) {
1.45      kristaps  685:                print_otag(h, TAG_BR, 0, NULL);
                    686:                mh->fl |= MANH_LITERAL;
1.48      kristaps  687:        } else
1.45      kristaps  688:                mh->fl &= ~MANH_LITERAL;
                    689:
1.67      schwarze  690:        return(0);
1.45      kristaps  691: }
                    692:
                    693:
                    694: /* ARGSUSED */
                    695: static int
                    696: man_in_pre(MAN_ARGS)
                    697: {
                    698:
                    699:        print_otag(h, TAG_BR, 0, NULL);
                    700:        return(0);
1.8       kristaps  701: }
                    702:
                    703:
                    704: /* ARGSUSED */
                    705: static int
                    706: man_ign_pre(MAN_ARGS)
                    707: {
                    708:
                    709:        return(0);
                    710: }
1.9       kristaps  711:
                    712:
                    713: /* ARGSUSED */
                    714: static int
                    715: man_RS_pre(MAN_ARGS)
                    716: {
                    717:        struct htmlpair  tag;
                    718:        struct roffsu    su;
                    719:
                    720:        if (MAN_HEAD == n->type)
                    721:                return(0);
                    722:        else if (MAN_BODY == n->type)
                    723:                return(1);
                    724:
                    725:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  726:        if (n->head->child)
1.9       kristaps  727:                a2width(n->head->child, &su);
                    728:
1.72      kristaps  729:        bufinit(h);
1.56      kristaps  730:        bufcat_su(h, "margin-left", &su);
1.9       kristaps  731:        PAIR_STYLE_INIT(&tag, h);
                    732:        print_otag(h, TAG_DIV, 1, &tag);
                    733:        return(1);
                    734: }

CVSweb