[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.57

1.57    ! schwarze    1: /*     $OpenBSD$ */
1.1       schwarze    2: /*
1.56      schwarze    3:  * Copyright (c) 2008-2012, 2014 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:
1.56      schwarze  143:        print_paragraph(h);
1.39      schwarze  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) {
1.56      schwarze  220:                        print_paragraph(h);
1.31      schwarze  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.56      schwarze  300:        struct htmlpair  tag;
1.1       schwarze  301:        struct tag      *t, *tt;
1.53      schwarze  302:        char            *title;
1.1       schwarze  303:
1.48      schwarze  304:        assert(man->title);
                    305:        assert(man->msec);
1.53      schwarze  306:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.1       schwarze  307:
1.56      schwarze  308:        PAIR_CLASS_INIT(&tag, "head");
                    309:        t = print_otag(h, TAG_TABLE, 1, &tag);
1.26      schwarze  310:
                    311:        print_otag(h, TAG_TBODY, 0, NULL);
1.3       schwarze  312:
1.1       schwarze  313:        tt = print_otag(h, TAG_TR, 0, NULL);
                    314:
1.56      schwarze  315:        PAIR_CLASS_INIT(&tag, "head-ltitle");
                    316:        print_otag(h, TAG_TD, 1, &tag);
1.1       schwarze  317:        print_text(h, title);
                    318:        print_stagq(h, tt);
                    319:
1.56      schwarze  320:        PAIR_CLASS_INIT(&tag, "head-vol");
                    321:        print_otag(h, TAG_TD, 1, &tag);
1.54      schwarze  322:        if (NULL != man->vol)
                    323:                print_text(h, man->vol);
1.1       schwarze  324:        print_stagq(h, tt);
                    325:
1.56      schwarze  326:        PAIR_CLASS_INIT(&tag, "head-rtitle");
                    327:        print_otag(h, TAG_TD, 1, &tag);
1.1       schwarze  328:        print_text(h, title);
                    329:        print_tagq(h, t);
1.53      schwarze  330:        free(title);
1.1       schwarze  331: }
                    332:
                    333: static void
                    334: man_root_post(MAN_ARGS)
                    335: {
1.56      schwarze  336:        struct htmlpair  tag;
1.1       schwarze  337:        struct tag      *t, *tt;
                    338:
1.56      schwarze  339:        PAIR_CLASS_INIT(&tag, "foot");
                    340:        t = print_otag(h, TAG_TABLE, 1, &tag);
1.3       schwarze  341:
1.1       schwarze  342:        tt = print_otag(h, TAG_TR, 0, NULL);
                    343:
1.56      schwarze  344:        PAIR_CLASS_INIT(&tag, "foot-date");
                    345:        print_otag(h, TAG_TD, 1, &tag);
1.25      schwarze  346:
1.48      schwarze  347:        assert(man->date);
                    348:        print_text(h, man->date);
1.1       schwarze  349:        print_stagq(h, tt);
                    350:
1.56      schwarze  351:        PAIR_CLASS_INIT(&tag, "foot-os");
                    352:        print_otag(h, TAG_TD, 1, &tag);
1.25      schwarze  353:
1.48      schwarze  354:        if (man->source)
                    355:                print_text(h, man->source);
1.1       schwarze  356:        print_tagq(h, t);
                    357: }
                    358:
                    359:
                    360: static int
                    361: man_br_pre(MAN_ARGS)
                    362: {
                    363:        struct roffsu    su;
                    364:        struct htmlpair  tag;
                    365:
                    366:        SCALE_VS_INIT(&su, 1);
                    367:
1.21      schwarze  368:        if (MAN_sp == n->tok) {
1.39      schwarze  369:                if (NULL != (n = n->child))
                    370:                        if ( ! a2roffsu(n->string, &su, SCALE_VS))
                    371:                                SCALE_VS_INIT(&su, atoi(n->string));
1.21      schwarze  372:        } else
1.55      schwarze  373:                su.scale = 0.0;
1.1       schwarze  374:
1.38      schwarze  375:        bufinit(h);
1.1       schwarze  376:        bufcat_su(h, "height", &su);
                    377:        PAIR_STYLE_INIT(&tag, h);
                    378:        print_otag(h, TAG_DIV, 1, &tag);
1.4       schwarze  379:
1.3       schwarze  380:        /* So the div isn't empty: */
                    381:        print_text(h, "\\~");
                    382:
1.1       schwarze  383:        return(0);
                    384: }
                    385:
                    386: static int
                    387: man_SH_pre(MAN_ARGS)
                    388: {
1.25      schwarze  389:        struct htmlpair  tag;
1.1       schwarze  390:
1.25      schwarze  391:        if (MAN_BLOCK == n->type) {
1.39      schwarze  392:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  393:                PAIR_CLASS_INIT(&tag, "section");
                    394:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  395:                return(1);
1.25      schwarze  396:        } else if (MAN_BODY == n->type)
1.1       schwarze  397:                return(1);
                    398:
1.25      schwarze  399:        print_otag(h, TAG_H1, 0, NULL);
1.1       schwarze  400:        return(1);
                    401: }
                    402:
                    403: static int
                    404: man_alt_pre(MAN_ARGS)
                    405: {
                    406:        const struct man_node   *nn;
1.40      schwarze  407:        int              i, savelit;
1.27      schwarze  408:        enum htmltag     fp;
                    409:        struct tag      *t;
1.1       schwarze  410:
1.52      schwarze  411:        if ((savelit = mh->fl & MANH_LITERAL))
1.40      schwarze  412:                print_otag(h, TAG_BR, 0, NULL);
                    413:
                    414:        mh->fl &= ~MANH_LITERAL;
                    415:
1.1       schwarze  416:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.27      schwarze  417:                t = NULL;
1.1       schwarze  418:                switch (n->tok) {
1.52      schwarze  419:                case MAN_BI:
1.27      schwarze  420:                        fp = i % 2 ? TAG_I : TAG_B;
1.1       schwarze  421:                        break;
1.52      schwarze  422:                case MAN_IB:
1.27      schwarze  423:                        fp = i % 2 ? TAG_B : TAG_I;
1.1       schwarze  424:                        break;
1.52      schwarze  425:                case MAN_RI:
1.27      schwarze  426:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.1       schwarze  427:                        break;
1.52      schwarze  428:                case MAN_IR:
1.27      schwarze  429:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.1       schwarze  430:                        break;
1.52      schwarze  431:                case MAN_BR:
1.27      schwarze  432:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.1       schwarze  433:                        break;
1.52      schwarze  434:                case MAN_RB:
1.27      schwarze  435:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.1       schwarze  436:                        break;
                    437:                default:
                    438:                        abort();
                    439:                        /* NOTREACHED */
                    440:                }
                    441:
                    442:                if (i)
                    443:                        h->flags |= HTML_NOSPACE;
                    444:
1.27      schwarze  445:                if (TAG_MAX != fp)
                    446:                        t = print_otag(h, fp, 0, NULL);
                    447:
1.48      schwarze  448:                print_man_node(man, nn, mh, h);
1.27      schwarze  449:
                    450:                if (t)
                    451:                        print_tagq(h, t);
1.1       schwarze  452:        }
                    453:
1.40      schwarze  454:        if (savelit)
                    455:                mh->fl |= MANH_LITERAL;
                    456:
1.1       schwarze  457:        return(0);
                    458: }
                    459:
                    460: static int
1.26      schwarze  461: man_SM_pre(MAN_ARGS)
1.1       schwarze  462: {
1.52      schwarze  463:
1.27      schwarze  464:        print_otag(h, TAG_SMALL, 0, NULL);
1.26      schwarze  465:        if (MAN_SB == n->tok)
1.27      schwarze  466:                print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  467:        return(1);
                    468: }
                    469:
                    470: static int
                    471: man_SS_pre(MAN_ARGS)
                    472: {
1.25      schwarze  473:        struct htmlpair  tag;
1.1       schwarze  474:
1.25      schwarze  475:        if (MAN_BLOCK == n->type) {
1.39      schwarze  476:                mh->fl &= ~MANH_LITERAL;
1.25      schwarze  477:                PAIR_CLASS_INIT(&tag, "subsection");
                    478:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  479:                return(1);
1.25      schwarze  480:        } else if (MAN_BODY == n->type)
1.1       schwarze  481:                return(1);
                    482:
1.25      schwarze  483:        print_otag(h, TAG_H2, 0, NULL);
1.1       schwarze  484:        return(1);
                    485: }
                    486:
                    487: static int
                    488: man_PP_pre(MAN_ARGS)
                    489: {
                    490:
1.22      schwarze  491:        if (MAN_HEAD == n->type)
                    492:                return(0);
1.39      schwarze  493:        else if (MAN_BLOCK == n->type)
                    494:                print_bvspace(h, n);
1.22      schwarze  495:
1.1       schwarze  496:        return(1);
                    497: }
                    498:
                    499: static int
                    500: man_IP_pre(MAN_ARGS)
                    501: {
                    502:        const struct man_node   *nn;
                    503:
1.52      schwarze  504:        if (MAN_BODY == n->type) {
1.40      schwarze  505:                print_otag(h, TAG_DD, 0, NULL);
                    506:                return(1);
                    507:        } else if (MAN_HEAD != n->type) {
                    508:                print_otag(h, TAG_DL, 0, NULL);
1.1       schwarze  509:                return(1);
                    510:        }
                    511:
1.40      schwarze  512:        /* FIXME: width specification. */
1.7       schwarze  513:
1.40      schwarze  514:        print_otag(h, TAG_DT, 0, NULL);
1.1       schwarze  515:
1.28      schwarze  516:        /* For IP, only print the first header element. */
1.1       schwarze  517:
1.28      schwarze  518:        if (MAN_IP == n->tok && n->child)
1.48      schwarze  519:                print_man_node(man, n->child, mh, h);
1.7       schwarze  520:
1.28      schwarze  521:        /* For TP, only print next-line header elements. */
1.1       schwarze  522:
1.50      schwarze  523:        if (MAN_TP == n->tok) {
                    524:                nn = n->child;
                    525:                while (NULL != nn && 0 == (MAN_LINE & nn->flags))
                    526:                        nn = nn->next;
                    527:                while (NULL != nn) {
                    528:                        print_man_node(man, nn, mh, h);
                    529:                        nn = nn->next;
                    530:                }
                    531:        }
1.1       schwarze  532:
                    533:        return(0);
                    534: }
                    535:
                    536: static int
                    537: man_HP_pre(MAN_ARGS)
                    538: {
1.56      schwarze  539:        struct htmlpair  tag[2];
1.26      schwarze  540:        struct roffsu    su;
                    541:        const struct man_node *np;
1.1       schwarze  542:
1.40      schwarze  543:        if (MAN_HEAD == n->type)
                    544:                return(0);
                    545:        else if (MAN_BLOCK != n->type)
                    546:                return(1);
1.38      schwarze  547:
1.40      schwarze  548:        np = n->head->child;
1.1       schwarze  549:
1.26      schwarze  550:        if (NULL == np || ! a2width(np, &su))
                    551:                SCALE_HS_INIT(&su, INDENT);
1.1       schwarze  552:
1.40      schwarze  553:        bufinit(h);
1.1       schwarze  554:
1.40      schwarze  555:        print_bvspace(h, n);
                    556:        bufcat_su(h, "margin-left", &su);
1.26      schwarze  557:        su.scale = -su.scale;
1.1       schwarze  558:        bufcat_su(h, "text-indent", &su);
1.56      schwarze  559:        PAIR_STYLE_INIT(&tag[0], h);
                    560:        PAIR_CLASS_INIT(&tag[1], "spacer");
                    561:        print_otag(h, TAG_DIV, 2, tag);
1.1       schwarze  562:        return(1);
                    563: }
1.46      schwarze  564:
                    565: static int
                    566: man_OP_pre(MAN_ARGS)
                    567: {
                    568:        struct tag      *tt;
                    569:        struct htmlpair  tag;
                    570:
                    571:        print_text(h, "[");
                    572:        h->flags |= HTML_NOSPACE;
                    573:        PAIR_CLASS_INIT(&tag, "opt");
                    574:        tt = print_otag(h, TAG_SPAN, 1, &tag);
                    575:
                    576:        if (NULL != (n = n->child)) {
                    577:                print_otag(h, TAG_B, 0, NULL);
                    578:                print_text(h, n->string);
                    579:        }
                    580:
                    581:        print_stagq(h, tt);
                    582:
                    583:        if (NULL != n && NULL != n->next) {
                    584:                print_otag(h, TAG_I, 0, NULL);
                    585:                print_text(h, n->next->string);
                    586:        }
                    587:
                    588:        print_stagq(h, tt);
                    589:        h->flags |= HTML_NOSPACE;
                    590:        print_text(h, "]");
                    591:        return(0);
                    592: }
                    593:
1.1       schwarze  594: static int
                    595: man_B_pre(MAN_ARGS)
                    596: {
                    597:
1.27      schwarze  598:        print_otag(h, TAG_B, 0, NULL);
1.1       schwarze  599:        return(1);
                    600: }
                    601:
                    602: static int
                    603: man_I_pre(MAN_ARGS)
                    604: {
1.52      schwarze  605:
1.27      schwarze  606:        print_otag(h, TAG_I, 0, NULL);
1.1       schwarze  607:        return(1);
1.18      schwarze  608: }
                    609:
                    610: static int
                    611: man_literal_pre(MAN_ARGS)
                    612: {
                    613:
1.47      schwarze  614:        if (MAN_fi == n->tok || MAN_EE == n->tok) {
1.18      schwarze  615:                print_otag(h, TAG_BR, 0, NULL);
1.40      schwarze  616:                mh->fl &= ~MANH_LITERAL;
                    617:        } else
1.18      schwarze  618:                mh->fl |= MANH_LITERAL;
                    619:
1.34      schwarze  620:        return(0);
1.18      schwarze  621: }
                    622:
                    623: static int
                    624: man_in_pre(MAN_ARGS)
                    625: {
                    626:
                    627:        print_otag(h, TAG_BR, 0, NULL);
                    628:        return(0);
1.1       schwarze  629: }
                    630:
                    631: static int
                    632: man_ign_pre(MAN_ARGS)
                    633: {
                    634:
                    635:        return(0);
                    636: }
                    637:
                    638: static int
                    639: man_RS_pre(MAN_ARGS)
                    640: {
                    641:        struct htmlpair  tag;
                    642:        struct roffsu    su;
                    643:
                    644:        if (MAN_HEAD == n->type)
                    645:                return(0);
                    646:        else if (MAN_BODY == n->type)
                    647:                return(1);
                    648:
                    649:        SCALE_HS_INIT(&su, INDENT);
1.26      schwarze  650:        if (n->head->child)
1.1       schwarze  651:                a2width(n->head->child, &su);
                    652:
1.38      schwarze  653:        bufinit(h);
1.26      schwarze  654:        bufcat_su(h, "margin-left", &su);
1.1       schwarze  655:        PAIR_STYLE_INIT(&tag, h);
                    656:        print_otag(h, TAG_DIV, 1, &tag);
                    657:        return(1);
1.49      schwarze  658: }
                    659:
                    660: static int
                    661: man_UR_pre(MAN_ARGS)
                    662: {
                    663:        struct htmlpair          tag[2];
                    664:
                    665:        n = n->child;
                    666:        assert(MAN_HEAD == n->type);
                    667:        if (n->nchild) {
                    668:                assert(MAN_TEXT == n->child->type);
                    669:                PAIR_CLASS_INIT(&tag[0], "link-ext");
                    670:                PAIR_HREF_INIT(&tag[1], n->child->string);
                    671:                print_otag(h, TAG_A, 2, tag);
                    672:        }
                    673:
                    674:        assert(MAN_BODY == n->next->type);
                    675:        if (n->next->nchild)
                    676:                n = n->next;
                    677:
                    678:        print_man_nodelist(man, n->child, mh, h);
                    679:
                    680:        return(0);
1.1       schwarze  681: }