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

Annotation of mandoc/man_html.c, Revision 1.188

1.188   ! schwarze    1: /* $Id: man_html.c,v 1.187 2023/10/24 20:53:12 schwarze Exp $ */
1.1       kristaps    2: /*
1.188   ! schwarze    3:  * Copyright (c) 2013-2020,2022-2023,2025 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.187     schwarze   56: static int               man_MR_pre(MAN_ARGS);
1.86      kristaps   57: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   58: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   59: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   60: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   61: static int               man_SM_pre(MAN_ARGS);
1.156     schwarze   62: static int               man_SY_pre(MAN_ARGS);
1.90      schwarze   63: static int               man_UR_pre(MAN_ARGS);
1.86      kristaps   64: static int               man_alt_pre(MAN_ARGS);
                     65: static int               man_ign_pre(MAN_ARGS);
                     66: static int               man_in_pre(MAN_ARGS);
1.147     schwarze   67: static void              man_root_post(const struct roff_meta *,
                     68:                                struct html *);
                     69: static void              man_root_pre(const struct roff_meta *,
                     70:                                struct html *);
1.4       kristaps   71:
1.155     schwarze   72: static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = {
1.3       kristaps   73:        { NULL, NULL }, /* TH */
1.4       kristaps   74:        { man_SH_pre, NULL }, /* SH */
1.166     schwarze   75:        { man_SH_pre, NULL }, /* SS */
1.6       kristaps   76:        { man_IP_pre, NULL }, /* TP */
1.154     schwarze   77:        { man_IP_pre, NULL }, /* TQ */
1.185     schwarze   78:        { man_PP_pre, NULL }, /* LP */
1.4       kristaps   79:        { man_PP_pre, NULL }, /* PP */
1.185     schwarze   80:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   81:        { man_IP_pre, NULL }, /* IP */
1.166     schwarze   82:        { man_PP_pre, NULL }, /* HP */
1.8       kristaps   83:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   84:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   85:        { man_alt_pre, NULL }, /* BI */
                     86:        { man_alt_pre, NULL }, /* IB */
                     87:        { man_alt_pre, NULL }, /* BR */
                     88:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   89:        { NULL, NULL }, /* R */
1.8       kristaps   90:        { man_B_pre, NULL }, /* B */
                     91:        { man_I_pre, NULL }, /* I */
                     92:        { man_alt_pre, NULL }, /* IR */
                     93:        { man_alt_pre, NULL }, /* RI */
1.3       kristaps   94:        { NULL, NULL }, /* RE */
1.9       kristaps   95:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps   96:        { man_ign_pre, NULL }, /* DT */
                     97:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps   98:        { man_ign_pre, NULL }, /* PD */
1.34      joerg      99:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  100:        { man_in_pre, NULL }, /* in */
1.156     schwarze  101:        { man_SY_pre, NULL }, /* SY */
                    102:        { NULL, NULL }, /* YS */
1.86      kristaps  103:        { man_OP_pre, NULL }, /* OP */
1.132     schwarze  104:        { NULL, NULL }, /* EX */
                    105:        { NULL, NULL }, /* EE */
1.90      schwarze  106:        { man_UR_pre, NULL }, /* UR */
                    107:        { NULL, NULL }, /* UE */
1.145     schwarze  108:        { man_UR_pre, NULL }, /* MT */
                    109:        { NULL, NULL }, /* ME */
1.187     schwarze  110:        { man_MR_pre, NULL }, /* MR */
1.3       kristaps  111: };
                    112:
1.93      schwarze  113:
1.1       kristaps  114: void
1.161     schwarze  115: html_man(void *arg, const struct roff_meta *man)
1.1       kristaps  116: {
1.147     schwarze  117:        struct html             *h;
                    118:        struct roff_node        *n;
                    119:        struct tag              *t;
1.82      kristaps  120:
1.117     schwarze  121:        h = (struct html *)arg;
1.147     schwarze  122:        n = man->first->child;
1.3       kristaps  123:
1.126     schwarze  124:        if ((h->oflags & HTML_FRAGMENT) == 0) {
1.82      kristaps  125:                print_gen_decls(h);
1.126     schwarze  126:                print_otag(h, TAG_HTML, "");
                    127:                t = print_otag(h, TAG_HEAD, "");
1.161     schwarze  128:                print_man_head(man, h);
1.126     schwarze  129:                print_tagq(h, t);
1.181     schwarze  130:                if (n != NULL && n->type == ROFFT_COMMENT)
                    131:                        print_gen_comment(h, n);
1.122     schwarze  132:                print_otag(h, TAG_BODY, "");
1.126     schwarze  133:        }
1.53      kristaps  134:
1.161     schwarze  135:        man_root_pre(man, h);
1.180     schwarze  136:        t = print_otag(h, TAG_MAIN, "c", "manual-text");
1.161     schwarze  137:        print_man_nodelist(man, n, h);
1.127     schwarze  138:        print_tagq(h, t);
1.161     schwarze  139:        man_root_post(man, h);
1.126     schwarze  140:        print_tagq(h, NULL);
1.3       kristaps  141: }
                    142:
                    143: static void
1.147     schwarze  144: print_man_head(const struct roff_meta *man, struct html *h)
1.3       kristaps  145: {
1.123     schwarze  146:        char    *cp;
1.3       kristaps  147:
                    148:        print_gen_head(h);
1.123     schwarze  149:        mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.122     schwarze  150:        print_otag(h, TAG_TITLE, "");
1.123     schwarze  151:        print_text(h, cp);
                    152:        free(cp);
1.1       kristaps  153: }
1.4       kristaps  154:
                    155: static void
                    156: print_man_nodelist(MAN_ARGS)
                    157: {
1.110     schwarze  158:        while (n != NULL) {
1.132     schwarze  159:                print_man_node(man, n, h);
1.110     schwarze  160:                n = n->next;
                    161:        }
1.4       kristaps  162: }
                    163:
                    164: static void
                    165: print_man_node(MAN_ARGS)
                    166: {
1.132     schwarze  167:        struct tag      *t;
1.4       kristaps  168:        int              child;
                    169:
1.167     schwarze  170:        if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
                    171:                return;
                    172:
1.179     schwarze  173:        if ((n->flags & NODE_NOFILL) == 0)
                    174:                html_fillmode(h, ROFF_fi);
                    175:        else if (html_fillmode(h, ROFF_nf) == ROFF_nf &&
                    176:            n->tok != ROFF_fi && n->flags & NODE_LINE &&
                    177:            (n->prev == NULL || n->prev->tok != MAN_YS))
                    178:                print_endline(h);
1.132     schwarze  179:
                    180:        child = 1;
                    181:        switch (n->type) {
                    182:        case ROFFT_TEXT:
1.163     schwarze  183:                if (*n->string == '\0') {
                    184:                        print_endline(h);
                    185:                        return;
                    186:                }
                    187:                if (*n->string == ' ' && n->flags & NODE_LINE &&
                    188:                    (h->flags & HTML_NONEWLINE) == 0)
1.175     schwarze  189:                        print_otag(h, TAG_BR, "");
1.163     schwarze  190:                else if (n->flags & NODE_DELIMC)
                    191:                        h->flags |= HTML_NOSPACE;
1.170     schwarze  192:                t = h->tag;
                    193:                t->refcnt++;
1.4       kristaps  194:                print_text(h, n->string);
1.130     schwarze  195:                break;
1.113     schwarze  196:        case ROFFT_EQN:
1.170     schwarze  197:                t = h->tag;
                    198:                t->refcnt++;
1.80      kristaps  199:                print_eqn(h, n->eqn);
1.69      kristaps  200:                break;
1.113     schwarze  201:        case ROFFT_TBL:
1.66      kristaps  202:                /*
                    203:                 * This will take care of initialising all of the table
                    204:                 * state data for the first table, then tearing it down
                    205:                 * for the last one.
                    206:                 */
1.60      kristaps  207:                print_tbl(h, n->span);
1.64      kristaps  208:                return;
1.4       kristaps  209:        default:
1.93      schwarze  210:                /*
1.21      kristaps  211:                 * Close out scope of font prior to opening a macro
1.66      kristaps  212:                 * scope.
1.21      kristaps  213:                 */
1.174     schwarze  214:                if (h->metac != ESCAPE_FONTROMAN) {
1.57      kristaps  215:                        h->metal = h->metac;
1.174     schwarze  216:                        h->metac = ESCAPE_FONTROMAN;
1.66      kristaps  217:                }
                    218:
                    219:                /*
                    220:                 * Close out the current table, if it's open, and unset
                    221:                 * the "meta" table state.  This will be reopened on the
                    222:                 * next table element.
                    223:                 */
1.170     schwarze  224:                if (h->tblt != NULL)
1.66      kristaps  225:                        print_tblclose(h);
1.170     schwarze  226:                t = h->tag;
                    227:                t->refcnt++;
1.137     schwarze  228:                if (n->tok < ROFF_MAX) {
1.138     schwarze  229:                        roff_html_pre(h, n);
1.170     schwarze  230:                        t->refcnt--;
1.167     schwarze  231:                        print_stagq(h, t);
1.163     schwarze  232:                        return;
1.137     schwarze  233:                }
                    234:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.155     schwarze  235:                if (man_html_acts[n->tok - MAN_TH].pre != NULL)
                    236:                        child = (*man_html_acts[n->tok - MAN_TH].pre)(man,
                    237:                            n, h);
1.4       kristaps  238:                break;
                    239:        }
                    240:
1.164     schwarze  241:        if (child && n->child != NULL)
1.132     schwarze  242:                print_man_nodelist(man, n->child, h);
1.21      kristaps  243:
1.24      kristaps  244:        /* This will automatically close out any font scope. */
1.170     schwarze  245:        t->refcnt--;
1.171     schwarze  246:        if (n->type == ROFFT_BLOCK &&
                    247:            (n->tok == MAN_IP || n->tok == MAN_TP || n->tok == MAN_TQ)) {
                    248:                t = h->tag;
1.173     schwarze  249:                while (t->tag != TAG_DL && t->tag != TAG_UL)
1.171     schwarze  250:                        t = t->next;
                    251:                /*
                    252:                 * Close the list if no further item of the same type
                    253:                 * follows; otherwise, close the item only.
                    254:                 */
1.176     schwarze  255:                if (list_continues(n, roff_node_next(n)) == '\0') {
1.171     schwarze  256:                        print_tagq(h, t);
                    257:                        t = NULL;
                    258:                }
                    259:        }
                    260:        if (t != NULL)
                    261:                print_stagq(h, t);
1.4       kristaps  262: }
                    263:
1.65      kristaps  264: static void
1.147     schwarze  265: man_root_pre(const struct roff_meta *man, struct html *h)
1.4       kristaps  266: {
1.182     schwarze  267:        struct tag      *t;
1.94      schwarze  268:        char            *title;
1.4       kristaps  269:
1.89      schwarze  270:        assert(man->title);
                    271:        assert(man->msec);
1.94      schwarze  272:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4       kristaps  273:
1.182     schwarze  274:        t = print_otag(h, TAG_DIV, "cr?", "head", "doc-pageheader",
1.184     schwarze  275:            "aria-label", "Manual header line");
1.4       kristaps  276:
1.182     schwarze  277:        print_otag(h, TAG_SPAN, "c", "head-ltitle");
1.4       kristaps  278:        print_text(h, title);
1.182     schwarze  279:        print_stagq(h, t);
1.4       kristaps  280:
1.182     schwarze  281:        print_otag(h, TAG_SPAN, "c", "head-vol");
1.164     schwarze  282:        if (man->vol != NULL)
1.95      schwarze  283:                print_text(h, man->vol);
1.182     schwarze  284:        print_stagq(h, t);
1.4       kristaps  285:
1.182     schwarze  286:        print_otag(h, TAG_SPAN, "c", "head-rtitle");
1.4       kristaps  287:        print_text(h, title);
                    288:        print_tagq(h, t);
1.94      schwarze  289:        free(title);
1.4       kristaps  290: }
                    291:
                    292: static void
1.147     schwarze  293: man_root_post(const struct roff_meta *man, struct html *h)
1.4       kristaps  294: {
1.182     schwarze  295:        struct tag      *t;
1.188   ! schwarze  296:        char            *title;
        !           297:
        !           298:        assert(man->title != NULL);
        !           299:        if (man->msec == NULL)
        !           300:                title = mandoc_strdup(man->title);
        !           301:        else
        !           302:                mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.182     schwarze  303:
                    304:        t = print_otag(h, TAG_DIV, "cr?", "foot", "doc-pagefooter",
1.184     schwarze  305:            "aria-label", "Manual footer line");
1.4       kristaps  306:
1.182     schwarze  307:        print_otag(h, TAG_SPAN, "c", "foot-left");
1.188   ! schwarze  308:        if (man->os != NULL)
        !           309:                print_text(h, man->os);
1.182     schwarze  310:        print_stagq(h, t);
1.55      kristaps  311:
1.182     schwarze  312:        print_otag(h, TAG_SPAN, "c", "foot-date");
1.89      schwarze  313:        print_text(h, man->date);
1.182     schwarze  314:        print_stagq(h, t);
1.4       kristaps  315:
1.188   ! schwarze  316:        print_otag(h, TAG_SPAN, "c", "foot-right");
        !           317:        print_text(h, title);
1.4       kristaps  318:        print_tagq(h, t);
1.188   ! schwarze  319:        free(title);
1.4       kristaps  320: }
                    321:
                    322: static int
                    323: man_SH_pre(MAN_ARGS)
                    324: {
1.172     schwarze  325:        const char      *class;
                    326:        enum htmltag     tag;
                    327:
                    328:        if (n->tok == MAN_SH) {
1.183     schwarze  329:                tag = TAG_H2;
1.172     schwarze  330:                class = "Sh";
                    331:        } else {
1.183     schwarze  332:                tag = TAG_H3;
1.172     schwarze  333:                class = "Ss";
                    334:        }
1.166     schwarze  335:        switch (n->type) {
                    336:        case ROFFT_BLOCK:
                    337:                html_close_paragraph(h);
1.172     schwarze  338:                print_otag(h, TAG_SECTION, "c", class);
1.166     schwarze  339:                break;
                    340:        case ROFFT_HEAD:
1.177     schwarze  341:                print_otag_id(h, tag, class, n);
1.166     schwarze  342:                break;
                    343:        case ROFFT_BODY:
                    344:                break;
                    345:        default:
                    346:                abort();
1.134     schwarze  347:        }
1.119     schwarze  348:        return 1;
1.4       kristaps  349: }
                    350:
                    351: static int
1.8       kristaps  352: man_alt_pre(MAN_ARGS)
                    353: {
1.114     schwarze  354:        const struct roff_node  *nn;
1.164     schwarze  355:        struct tag      *t;
1.130     schwarze  356:        int              i;
1.57      kristaps  357:        enum htmltag     fp;
1.8       kristaps  358:
1.164     schwarze  359:        for (i = 0, nn = n->child; nn != NULL; nn = nn->next, i++) {
1.8       kristaps  360:                switch (n->tok) {
1.93      schwarze  361:                case MAN_BI:
1.57      kristaps  362:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  363:                        break;
1.93      schwarze  364:                case MAN_IB:
1.57      kristaps  365:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  366:                        break;
1.93      schwarze  367:                case MAN_RI:
1.57      kristaps  368:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  369:                        break;
1.93      schwarze  370:                case MAN_IR:
1.57      kristaps  371:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  372:                        break;
1.93      schwarze  373:                case MAN_BR:
1.57      kristaps  374:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  375:                        break;
1.93      schwarze  376:                case MAN_RB:
1.57      kristaps  377:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  378:                        break;
                    379:                default:
                    380:                        abort();
                    381:                }
                    382:
                    383:                if (i)
                    384:                        h->flags |= HTML_NOSPACE;
                    385:
1.130     schwarze  386:                if (fp != TAG_MAX)
1.122     schwarze  387:                        t = print_otag(h, fp, "");
1.57      kristaps  388:
1.130     schwarze  389:                print_text(h, nn->string);
1.57      kristaps  390:
1.130     schwarze  391:                if (fp != TAG_MAX)
1.57      kristaps  392:                        print_tagq(h, t);
1.8       kristaps  393:        }
1.119     schwarze  394:        return 0;
1.8       kristaps  395: }
                    396:
                    397: static int
1.56      kristaps  398: man_SM_pre(MAN_ARGS)
1.8       kristaps  399: {
1.122     schwarze  400:        print_otag(h, TAG_SMALL, "");
1.164     schwarze  401:        if (n->tok == MAN_SB)
1.122     schwarze  402:                print_otag(h, TAG_B, "");
1.119     schwarze  403:        return 1;
1.8       kristaps  404: }
                    405:
                    406: static int
1.4       kristaps  407: man_PP_pre(MAN_ARGS)
                    408: {
1.166     schwarze  409:        switch (n->type) {
                    410:        case ROFFT_BLOCK:
                    411:                html_close_paragraph(h);
                    412:                break;
                    413:        case ROFFT_HEAD:
1.119     schwarze  414:                return 0;
1.166     schwarze  415:        case ROFFT_BODY:
                    416:                if (n->child != NULL &&
                    417:                    (n->child->flags & NODE_NOFILL) == 0)
                    418:                        print_otag(h, TAG_P, "c",
1.185     schwarze  419:                            n->tok == MAN_HP ? "Pp HP" : "Pp");
1.166     schwarze  420:                break;
                    421:        default:
                    422:                abort();
                    423:        }
1.119     schwarze  424:        return 1;
1.5       kristaps  425: }
                    426:
1.173     schwarze  427: static char
                    428: list_continues(const struct roff_node *n1, const struct roff_node *n2)
                    429: {
                    430:        const char *s1, *s2;
                    431:        char c1, c2;
                    432:
                    433:        if (n1 == NULL || n1->type != ROFFT_BLOCK ||
                    434:            n2 == NULL || n2->type != ROFFT_BLOCK)
                    435:                return '\0';
                    436:        if ((n1->tok == MAN_TP || n1->tok == MAN_TQ) &&
                    437:            (n2->tok == MAN_TP || n2->tok == MAN_TQ))
                    438:                return ' ';
                    439:        if (n1->tok != MAN_IP || n2->tok != MAN_IP)
                    440:                return '\0';
                    441:        n1 = n1->head->child;
                    442:        n2 = n2->head->child;
                    443:        s1 = n1 == NULL ? "" : n1->string;
                    444:        s2 = n2 == NULL ? "" : n2->string;
                    445:        c1 = strcmp(s1, "*") == 0 ? '*' :
                    446:             strcmp(s1, "\\-") == 0 ? '-' :
1.186     schwarze  447:             strcmp(s1, "\\(bu") == 0 ? 'b' :
                    448:             strcmp(s1, "\\[bu]") == 0 ? 'b' : ' ';
1.173     schwarze  449:        c2 = strcmp(s2, "*") == 0 ? '*' :
                    450:             strcmp(s2, "\\-") == 0 ? '-' :
1.186     schwarze  451:             strcmp(s2, "\\(bu") == 0 ? 'b' :
                    452:             strcmp(s2, "\\[bu]") == 0 ? 'b' : ' ';
1.173     schwarze  453:        return c1 != c2 ? '\0' : c1 == 'b' ? '*' : c1;
                    454: }
                    455:
1.5       kristaps  456: static int
                    457: man_IP_pre(MAN_ARGS)
                    458: {
1.176     schwarze  459:        struct roff_node        *nn;
1.173     schwarze  460:        const char              *list_class;
                    461:        enum htmltag             list_elem, body_elem;
                    462:        char                     list_type;
                    463:
                    464:        nn = n->type == ROFFT_BLOCK ? n : n->parent;
1.176     schwarze  465:        list_type = list_continues(roff_node_prev(nn), nn);
                    466:        if (list_type == '\0') {
1.173     schwarze  467:                /* Start a new list. */
1.176     schwarze  468:                list_type = list_continues(nn, roff_node_next(nn));
                    469:                if (list_type == '\0')
1.173     schwarze  470:                        list_type = ' ';
                    471:                switch (list_type) {
                    472:                case ' ':
                    473:                        list_class = "Bl-tag";
                    474:                        list_elem = TAG_DL;
                    475:                        break;
                    476:                case '*':
                    477:                        list_class = "Bl-bullet";
                    478:                        list_elem = TAG_UL;
                    479:                        break;
                    480:                case '-':
                    481:                        list_class = "Bl-dash";
                    482:                        list_elem = TAG_UL;
                    483:                        break;
                    484:                default:
                    485:                        abort();
                    486:                }
                    487:        } else {
                    488:                /* Continue a list that was started earlier. */
                    489:                list_class = NULL;
                    490:                list_elem = TAG_MAX;
                    491:        }
                    492:        body_elem = list_type == ' ' ? TAG_DD : TAG_LI;
1.5       kristaps  493:
1.166     schwarze  494:        switch (n->type) {
                    495:        case ROFFT_BLOCK:
                    496:                html_close_paragraph(h);
1.173     schwarze  497:                if (list_elem != TAG_MAX)
                    498:                        print_otag(h, list_elem, "c", list_class);
1.166     schwarze  499:                return 1;
                    500:        case ROFFT_HEAD:
1.173     schwarze  501:                if (body_elem == TAG_LI)
                    502:                        return 0;
1.177     schwarze  503:                print_otag_id(h, TAG_DT, NULL, n);
1.166     schwarze  504:                break;
                    505:        case ROFFT_BODY:
1.173     schwarze  506:                print_otag(h, body_elem, "");
1.119     schwarze  507:                return 1;
1.166     schwarze  508:        default:
                    509:                abort();
1.6       kristaps  510:        }
1.154     schwarze  511:        switch(n->tok) {
                    512:        case MAN_IP:  /* Only print the first header element. */
                    513:                if (n->child != NULL)
                    514:                        print_man_node(man, n->child, h);
                    515:                break;
                    516:        case MAN_TP:  /* Only print next-line header elements. */
                    517:        case MAN_TQ:
1.91      schwarze  518:                nn = n->child;
1.154     schwarze  519:                while (nn != NULL && (NODE_LINE & nn->flags) == 0)
1.91      schwarze  520:                        nn = nn->next;
1.154     schwarze  521:                while (nn != NULL) {
1.132     schwarze  522:                        print_man_node(man, nn, h);
1.91      schwarze  523:                        nn = nn->next;
                    524:                }
1.154     schwarze  525:                break;
                    526:        default:
                    527:                abort();
1.187     schwarze  528:        }
                    529:        return 0;
                    530: }
                    531:
                    532: static int
                    533: man_MR_pre(MAN_ARGS)
                    534: {
                    535:        struct tag      *t;
                    536:        const char      *name, *section, *suffix;
                    537:        char            *label;
                    538:
                    539:        html_setfont(h, ESCAPE_FONTROMAN);
                    540:        name = section = suffix = label = NULL;
                    541:        if (n->child != NULL) {
                    542:                name = n->child->string;
                    543:                if (n->child->next != NULL) {
                    544:                        section = n->child->next->string;
                    545:                        mandoc_asprintf(&label,
                    546:                            "%s, section %s", name, section);
                    547:                        if (n->child->next->next != NULL)
                    548:                                suffix = n->child->next->next->string;
                    549:                }
                    550:        }
                    551:
                    552:        if (name != NULL && section != NULL && h->base_man1 != NULL)
                    553:                t = print_otag(h, TAG_A, "chM?", "Xr",
                    554:                    name, section, "aria-label", label);
                    555:        else
                    556:                t = print_otag(h, TAG_A, "c?", "Xr", "aria-label", label);
                    557:
                    558:        free(label);
                    559:        if (name != NULL) {
                    560:                print_text(h, name);
                    561:                h->flags |= HTML_NOSPACE;
                    562:        }
                    563:        print_text(h, "(");
                    564:        h->flags |= HTML_NOSPACE;
                    565:        if (section != NULL) {
                    566:                print_text(h, section);
                    567:                h->flags |= HTML_NOSPACE;
                    568:        }
                    569:        print_text(h, ")");
                    570:        print_tagq(h, t);
                    571:        if (suffix != NULL) {
                    572:                h->flags |= HTML_NOSPACE;
                    573:                print_text(h, suffix);
1.91      schwarze  574:        }
1.119     schwarze  575:        return 0;
1.6       kristaps  576: }
                    577:
                    578: static int
1.86      kristaps  579: man_OP_pre(MAN_ARGS)
                    580: {
                    581:        struct tag      *tt;
                    582:
                    583:        print_text(h, "[");
                    584:        h->flags |= HTML_NOSPACE;
1.128     schwarze  585:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86      kristaps  586:
1.164     schwarze  587:        if ((n = n->child) != NULL) {
1.122     schwarze  588:                print_otag(h, TAG_B, "");
1.86      kristaps  589:                print_text(h, n->string);
                    590:        }
                    591:
                    592:        print_stagq(h, tt);
                    593:
1.164     schwarze  594:        if (n != NULL && n->next != NULL) {
1.122     schwarze  595:                print_otag(h, TAG_I, "");
1.86      kristaps  596:                print_text(h, n->next->string);
                    597:        }
                    598:
                    599:        print_stagq(h, tt);
                    600:        h->flags |= HTML_NOSPACE;
                    601:        print_text(h, "]");
1.119     schwarze  602:        return 0;
1.86      kristaps  603: }
                    604:
1.8       kristaps  605: static int
                    606: man_B_pre(MAN_ARGS)
                    607: {
1.122     schwarze  608:        print_otag(h, TAG_B, "");
1.119     schwarze  609:        return 1;
1.8       kristaps  610: }
                    611:
                    612: static int
                    613: man_I_pre(MAN_ARGS)
                    614: {
1.122     schwarze  615:        print_otag(h, TAG_I, "");
1.119     schwarze  616:        return 1;
1.45      kristaps  617: }
                    618:
                    619: static int
                    620: man_in_pre(MAN_ARGS)
                    621: {
1.122     schwarze  622:        print_otag(h, TAG_BR, "");
1.119     schwarze  623:        return 0;
1.8       kristaps  624: }
                    625:
                    626: static int
                    627: man_ign_pre(MAN_ARGS)
                    628: {
1.119     schwarze  629:        return 0;
1.8       kristaps  630: }
1.9       kristaps  631:
                    632: static int
                    633: man_RS_pre(MAN_ARGS)
                    634: {
1.166     schwarze  635:        switch (n->type) {
                    636:        case ROFFT_BLOCK:
                    637:                html_close_paragraph(h);
                    638:                break;
                    639:        case ROFFT_HEAD:
1.119     schwarze  640:                return 0;
1.166     schwarze  641:        case ROFFT_BODY:
1.152     schwarze  642:                print_otag(h, TAG_DIV, "c", "Bd-indent");
1.166     schwarze  643:                break;
                    644:        default:
                    645:                abort();
                    646:        }
1.156     schwarze  647:        return 1;
                    648: }
                    649:
                    650: static int
                    651: man_SY_pre(MAN_ARGS)
                    652: {
                    653:        switch (n->type) {
                    654:        case ROFFT_BLOCK:
1.166     schwarze  655:                html_close_paragraph(h);
1.156     schwarze  656:                print_otag(h, TAG_TABLE, "c", "Nm");
                    657:                print_otag(h, TAG_TR, "");
                    658:                break;
                    659:        case ROFFT_HEAD:
                    660:                print_otag(h, TAG_TD, "");
1.168     schwarze  661:                print_otag(h, TAG_CODE, "c", "Nm");
1.156     schwarze  662:                break;
                    663:        case ROFFT_BODY:
                    664:                print_otag(h, TAG_TD, "");
                    665:                break;
                    666:        default:
                    667:                abort();
                    668:        }
1.119     schwarze  669:        return 1;
1.90      schwarze  670: }
                    671:
                    672: static int
                    673: man_UR_pre(MAN_ARGS)
                    674: {
1.145     schwarze  675:        char *cp;
1.164     schwarze  676:
1.90      schwarze  677:        n = n->child;
1.113     schwarze  678:        assert(n->type == ROFFT_HEAD);
1.120     schwarze  679:        if (n->child != NULL) {
1.113     schwarze  680:                assert(n->child->type == ROFFT_TEXT);
1.145     schwarze  681:                if (n->tok == MAN_MT) {
                    682:                        mandoc_asprintf(&cp, "mailto:%s", n->child->string);
1.168     schwarze  683:                        print_otag(h, TAG_A, "ch", "Mt", cp);
1.145     schwarze  684:                        free(cp);
                    685:                } else
1.168     schwarze  686:                        print_otag(h, TAG_A, "ch", "Lk", n->child->string);
1.90      schwarze  687:        }
                    688:
1.113     schwarze  689:        assert(n->next->type == ROFFT_BODY);
1.120     schwarze  690:        if (n->next->child != NULL)
1.90      schwarze  691:                n = n->next;
                    692:
1.132     schwarze  693:        print_man_nodelist(man, n->child, h);
1.119     schwarze  694:        return 0;
1.9       kristaps  695: }

CVSweb