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

Annotation of mandoc/man_html.c, Revision 1.141

1.141   ! schwarze    1: /*     $Id: man_html.c,v 1.140 2017/05/05 13:17:54 schwarze Exp $ */
1.1       kristaps    2: /*
1.104     kristaps    3:  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.122     schwarze    4:  * Copyright (c) 2013, 2014, 2015, 2017 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.13      kristaps   35: /* FIXME: have PD set the default vspace width. */
1.6       kristaps   36:
                     37: #define        INDENT            5
1.4       kristaps   38:
1.115     schwarze   39: #define        MAN_ARGS          const struct roff_meta *man, \
1.114     schwarze   40:                          const struct roff_node *n, \
1.3       kristaps   41:                          struct html *h
                     42:
                     43: struct htmlman {
                     44:        int             (*pre)(MAN_ARGS);
                     45:        int             (*post)(MAN_ARGS);
                     46: };
                     47:
1.93      schwarze   48: static void              print_bvspace(struct html *,
1.114     schwarze   49:                                const struct roff_node *);
1.3       kristaps   50: static void              print_man_head(MAN_ARGS);
1.4       kristaps   51: static void              print_man_nodelist(MAN_ARGS);
                     52: static void              print_man_node(MAN_ARGS);
1.132     schwarze   53: static int               fillmode(struct html *, int);
1.114     schwarze   54: static int               a2width(const struct roff_node *,
1.7       kristaps   55:                                struct roffsu *);
1.8       kristaps   56: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   57: static int               man_HP_pre(MAN_ARGS);
1.86      kristaps   58: static int               man_IP_pre(MAN_ARGS);
1.8       kristaps   59: static int               man_I_pre(MAN_ARGS);
1.86      kristaps   60: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   61: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   62: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   63: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   64: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   65: static int               man_SS_pre(MAN_ARGS);
1.90      schwarze   66: static int               man_UR_pre(MAN_ARGS);
1.86      kristaps   67: static int               man_alt_pre(MAN_ARGS);
                     68: static int               man_ign_pre(MAN_ARGS);
                     69: static int               man_in_pre(MAN_ARGS);
                     70: static void              man_root_post(MAN_ARGS);
                     71: static void              man_root_pre(MAN_ARGS);
1.4       kristaps   72:
1.136     schwarze   73: static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
1.3       kristaps   74:        { NULL, NULL }, /* TH */
1.4       kristaps   75:        { man_SH_pre, NULL }, /* SH */
                     76:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   77:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   78:        { man_PP_pre, NULL }, /* LP */
                     79:        { man_PP_pre, NULL }, /* PP */
                     80:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   81:        { man_IP_pre, NULL }, /* IP */
1.93      schwarze   82:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   83:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   84:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   85:        { man_alt_pre, NULL }, /* BI */
                     86:        { man_alt_pre, NULL }, /* IB */
                     87:        { man_alt_pre, NULL }, /* BR */
                     88:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   89:        { NULL, NULL }, /* R */
1.8       kristaps   90:        { man_B_pre, NULL }, /* B */
                     91:        { man_I_pre, NULL }, /* I */
                     92:        { man_alt_pre, NULL }, /* IR */
                     93:        { man_alt_pre, NULL }, /* RI */
1.132     schwarze   94:        { NULL, NULL }, /* nf */
                     95:        { NULL, NULL }, /* fi */
1.3       kristaps   96:        { NULL, NULL }, /* RE */
1.9       kristaps   97:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps   98:        { man_ign_pre, NULL }, /* DT */
                     99:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  100:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     101:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  102:        { man_in_pre, NULL }, /* in */
1.86      kristaps  103:        { man_OP_pre, NULL }, /* OP */
1.132     schwarze  104:        { NULL, NULL }, /* EX */
                    105:        { NULL, NULL }, /* EE */
1.90      schwarze  106:        { man_UR_pre, NULL }, /* UR */
                    107:        { NULL, NULL }, /* UE */
1.3       kristaps  108: };
1.136     schwarze  109: static const struct htmlman *const mans = __mans - MAN_TH;
1.3       kristaps  110:
1.93      schwarze  111:
1.74      kristaps  112: /*
                    113:  * Printing leading vertical space before a block.
                    114:  * This is used for the paragraph macros.
                    115:  * The rules are pretty simple, since there's very little nesting going
                    116:  * on here.  Basically, if we're the first within another block (SS/SH),
                    117:  * then don't emit vertical space.  If we are (RS), then do.  If not the
                    118:  * first, print it.
                    119:  */
                    120: static void
1.114     schwarze  121: print_bvspace(struct html *h, const struct roff_node *n)
1.74      kristaps  122: {
                    123:
                    124:        if (n->body && n->body->child)
1.113     schwarze  125:                if (n->body->child->type == ROFFT_TBL)
1.74      kristaps  126:                        return;
                    127:
1.113     schwarze  128:        if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
1.74      kristaps  129:                if (NULL == n->prev)
                    130:                        return;
                    131:
1.103     kristaps  132:        print_paragraph(h);
1.74      kristaps  133: }
1.1       kristaps  134:
                    135: void
1.116     schwarze  136: html_man(void *arg, const struct roff_man *man)
1.1       kristaps  137: {
1.117     schwarze  138:        struct html     *h;
1.126     schwarze  139:        struct tag      *t;
1.82      kristaps  140:
1.117     schwarze  141:        h = (struct html *)arg;
1.3       kristaps  142:
1.126     schwarze  143:        if ((h->oflags & HTML_FRAGMENT) == 0) {
1.82      kristaps  144:                print_gen_decls(h);
1.126     schwarze  145:                print_otag(h, TAG_HTML, "");
                    146:                t = print_otag(h, TAG_HEAD, "");
1.132     schwarze  147:                print_man_head(&man->meta, man->first, h);
1.126     schwarze  148:                print_tagq(h, t);
1.122     schwarze  149:                print_otag(h, TAG_BODY, "");
1.126     schwarze  150:        }
1.53      kristaps  151:
1.132     schwarze  152:        man_root_pre(&man->meta, man->first, h);
1.127     schwarze  153:        t = print_otag(h, TAG_DIV, "c", "manual-text");
1.132     schwarze  154:        print_man_nodelist(&man->meta, man->first->child, h);
1.127     schwarze  155:        print_tagq(h, t);
1.132     schwarze  156:        man_root_post(&man->meta, man->first, h);
1.126     schwarze  157:        print_tagq(h, NULL);
1.3       kristaps  158: }
                    159:
                    160: static void
                    161: print_man_head(MAN_ARGS)
                    162: {
1.123     schwarze  163:        char    *cp;
1.3       kristaps  164:
                    165:        print_gen_head(h);
1.123     schwarze  166:        mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.122     schwarze  167:        print_otag(h, TAG_TITLE, "");
1.123     schwarze  168:        print_text(h, cp);
                    169:        free(cp);
1.1       kristaps  170: }
1.4       kristaps  171:
                    172: static void
                    173: print_man_nodelist(MAN_ARGS)
                    174: {
                    175:
1.110     schwarze  176:        while (n != NULL) {
1.132     schwarze  177:                print_man_node(man, n, h);
1.110     schwarze  178:                n = n->next;
                    179:        }
1.4       kristaps  180: }
                    181:
                    182: static void
                    183: print_man_node(MAN_ARGS)
                    184: {
1.132     schwarze  185:        static int       want_fillmode = MAN_fi;
                    186:        static int       save_fillmode;
                    187:
                    188:        struct tag      *t;
1.4       kristaps  189:        int              child;
                    190:
1.132     schwarze  191:        /*
                    192:         * Handle fill mode switch requests up front,
                    193:         * they would just cause trouble in the subsequent code.
                    194:         */
                    195:
                    196:        switch (n->tok) {
                    197:        case MAN_nf:
                    198:        case MAN_EX:
                    199:                want_fillmode = MAN_nf;
                    200:                return;
                    201:        case MAN_fi:
                    202:        case MAN_EE:
                    203:                want_fillmode = MAN_fi;
                    204:                if (fillmode(h, 0) == MAN_fi)
                    205:                        print_otag(h, TAG_BR, "");
                    206:                return;
                    207:        default:
                    208:                break;
                    209:        }
                    210:
                    211:        /* Set up fill mode for the upcoming node. */
1.4       kristaps  212:
                    213:        switch (n->type) {
1.132     schwarze  214:        case ROFFT_BLOCK:
                    215:                save_fillmode = 0;
                    216:                /* Some block macros suspend or cancel .nf. */
                    217:                switch (n->tok) {
                    218:                case MAN_TP:  /* Tagged paragraphs              */
                    219:                case MAN_IP:  /* temporarily disable .nf        */
                    220:                case MAN_HP:  /* for the head.                  */
                    221:                        save_fillmode = want_fillmode;
                    222:                        /* FALLTHROUGH */
                    223:                case MAN_SH:  /* Section headers                */
                    224:                case MAN_SS:  /* permanently cancel .nf.        */
                    225:                        want_fillmode = MAN_fi;
                    226:                        /* FALLTHROUGH */
                    227:                case MAN_PP:  /* These have no head.            */
                    228:                case MAN_LP:  /* They will simply               */
                    229:                case MAN_P:   /* reopen .nf in the body.        */
                    230:                case MAN_RS:
                    231:                case MAN_UR:
                    232:                        fillmode(h, MAN_fi);
                    233:                        break;
                    234:                default:
                    235:                        break;
                    236:                }
                    237:                break;
                    238:        case ROFFT_TBL:
                    239:                fillmode(h, MAN_fi);
                    240:                break;
                    241:        case ROFFT_ELEM:
                    242:                /*
                    243:                 * Some in-line macros produce tags and/or text
                    244:                 * in the handler, so they require fill mode to be
                    245:                 * configured up front just like for text nodes.
                    246:                 * For the others, keep the traditional approach
                    247:                 * of doing the same, for now.
                    248:                 */
                    249:                fillmode(h, want_fillmode);
                    250:                break;
1.113     schwarze  251:        case ROFFT_TEXT:
1.132     schwarze  252:                if (fillmode(h, want_fillmode) == MAN_fi &&
                    253:                    want_fillmode == MAN_fi &&
1.130     schwarze  254:                    n->flags & NODE_LINE && *n->string == ' ')
1.122     schwarze  255:                        print_otag(h, TAG_BR, "");
1.132     schwarze  256:                if (*n->string != '\0')
                    257:                        break;
                    258:                print_paragraph(h);
                    259:                return;
                    260:        default:
                    261:                break;
                    262:        }
                    263:
                    264:        /* Produce output for this node. */
                    265:
                    266:        child = 1;
                    267:        switch (n->type) {
                    268:        case ROFFT_TEXT:
                    269:                t = h->tag;
1.4       kristaps  270:                print_text(h, n->string);
1.130     schwarze  271:                break;
1.113     schwarze  272:        case ROFFT_EQN:
1.132     schwarze  273:                t = h->tag;
1.80      kristaps  274:                print_eqn(h, n->eqn);
1.69      kristaps  275:                break;
1.113     schwarze  276:        case ROFFT_TBL:
1.66      kristaps  277:                /*
                    278:                 * This will take care of initialising all of the table
                    279:                 * state data for the first table, then tearing it down
                    280:                 * for the last one.
                    281:                 */
1.60      kristaps  282:                print_tbl(h, n->span);
1.64      kristaps  283:                return;
1.4       kristaps  284:        default:
1.93      schwarze  285:                /*
1.21      kristaps  286:                 * Close out scope of font prior to opening a macro
1.66      kristaps  287:                 * scope.
1.21      kristaps  288:                 */
1.57      kristaps  289:                if (HTMLFONT_NONE != h->metac) {
                    290:                        h->metal = h->metac;
                    291:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  292:                }
                    293:
                    294:                /*
                    295:                 * Close out the current table, if it's open, and unset
                    296:                 * the "meta" table state.  This will be reopened on the
                    297:                 * next table element.
                    298:                 */
1.132     schwarze  299:                if (h->tblt)
1.66      kristaps  300:                        print_tblclose(h);
1.132     schwarze  301:
                    302:                t = h->tag;
1.137     schwarze  303:                if (n->tok < ROFF_MAX) {
1.138     schwarze  304:                        roff_html_pre(h, n);
1.141   ! schwarze  305:                        child = 0;
1.137     schwarze  306:                        break;
                    307:                }
                    308:
                    309:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.4       kristaps  310:                if (mans[n->tok].pre)
1.132     schwarze  311:                        child = (*mans[n->tok].pre)(man, n, h);
                    312:
                    313:                /* Some block macros resume .nf in the body. */
                    314:                if (save_fillmode && n->type == ROFFT_BODY)
                    315:                        want_fillmode = save_fillmode;
                    316:
1.4       kristaps  317:                break;
                    318:        }
                    319:
1.21      kristaps  320:        if (child && n->child)
1.132     schwarze  321:                print_man_nodelist(man, n->child, h);
1.21      kristaps  322:
1.24      kristaps  323:        /* This will automatically close out any font scope. */
1.132     schwarze  324:        print_stagq(h, t);
                    325:
                    326:        if (fillmode(h, 0) == MAN_nf &&
                    327:            n->next != NULL && n->next->flags & NODE_LINE)
                    328:                print_endline(h);
                    329: }
                    330:
                    331: /*
                    332:  * MAN_nf switches to no-fill mode, MAN_fi to fill mode.
                    333:  * Other arguments do not switch.
                    334:  * The old mode is returned.
                    335:  */
                    336: static int
                    337: fillmode(struct html *h, int want)
                    338: {
                    339:        struct tag      *pre;
                    340:        int              had;
1.4       kristaps  341:
1.132     schwarze  342:        for (pre = h->tag; pre != NULL; pre = pre->next)
                    343:                if (pre->tag == TAG_PRE)
                    344:                        break;
                    345:
                    346:        had = pre == NULL ? MAN_fi : MAN_nf;
1.130     schwarze  347:
1.132     schwarze  348:        if (want && want != had) {
                    349:                if (want == MAN_nf)
                    350:                        print_otag(h, TAG_PRE, "");
                    351:                else
                    352:                        print_tagq(h, pre);
                    353:        }
                    354:        return had;
1.4       kristaps  355: }
                    356:
1.5       kristaps  357: static int
1.114     schwarze  358: a2width(const struct roff_node *n, struct roffsu *su)
1.5       kristaps  359: {
                    360:
1.113     schwarze  361:        if (n->type != ROFFT_TEXT)
1.119     schwarze  362:                return 0;
1.107     schwarze  363:        if (a2roffsu(n->string, su, SCALE_EN))
1.119     schwarze  364:                return 1;
1.5       kristaps  365:
1.119     schwarze  366:        return 0;
1.5       kristaps  367: }
                    368:
1.65      kristaps  369: static void
1.4       kristaps  370: man_root_pre(MAN_ARGS)
                    371: {
                    372:        struct tag      *t, *tt;
1.94      schwarze  373:        char            *title;
1.4       kristaps  374:
1.89      schwarze  375:        assert(man->title);
                    376:        assert(man->msec);
1.94      schwarze  377:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4       kristaps  378:
1.122     schwarze  379:        t = print_otag(h, TAG_TABLE, "c", "head");
                    380:        tt = print_otag(h, TAG_TR, "");
1.4       kristaps  381:
1.122     schwarze  382:        print_otag(h, TAG_TD, "c", "head-ltitle");
1.4       kristaps  383:        print_text(h, title);
                    384:        print_stagq(h, tt);
                    385:
1.122     schwarze  386:        print_otag(h, TAG_TD, "c", "head-vol");
1.95      schwarze  387:        if (NULL != man->vol)
                    388:                print_text(h, man->vol);
1.4       kristaps  389:        print_stagq(h, tt);
                    390:
1.122     schwarze  391:        print_otag(h, TAG_TD, "c", "head-rtitle");
1.4       kristaps  392:        print_text(h, title);
                    393:        print_tagq(h, t);
1.94      schwarze  394:        free(title);
1.4       kristaps  395: }
                    396:
                    397: static void
                    398: man_root_post(MAN_ARGS)
                    399: {
                    400:        struct tag      *t, *tt;
                    401:
1.122     schwarze  402:        t = print_otag(h, TAG_TABLE, "c", "foot");
                    403:        tt = print_otag(h, TAG_TR, "");
1.55      kristaps  404:
1.122     schwarze  405:        print_otag(h, TAG_TD, "c", "foot-date");
1.89      schwarze  406:        print_text(h, man->date);
1.4       kristaps  407:        print_stagq(h, tt);
                    408:
1.122     schwarze  409:        print_otag(h, TAG_TD, "c", "foot-os");
1.115     schwarze  410:        if (man->os)
                    411:                print_text(h, man->os);
1.4       kristaps  412:        print_tagq(h, t);
                    413: }
                    414:
                    415: static int
                    416: man_SH_pre(MAN_ARGS)
                    417: {
1.134     schwarze  418:        char    *id;
                    419:
                    420:        if (n->type == ROFFT_HEAD) {
                    421:                id = html_make_id(n);
                    422:                print_otag(h, TAG_H1, "cTi", "Sh", id);
1.135     schwarze  423:                if (id != NULL)
                    424:                        print_otag(h, TAG_A, "chR", "selflink", id);
1.134     schwarze  425:                free(id);
                    426:        }
1.119     schwarze  427:        return 1;
1.4       kristaps  428: }
                    429:
                    430: static int
1.8       kristaps  431: man_alt_pre(MAN_ARGS)
                    432: {
1.114     schwarze  433:        const struct roff_node  *nn;
1.130     schwarze  434:        int              i;
1.57      kristaps  435:        enum htmltag     fp;
                    436:        struct tag      *t;
1.8       kristaps  437:
                    438:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    439:                switch (n->tok) {
1.93      schwarze  440:                case MAN_BI:
1.57      kristaps  441:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  442:                        break;
1.93      schwarze  443:                case MAN_IB:
1.57      kristaps  444:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  445:                        break;
1.93      schwarze  446:                case MAN_RI:
1.57      kristaps  447:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  448:                        break;
1.93      schwarze  449:                case MAN_IR:
1.57      kristaps  450:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  451:                        break;
1.93      schwarze  452:                case MAN_BR:
1.57      kristaps  453:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  454:                        break;
1.93      schwarze  455:                case MAN_RB:
1.57      kristaps  456:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  457:                        break;
                    458:                default:
                    459:                        abort();
                    460:                }
                    461:
                    462:                if (i)
                    463:                        h->flags |= HTML_NOSPACE;
                    464:
1.130     schwarze  465:                if (fp != TAG_MAX)
1.122     schwarze  466:                        t = print_otag(h, fp, "");
1.57      kristaps  467:
1.130     schwarze  468:                print_text(h, nn->string);
1.57      kristaps  469:
1.130     schwarze  470:                if (fp != TAG_MAX)
1.57      kristaps  471:                        print_tagq(h, t);
1.8       kristaps  472:        }
1.119     schwarze  473:        return 0;
1.8       kristaps  474: }
                    475:
                    476: static int
1.56      kristaps  477: man_SM_pre(MAN_ARGS)
1.8       kristaps  478: {
1.122     schwarze  479:        print_otag(h, TAG_SMALL, "");
1.56      kristaps  480:        if (MAN_SB == n->tok)
1.122     schwarze  481:                print_otag(h, TAG_B, "");
1.119     schwarze  482:        return 1;
1.8       kristaps  483: }
                    484:
                    485: static int
1.4       kristaps  486: man_SS_pre(MAN_ARGS)
                    487: {
1.134     schwarze  488:        char    *id;
                    489:
                    490:        if (n->type == ROFFT_HEAD) {
                    491:                id = html_make_id(n);
                    492:                print_otag(h, TAG_H2, "cTi", "Ss", id);
1.135     schwarze  493:                if (id != NULL)
                    494:                        print_otag(h, TAG_A, "chR", "selflink", id);
1.134     schwarze  495:                free(id);
                    496:        }
1.119     schwarze  497:        return 1;
1.4       kristaps  498: }
                    499:
                    500: static int
                    501: man_PP_pre(MAN_ARGS)
                    502: {
                    503:
1.113     schwarze  504:        if (n->type == ROFFT_HEAD)
1.119     schwarze  505:                return 0;
1.113     schwarze  506:        else if (n->type == ROFFT_BLOCK)
1.74      kristaps  507:                print_bvspace(h, n);
1.47      kristaps  508:
1.119     schwarze  509:        return 1;
1.5       kristaps  510: }
                    511:
                    512: static int
                    513: man_IP_pre(MAN_ARGS)
                    514: {
1.114     schwarze  515:        const struct roff_node  *nn;
1.5       kristaps  516:
1.113     schwarze  517:        if (n->type == ROFFT_BODY) {
1.129     schwarze  518:                print_otag(h, TAG_DD, "c", "It-tag");
1.119     schwarze  519:                return 1;
1.113     schwarze  520:        } else if (n->type != ROFFT_HEAD) {
1.129     schwarze  521:                print_otag(h, TAG_DL, "c", "Bl-tag");
1.119     schwarze  522:                return 1;
1.6       kristaps  523:        }
                    524:
1.78      kristaps  525:        /* FIXME: width specification. */
                    526:
1.129     schwarze  527:        print_otag(h, TAG_DT, "c", "It-tag");
1.6       kristaps  528:
1.59      schwarze  529:        /* For IP, only print the first header element. */
1.7       kristaps  530:
1.59      schwarze  531:        if (MAN_IP == n->tok && n->child)
1.132     schwarze  532:                print_man_node(man, n->child, h);
1.27      kristaps  533:
1.59      schwarze  534:        /* For TP, only print next-line header elements. */
1.6       kristaps  535:
1.91      schwarze  536:        if (MAN_TP == n->tok) {
                    537:                nn = n->child;
1.121     schwarze  538:                while (NULL != nn && 0 == (NODE_LINE & nn->flags))
1.91      schwarze  539:                        nn = nn->next;
                    540:                while (NULL != nn) {
1.132     schwarze  541:                        print_man_node(man, nn, h);
1.91      schwarze  542:                        nn = nn->next;
                    543:                }
                    544:        }
1.6       kristaps  545:
1.119     schwarze  546:        return 0;
1.6       kristaps  547: }
                    548:
                    549: static int
                    550: man_HP_pre(MAN_ARGS)
                    551: {
1.122     schwarze  552:        struct roffsu    sum, sui;
1.114     schwarze  553:        const struct roff_node *np;
1.6       kristaps  554:
1.113     schwarze  555:        if (n->type == ROFFT_HEAD)
1.119     schwarze  556:                return 0;
1.113     schwarze  557:        else if (n->type != ROFFT_BLOCK)
1.119     schwarze  558:                return 1;
1.72      kristaps  559:
1.77      kristaps  560:        np = n->head->child;
1.6       kristaps  561:
1.122     schwarze  562:        if (np == NULL || !a2width(np, &sum))
                    563:                SCALE_HS_INIT(&sum, INDENT);
1.6       kristaps  564:
1.122     schwarze  565:        sui.unit = sum.unit;
                    566:        sui.scale = -sum.scale;
1.5       kristaps  567:
1.77      kristaps  568:        print_bvspace(h, n);
1.127     schwarze  569:        print_otag(h, TAG_DIV, "csului", "Pp", &sum, &sui);
1.119     schwarze  570:        return 1;
1.4       kristaps  571: }
1.86      kristaps  572:
                    573: static int
                    574: man_OP_pre(MAN_ARGS)
                    575: {
                    576:        struct tag      *tt;
                    577:
                    578:        print_text(h, "[");
                    579:        h->flags |= HTML_NOSPACE;
1.128     schwarze  580:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86      kristaps  581:
                    582:        if (NULL != (n = n->child)) {
1.122     schwarze  583:                print_otag(h, TAG_B, "");
1.86      kristaps  584:                print_text(h, n->string);
                    585:        }
                    586:
                    587:        print_stagq(h, tt);
                    588:
                    589:        if (NULL != n && NULL != n->next) {
1.122     schwarze  590:                print_otag(h, TAG_I, "");
1.86      kristaps  591:                print_text(h, n->next->string);
                    592:        }
                    593:
                    594:        print_stagq(h, tt);
                    595:        h->flags |= HTML_NOSPACE;
                    596:        print_text(h, "]");
1.119     schwarze  597:        return 0;
1.86      kristaps  598: }
                    599:
1.8       kristaps  600: static int
                    601: man_B_pre(MAN_ARGS)
                    602: {
1.122     schwarze  603:        print_otag(h, TAG_B, "");
1.119     schwarze  604:        return 1;
1.8       kristaps  605: }
                    606:
                    607: static int
                    608: man_I_pre(MAN_ARGS)
                    609: {
1.122     schwarze  610:        print_otag(h, TAG_I, "");
1.119     schwarze  611:        return 1;
1.45      kristaps  612: }
                    613:
                    614: static int
                    615: man_in_pre(MAN_ARGS)
                    616: {
1.122     schwarze  617:        print_otag(h, TAG_BR, "");
1.119     schwarze  618:        return 0;
1.8       kristaps  619: }
                    620:
                    621: static int
                    622: man_ign_pre(MAN_ARGS)
                    623: {
                    624:
1.119     schwarze  625:        return 0;
1.8       kristaps  626: }
1.9       kristaps  627:
                    628: static int
                    629: man_RS_pre(MAN_ARGS)
                    630: {
                    631:        struct roffsu    su;
                    632:
1.113     schwarze  633:        if (n->type == ROFFT_HEAD)
1.119     schwarze  634:                return 0;
1.113     schwarze  635:        else if (n->type == ROFFT_BODY)
1.119     schwarze  636:                return 1;
1.9       kristaps  637:
                    638:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  639:        if (n->head->child)
1.9       kristaps  640:                a2width(n->head->child, &su);
                    641:
1.122     schwarze  642:        print_otag(h, TAG_DIV, "sul", &su);
1.119     schwarze  643:        return 1;
1.90      schwarze  644: }
                    645:
                    646: static int
                    647: man_UR_pre(MAN_ARGS)
                    648: {
                    649:        n = n->child;
1.113     schwarze  650:        assert(n->type == ROFFT_HEAD);
1.120     schwarze  651:        if (n->child != NULL) {
1.113     schwarze  652:                assert(n->child->type == ROFFT_TEXT);
1.134     schwarze  653:                print_otag(h, TAG_A, "cTh", "Lk", n->child->string);
1.90      schwarze  654:        }
                    655:
1.113     schwarze  656:        assert(n->next->type == ROFFT_BODY);
1.120     schwarze  657:        if (n->next->child != NULL)
1.90      schwarze  658:                n = n->next;
                    659:
1.132     schwarze  660:        print_man_nodelist(man, n->child, h);
1.90      schwarze  661:
1.119     schwarze  662:        return 0;
1.9       kristaps  663: }

CVSweb