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

Annotation of mandoc/man_html.c, Revision 1.158

1.158   ! schwarze    1: /*     $Id: man_html.c,v 1.157 2018/10/23 17:18:01 schwarze Exp $ */
1.1       kristaps    2: /*
1.104     kristaps    3:  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.147     schwarze    4:  * Copyright (c) 2013,2014,2015,2017,2018 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.144     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.13      kristaps   36: /* FIXME: have PD set the default vspace width. */
1.4       kristaps   37:
1.115     schwarze   38: #define        MAN_ARGS          const struct roff_meta *man, \
1.114     schwarze   39:                          const 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.93      schwarze   47: static void              print_bvspace(struct html *,
1.114     schwarze   48:                                const struct roff_node *);
1.147     schwarze   49: static void              print_man_head(const struct roff_meta *,
                     50:                                struct html *);
1.4       kristaps   51: static void              print_man_nodelist(MAN_ARGS);
                     52: static void              print_man_node(MAN_ARGS);
1.132     schwarze   53: static int               fillmode(struct html *, int);
1.8       kristaps   54: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   55: static int               man_HP_pre(MAN_ARGS);
1.86      kristaps   56: static int               man_IP_pre(MAN_ARGS);
1.8       kristaps   57: static int               man_I_pre(MAN_ARGS);
1.86      kristaps   58: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   59: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   60: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   61: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   62: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   63: static int               man_SS_pre(MAN_ARGS);
1.156     schwarze   64: static int               man_SY_pre(MAN_ARGS);
1.90      schwarze   65: static int               man_UR_pre(MAN_ARGS);
1.158   ! schwarze   66: static int               man_abort_pre(MAN_ARGS);
1.86      kristaps   67: static int               man_alt_pre(MAN_ARGS);
                     68: static int               man_ign_pre(MAN_ARGS);
                     69: static int               man_in_pre(MAN_ARGS);
1.147     schwarze   70: static void              man_root_post(const struct roff_meta *,
                     71:                                struct html *);
                     72: static void              man_root_pre(const struct roff_meta *,
                     73:                                struct html *);
1.4       kristaps   74:
1.155     schwarze   75: static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = {
1.3       kristaps   76:        { NULL, NULL }, /* TH */
1.4       kristaps   77:        { man_SH_pre, NULL }, /* SH */
                     78:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   79:        { man_IP_pre, NULL }, /* TP */
1.154     schwarze   80:        { man_IP_pre, NULL }, /* TQ */
1.158   ! schwarze   81:        { man_abort_pre, NULL }, /* LP */
1.4       kristaps   82:        { man_PP_pre, NULL }, /* PP */
1.158   ! schwarze   83:        { man_abort_pre, NULL }, /* P */
1.5       kristaps   84:        { man_IP_pre, NULL }, /* IP */
1.93      schwarze   85:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   86:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   87:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   88:        { man_alt_pre, NULL }, /* BI */
                     89:        { man_alt_pre, NULL }, /* IB */
                     90:        { man_alt_pre, NULL }, /* BR */
                     91:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   92:        { NULL, NULL }, /* R */
1.8       kristaps   93:        { man_B_pre, NULL }, /* B */
                     94:        { man_I_pre, NULL }, /* I */
                     95:        { man_alt_pre, NULL }, /* IR */
                     96:        { man_alt_pre, NULL }, /* RI */
1.132     schwarze   97:        { NULL, NULL }, /* nf */
                     98:        { NULL, NULL }, /* fi */
1.3       kristaps   99:        { NULL, NULL }, /* RE */
1.9       kristaps  100:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  101:        { man_ign_pre, NULL }, /* DT */
                    102:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  103:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     104:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  105:        { man_in_pre, NULL }, /* in */
1.156     schwarze  106:        { man_SY_pre, NULL }, /* SY */
                    107:        { NULL, NULL }, /* YS */
1.86      kristaps  108:        { man_OP_pre, NULL }, /* OP */
1.132     schwarze  109:        { NULL, NULL }, /* EX */
                    110:        { NULL, NULL }, /* EE */
1.90      schwarze  111:        { man_UR_pre, NULL }, /* UR */
                    112:        { NULL, NULL }, /* UE */
1.145     schwarze  113:        { man_UR_pre, NULL }, /* MT */
                    114:        { NULL, NULL }, /* ME */
1.3       kristaps  115: };
                    116:
1.93      schwarze  117:
1.74      kristaps  118: /*
                    119:  * Printing leading vertical space before a block.
                    120:  * This is used for the paragraph macros.
                    121:  * The rules are pretty simple, since there's very little nesting going
                    122:  * on here.  Basically, if we're the first within another block (SS/SH),
                    123:  * then don't emit vertical space.  If we are (RS), then do.  If not the
                    124:  * first, print it.
                    125:  */
                    126: static void
1.114     schwarze  127: print_bvspace(struct html *h, const struct roff_node *n)
1.74      kristaps  128: {
                    129:
                    130:        if (n->body && n->body->child)
1.113     schwarze  131:                if (n->body->child->type == ROFFT_TBL)
1.74      kristaps  132:                        return;
                    133:
1.113     schwarze  134:        if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
1.74      kristaps  135:                if (NULL == n->prev)
                    136:                        return;
                    137:
1.103     kristaps  138:        print_paragraph(h);
1.74      kristaps  139: }
1.1       kristaps  140:
                    141: void
1.116     schwarze  142: html_man(void *arg, const struct roff_man *man)
1.1       kristaps  143: {
1.147     schwarze  144:        struct html             *h;
                    145:        struct roff_node        *n;
                    146:        struct tag              *t;
1.82      kristaps  147:
1.117     schwarze  148:        h = (struct html *)arg;
1.147     schwarze  149:        n = man->first->child;
1.3       kristaps  150:
1.126     schwarze  151:        if ((h->oflags & HTML_FRAGMENT) == 0) {
1.82      kristaps  152:                print_gen_decls(h);
1.126     schwarze  153:                print_otag(h, TAG_HTML, "");
1.147     schwarze  154:                if (n->type == ROFFT_COMMENT)
                    155:                        print_gen_comment(h, n);
1.126     schwarze  156:                t = print_otag(h, TAG_HEAD, "");
1.147     schwarze  157:                print_man_head(&man->meta, h);
1.126     schwarze  158:                print_tagq(h, t);
1.122     schwarze  159:                print_otag(h, TAG_BODY, "");
1.126     schwarze  160:        }
1.53      kristaps  161:
1.147     schwarze  162:        man_root_pre(&man->meta, h);
1.127     schwarze  163:        t = print_otag(h, TAG_DIV, "c", "manual-text");
1.147     schwarze  164:        print_man_nodelist(&man->meta, n, h);
1.127     schwarze  165:        print_tagq(h, t);
1.147     schwarze  166:        man_root_post(&man->meta, h);
1.126     schwarze  167:        print_tagq(h, NULL);
1.3       kristaps  168: }
                    169:
                    170: static void
1.147     schwarze  171: print_man_head(const struct roff_meta *man, struct html *h)
1.3       kristaps  172: {
1.123     schwarze  173:        char    *cp;
1.3       kristaps  174:
                    175:        print_gen_head(h);
1.123     schwarze  176:        mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.122     schwarze  177:        print_otag(h, TAG_TITLE, "");
1.123     schwarze  178:        print_text(h, cp);
                    179:        free(cp);
1.1       kristaps  180: }
1.4       kristaps  181:
                    182: static void
                    183: print_man_nodelist(MAN_ARGS)
                    184: {
                    185:
1.110     schwarze  186:        while (n != NULL) {
1.132     schwarze  187:                print_man_node(man, n, h);
1.110     schwarze  188:                n = n->next;
                    189:        }
1.4       kristaps  190: }
                    191:
                    192: static void
                    193: print_man_node(MAN_ARGS)
                    194: {
1.132     schwarze  195:        static int       want_fillmode = MAN_fi;
                    196:        static int       save_fillmode;
                    197:
                    198:        struct tag      *t;
1.4       kristaps  199:        int              child;
                    200:
1.132     schwarze  201:        /*
                    202:         * Handle fill mode switch requests up front,
                    203:         * they would just cause trouble in the subsequent code.
                    204:         */
                    205:
                    206:        switch (n->tok) {
                    207:        case MAN_nf:
                    208:        case MAN_EX:
                    209:                want_fillmode = MAN_nf;
                    210:                return;
                    211:        case MAN_fi:
                    212:        case MAN_EE:
                    213:                want_fillmode = MAN_fi;
                    214:                if (fillmode(h, 0) == MAN_fi)
                    215:                        print_otag(h, TAG_BR, "");
                    216:                return;
                    217:        default:
                    218:                break;
                    219:        }
                    220:
                    221:        /* Set up fill mode for the upcoming node. */
1.4       kristaps  222:
                    223:        switch (n->type) {
1.132     schwarze  224:        case ROFFT_BLOCK:
                    225:                save_fillmode = 0;
                    226:                /* Some block macros suspend or cancel .nf. */
                    227:                switch (n->tok) {
                    228:                case MAN_TP:  /* Tagged paragraphs              */
                    229:                case MAN_IP:  /* temporarily disable .nf        */
                    230:                case MAN_HP:  /* for the head.                  */
                    231:                        save_fillmode = want_fillmode;
                    232:                        /* FALLTHROUGH */
                    233:                case MAN_SH:  /* Section headers                */
                    234:                case MAN_SS:  /* permanently cancel .nf.        */
                    235:                        want_fillmode = MAN_fi;
                    236:                        /* FALLTHROUGH */
                    237:                case MAN_PP:  /* These have no head.            */
1.158   ! schwarze  238:                case MAN_RS:  /* They will simply               */
        !           239:                case MAN_UR:  /* reopen .nf in the body.        */
1.145     schwarze  240:                case MAN_MT:
1.132     schwarze  241:                        fillmode(h, MAN_fi);
                    242:                        break;
                    243:                default:
                    244:                        break;
                    245:                }
                    246:                break;
                    247:        case ROFFT_TBL:
                    248:                fillmode(h, MAN_fi);
                    249:                break;
                    250:        case ROFFT_ELEM:
                    251:                /*
                    252:                 * Some in-line macros produce tags and/or text
                    253:                 * in the handler, so they require fill mode to be
                    254:                 * configured up front just like for text nodes.
                    255:                 * For the others, keep the traditional approach
                    256:                 * of doing the same, for now.
                    257:                 */
                    258:                fillmode(h, want_fillmode);
                    259:                break;
1.113     schwarze  260:        case ROFFT_TEXT:
1.132     schwarze  261:                if (fillmode(h, want_fillmode) == MAN_fi &&
                    262:                    want_fillmode == MAN_fi &&
1.142     schwarze  263:                    n->flags & NODE_LINE && *n->string == ' ' &&
                    264:                    (h->flags & HTML_NONEWLINE) == 0)
1.122     schwarze  265:                        print_otag(h, TAG_BR, "");
1.157     schwarze  266:                if (want_fillmode == MAN_nf || *n->string != '\0')
1.132     schwarze  267:                        break;
                    268:                print_paragraph(h);
1.146     schwarze  269:                return;
                    270:        case ROFFT_COMMENT:
1.132     schwarze  271:                return;
                    272:        default:
                    273:                break;
                    274:        }
                    275:
                    276:        /* Produce output for this node. */
                    277:
                    278:        child = 1;
                    279:        switch (n->type) {
                    280:        case ROFFT_TEXT:
                    281:                t = h->tag;
1.4       kristaps  282:                print_text(h, n->string);
1.130     schwarze  283:                break;
1.113     schwarze  284:        case ROFFT_EQN:
1.132     schwarze  285:                t = h->tag;
1.80      kristaps  286:                print_eqn(h, n->eqn);
1.69      kristaps  287:                break;
1.113     schwarze  288:        case ROFFT_TBL:
1.66      kristaps  289:                /*
                    290:                 * This will take care of initialising all of the table
                    291:                 * state data for the first table, then tearing it down
                    292:                 * for the last one.
                    293:                 */
1.60      kristaps  294:                print_tbl(h, n->span);
1.64      kristaps  295:                return;
1.4       kristaps  296:        default:
1.93      schwarze  297:                /*
1.21      kristaps  298:                 * Close out scope of font prior to opening a macro
1.66      kristaps  299:                 * scope.
1.21      kristaps  300:                 */
1.57      kristaps  301:                if (HTMLFONT_NONE != h->metac) {
                    302:                        h->metal = h->metac;
                    303:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  304:                }
                    305:
                    306:                /*
                    307:                 * Close out the current table, if it's open, and unset
                    308:                 * the "meta" table state.  This will be reopened on the
                    309:                 * next table element.
                    310:                 */
1.132     schwarze  311:                if (h->tblt)
1.66      kristaps  312:                        print_tblclose(h);
1.132     schwarze  313:
                    314:                t = h->tag;
1.137     schwarze  315:                if (n->tok < ROFF_MAX) {
1.138     schwarze  316:                        roff_html_pre(h, n);
1.141     schwarze  317:                        child = 0;
1.137     schwarze  318:                        break;
                    319:                }
                    320:
                    321:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.155     schwarze  322:                if (man_html_acts[n->tok - MAN_TH].pre != NULL)
                    323:                        child = (*man_html_acts[n->tok - MAN_TH].pre)(man,
                    324:                            n, h);
1.132     schwarze  325:
                    326:                /* Some block macros resume .nf in the body. */
                    327:                if (save_fillmode && n->type == ROFFT_BODY)
                    328:                        want_fillmode = save_fillmode;
                    329:
1.4       kristaps  330:                break;
                    331:        }
                    332:
1.21      kristaps  333:        if (child && n->child)
1.132     schwarze  334:                print_man_nodelist(man, n->child, h);
1.21      kristaps  335:
1.24      kristaps  336:        /* This will automatically close out any font scope. */
1.132     schwarze  337:        print_stagq(h, t);
                    338:
                    339:        if (fillmode(h, 0) == MAN_nf &&
1.157     schwarze  340:            n->next != NULL && n->next->flags & NODE_LINE) {
                    341:                /* In .nf = <pre>, print even empty lines. */
                    342:                h->col++;
1.132     schwarze  343:                print_endline(h);
1.157     schwarze  344:        }
1.132     schwarze  345: }
                    346:
                    347: /*
                    348:  * MAN_nf switches to no-fill mode, MAN_fi to fill mode.
                    349:  * Other arguments do not switch.
                    350:  * The old mode is returned.
                    351:  */
                    352: static int
                    353: fillmode(struct html *h, int want)
                    354: {
                    355:        struct tag      *pre;
                    356:        int              had;
1.4       kristaps  357:
1.132     schwarze  358:        for (pre = h->tag; pre != NULL; pre = pre->next)
                    359:                if (pre->tag == TAG_PRE)
                    360:                        break;
                    361:
                    362:        had = pre == NULL ? MAN_fi : MAN_nf;
1.130     schwarze  363:
1.132     schwarze  364:        if (want && want != had) {
                    365:                if (want == MAN_nf)
                    366:                        print_otag(h, TAG_PRE, "");
                    367:                else
                    368:                        print_tagq(h, pre);
                    369:        }
                    370:        return had;
1.4       kristaps  371: }
                    372:
1.65      kristaps  373: static void
1.147     schwarze  374: man_root_pre(const struct roff_meta *man, struct html *h)
1.4       kristaps  375: {
                    376:        struct tag      *t, *tt;
1.94      schwarze  377:        char            *title;
1.4       kristaps  378:
1.89      schwarze  379:        assert(man->title);
                    380:        assert(man->msec);
1.94      schwarze  381:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4       kristaps  382:
1.122     schwarze  383:        t = print_otag(h, TAG_TABLE, "c", "head");
                    384:        tt = print_otag(h, TAG_TR, "");
1.4       kristaps  385:
1.122     schwarze  386:        print_otag(h, TAG_TD, "c", "head-ltitle");
1.4       kristaps  387:        print_text(h, title);
                    388:        print_stagq(h, tt);
                    389:
1.122     schwarze  390:        print_otag(h, TAG_TD, "c", "head-vol");
1.95      schwarze  391:        if (NULL != man->vol)
                    392:                print_text(h, man->vol);
1.4       kristaps  393:        print_stagq(h, tt);
                    394:
1.122     schwarze  395:        print_otag(h, TAG_TD, "c", "head-rtitle");
1.4       kristaps  396:        print_text(h, title);
                    397:        print_tagq(h, t);
1.94      schwarze  398:        free(title);
1.4       kristaps  399: }
                    400:
                    401: static void
1.147     schwarze  402: man_root_post(const struct roff_meta *man, struct html *h)
1.4       kristaps  403: {
                    404:        struct tag      *t, *tt;
                    405:
1.122     schwarze  406:        t = print_otag(h, TAG_TABLE, "c", "foot");
                    407:        tt = print_otag(h, TAG_TR, "");
1.55      kristaps  408:
1.122     schwarze  409:        print_otag(h, TAG_TD, "c", "foot-date");
1.89      schwarze  410:        print_text(h, man->date);
1.4       kristaps  411:        print_stagq(h, tt);
                    412:
1.122     schwarze  413:        print_otag(h, TAG_TD, "c", "foot-os");
1.115     schwarze  414:        if (man->os)
                    415:                print_text(h, man->os);
1.4       kristaps  416:        print_tagq(h, t);
                    417: }
                    418:
                    419: static int
                    420: man_SH_pre(MAN_ARGS)
                    421: {
1.134     schwarze  422:        char    *id;
                    423:
                    424:        if (n->type == ROFFT_HEAD) {
1.150     schwarze  425:                id = html_make_id(n, 1);
1.134     schwarze  426:                print_otag(h, TAG_H1, "cTi", "Sh", id);
1.135     schwarze  427:                if (id != NULL)
1.148     schwarze  428:                        print_otag(h, TAG_A, "chR", "permalink", id);
1.134     schwarze  429:        }
1.119     schwarze  430:        return 1;
1.4       kristaps  431: }
                    432:
                    433: static int
1.8       kristaps  434: man_alt_pre(MAN_ARGS)
                    435: {
1.114     schwarze  436:        const struct roff_node  *nn;
1.130     schwarze  437:        int              i;
1.57      kristaps  438:        enum htmltag     fp;
                    439:        struct tag      *t;
1.8       kristaps  440:
                    441:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    442:                switch (n->tok) {
1.93      schwarze  443:                case MAN_BI:
1.57      kristaps  444:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  445:                        break;
1.93      schwarze  446:                case MAN_IB:
1.57      kristaps  447:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  448:                        break;
1.93      schwarze  449:                case MAN_RI:
1.57      kristaps  450:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  451:                        break;
1.93      schwarze  452:                case MAN_IR:
1.57      kristaps  453:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  454:                        break;
1.93      schwarze  455:                case MAN_BR:
1.57      kristaps  456:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  457:                        break;
1.93      schwarze  458:                case MAN_RB:
1.57      kristaps  459:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  460:                        break;
                    461:                default:
                    462:                        abort();
                    463:                }
                    464:
                    465:                if (i)
                    466:                        h->flags |= HTML_NOSPACE;
                    467:
1.130     schwarze  468:                if (fp != TAG_MAX)
1.122     schwarze  469:                        t = print_otag(h, fp, "");
1.57      kristaps  470:
1.130     schwarze  471:                print_text(h, nn->string);
1.57      kristaps  472:
1.130     schwarze  473:                if (fp != TAG_MAX)
1.57      kristaps  474:                        print_tagq(h, t);
1.8       kristaps  475:        }
1.119     schwarze  476:        return 0;
1.8       kristaps  477: }
                    478:
                    479: static int
1.56      kristaps  480: man_SM_pre(MAN_ARGS)
1.8       kristaps  481: {
1.122     schwarze  482:        print_otag(h, TAG_SMALL, "");
1.56      kristaps  483:        if (MAN_SB == n->tok)
1.122     schwarze  484:                print_otag(h, TAG_B, "");
1.119     schwarze  485:        return 1;
1.8       kristaps  486: }
                    487:
                    488: static int
1.4       kristaps  489: man_SS_pre(MAN_ARGS)
                    490: {
1.134     schwarze  491:        char    *id;
                    492:
                    493:        if (n->type == ROFFT_HEAD) {
1.150     schwarze  494:                id = html_make_id(n, 1);
1.134     schwarze  495:                print_otag(h, TAG_H2, "cTi", "Ss", id);
1.135     schwarze  496:                if (id != NULL)
1.148     schwarze  497:                        print_otag(h, TAG_A, "chR", "permalink", id);
1.134     schwarze  498:        }
1.119     schwarze  499:        return 1;
1.4       kristaps  500: }
                    501:
                    502: static int
                    503: man_PP_pre(MAN_ARGS)
                    504: {
                    505:
1.113     schwarze  506:        if (n->type == ROFFT_HEAD)
1.119     schwarze  507:                return 0;
1.113     schwarze  508:        else if (n->type == ROFFT_BLOCK)
1.74      kristaps  509:                print_bvspace(h, n);
1.47      kristaps  510:
1.119     schwarze  511:        return 1;
1.5       kristaps  512: }
                    513:
                    514: static int
                    515: man_IP_pre(MAN_ARGS)
                    516: {
1.114     schwarze  517:        const struct roff_node  *nn;
1.5       kristaps  518:
1.113     schwarze  519:        if (n->type == ROFFT_BODY) {
1.149     schwarze  520:                print_otag(h, TAG_DD, "");
1.119     schwarze  521:                return 1;
1.113     schwarze  522:        } else if (n->type != ROFFT_HEAD) {
1.129     schwarze  523:                print_otag(h, TAG_DL, "c", "Bl-tag");
1.119     schwarze  524:                return 1;
1.6       kristaps  525:        }
                    526:
1.149     schwarze  527:        print_otag(h, TAG_DT, "");
1.6       kristaps  528:
1.154     schwarze  529:        switch(n->tok) {
                    530:        case MAN_IP:  /* Only print the first header element. */
                    531:                if (n->child != NULL)
                    532:                        print_man_node(man, n->child, h);
                    533:                break;
                    534:        case MAN_TP:  /* Only print next-line header elements. */
                    535:        case MAN_TQ:
1.91      schwarze  536:                nn = n->child;
1.154     schwarze  537:                while (nn != NULL && (NODE_LINE & nn->flags) == 0)
1.91      schwarze  538:                        nn = nn->next;
1.154     schwarze  539:                while (nn != NULL) {
1.132     schwarze  540:                        print_man_node(man, nn, h);
1.91      schwarze  541:                        nn = nn->next;
                    542:                }
1.154     schwarze  543:                break;
                    544:        default:
                    545:                abort();
1.91      schwarze  546:        }
1.6       kristaps  547:
1.119     schwarze  548:        return 0;
1.6       kristaps  549: }
                    550:
                    551: static int
                    552: man_HP_pre(MAN_ARGS)
                    553: {
1.113     schwarze  554:        if (n->type == ROFFT_HEAD)
1.119     schwarze  555:                return 0;
1.72      kristaps  556:
1.151     schwarze  557:        if (n->type == ROFFT_BLOCK) {
                    558:                print_bvspace(h, n);
                    559:                print_otag(h, TAG_DIV, "c", "HP");
                    560:        }
1.119     schwarze  561:        return 1;
1.4       kristaps  562: }
1.86      kristaps  563:
                    564: static int
                    565: man_OP_pre(MAN_ARGS)
                    566: {
                    567:        struct tag      *tt;
                    568:
                    569:        print_text(h, "[");
                    570:        h->flags |= HTML_NOSPACE;
1.128     schwarze  571:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86      kristaps  572:
                    573:        if (NULL != (n = n->child)) {
1.122     schwarze  574:                print_otag(h, TAG_B, "");
1.86      kristaps  575:                print_text(h, n->string);
                    576:        }
                    577:
                    578:        print_stagq(h, tt);
                    579:
                    580:        if (NULL != n && NULL != n->next) {
1.122     schwarze  581:                print_otag(h, TAG_I, "");
1.86      kristaps  582:                print_text(h, n->next->string);
                    583:        }
                    584:
                    585:        print_stagq(h, tt);
                    586:        h->flags |= HTML_NOSPACE;
                    587:        print_text(h, "]");
1.119     schwarze  588:        return 0;
1.86      kristaps  589: }
                    590:
1.8       kristaps  591: static int
                    592: man_B_pre(MAN_ARGS)
                    593: {
1.122     schwarze  594:        print_otag(h, TAG_B, "");
1.119     schwarze  595:        return 1;
1.8       kristaps  596: }
                    597:
                    598: static int
                    599: man_I_pre(MAN_ARGS)
                    600: {
1.122     schwarze  601:        print_otag(h, TAG_I, "");
1.119     schwarze  602:        return 1;
1.45      kristaps  603: }
                    604:
                    605: static int
                    606: man_in_pre(MAN_ARGS)
                    607: {
1.122     schwarze  608:        print_otag(h, TAG_BR, "");
1.119     schwarze  609:        return 0;
1.8       kristaps  610: }
                    611:
                    612: static int
                    613: man_ign_pre(MAN_ARGS)
                    614: {
                    615:
1.119     schwarze  616:        return 0;
1.8       kristaps  617: }
1.9       kristaps  618:
                    619: static int
                    620: man_RS_pre(MAN_ARGS)
                    621: {
1.113     schwarze  622:        if (n->type == ROFFT_HEAD)
1.119     schwarze  623:                return 0;
1.152     schwarze  624:        if (n->type == ROFFT_BLOCK)
                    625:                print_otag(h, TAG_DIV, "c", "Bd-indent");
1.156     schwarze  626:        return 1;
                    627: }
                    628:
                    629: static int
                    630: man_SY_pre(MAN_ARGS)
                    631: {
                    632:        switch (n->type) {
                    633:        case ROFFT_BLOCK:
                    634:                print_otag(h, TAG_TABLE, "c", "Nm");
                    635:                print_otag(h, TAG_TR, "");
                    636:                break;
                    637:        case ROFFT_HEAD:
                    638:                print_otag(h, TAG_TD, "");
                    639:                print_otag(h, TAG_CODE, "cT", "Nm");
                    640:                break;
                    641:        case ROFFT_BODY:
                    642:                print_otag(h, TAG_TD, "");
                    643:                break;
                    644:        default:
                    645:                abort();
                    646:        }
1.119     schwarze  647:        return 1;
1.90      schwarze  648: }
                    649:
                    650: static int
                    651: man_UR_pre(MAN_ARGS)
                    652: {
1.145     schwarze  653:        char *cp;
1.90      schwarze  654:        n = n->child;
1.113     schwarze  655:        assert(n->type == ROFFT_HEAD);
1.120     schwarze  656:        if (n->child != NULL) {
1.113     schwarze  657:                assert(n->child->type == ROFFT_TEXT);
1.145     schwarze  658:                if (n->tok == MAN_MT) {
                    659:                        mandoc_asprintf(&cp, "mailto:%s", n->child->string);
                    660:                        print_otag(h, TAG_A, "cTh", "Mt", cp);
                    661:                        free(cp);
                    662:                } else
                    663:                        print_otag(h, TAG_A, "cTh", "Lk", n->child->string);
1.90      schwarze  664:        }
                    665:
1.113     schwarze  666:        assert(n->next->type == ROFFT_BODY);
1.120     schwarze  667:        if (n->next->child != NULL)
1.90      schwarze  668:                n = n->next;
                    669:
1.132     schwarze  670:        print_man_nodelist(man, n->child, h);
1.90      schwarze  671:
1.119     schwarze  672:        return 0;
1.158   ! schwarze  673: }
        !           674:
        !           675: static int
        !           676: man_abort_pre(MAN_ARGS)
        !           677: {
        !           678:        abort();
1.9       kristaps  679: }

CVSweb