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

Annotation of mandoc/man_html.c, Revision 1.117

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

CVSweb