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

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