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

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