[BACK]Return to man_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/man_html.c, Revision 1.107

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