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

Annotation of mandoc/man_html.c, Revision 1.109

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

CVSweb