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

Annotation of mandoc/man_html.c, Revision 1.185

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

CVSweb