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

Annotation of mandoc/man_html.c, Revision 1.151

1.151   ! schwarze    1: /*     $Id: man_html.c,v 1.150 2018/05/25 20:23:51 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.6       kristaps   37:
                     38: #define        INDENT            5
1.4       kristaps   39:
1.115     schwarze   40: #define        MAN_ARGS          const struct roff_meta *man, \
1.114     schwarze   41:                          const struct roff_node *n, \
1.3       kristaps   42:                          struct html *h
                     43:
                     44: struct htmlman {
                     45:        int             (*pre)(MAN_ARGS);
                     46:        int             (*post)(MAN_ARGS);
                     47: };
                     48:
1.93      schwarze   49: static void              print_bvspace(struct html *,
1.114     schwarze   50:                                const struct roff_node *);
1.147     schwarze   51: static void              print_man_head(const struct roff_meta *,
                     52:                                struct html *);
1.4       kristaps   53: static void              print_man_nodelist(MAN_ARGS);
                     54: static void              print_man_node(MAN_ARGS);
1.132     schwarze   55: static int               fillmode(struct html *, int);
1.114     schwarze   56: static int               a2width(const struct roff_node *,
1.7       kristaps   57:                                struct roffsu *);
1.8       kristaps   58: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   59: static int               man_HP_pre(MAN_ARGS);
1.86      kristaps   60: static int               man_IP_pre(MAN_ARGS);
1.8       kristaps   61: static int               man_I_pre(MAN_ARGS);
1.86      kristaps   62: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   63: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   64: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   65: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   66: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   67: static int               man_SS_pre(MAN_ARGS);
1.90      schwarze   68: static int               man_UR_pre(MAN_ARGS);
1.86      kristaps   69: static int               man_alt_pre(MAN_ARGS);
                     70: static int               man_ign_pre(MAN_ARGS);
                     71: static int               man_in_pre(MAN_ARGS);
1.147     schwarze   72: static void              man_root_post(const struct roff_meta *,
                     73:                                struct html *);
                     74: static void              man_root_pre(const struct roff_meta *,
                     75:                                struct html *);
1.4       kristaps   76:
1.136     schwarze   77: static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
1.3       kristaps   78:        { NULL, NULL }, /* TH */
1.4       kristaps   79:        { man_SH_pre, NULL }, /* SH */
                     80:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   81:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   82:        { man_PP_pre, NULL }, /* LP */
                     83:        { man_PP_pre, NULL }, /* PP */
                     84:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   85:        { man_IP_pre, NULL }, /* IP */
1.93      schwarze   86:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   87:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   88:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   89:        { man_alt_pre, NULL }, /* BI */
                     90:        { man_alt_pre, NULL }, /* IB */
                     91:        { man_alt_pre, NULL }, /* BR */
                     92:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   93:        { NULL, NULL }, /* R */
1.8       kristaps   94:        { man_B_pre, NULL }, /* B */
                     95:        { man_I_pre, NULL }, /* I */
                     96:        { man_alt_pre, NULL }, /* IR */
                     97:        { man_alt_pre, NULL }, /* RI */
1.132     schwarze   98:        { NULL, NULL }, /* nf */
                     99:        { NULL, NULL }, /* fi */
1.3       kristaps  100:        { NULL, NULL }, /* RE */
1.9       kristaps  101:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  102:        { man_ign_pre, NULL }, /* DT */
                    103:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  104:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     105:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  106:        { man_in_pre, NULL }, /* in */
1.86      kristaps  107:        { man_OP_pre, NULL }, /* OP */
1.132     schwarze  108:        { NULL, NULL }, /* EX */
                    109:        { NULL, NULL }, /* EE */
1.90      schwarze  110:        { man_UR_pre, NULL }, /* UR */
                    111:        { NULL, NULL }, /* UE */
1.145     schwarze  112:        { man_UR_pre, NULL }, /* MT */
                    113:        { NULL, NULL }, /* ME */
1.3       kristaps  114: };
1.136     schwarze  115: static const struct htmlman *const mans = __mans - MAN_TH;
1.3       kristaps  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.            */
                    238:                case MAN_LP:  /* They will simply               */
                    239:                case MAN_P:   /* reopen .nf in the body.        */
                    240:                case MAN_RS:
                    241:                case MAN_UR:
1.145     schwarze  242:                case MAN_MT:
1.132     schwarze  243:                        fillmode(h, MAN_fi);
                    244:                        break;
                    245:                default:
                    246:                        break;
                    247:                }
                    248:                break;
                    249:        case ROFFT_TBL:
                    250:                fillmode(h, MAN_fi);
                    251:                break;
                    252:        case ROFFT_ELEM:
                    253:                /*
                    254:                 * Some in-line macros produce tags and/or text
                    255:                 * in the handler, so they require fill mode to be
                    256:                 * configured up front just like for text nodes.
                    257:                 * For the others, keep the traditional approach
                    258:                 * of doing the same, for now.
                    259:                 */
                    260:                fillmode(h, want_fillmode);
                    261:                break;
1.113     schwarze  262:        case ROFFT_TEXT:
1.132     schwarze  263:                if (fillmode(h, want_fillmode) == MAN_fi &&
                    264:                    want_fillmode == MAN_fi &&
1.142     schwarze  265:                    n->flags & NODE_LINE && *n->string == ' ' &&
                    266:                    (h->flags & HTML_NONEWLINE) == 0)
1.122     schwarze  267:                        print_otag(h, TAG_BR, "");
1.132     schwarze  268:                if (*n->string != '\0')
                    269:                        break;
                    270:                print_paragraph(h);
1.146     schwarze  271:                return;
                    272:        case ROFFT_COMMENT:
1.132     schwarze  273:                return;
                    274:        default:
                    275:                break;
                    276:        }
                    277:
                    278:        /* Produce output for this node. */
                    279:
                    280:        child = 1;
                    281:        switch (n->type) {
                    282:        case ROFFT_TEXT:
                    283:                t = h->tag;
1.4       kristaps  284:                print_text(h, n->string);
1.130     schwarze  285:                break;
1.113     schwarze  286:        case ROFFT_EQN:
1.132     schwarze  287:                t = h->tag;
1.80      kristaps  288:                print_eqn(h, n->eqn);
1.69      kristaps  289:                break;
1.113     schwarze  290:        case ROFFT_TBL:
1.66      kristaps  291:                /*
                    292:                 * This will take care of initialising all of the table
                    293:                 * state data for the first table, then tearing it down
                    294:                 * for the last one.
                    295:                 */
1.60      kristaps  296:                print_tbl(h, n->span);
1.64      kristaps  297:                return;
1.4       kristaps  298:        default:
1.93      schwarze  299:                /*
1.21      kristaps  300:                 * Close out scope of font prior to opening a macro
1.66      kristaps  301:                 * scope.
1.21      kristaps  302:                 */
1.57      kristaps  303:                if (HTMLFONT_NONE != h->metac) {
                    304:                        h->metal = h->metac;
                    305:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  306:                }
                    307:
                    308:                /*
                    309:                 * Close out the current table, if it's open, and unset
                    310:                 * the "meta" table state.  This will be reopened on the
                    311:                 * next table element.
                    312:                 */
1.132     schwarze  313:                if (h->tblt)
1.66      kristaps  314:                        print_tblclose(h);
1.132     schwarze  315:
                    316:                t = h->tag;
1.137     schwarze  317:                if (n->tok < ROFF_MAX) {
1.138     schwarze  318:                        roff_html_pre(h, n);
1.141     schwarze  319:                        child = 0;
1.137     schwarze  320:                        break;
                    321:                }
                    322:
                    323:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.4       kristaps  324:                if (mans[n->tok].pre)
1.132     schwarze  325:                        child = (*mans[n->tok].pre)(man, n, h);
                    326:
                    327:                /* Some block macros resume .nf in the body. */
                    328:                if (save_fillmode && n->type == ROFFT_BODY)
                    329:                        want_fillmode = save_fillmode;
                    330:
1.4       kristaps  331:                break;
                    332:        }
                    333:
1.21      kristaps  334:        if (child && n->child)
1.132     schwarze  335:                print_man_nodelist(man, n->child, h);
1.21      kristaps  336:
1.24      kristaps  337:        /* This will automatically close out any font scope. */
1.132     schwarze  338:        print_stagq(h, t);
                    339:
                    340:        if (fillmode(h, 0) == MAN_nf &&
                    341:            n->next != NULL && n->next->flags & NODE_LINE)
                    342:                print_endline(h);
                    343: }
                    344:
                    345: /*
                    346:  * MAN_nf switches to no-fill mode, MAN_fi to fill mode.
                    347:  * Other arguments do not switch.
                    348:  * The old mode is returned.
                    349:  */
                    350: static int
                    351: fillmode(struct html *h, int want)
                    352: {
                    353:        struct tag      *pre;
                    354:        int              had;
1.4       kristaps  355:
1.132     schwarze  356:        for (pre = h->tag; pre != NULL; pre = pre->next)
                    357:                if (pre->tag == TAG_PRE)
                    358:                        break;
                    359:
                    360:        had = pre == NULL ? MAN_fi : MAN_nf;
1.130     schwarze  361:
1.132     schwarze  362:        if (want && want != had) {
                    363:                if (want == MAN_nf)
                    364:                        print_otag(h, TAG_PRE, "");
                    365:                else
                    366:                        print_tagq(h, pre);
                    367:        }
                    368:        return had;
1.4       kristaps  369: }
                    370:
1.5       kristaps  371: static int
1.114     schwarze  372: a2width(const struct roff_node *n, struct roffsu *su)
1.5       kristaps  373: {
1.113     schwarze  374:        if (n->type != ROFFT_TEXT)
1.119     schwarze  375:                return 0;
1.143     schwarze  376:        return a2roffsu(n->string, su, SCALE_EN) != NULL;
1.5       kristaps  377: }
                    378:
1.65      kristaps  379: static void
1.147     schwarze  380: man_root_pre(const struct roff_meta *man, struct html *h)
1.4       kristaps  381: {
                    382:        struct tag      *t, *tt;
1.94      schwarze  383:        char            *title;
1.4       kristaps  384:
1.89      schwarze  385:        assert(man->title);
                    386:        assert(man->msec);
1.94      schwarze  387:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4       kristaps  388:
1.122     schwarze  389:        t = print_otag(h, TAG_TABLE, "c", "head");
                    390:        tt = print_otag(h, TAG_TR, "");
1.4       kristaps  391:
1.122     schwarze  392:        print_otag(h, TAG_TD, "c", "head-ltitle");
1.4       kristaps  393:        print_text(h, title);
                    394:        print_stagq(h, tt);
                    395:
1.122     schwarze  396:        print_otag(h, TAG_TD, "c", "head-vol");
1.95      schwarze  397:        if (NULL != man->vol)
                    398:                print_text(h, man->vol);
1.4       kristaps  399:        print_stagq(h, tt);
                    400:
1.122     schwarze  401:        print_otag(h, TAG_TD, "c", "head-rtitle");
1.4       kristaps  402:        print_text(h, title);
                    403:        print_tagq(h, t);
1.94      schwarze  404:        free(title);
1.4       kristaps  405: }
                    406:
                    407: static void
1.147     schwarze  408: man_root_post(const struct roff_meta *man, struct html *h)
1.4       kristaps  409: {
                    410:        struct tag      *t, *tt;
                    411:
1.122     schwarze  412:        t = print_otag(h, TAG_TABLE, "c", "foot");
                    413:        tt = print_otag(h, TAG_TR, "");
1.55      kristaps  414:
1.122     schwarze  415:        print_otag(h, TAG_TD, "c", "foot-date");
1.89      schwarze  416:        print_text(h, man->date);
1.4       kristaps  417:        print_stagq(h, tt);
                    418:
1.122     schwarze  419:        print_otag(h, TAG_TD, "c", "foot-os");
1.115     schwarze  420:        if (man->os)
                    421:                print_text(h, man->os);
1.4       kristaps  422:        print_tagq(h, t);
                    423: }
                    424:
                    425: static int
                    426: man_SH_pre(MAN_ARGS)
                    427: {
1.134     schwarze  428:        char    *id;
                    429:
                    430:        if (n->type == ROFFT_HEAD) {
1.150     schwarze  431:                id = html_make_id(n, 1);
1.134     schwarze  432:                print_otag(h, TAG_H1, "cTi", "Sh", id);
1.135     schwarze  433:                if (id != NULL)
1.148     schwarze  434:                        print_otag(h, TAG_A, "chR", "permalink", id);
1.134     schwarze  435:        }
1.119     schwarze  436:        return 1;
1.4       kristaps  437: }
                    438:
                    439: static int
1.8       kristaps  440: man_alt_pre(MAN_ARGS)
                    441: {
1.114     schwarze  442:        const struct roff_node  *nn;
1.130     schwarze  443:        int              i;
1.57      kristaps  444:        enum htmltag     fp;
                    445:        struct tag      *t;
1.8       kristaps  446:
                    447:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    448:                switch (n->tok) {
1.93      schwarze  449:                case MAN_BI:
1.57      kristaps  450:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  451:                        break;
1.93      schwarze  452:                case MAN_IB:
1.57      kristaps  453:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  454:                        break;
1.93      schwarze  455:                case MAN_RI:
1.57      kristaps  456:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  457:                        break;
1.93      schwarze  458:                case MAN_IR:
1.57      kristaps  459:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  460:                        break;
1.93      schwarze  461:                case MAN_BR:
1.57      kristaps  462:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  463:                        break;
1.93      schwarze  464:                case MAN_RB:
1.57      kristaps  465:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  466:                        break;
                    467:                default:
                    468:                        abort();
                    469:                }
                    470:
                    471:                if (i)
                    472:                        h->flags |= HTML_NOSPACE;
                    473:
1.130     schwarze  474:                if (fp != TAG_MAX)
1.122     schwarze  475:                        t = print_otag(h, fp, "");
1.57      kristaps  476:
1.130     schwarze  477:                print_text(h, nn->string);
1.57      kristaps  478:
1.130     schwarze  479:                if (fp != TAG_MAX)
1.57      kristaps  480:                        print_tagq(h, t);
1.8       kristaps  481:        }
1.119     schwarze  482:        return 0;
1.8       kristaps  483: }
                    484:
                    485: static int
1.56      kristaps  486: man_SM_pre(MAN_ARGS)
1.8       kristaps  487: {
1.122     schwarze  488:        print_otag(h, TAG_SMALL, "");
1.56      kristaps  489:        if (MAN_SB == n->tok)
1.122     schwarze  490:                print_otag(h, TAG_B, "");
1.119     schwarze  491:        return 1;
1.8       kristaps  492: }
                    493:
                    494: static int
1.4       kristaps  495: man_SS_pre(MAN_ARGS)
                    496: {
1.134     schwarze  497:        char    *id;
                    498:
                    499:        if (n->type == ROFFT_HEAD) {
1.150     schwarze  500:                id = html_make_id(n, 1);
1.134     schwarze  501:                print_otag(h, TAG_H2, "cTi", "Ss", id);
1.135     schwarze  502:                if (id != NULL)
1.148     schwarze  503:                        print_otag(h, TAG_A, "chR", "permalink", id);
1.134     schwarze  504:        }
1.119     schwarze  505:        return 1;
1.4       kristaps  506: }
                    507:
                    508: static int
                    509: man_PP_pre(MAN_ARGS)
                    510: {
                    511:
1.113     schwarze  512:        if (n->type == ROFFT_HEAD)
1.119     schwarze  513:                return 0;
1.113     schwarze  514:        else if (n->type == ROFFT_BLOCK)
1.74      kristaps  515:                print_bvspace(h, n);
1.47      kristaps  516:
1.119     schwarze  517:        return 1;
1.5       kristaps  518: }
                    519:
                    520: static int
                    521: man_IP_pre(MAN_ARGS)
                    522: {
1.114     schwarze  523:        const struct roff_node  *nn;
1.5       kristaps  524:
1.113     schwarze  525:        if (n->type == ROFFT_BODY) {
1.149     schwarze  526:                print_otag(h, TAG_DD, "");
1.119     schwarze  527:                return 1;
1.113     schwarze  528:        } else if (n->type != ROFFT_HEAD) {
1.129     schwarze  529:                print_otag(h, TAG_DL, "c", "Bl-tag");
1.119     schwarze  530:                return 1;
1.6       kristaps  531:        }
                    532:
1.78      kristaps  533:        /* FIXME: width specification. */
                    534:
1.149     schwarze  535:        print_otag(h, TAG_DT, "");
1.6       kristaps  536:
1.59      schwarze  537:        /* For IP, only print the first header element. */
1.7       kristaps  538:
1.59      schwarze  539:        if (MAN_IP == n->tok && n->child)
1.132     schwarze  540:                print_man_node(man, n->child, h);
1.27      kristaps  541:
1.59      schwarze  542:        /* For TP, only print next-line header elements. */
1.6       kristaps  543:
1.91      schwarze  544:        if (MAN_TP == n->tok) {
                    545:                nn = n->child;
1.121     schwarze  546:                while (NULL != nn && 0 == (NODE_LINE & nn->flags))
1.91      schwarze  547:                        nn = nn->next;
                    548:                while (NULL != nn) {
1.132     schwarze  549:                        print_man_node(man, nn, h);
1.91      schwarze  550:                        nn = nn->next;
                    551:                }
                    552:        }
1.6       kristaps  553:
1.119     schwarze  554:        return 0;
1.6       kristaps  555: }
                    556:
                    557: static int
                    558: man_HP_pre(MAN_ARGS)
                    559: {
1.113     schwarze  560:        if (n->type == ROFFT_HEAD)
1.119     schwarze  561:                return 0;
1.72      kristaps  562:
1.151   ! schwarze  563:        if (n->type == ROFFT_BLOCK) {
        !           564:                print_bvspace(h, n);
        !           565:                print_otag(h, TAG_DIV, "c", "HP");
        !           566:        }
1.119     schwarze  567:        return 1;
1.4       kristaps  568: }
1.86      kristaps  569:
                    570: static int
                    571: man_OP_pre(MAN_ARGS)
                    572: {
                    573:        struct tag      *tt;
                    574:
                    575:        print_text(h, "[");
                    576:        h->flags |= HTML_NOSPACE;
1.128     schwarze  577:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86      kristaps  578:
                    579:        if (NULL != (n = n->child)) {
1.122     schwarze  580:                print_otag(h, TAG_B, "");
1.86      kristaps  581:                print_text(h, n->string);
                    582:        }
                    583:
                    584:        print_stagq(h, tt);
                    585:
                    586:        if (NULL != n && NULL != n->next) {
1.122     schwarze  587:                print_otag(h, TAG_I, "");
1.86      kristaps  588:                print_text(h, n->next->string);
                    589:        }
                    590:
                    591:        print_stagq(h, tt);
                    592:        h->flags |= HTML_NOSPACE;
                    593:        print_text(h, "]");
1.119     schwarze  594:        return 0;
1.86      kristaps  595: }
                    596:
1.8       kristaps  597: static int
                    598: man_B_pre(MAN_ARGS)
                    599: {
1.122     schwarze  600:        print_otag(h, TAG_B, "");
1.119     schwarze  601:        return 1;
1.8       kristaps  602: }
                    603:
                    604: static int
                    605: man_I_pre(MAN_ARGS)
                    606: {
1.122     schwarze  607:        print_otag(h, TAG_I, "");
1.119     schwarze  608:        return 1;
1.45      kristaps  609: }
                    610:
                    611: static int
                    612: man_in_pre(MAN_ARGS)
                    613: {
1.122     schwarze  614:        print_otag(h, TAG_BR, "");
1.119     schwarze  615:        return 0;
1.8       kristaps  616: }
                    617:
                    618: static int
                    619: man_ign_pre(MAN_ARGS)
                    620: {
                    621:
1.119     schwarze  622:        return 0;
1.8       kristaps  623: }
1.9       kristaps  624:
                    625: static int
                    626: man_RS_pre(MAN_ARGS)
                    627: {
                    628:        struct roffsu    su;
                    629:
1.113     schwarze  630:        if (n->type == ROFFT_HEAD)
1.119     schwarze  631:                return 0;
1.113     schwarze  632:        else if (n->type == ROFFT_BODY)
1.119     schwarze  633:                return 1;
1.9       kristaps  634:
                    635:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  636:        if (n->head->child)
1.9       kristaps  637:                a2width(n->head->child, &su);
                    638:
1.122     schwarze  639:        print_otag(h, TAG_DIV, "sul", &su);
1.119     schwarze  640:        return 1;
1.90      schwarze  641: }
                    642:
                    643: static int
                    644: man_UR_pre(MAN_ARGS)
                    645: {
1.145     schwarze  646:        char *cp;
1.90      schwarze  647:        n = n->child;
1.113     schwarze  648:        assert(n->type == ROFFT_HEAD);
1.120     schwarze  649:        if (n->child != NULL) {
1.113     schwarze  650:                assert(n->child->type == ROFFT_TEXT);
1.145     schwarze  651:                if (n->tok == MAN_MT) {
                    652:                        mandoc_asprintf(&cp, "mailto:%s", n->child->string);
                    653:                        print_otag(h, TAG_A, "cTh", "Mt", cp);
                    654:                        free(cp);
                    655:                } else
                    656:                        print_otag(h, TAG_A, "cTh", "Lk", n->child->string);
1.90      schwarze  657:        }
                    658:
1.113     schwarze  659:        assert(n->next->type == ROFFT_BODY);
1.120     schwarze  660:        if (n->next->child != NULL)
1.90      schwarze  661:                n = n->next;
                    662:
1.132     schwarze  663:        print_man_nodelist(man, n->child, h);
1.90      schwarze  664:
1.119     schwarze  665:        return 0;
1.9       kristaps  666: }

CVSweb