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

Annotation of mandoc/man_html.c, Revision 1.152

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

CVSweb