[BACK]Return to man_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/man_html.c, Revision 1.53

1.53    ! schwarze    1: /*     $Id: man_html.c,v 1.52 2014/04/20 16:44:44 schwarze Exp $ */
1.1       schwarze    2: /*
1.49      schwarze    3:  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.50      schwarze    4:  * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
1.1       schwarze    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18: #include <sys/types.h>
                     19:
                     20: #include <assert.h>
                     21: #include <ctype.h>
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24: #include <string.h>
                     25:
1.14      schwarze   26: #include "mandoc.h"
1.53    ! schwarze   27: #include "mandoc_aux.h"
1.1       schwarze   28: #include "out.h"
                     29: #include "html.h"
                     30: #include "man.h"
                     31: #include "main.h"
                     32:
                     33: /* TODO: preserve ident widths. */
1.2       schwarze   34: /* FIXME: have PD set the default vspace width. */
1.1       schwarze   35:
                     36: #define        INDENT            5
                     37:
1.48      schwarze   38: #define        MAN_ARGS          const struct man_meta *man, \
1.1       schwarze   39:                          const struct man_node *n, \
1.18      schwarze   40:                          struct mhtml *mh, \
1.1       schwarze   41:                          struct html *h
                     42:
1.18      schwarze   43: struct mhtml {
                     44:        int               fl;
                     45: #define        MANH_LITERAL     (1 << 0) /* literal context */
                     46: };
                     47:
1.1       schwarze   48: struct htmlman {
                     49:        int             (*pre)(MAN_ARGS);
                     50:        int             (*post)(MAN_ARGS);
                     51: };
                     52:
1.52      schwarze   53: static void              print_bvspace(struct html *,
1.39      schwarze   54:                                const struct man_node *);
1.1       schwarze   55: static void              print_man(MAN_ARGS);
                     56: static void              print_man_head(MAN_ARGS);
                     57: static void              print_man_nodelist(MAN_ARGS);
                     58: static void              print_man_node(MAN_ARGS);
                     59: static int               a2width(const struct man_node *,
                     60:                                struct roffsu *);
                     61: static int               man_B_pre(MAN_ARGS);
                     62: static int               man_HP_pre(MAN_ARGS);
1.46      schwarze   63: static int               man_IP_pre(MAN_ARGS);
1.1       schwarze   64: static int               man_I_pre(MAN_ARGS);
1.46      schwarze   65: static int               man_OP_pre(MAN_ARGS);
1.1       schwarze   66: static int               man_PP_pre(MAN_ARGS);
                     67: static int               man_RS_pre(MAN_ARGS);
                     68: static int               man_SH_pre(MAN_ARGS);
                     69: static int               man_SM_pre(MAN_ARGS);
                     70: static int               man_SS_pre(MAN_ARGS);
1.49      schwarze   71: static int               man_UR_pre(MAN_ARGS);
1.46      schwarze   72: static int               man_alt_pre(MAN_ARGS);
                     73: static int               man_br_pre(MAN_ARGS);
                     74: static int               man_ign_pre(MAN_ARGS);
                     75: static int               man_in_pre(MAN_ARGS);
                     76: static int               man_literal_pre(MAN_ARGS);
                     77: static void              man_root_post(MAN_ARGS);
                     78: static void              man_root_pre(MAN_ARGS);
1.1       schwarze   79:
                     80: static const struct htmlman mans[MAN_MAX] = {
                     81:        { man_br_pre, NULL }, /* br */
                     82:        { NULL, NULL }, /* TH */
                     83:        { man_SH_pre, NULL }, /* SH */
                     84:        { man_SS_pre, NULL }, /* SS */
                     85:        { man_IP_pre, NULL }, /* TP */
                     86:        { man_PP_pre, NULL }, /* LP */
                     87:        { man_PP_pre, NULL }, /* PP */
                     88:        { man_PP_pre, NULL }, /* P */
                     89:        { man_IP_pre, NULL }, /* IP */
1.52      schwarze   90:        { man_HP_pre, NULL }, /* HP */
1.1       schwarze   91:        { man_SM_pre, NULL }, /* SM */
1.26      schwarze   92:        { man_SM_pre, NULL }, /* SB */
1.1       schwarze   93:        { man_alt_pre, NULL }, /* BI */
                     94:        { man_alt_pre, NULL }, /* IB */
                     95:        { man_alt_pre, NULL }, /* BR */
                     96:        { man_alt_pre, NULL }, /* RB */
                     97:        { NULL, NULL }, /* R */
                     98:        { man_B_pre, NULL }, /* B */
                     99:        { man_I_pre, NULL }, /* I */
                    100:        { man_alt_pre, NULL }, /* IR */
                    101:        { man_alt_pre, NULL }, /* RI */
1.34      schwarze  102:        { man_ign_pre, NULL }, /* na */
1.1       schwarze  103:        { man_br_pre, NULL }, /* sp */
1.18      schwarze  104:        { man_literal_pre, NULL }, /* nf */
                    105:        { man_literal_pre, NULL }, /* fi */
1.1       schwarze  106:        { NULL, NULL }, /* RE */
                    107:        { man_RS_pre, NULL }, /* RS */
                    108:        { man_ign_pre, NULL }, /* DT */
                    109:        { man_ign_pre, NULL }, /* UC */
1.2       schwarze  110:        { man_ign_pre, NULL }, /* PD */
1.13      schwarze  111:        { man_ign_pre, NULL }, /* AT */
1.18      schwarze  112:        { man_in_pre, NULL }, /* in */
1.23      schwarze  113:        { man_ign_pre, NULL }, /* ft */
1.46      schwarze  114:        { man_OP_pre, NULL }, /* OP */
1.47      schwarze  115:        { man_literal_pre, NULL }, /* EX */
                    116:        { man_literal_pre, NULL }, /* EE */
1.49      schwarze  117:        { man_UR_pre, NULL }, /* UR */
                    118:        { NULL, NULL }, /* UE */
1.51      schwarze  119:        { man_ign_pre, NULL }, /* ll */
1.1       schwarze  120: };
                    121:
1.52      schwarze  122:
1.39      schwarze  123: /*
                    124:  * Printing leading vertical space before a block.
                    125:  * This is used for the paragraph macros.
                    126:  * The rules are pretty simple, since there's very little nesting going
                    127:  * on here.  Basically, if we're the first within another block (SS/SH),
                    128:  * then don't emit vertical space.  If we are (RS), then do.  If not the
                    129:  * first, print it.
                    130:  */
                    131: static void
                    132: print_bvspace(struct html *h, const struct man_node *n)
                    133: {
                    134:
                    135:        if (n->body && n->body->child)
                    136:                if (MAN_TBL == n->body->child->type)
                    137:                        return;
                    138:
                    139:        if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
                    140:                if (NULL == n->prev)
                    141:                        return;
                    142:
                    143:        print_otag(h, TAG_P, 0, NULL);
                    144: }
1.1       schwarze  145:
                    146: void
1.48      schwarze  147: html_man(void *arg, const struct man *man)
1.1       schwarze  148: {
1.18      schwarze  149:        struct mhtml     mh;
1.1       schwarze  150:
1.18      schwarze  151:        memset(&mh, 0, sizeof(struct mhtml));
1.48      schwarze  152:        print_man(man_meta(man), man_node(man), &mh, (struct html *)arg);
1.43      schwarze  153:        putchar('\n');
1.1       schwarze  154: }
                    155:
                    156: static void
1.52      schwarze  157: print_man(MAN_ARGS)
1.1       schwarze  158: {
1.43      schwarze  159:        struct tag      *t, *tt;
                    160:        struct htmlpair  tag;
                    161:
                    162:        PAIR_CLASS_INIT(&tag, "mandoc");
1.1       schwarze  163:
1.43      schwarze  164:        if ( ! (HTML_FRAGMENT & h->oflags)) {
                    165:                print_gen_decls(h);
                    166:                t = print_otag(h, TAG_HTML, 0, NULL);
                    167:                tt = print_otag(h, TAG_HEAD, 0, NULL);
1.48      schwarze  168:                print_man_head(man, n, mh, h);
1.43      schwarze  169:                print_tagq(h, tt);
                    170:                print_otag(h, TAG_BODY, 0, NULL);
                    171:                print_otag(h, TAG_DIV, 1, &tag);
1.52      schwarze  172:        } else
1.43      schwarze  173:                t = print_otag(h, TAG_DIV, 1, &tag);
1.25      schwarze  174:
1.48      schwarze  175:        print_man_nodelist(man, n, mh, h);
1.1       schwarze  176:        print_tagq(h, t);
                    177: }
                    178:
                    179: static void
                    180: print_man_head(MAN_ARGS)
                    181: {
                    182:
                    183:        print_gen_head(h);
1.48      schwarze  184:        assert(man->title);
                    185:        assert(man->msec);
                    186:        bufcat_fmt(h, "%s(%s)", man->title, man->msec);
1.1       schwarze  187:        print_otag(h, TAG_TITLE, 0, NULL);
                    188:        print_text(h, h->buf);
                    189: }
                    190:
                    191: static void
                    192: print_man_nodelist(MAN_ARGS)
                    193: {
                    194:
1.48      schwarze  195:        print_man_node(man, n, mh, h);
1.1       schwarze  196:        if (n->next)
1.48      schwarze  197:                print_man_nodelist(man, n->next, mh, h);
1.1       schwarze  198: }
                    199:
                    200: static void
                    201: print_man_node(MAN_ARGS)
                    202: {
                    203:        int              child;
                    204:        struct tag      *t;
                    205:
                    206:        child = 1;
1.2       schwarze  207:        t = h->tags.head;
1.1       schwarze  208:
                    209:        switch (n->type) {
1.52      schwarze  210:        case MAN_ROOT:
1.48      schwarze  211:                man_root_pre(man, n, mh, h);
1.1       schwarze  212:                break;
1.52      schwarze  213:        case MAN_TEXT:
1.38      schwarze  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.31      schwarze  219:                if ('\0' == *n->string) {
                    220:                        print_otag(h, TAG_P, 0, NULL);
                    221:                        return;
1.40      schwarze  222:                }
                    223:
                    224:                if (' ' == *n->string && MAN_LINE & n->flags)
                    225:                        print_otag(h, TAG_BR, 0, NULL);
                    226:                else if (MANH_LITERAL & mh->fl && n->prev)
1.31      schwarze  227:                        print_otag(h, TAG_BR, 0, NULL);
                    228:
1.1       schwarze  229:                print_text(h, n->string);
1.36      schwarze  230:                return;
1.52      schwarze  231:        case MAN_EQN:
1.41      schwarze  232:                print_eqn(h, n->eqn);
1.37      schwarze  233:                break;
1.52      schwarze  234:        case MAN_TBL:
1.33      schwarze  235:                /*
                    236:                 * This will take care of initialising all of the table
                    237:                 * state data for the first table, then tearing it down
                    238:                 * for the last one.
                    239:                 */
1.29      schwarze  240:                print_tbl(h, n->span);
1.32      schwarze  241:                return;
1.1       schwarze  242:        default:
1.52      schwarze  243:                /*
1.4       schwarze  244:                 * Close out scope of font prior to opening a macro
1.33      schwarze  245:                 * scope.
1.4       schwarze  246:                 */
1.27      schwarze  247:                if (HTMLFONT_NONE != h->metac) {
                    248:                        h->metal = h->metac;
                    249:                        h->metac = HTMLFONT_NONE;
1.33      schwarze  250:                }
                    251:
                    252:                /*
                    253:                 * Close out the current table, if it's open, and unset
                    254:                 * the "meta" table state.  This will be reopened on the
                    255:                 * next table element.
                    256:                 */
                    257:                if (h->tblt) {
                    258:                        print_tblclose(h);
                    259:                        t = h->tags.head;
1.4       schwarze  260:                }
1.1       schwarze  261:                if (mans[n->tok].pre)
1.48      schwarze  262:                        child = (*mans[n->tok].pre)(man, n, mh, h);
1.1       schwarze  263:                break;
                    264:        }
                    265:
                    266:        if (child && n->child)
1.48      schwarze  267:                print_man_nodelist(man, n->child, mh, h);
1.1       schwarze  268:
1.4       schwarze  269:        /* This will automatically close out any font scope. */
1.1       schwarze  270:        print_stagq(h, t);
                    271:
                    272:        switch (n->type) {
1.52      schwarze  273:        case MAN_ROOT:
1.48      schwarze  274:                man_root_post(man, n, mh, h);
1.37      schwarze  275:                break;
1.52      schwarze  276:        case MAN_EQN:
1.1       schwarze  277:                break;
                    278:        default:
                    279:                if (mans[n->tok].post)
1.48      schwarze  280:                        (*mans[n->tok].post)(man, n, mh, h);
1.1       schwarze  281:                break;
                    282:        }
                    283: }
                    284:
                    285: static int
                    286: a2width(const struct man_node *n, struct roffsu *su)
                    287: {
                    288:
                    289:        if (MAN_TEXT != n->type)
                    290:                return(0);
                    291:        if (a2roffsu(n->string, su, SCALE_BU))
                    292:                return(1);
                    293:
                    294:        return(0);
                    295: }
                    296:
1.38      schwarze  297: static void
1.1       schwarze  298: man_root_pre(MAN_ARGS)
                    299: {
1.53    ! schwarze  300:        char             b[BUFSIZ];
1.26      schwarze  301:        struct htmlpair  tag[3];
1.1       schwarze  302:        struct tag      *t, *tt;
1.53    ! schwarze  303:        char            *title;
1.1       schwarze  304:
                    305:        b[0] = 0;
1.48      schwarze  306:        if (man->vol)
                    307:                (void)strlcat(b, man->vol, BUFSIZ);
1.1       schwarze  308:
1.48      schwarze  309:        assert(man->title);
                    310:        assert(man->msec);
1.53    ! schwarze  311:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.1       schwarze  312:
1.26      schwarze  313:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    314:        PAIR_CLASS_INIT(&tag[1], "head");
1.44      schwarze  315:        PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    316:        t = print_otag(h, TAG_TABLE, 3, tag);
                    317:        PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    318:        print_otag(h, TAG_COL, 1, tag);
                    319:        print_otag(h, TAG_COL, 1, tag);
                    320:        print_otag(h, TAG_COL, 1, tag);
1.26      schwarze  321:
                    322:        print_otag(h, TAG_TBODY, 0, NULL);
1.3       schwarze  323:
1.1       schwarze  324:        tt = print_otag(h, TAG_TR, 0, NULL);
                    325:
1.25      schwarze  326:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1       schwarze  327:        print_otag(h, TAG_TD, 1, tag);
                    328:        print_text(h, title);
                    329:        print_stagq(h, tt);
                    330:
1.25      schwarze  331:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.44      schwarze  332:        PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    333:        print_otag(h, TAG_TD, 2, tag);
1.1       schwarze  334:        print_text(h, b);
                    335:        print_stagq(h, tt);
                    336:
1.25      schwarze  337:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.44      schwarze  338:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    339:        print_otag(h, TAG_TD, 2, tag);
1.1       schwarze  340:        print_text(h, title);
                    341:        print_tagq(h, t);
1.53    ! schwarze  342:        free(title);
1.1       schwarze  343: }
                    344:
                    345: static void
                    346: man_root_post(MAN_ARGS)
                    347: {
1.26      schwarze  348:        struct htmlpair  tag[3];
1.1       schwarze  349:        struct tag      *t, *tt;
                    350:
1.26      schwarze  351:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    352:        PAIR_CLASS_INIT(&tag[1], "foot");
1.44      schwarze  353:        PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    354:        t = print_otag(h, TAG_TABLE, 3, tag);
                    355:        PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    356:        print_otag(h, TAG_COL, 1, tag);
                    357:        print_otag(h, TAG_COL, 1, tag);
1.3       schwarze  358:
1.1       schwarze  359:        tt = print_otag(h, TAG_TR, 0, NULL);
                    360:
1.25      schwarze  361:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1       schwarze  362:        print_otag(h, TAG_TD, 1, tag);
1.25      schwarze  363:
1.48      schwarze  364:        assert(man->date);
                    365:        print_text(h, man->date);
1.1       schwarze  366:        print_stagq(h, tt);
                    367:
1.25      schwarze  368:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.44      schwarze  369:        PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    370:        print_otag(h, TAG_TD, 2, tag);
1.25      schwarze  371:
1.48      schwarze  372:        if (man->source)
                    373:                print_text(h, man->source);
1.1       schwarze  374:        print_tagq(h, t);
                    375: }
                    376:
                    377:
                    378: static int
                    379: man_br_pre(MAN_ARGS)
                    380: {
                    381:        struct roffsu    su;
                    382:        struct htmlpair  tag;
                    383:
                    384:        SCALE_VS_INIT(&su, 1);
                    385:
1.21      schwarze  386:        if (MAN_sp == n->tok) {
1.39      schwarze  387:                if (NULL != (n = n->child))
                    388:                        if ( ! a2roffsu(n->string, &su, SCALE_VS))
                    389:                                SCALE_VS_INIT(&su, atoi(n->string));
1.21      schwarze  390:        } else
1.1       schwarze  391:                su.scale = 0;
                    392:
1.38      schwarze  393:        bufinit(h);
1.1       schwarze  394:        bufcat_su(h, "height", &su);
                    395:        PAIR_STYLE_INIT(&tag, h);
                    396:        print_otag(h, TAG_DIV, 1, &tag);
1.4       schwarze  397:
1.3       schwarze  398:        /* So the div isn't empty: */
                    399:        print_text(h, "\\~");
                    400:
1.1       schwarze  401:        return(0);
                    402: }
                    403:
                    404: static int
                    405: man_SH_pre(MAN_ARGS)
                    406: {
1.25      schwarze  407:        struct htmlpair  tag;
1.1       schwarze  408:
1.25      schwarze  409:        if (MAN_BLOCK == n->type) {
1.39      schwarze  410:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  411:                PAIR_CLASS_INIT(&tag, "section");
                    412:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  413:                return(1);
1.25      schwarze  414:        } else if (MAN_BODY == n->type)
1.1       schwarze  415:                return(1);
                    416:
1.25      schwarze  417:        print_otag(h, TAG_H1, 0, NULL);
1.1       schwarze  418:        return(1);
                    419: }
                    420:
                    421: static int
                    422: man_alt_pre(MAN_ARGS)
                    423: {
                    424:        const struct man_node   *nn;
1.40      schwarze  425:        int              i, savelit;
1.27      schwarze  426:        enum htmltag     fp;
                    427:        struct tag      *t;
1.1       schwarze  428:
1.52      schwarze  429:        if ((savelit = mh->fl & MANH_LITERAL))
1.40      schwarze  430:                print_otag(h, TAG_BR, 0, NULL);
                    431:
                    432:        mh->fl &= ~MANH_LITERAL;
                    433:
1.1       schwarze  434:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.27      schwarze  435:                t = NULL;
1.1       schwarze  436:                switch (n->tok) {
1.52      schwarze  437:                case MAN_BI:
1.27      schwarze  438:                        fp = i % 2 ? TAG_I : TAG_B;
1.1       schwarze  439:                        break;
1.52      schwarze  440:                case MAN_IB:
1.27      schwarze  441:                        fp = i % 2 ? TAG_B : TAG_I;
1.1       schwarze  442:                        break;
1.52      schwarze  443:                case MAN_RI:
1.27      schwarze  444:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.1       schwarze  445:                        break;
1.52      schwarze  446:                case MAN_IR:
1.27      schwarze  447:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.1       schwarze  448:                        break;
1.52      schwarze  449:                case MAN_BR:
1.27      schwarze  450:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.1       schwarze  451:                        break;
1.52      schwarze  452:                case MAN_RB:
1.27      schwarze  453:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.1       schwarze  454:                        break;
                    455:                default:
                    456:                        abort();
                    457:                        /* NOTREACHED */
                    458:                }
                    459:
                    460:                if (i)
                    461:                        h->flags |= HTML_NOSPACE;
                    462:
1.27      schwarze  463:                if (TAG_MAX != fp)
                    464:                        t = print_otag(h, fp, 0, NULL);
                    465:
1.48      schwarze  466:                print_man_node(man, nn, mh, h);
1.27      schwarze  467:
                    468:                if (t)
                    469:                        print_tagq(h, t);
1.1       schwarze  470:        }
                    471:
1.40      schwarze  472:        if (savelit)
                    473:                mh->fl |= MANH_LITERAL;
                    474:
1.1       schwarze  475:        return(0);
                    476: }
                    477:
                    478: static int
1.26      schwarze  479: man_SM_pre(MAN_ARGS)
1.1       schwarze  480: {
1.52      schwarze  481:
1.27      schwarze  482:        print_otag(h, TAG_SMALL, 0, NULL);
1.26      schwarze  483:        if (MAN_SB == n->tok)
1.27      schwarze  484:                print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  485:        return(1);
                    486: }
                    487:
                    488: static int
                    489: man_SS_pre(MAN_ARGS)
                    490: {
1.25      schwarze  491:        struct htmlpair  tag;
1.1       schwarze  492:
1.25      schwarze  493:        if (MAN_BLOCK == n->type) {
1.39      schwarze  494:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  495:                PAIR_CLASS_INIT(&tag, "subsection");
                    496:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  497:                return(1);
1.25      schwarze  498:        } else if (MAN_BODY == n->type)
1.1       schwarze  499:                return(1);
                    500:
1.25      schwarze  501:        print_otag(h, TAG_H2, 0, NULL);
1.1       schwarze  502:        return(1);
                    503: }
                    504:
                    505: static int
                    506: man_PP_pre(MAN_ARGS)
                    507: {
                    508:
1.22      schwarze  509:        if (MAN_HEAD == n->type)
                    510:                return(0);
1.39      schwarze  511:        else if (MAN_BLOCK == n->type)
                    512:                print_bvspace(h, n);
1.22      schwarze  513:
1.1       schwarze  514:        return(1);
                    515: }
                    516:
                    517: static int
                    518: man_IP_pre(MAN_ARGS)
                    519: {
                    520:        const struct man_node   *nn;
                    521:
1.52      schwarze  522:        if (MAN_BODY == n->type) {
1.40      schwarze  523:                print_otag(h, TAG_DD, 0, NULL);
                    524:                return(1);
                    525:        } else if (MAN_HEAD != n->type) {
                    526:                print_otag(h, TAG_DL, 0, NULL);
1.1       schwarze  527:                return(1);
                    528:        }
                    529:
1.40      schwarze  530:        /* FIXME: width specification. */
1.7       schwarze  531:
1.40      schwarze  532:        print_otag(h, TAG_DT, 0, NULL);
1.1       schwarze  533:
1.28      schwarze  534:        /* For IP, only print the first header element. */
1.1       schwarze  535:
1.28      schwarze  536:        if (MAN_IP == n->tok && n->child)
1.48      schwarze  537:                print_man_node(man, n->child, mh, h);
1.7       schwarze  538:
1.28      schwarze  539:        /* For TP, only print next-line header elements. */
1.1       schwarze  540:
1.50      schwarze  541:        if (MAN_TP == n->tok) {
                    542:                nn = n->child;
                    543:                while (NULL != nn && 0 == (MAN_LINE & nn->flags))
                    544:                        nn = nn->next;
                    545:                while (NULL != nn) {
                    546:                        print_man_node(man, nn, mh, h);
                    547:                        nn = nn->next;
                    548:                }
                    549:        }
1.1       schwarze  550:
                    551:        return(0);
                    552: }
                    553:
                    554: static int
                    555: man_HP_pre(MAN_ARGS)
                    556: {
1.26      schwarze  557:        struct htmlpair  tag;
                    558:        struct roffsu    su;
                    559:        const struct man_node *np;
1.1       schwarze  560:
1.40      schwarze  561:        if (MAN_HEAD == n->type)
                    562:                return(0);
                    563:        else if (MAN_BLOCK != n->type)
                    564:                return(1);
1.38      schwarze  565:
1.40      schwarze  566:        np = n->head->child;
1.1       schwarze  567:
1.26      schwarze  568:        if (NULL == np || ! a2width(np, &su))
                    569:                SCALE_HS_INIT(&su, INDENT);
1.1       schwarze  570:
1.40      schwarze  571:        bufinit(h);
1.1       schwarze  572:
1.40      schwarze  573:        print_bvspace(h, n);
                    574:        bufcat_su(h, "margin-left", &su);
1.26      schwarze  575:        su.scale = -su.scale;
1.1       schwarze  576:        bufcat_su(h, "text-indent", &su);
                    577:        PAIR_STYLE_INIT(&tag, h);
1.40      schwarze  578:        print_otag(h, TAG_P, 1, &tag);
1.1       schwarze  579:        return(1);
                    580: }
1.46      schwarze  581:
                    582: static int
                    583: man_OP_pre(MAN_ARGS)
                    584: {
                    585:        struct tag      *tt;
                    586:        struct htmlpair  tag;
                    587:
                    588:        print_text(h, "[");
                    589:        h->flags |= HTML_NOSPACE;
                    590:        PAIR_CLASS_INIT(&tag, "opt");
                    591:        tt = print_otag(h, TAG_SPAN, 1, &tag);
                    592:
                    593:        if (NULL != (n = n->child)) {
                    594:                print_otag(h, TAG_B, 0, NULL);
                    595:                print_text(h, n->string);
                    596:        }
                    597:
                    598:        print_stagq(h, tt);
                    599:
                    600:        if (NULL != n && NULL != n->next) {
                    601:                print_otag(h, TAG_I, 0, NULL);
                    602:                print_text(h, n->next->string);
                    603:        }
                    604:
                    605:        print_stagq(h, tt);
                    606:        h->flags |= HTML_NOSPACE;
                    607:        print_text(h, "]");
                    608:        return(0);
                    609: }
                    610:
1.1       schwarze  611: static int
                    612: man_B_pre(MAN_ARGS)
                    613: {
                    614:
1.27      schwarze  615:        print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  616:        return(1);
                    617: }
                    618:
                    619: static int
                    620: man_I_pre(MAN_ARGS)
                    621: {
1.52      schwarze  622:
1.27      schwarze  623:        print_otag(h, TAG_I, 0, NULL);
1.1       schwarze  624:        return(1);
1.18      schwarze  625: }
                    626:
                    627: static int
                    628: man_literal_pre(MAN_ARGS)
                    629: {
                    630:
1.47      schwarze  631:        if (MAN_fi == n->tok || MAN_EE == n->tok) {
1.18      schwarze  632:                print_otag(h, TAG_BR, 0, NULL);
1.40      schwarze  633:                mh->fl &= ~MANH_LITERAL;
                    634:        } else
1.18      schwarze  635:                mh->fl |= MANH_LITERAL;
                    636:
1.34      schwarze  637:        return(0);
1.18      schwarze  638: }
                    639:
                    640: static int
                    641: man_in_pre(MAN_ARGS)
                    642: {
                    643:
                    644:        print_otag(h, TAG_BR, 0, NULL);
                    645:        return(0);
1.1       schwarze  646: }
                    647:
                    648: static int
                    649: man_ign_pre(MAN_ARGS)
                    650: {
                    651:
                    652:        return(0);
                    653: }
                    654:
                    655: static int
                    656: man_RS_pre(MAN_ARGS)
                    657: {
                    658:        struct htmlpair  tag;
                    659:        struct roffsu    su;
                    660:
                    661:        if (MAN_HEAD == n->type)
                    662:                return(0);
                    663:        else if (MAN_BODY == n->type)
                    664:                return(1);
                    665:
                    666:        SCALE_HS_INIT(&su, INDENT);
1.26      schwarze  667:        if (n->head->child)
1.1       schwarze  668:                a2width(n->head->child, &su);
                    669:
1.38      schwarze  670:        bufinit(h);
1.26      schwarze  671:        bufcat_su(h, "margin-left", &su);
1.1       schwarze  672:        PAIR_STYLE_INIT(&tag, h);
                    673:        print_otag(h, TAG_DIV, 1, &tag);
                    674:        return(1);
1.49      schwarze  675: }
                    676:
                    677: static int
                    678: man_UR_pre(MAN_ARGS)
                    679: {
                    680:        struct htmlpair          tag[2];
                    681:
                    682:        n = n->child;
                    683:        assert(MAN_HEAD == n->type);
                    684:        if (n->nchild) {
                    685:                assert(MAN_TEXT == n->child->type);
                    686:                PAIR_CLASS_INIT(&tag[0], "link-ext");
                    687:                PAIR_HREF_INIT(&tag[1], n->child->string);
                    688:                print_otag(h, TAG_A, 2, tag);
                    689:        }
                    690:
                    691:        assert(MAN_BODY == n->next->type);
                    692:        if (n->next->nchild)
                    693:                n = n->next;
                    694:
                    695:        print_man_nodelist(man, n->child, mh, h);
                    696:
                    697:        return(0);
1.1       schwarze  698: }