[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.129

1.129   ! schwarze    1: /*     $OpenBSD: man_html.c,v 1.128 2020/02/12 21:14:24 schwarze Exp $ */
1.1       schwarze    2: /*
1.56      schwarze    3:  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.128     schwarze    4:  * Copyright (c) 2013-2015, 2017-2020 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.113     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.68      schwarze   34: #define        MAN_ARGS          const struct roff_meta *man, \
1.129   ! schwarze   35:                          struct roff_node *n, \
1.1       schwarze   36:                          struct html *h
                     37:
1.108     schwarze   38: struct man_html_act {
1.1       schwarze   39:        int             (*pre)(MAN_ARGS);
                     40:        int             (*post)(MAN_ARGS);
                     41: };
                     42:
1.100     schwarze   43: static void              print_man_head(const struct roff_meta *,
                     44:                                struct html *);
1.1       schwarze   45: static void              print_man_nodelist(MAN_ARGS);
                     46: static void              print_man_node(MAN_ARGS);
1.126     schwarze   47: static char              list_continues(const struct roff_node *,
                     48:                                const struct roff_node *);
1.1       schwarze   49: static int               man_B_pre(MAN_ARGS);
1.46      schwarze   50: static int               man_IP_pre(MAN_ARGS);
1.1       schwarze   51: static int               man_I_pre(MAN_ARGS);
1.46      schwarze   52: static int               man_OP_pre(MAN_ARGS);
1.1       schwarze   53: static int               man_PP_pre(MAN_ARGS);
                     54: static int               man_RS_pre(MAN_ARGS);
                     55: static int               man_SH_pre(MAN_ARGS);
                     56: static int               man_SM_pre(MAN_ARGS);
1.109     schwarze   57: static int               man_SY_pre(MAN_ARGS);
1.49      schwarze   58: static int               man_UR_pre(MAN_ARGS);
1.111     schwarze   59: static int               man_abort_pre(MAN_ARGS);
1.46      schwarze   60: static int               man_alt_pre(MAN_ARGS);
                     61: static int               man_ign_pre(MAN_ARGS);
                     62: static int               man_in_pre(MAN_ARGS);
1.100     schwarze   63: static void              man_root_post(const struct roff_meta *,
                     64:                                struct html *);
                     65: static void              man_root_pre(const struct roff_meta *,
                     66:                                struct html *);
1.1       schwarze   67:
1.108     schwarze   68: static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = {
1.1       schwarze   69:        { NULL, NULL }, /* TH */
                     70:        { man_SH_pre, NULL }, /* SH */
1.119     schwarze   71:        { man_SH_pre, NULL }, /* SS */
1.1       schwarze   72:        { man_IP_pre, NULL }, /* TP */
1.107     schwarze   73:        { man_IP_pre, NULL }, /* TQ */
1.111     schwarze   74:        { man_abort_pre, NULL }, /* LP */
1.1       schwarze   75:        { man_PP_pre, NULL }, /* PP */
1.111     schwarze   76:        { man_abort_pre, NULL }, /* P */
1.1       schwarze   77:        { man_IP_pre, NULL }, /* IP */
1.119     schwarze   78:        { man_PP_pre, NULL }, /* HP */
1.1       schwarze   79:        { man_SM_pre, NULL }, /* SM */
1.26      schwarze   80:        { man_SM_pre, NULL }, /* SB */
1.1       schwarze   81:        { man_alt_pre, NULL }, /* BI */
                     82:        { man_alt_pre, NULL }, /* IB */
                     83:        { man_alt_pre, NULL }, /* BR */
                     84:        { man_alt_pre, NULL }, /* RB */
                     85:        { NULL, NULL }, /* R */
                     86:        { man_B_pre, NULL }, /* B */
                     87:        { man_I_pre, NULL }, /* I */
                     88:        { man_alt_pre, NULL }, /* IR */
                     89:        { man_alt_pre, NULL }, /* RI */
                     90:        { NULL, NULL }, /* RE */
                     91:        { man_RS_pre, NULL }, /* RS */
                     92:        { man_ign_pre, NULL }, /* DT */
                     93:        { man_ign_pre, NULL }, /* UC */
1.2       schwarze   94:        { man_ign_pre, NULL }, /* PD */
1.13      schwarze   95:        { man_ign_pre, NULL }, /* AT */
1.18      schwarze   96:        { man_in_pre, NULL }, /* in */
1.109     schwarze   97:        { man_SY_pre, NULL }, /* SY */
                     98:        { NULL, NULL }, /* YS */
1.46      schwarze   99:        { man_OP_pre, NULL }, /* OP */
1.85      schwarze  100:        { NULL, NULL }, /* EX */
                    101:        { NULL, NULL }, /* EE */
1.49      schwarze  102:        { man_UR_pre, NULL }, /* UR */
                    103:        { NULL, NULL }, /* UE */
1.98      bentley   104:        { man_UR_pre, NULL }, /* MT */
                    105:        { NULL, NULL }, /* ME */
1.1       schwarze  106: };
                    107:
1.52      schwarze  108:
1.1       schwarze  109: void
1.114     schwarze  110: html_man(void *arg, const struct roff_meta *man)
1.1       schwarze  111: {
1.100     schwarze  112:        struct html             *h;
                    113:        struct roff_node        *n;
                    114:        struct tag              *t;
1.43      schwarze  115:
1.70      schwarze  116:        h = (struct html *)arg;
1.100     schwarze  117:        n = man->first->child;
1.1       schwarze  118:
1.79      schwarze  119:        if ((h->oflags & HTML_FRAGMENT) == 0) {
1.43      schwarze  120:                print_gen_decls(h);
1.79      schwarze  121:                print_otag(h, TAG_HTML, "");
1.122     schwarze  122:                if (n != NULL && n->type == ROFFT_COMMENT)
1.100     schwarze  123:                        print_gen_comment(h, n);
1.79      schwarze  124:                t = print_otag(h, TAG_HEAD, "");
1.114     schwarze  125:                print_man_head(man, h);
1.79      schwarze  126:                print_tagq(h, t);
1.75      schwarze  127:                print_otag(h, TAG_BODY, "");
1.79      schwarze  128:        }
1.25      schwarze  129:
1.114     schwarze  130:        man_root_pre(man, h);
1.80      schwarze  131:        t = print_otag(h, TAG_DIV, "c", "manual-text");
1.114     schwarze  132:        print_man_nodelist(man, n, h);
1.80      schwarze  133:        print_tagq(h, t);
1.114     schwarze  134:        man_root_post(man, h);
1.79      schwarze  135:        print_tagq(h, NULL);
1.1       schwarze  136: }
                    137:
                    138: static void
1.100     schwarze  139: print_man_head(const struct roff_meta *man, struct html *h)
1.1       schwarze  140: {
1.76      schwarze  141:        char    *cp;
1.1       schwarze  142:
                    143:        print_gen_head(h);
1.76      schwarze  144:        mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.75      schwarze  145:        print_otag(h, TAG_TITLE, "");
1.76      schwarze  146:        print_text(h, cp);
                    147:        free(cp);
1.1       schwarze  148: }
                    149:
                    150: static void
                    151: print_man_nodelist(MAN_ARGS)
                    152: {
1.63      schwarze  153:        while (n != NULL) {
1.85      schwarze  154:                print_man_node(man, n, h);
1.63      schwarze  155:                n = n->next;
                    156:        }
1.1       schwarze  157: }
                    158:
                    159: static void
                    160: print_man_node(MAN_ARGS)
                    161: {
1.85      schwarze  162:        struct tag      *t;
1.1       schwarze  163:        int              child;
                    164:
1.120     schwarze  165:        if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
                    166:                return;
                    167:
1.116     schwarze  168:        html_fillmode(h, n->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi);
1.85      schwarze  169:
                    170:        child = 1;
                    171:        switch (n->type) {
                    172:        case ROFFT_TEXT:
1.116     schwarze  173:                if (*n->string == '\0') {
                    174:                        print_endline(h);
                    175:                        return;
                    176:                }
                    177:                if (*n->string == ' ' && n->flags & NODE_LINE &&
                    178:                    (h->flags & HTML_NONEWLINE) == 0)
1.128     schwarze  179:                        print_otag(h, TAG_BR, "");
1.116     schwarze  180:                else if (n->flags & NODE_DELIMC)
                    181:                        h->flags |= HTML_NOSPACE;
1.123     schwarze  182:                t = h->tag;
                    183:                t->refcnt++;
1.1       schwarze  184:                print_text(h, n->string);
1.83      schwarze  185:                break;
1.66      schwarze  186:        case ROFFT_EQN:
1.123     schwarze  187:                t = h->tag;
                    188:                t->refcnt++;
1.41      schwarze  189:                print_eqn(h, n->eqn);
1.37      schwarze  190:                break;
1.66      schwarze  191:        case ROFFT_TBL:
1.33      schwarze  192:                /*
                    193:                 * This will take care of initialising all of the table
                    194:                 * state data for the first table, then tearing it down
                    195:                 * for the last one.
                    196:                 */
1.29      schwarze  197:                print_tbl(h, n->span);
1.32      schwarze  198:                return;
1.1       schwarze  199:        default:
1.52      schwarze  200:                /*
1.4       schwarze  201:                 * Close out scope of font prior to opening a macro
1.33      schwarze  202:                 * scope.
1.4       schwarze  203:                 */
1.127     schwarze  204:                if (h->metac != ESCAPE_FONTROMAN) {
1.27      schwarze  205:                        h->metal = h->metac;
1.127     schwarze  206:                        h->metac = ESCAPE_FONTROMAN;
1.33      schwarze  207:                }
                    208:
                    209:                /*
                    210:                 * Close out the current table, if it's open, and unset
                    211:                 * the "meta" table state.  This will be reopened on the
                    212:                 * next table element.
                    213:                 */
1.123     schwarze  214:                if (h->tblt != NULL)
1.33      schwarze  215:                        print_tblclose(h);
1.123     schwarze  216:                t = h->tag;
                    217:                t->refcnt++;
1.90      schwarze  218:                if (n->tok < ROFF_MAX) {
1.91      schwarze  219:                        roff_html_pre(h, n);
1.123     schwarze  220:                        t->refcnt--;
1.120     schwarze  221:                        print_stagq(h, t);
1.116     schwarze  222:                        return;
1.90      schwarze  223:                }
                    224:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.108     schwarze  225:                if (man_html_acts[n->tok - MAN_TH].pre != NULL)
                    226:                        child = (*man_html_acts[n->tok - MAN_TH].pre)(man,
                    227:                            n, h);
1.1       schwarze  228:                break;
                    229:        }
                    230:
1.117     schwarze  231:        if (child && n->child != NULL)
1.85      schwarze  232:                print_man_nodelist(man, n->child, h);
1.1       schwarze  233:
1.4       schwarze  234:        /* This will automatically close out any font scope. */
1.123     schwarze  235:        t->refcnt--;
1.124     schwarze  236:        if (n->type == ROFFT_BLOCK &&
                    237:            (n->tok == MAN_IP || n->tok == MAN_TP || n->tok == MAN_TQ)) {
                    238:                t = h->tag;
1.126     schwarze  239:                while (t->tag != TAG_DL && t->tag != TAG_UL)
1.124     schwarze  240:                        t = t->next;
                    241:                /*
                    242:                 * Close the list if no further item of the same type
                    243:                 * follows; otherwise, close the item only.
                    244:                 */
1.129   ! schwarze  245:                if (list_continues(n, roff_node_next(n)) == '\0') {
1.124     schwarze  246:                        print_tagq(h, t);
                    247:                        t = NULL;
                    248:                }
                    249:        }
                    250:        if (t != NULL)
                    251:                print_stagq(h, t);
1.85      schwarze  252:
1.118     schwarze  253:        if (n->flags & NODE_NOFILL && n->tok != MAN_YS &&
                    254:            (n->next != NULL && n->next->flags & NODE_LINE)) {
1.110     schwarze  255:                /* In .nf = <pre>, print even empty lines. */
                    256:                h->col++;
1.85      schwarze  257:                print_endline(h);
1.110     schwarze  258:        }
1.1       schwarze  259: }
                    260:
1.38      schwarze  261: static void
1.100     schwarze  262: man_root_pre(const struct roff_meta *man, struct html *h)
1.1       schwarze  263: {
                    264:        struct tag      *t, *tt;
1.53      schwarze  265:        char            *title;
1.1       schwarze  266:
1.48      schwarze  267:        assert(man->title);
                    268:        assert(man->msec);
1.53      schwarze  269:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.1       schwarze  270:
1.75      schwarze  271:        t = print_otag(h, TAG_TABLE, "c", "head");
                    272:        tt = print_otag(h, TAG_TR, "");
1.1       schwarze  273:
1.75      schwarze  274:        print_otag(h, TAG_TD, "c", "head-ltitle");
1.1       schwarze  275:        print_text(h, title);
                    276:        print_stagq(h, tt);
                    277:
1.75      schwarze  278:        print_otag(h, TAG_TD, "c", "head-vol");
1.117     schwarze  279:        if (man->vol != NULL)
1.54      schwarze  280:                print_text(h, man->vol);
1.1       schwarze  281:        print_stagq(h, tt);
                    282:
1.75      schwarze  283:        print_otag(h, TAG_TD, "c", "head-rtitle");
1.1       schwarze  284:        print_text(h, title);
                    285:        print_tagq(h, t);
1.53      schwarze  286:        free(title);
1.1       schwarze  287: }
                    288:
                    289: static void
1.100     schwarze  290: man_root_post(const struct roff_meta *man, struct html *h)
1.1       schwarze  291: {
                    292:        struct tag      *t, *tt;
                    293:
1.75      schwarze  294:        t = print_otag(h, TAG_TABLE, "c", "foot");
                    295:        tt = print_otag(h, TAG_TR, "");
1.25      schwarze  296:
1.75      schwarze  297:        print_otag(h, TAG_TD, "c", "foot-date");
1.48      schwarze  298:        print_text(h, man->date);
1.1       schwarze  299:        print_stagq(h, tt);
                    300:
1.75      schwarze  301:        print_otag(h, TAG_TD, "c", "foot-os");
1.117     schwarze  302:        if (man->os != NULL)
1.68      schwarze  303:                print_text(h, man->os);
1.1       schwarze  304:        print_tagq(h, t);
                    305: }
                    306:
                    307: static int
                    308: man_SH_pre(MAN_ARGS)
                    309: {
1.125     schwarze  310:        const char      *class;
                    311:        char            *id;
                    312:        enum htmltag     tag;
                    313:
                    314:        if (n->tok == MAN_SH) {
                    315:                tag = TAG_H1;
                    316:                class = "Sh";
                    317:        } else {
                    318:                tag = TAG_H2;
                    319:                class = "Ss";
                    320:        }
1.119     schwarze  321:        switch (n->type) {
                    322:        case ROFFT_BLOCK:
                    323:                html_close_paragraph(h);
1.125     schwarze  324:                print_otag(h, TAG_SECTION, "c", class);
1.119     schwarze  325:                break;
                    326:        case ROFFT_HEAD:
1.103     schwarze  327:                id = html_make_id(n, 1);
1.125     schwarze  328:                print_otag(h, tag, "ci", class, id);
1.88      schwarze  329:                if (id != NULL)
1.101     schwarze  330:                        print_otag(h, TAG_A, "chR", "permalink", id);
1.119     schwarze  331:                break;
                    332:        case ROFFT_BODY:
                    333:                break;
                    334:        default:
                    335:                abort();
1.87      schwarze  336:        }
1.72      schwarze  337:        return 1;
1.1       schwarze  338: }
                    339:
                    340: static int
                    341: man_alt_pre(MAN_ARGS)
                    342: {
1.67      schwarze  343:        const struct roff_node  *nn;
1.117     schwarze  344:        struct tag      *t;
1.83      schwarze  345:        int              i;
1.27      schwarze  346:        enum htmltag     fp;
1.1       schwarze  347:
1.117     schwarze  348:        for (i = 0, nn = n->child; nn != NULL; nn = nn->next, i++) {
1.1       schwarze  349:                switch (n->tok) {
1.52      schwarze  350:                case MAN_BI:
1.27      schwarze  351:                        fp = i % 2 ? TAG_I : TAG_B;
1.1       schwarze  352:                        break;
1.52      schwarze  353:                case MAN_IB:
1.27      schwarze  354:                        fp = i % 2 ? TAG_B : TAG_I;
1.1       schwarze  355:                        break;
1.52      schwarze  356:                case MAN_RI:
1.27      schwarze  357:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.1       schwarze  358:                        break;
1.52      schwarze  359:                case MAN_IR:
1.27      schwarze  360:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.1       schwarze  361:                        break;
1.52      schwarze  362:                case MAN_BR:
1.27      schwarze  363:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.1       schwarze  364:                        break;
1.52      schwarze  365:                case MAN_RB:
1.27      schwarze  366:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.1       schwarze  367:                        break;
                    368:                default:
                    369:                        abort();
                    370:                }
                    371:
                    372:                if (i)
                    373:                        h->flags |= HTML_NOSPACE;
                    374:
1.83      schwarze  375:                if (fp != TAG_MAX)
1.75      schwarze  376:                        t = print_otag(h, fp, "");
1.27      schwarze  377:
1.83      schwarze  378:                print_text(h, nn->string);
1.27      schwarze  379:
1.83      schwarze  380:                if (fp != TAG_MAX)
1.27      schwarze  381:                        print_tagq(h, t);
1.1       schwarze  382:        }
1.72      schwarze  383:        return 0;
1.1       schwarze  384: }
                    385:
                    386: static int
1.26      schwarze  387: man_SM_pre(MAN_ARGS)
1.1       schwarze  388: {
1.75      schwarze  389:        print_otag(h, TAG_SMALL, "");
1.117     schwarze  390:        if (n->tok == MAN_SB)
1.75      schwarze  391:                print_otag(h, TAG_B, "");
1.72      schwarze  392:        return 1;
1.1       schwarze  393: }
                    394:
                    395: static int
                    396: man_PP_pre(MAN_ARGS)
                    397: {
1.119     schwarze  398:        switch (n->type) {
                    399:        case ROFFT_BLOCK:
                    400:                html_close_paragraph(h);
                    401:                break;
                    402:        case ROFFT_HEAD:
1.72      schwarze  403:                return 0;
1.119     schwarze  404:        case ROFFT_BODY:
                    405:                if (n->child != NULL &&
                    406:                    (n->child->flags & NODE_NOFILL) == 0)
                    407:                        print_otag(h, TAG_P, "c",
                    408:                            n->tok == MAN_PP ? "Pp" : "Pp HP");
                    409:                break;
                    410:        default:
                    411:                abort();
                    412:        }
1.72      schwarze  413:        return 1;
1.1       schwarze  414: }
                    415:
1.126     schwarze  416: static char
                    417: list_continues(const struct roff_node *n1, const struct roff_node *n2)
                    418: {
                    419:        const char *s1, *s2;
                    420:        char c1, c2;
                    421:
                    422:        if (n1 == NULL || n1->type != ROFFT_BLOCK ||
                    423:            n2 == NULL || n2->type != ROFFT_BLOCK)
                    424:                return '\0';
                    425:        if ((n1->tok == MAN_TP || n1->tok == MAN_TQ) &&
                    426:            (n2->tok == MAN_TP || n2->tok == MAN_TQ))
                    427:                return ' ';
                    428:        if (n1->tok != MAN_IP || n2->tok != MAN_IP)
                    429:                return '\0';
                    430:        n1 = n1->head->child;
                    431:        n2 = n2->head->child;
                    432:        s1 = n1 == NULL ? "" : n1->string;
                    433:        s2 = n2 == NULL ? "" : n2->string;
                    434:        c1 = strcmp(s1, "*") == 0 ? '*' :
                    435:             strcmp(s1, "\\-") == 0 ? '-' :
                    436:             strcmp(s1, "\\(bu") == 0 ? 'b' : ' ';
                    437:        c2 = strcmp(s2, "*") == 0 ? '*' :
                    438:             strcmp(s2, "\\-") == 0 ? '-' :
                    439:             strcmp(s2, "\\(bu") == 0 ? 'b' : ' ';
                    440:        return c1 != c2 ? '\0' : c1 == 'b' ? '*' : c1;
                    441: }
                    442:
1.1       schwarze  443: static int
                    444: man_IP_pre(MAN_ARGS)
                    445: {
1.129   ! schwarze  446:        struct roff_node        *nn;
1.126     schwarze  447:        const char              *list_class;
                    448:        enum htmltag             list_elem, body_elem;
                    449:        char                     list_type;
                    450:
                    451:        nn = n->type == ROFFT_BLOCK ? n : n->parent;
1.129   ! schwarze  452:        list_type = list_continues(roff_node_prev(nn), nn);
        !           453:        if (list_type == '\0') {
1.126     schwarze  454:                /* Start a new list. */
1.129   ! schwarze  455:                list_type = list_continues(nn, roff_node_next(nn));
        !           456:                if (list_type == '\0')
1.126     schwarze  457:                        list_type = ' ';
                    458:                switch (list_type) {
                    459:                case ' ':
                    460:                        list_class = "Bl-tag";
                    461:                        list_elem = TAG_DL;
                    462:                        break;
                    463:                case '*':
                    464:                        list_class = "Bl-bullet";
                    465:                        list_elem = TAG_UL;
                    466:                        break;
                    467:                case '-':
                    468:                        list_class = "Bl-dash";
                    469:                        list_elem = TAG_UL;
                    470:                        break;
                    471:                default:
                    472:                        abort();
                    473:                }
                    474:        } else {
                    475:                /* Continue a list that was started earlier. */
                    476:                list_class = NULL;
                    477:                list_elem = TAG_MAX;
                    478:        }
                    479:        body_elem = list_type == ' ' ? TAG_DD : TAG_LI;
1.1       schwarze  480:
1.119     schwarze  481:        switch (n->type) {
                    482:        case ROFFT_BLOCK:
                    483:                html_close_paragraph(h);
1.126     schwarze  484:                if (list_elem != TAG_MAX)
                    485:                        print_otag(h, list_elem, "c", list_class);
1.119     schwarze  486:                return 1;
                    487:        case ROFFT_HEAD:
1.126     schwarze  488:                if (body_elem == TAG_LI)
                    489:                        return 0;
1.119     schwarze  490:                print_otag(h, TAG_DT, "");
                    491:                break;
                    492:        case ROFFT_BODY:
1.126     schwarze  493:                print_otag(h, body_elem, "");
1.72      schwarze  494:                return 1;
1.119     schwarze  495:        default:
                    496:                abort();
1.1       schwarze  497:        }
                    498:
1.107     schwarze  499:        switch(n->tok) {
                    500:        case MAN_IP:  /* Only print the first header element. */
                    501:                if (n->child != NULL)
                    502:                        print_man_node(man, n->child, h);
                    503:                break;
                    504:        case MAN_TP:  /* Only print next-line header elements. */
                    505:        case MAN_TQ:
1.50      schwarze  506:                nn = n->child;
1.107     schwarze  507:                while (nn != NULL && (NODE_LINE & nn->flags) == 0)
1.50      schwarze  508:                        nn = nn->next;
1.107     schwarze  509:                while (nn != NULL) {
1.85      schwarze  510:                        print_man_node(man, nn, h);
1.50      schwarze  511:                        nn = nn->next;
                    512:                }
1.107     schwarze  513:                break;
                    514:        default:
                    515:                abort();
1.50      schwarze  516:        }
1.72      schwarze  517:        return 0;
1.1       schwarze  518: }
                    519:
                    520: static int
1.46      schwarze  521: man_OP_pre(MAN_ARGS)
                    522: {
                    523:        struct tag      *tt;
                    524:
                    525:        print_text(h, "[");
                    526:        h->flags |= HTML_NOSPACE;
1.81      schwarze  527:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.46      schwarze  528:
1.117     schwarze  529:        if ((n = n->child) != NULL) {
1.75      schwarze  530:                print_otag(h, TAG_B, "");
1.46      schwarze  531:                print_text(h, n->string);
                    532:        }
                    533:
                    534:        print_stagq(h, tt);
                    535:
1.117     schwarze  536:        if (n != NULL && n->next != NULL) {
1.75      schwarze  537:                print_otag(h, TAG_I, "");
1.46      schwarze  538:                print_text(h, n->next->string);
                    539:        }
                    540:
                    541:        print_stagq(h, tt);
                    542:        h->flags |= HTML_NOSPACE;
                    543:        print_text(h, "]");
1.72      schwarze  544:        return 0;
1.46      schwarze  545: }
                    546:
1.1       schwarze  547: static int
                    548: man_B_pre(MAN_ARGS)
                    549: {
1.75      schwarze  550:        print_otag(h, TAG_B, "");
1.72      schwarze  551:        return 1;
1.1       schwarze  552: }
                    553:
                    554: static int
                    555: man_I_pre(MAN_ARGS)
                    556: {
1.75      schwarze  557:        print_otag(h, TAG_I, "");
1.72      schwarze  558:        return 1;
1.18      schwarze  559: }
                    560:
                    561: static int
                    562: man_in_pre(MAN_ARGS)
                    563: {
1.75      schwarze  564:        print_otag(h, TAG_BR, "");
1.72      schwarze  565:        return 0;
1.1       schwarze  566: }
                    567:
                    568: static int
                    569: man_ign_pre(MAN_ARGS)
                    570: {
1.72      schwarze  571:        return 0;
1.1       schwarze  572: }
                    573:
                    574: static int
                    575: man_RS_pre(MAN_ARGS)
                    576: {
1.119     schwarze  577:        switch (n->type) {
                    578:        case ROFFT_BLOCK:
                    579:                html_close_paragraph(h);
                    580:                break;
                    581:        case ROFFT_HEAD:
1.72      schwarze  582:                return 0;
1.119     schwarze  583:        case ROFFT_BODY:
1.105     schwarze  584:                print_otag(h, TAG_DIV, "c", "Bd-indent");
1.119     schwarze  585:                break;
                    586:        default:
                    587:                abort();
                    588:        }
1.109     schwarze  589:        return 1;
                    590: }
                    591:
                    592: static int
                    593: man_SY_pre(MAN_ARGS)
                    594: {
                    595:        switch (n->type) {
                    596:        case ROFFT_BLOCK:
1.119     schwarze  597:                html_close_paragraph(h);
1.109     schwarze  598:                print_otag(h, TAG_TABLE, "c", "Nm");
                    599:                print_otag(h, TAG_TR, "");
                    600:                break;
                    601:        case ROFFT_HEAD:
                    602:                print_otag(h, TAG_TD, "");
1.121     schwarze  603:                print_otag(h, TAG_CODE, "c", "Nm");
1.109     schwarze  604:                break;
                    605:        case ROFFT_BODY:
                    606:                print_otag(h, TAG_TD, "");
                    607:                break;
                    608:        default:
                    609:                abort();
                    610:        }
1.72      schwarze  611:        return 1;
1.49      schwarze  612: }
                    613:
                    614: static int
                    615: man_UR_pre(MAN_ARGS)
                    616: {
1.98      bentley   617:        char *cp;
1.117     schwarze  618:
1.49      schwarze  619:        n = n->child;
1.66      schwarze  620:        assert(n->type == ROFFT_HEAD);
1.73      schwarze  621:        if (n->child != NULL) {
1.66      schwarze  622:                assert(n->child->type == ROFFT_TEXT);
1.98      bentley   623:                if (n->tok == MAN_MT) {
                    624:                        mandoc_asprintf(&cp, "mailto:%s", n->child->string);
1.121     schwarze  625:                        print_otag(h, TAG_A, "ch", "Mt", cp);
1.98      bentley   626:                        free(cp);
                    627:                } else
1.121     schwarze  628:                        print_otag(h, TAG_A, "ch", "Lk", n->child->string);
1.49      schwarze  629:        }
                    630:
1.66      schwarze  631:        assert(n->next->type == ROFFT_BODY);
1.73      schwarze  632:        if (n->next->child != NULL)
1.49      schwarze  633:                n = n->next;
                    634:
1.85      schwarze  635:        print_man_nodelist(man, n->child, h);
1.72      schwarze  636:        return 0;
1.111     schwarze  637: }
                    638:
                    639: static int
                    640: man_abort_pre(MAN_ARGS)
                    641: {
                    642:        abort();
1.1       schwarze  643: }