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

Annotation of mandoc/man_html.c, Revision 1.176

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

CVSweb