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

Annotation of mandoc/man_html.c, Revision 1.146

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

CVSweb