Annotation of mandoc/man_html.c, Revision 1.94
1.94 ! schwarze 1: /* $Id: man_html.c,v 1.93 2014/04/20 16:46:04 schwarze Exp $ */
1.1 kristaps 2: /*
1.87 schwarze 3: * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.91 schwarze 4: * Copyright (c) 2013, 2014 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: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
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: #ifdef HAVE_CONFIG_H
19: #include "config.h"
20: #endif
21:
1.1 kristaps 22: #include <sys/types.h>
23:
1.5 kristaps 24: #include <assert.h>
25: #include <ctype.h>
1.2 kristaps 26: #include <stdio.h>
1.1 kristaps 27: #include <stdlib.h>
1.4 kristaps 28: #include <string.h>
1.1 kristaps 29:
1.35 kristaps 30: #include "mandoc.h"
1.94 ! schwarze 31: #include "mandoc_aux.h"
1.7 kristaps 32: #include "out.h"
1.1 kristaps 33: #include "html.h"
34: #include "man.h"
1.10 kristaps 35: #include "main.h"
1.1 kristaps 36:
1.6 kristaps 37: /* TODO: preserve ident widths. */
1.13 kristaps 38: /* FIXME: have PD set the default vspace width. */
1.6 kristaps 39:
40: #define INDENT 5
1.4 kristaps 41:
1.89 schwarze 42: #define MAN_ARGS const struct man_meta *man, \
1.3 kristaps 43: const struct man_node *n, \
1.45 kristaps 44: struct mhtml *mh, \
1.3 kristaps 45: struct html *h
46:
1.45 kristaps 47: struct mhtml {
48: int fl;
49: #define MANH_LITERAL (1 << 0) /* literal context */
50: };
51:
1.3 kristaps 52: struct htmlman {
53: int (*pre)(MAN_ARGS);
54: int (*post)(MAN_ARGS);
55: };
56:
1.93 schwarze 57: static void print_bvspace(struct html *,
1.74 kristaps 58: const struct man_node *);
1.3 kristaps 59: static void print_man(MAN_ARGS);
60: static void print_man_head(MAN_ARGS);
1.4 kristaps 61: static void print_man_nodelist(MAN_ARGS);
62: static void print_man_node(MAN_ARGS);
1.7 kristaps 63: static int a2width(const struct man_node *,
64: struct roffsu *);
1.8 kristaps 65: static int man_B_pre(MAN_ARGS);
1.6 kristaps 66: static int man_HP_pre(MAN_ARGS);
1.86 kristaps 67: static int man_IP_pre(MAN_ARGS);
1.8 kristaps 68: static int man_I_pre(MAN_ARGS);
1.86 kristaps 69: static int man_OP_pre(MAN_ARGS);
1.4 kristaps 70: static int man_PP_pre(MAN_ARGS);
1.9 kristaps 71: static int man_RS_pre(MAN_ARGS);
1.4 kristaps 72: static int man_SH_pre(MAN_ARGS);
1.8 kristaps 73: static int man_SM_pre(MAN_ARGS);
1.4 kristaps 74: static int man_SS_pre(MAN_ARGS);
1.90 schwarze 75: static int man_UR_pre(MAN_ARGS);
1.86 kristaps 76: static int man_alt_pre(MAN_ARGS);
77: static int man_br_pre(MAN_ARGS);
78: static int man_ign_pre(MAN_ARGS);
79: static int man_in_pre(MAN_ARGS);
80: static int man_literal_pre(MAN_ARGS);
81: static void man_root_post(MAN_ARGS);
82: static void man_root_pre(MAN_ARGS);
1.4 kristaps 83:
1.3 kristaps 84: static const struct htmlman mans[MAN_MAX] = {
1.4 kristaps 85: { man_br_pre, NULL }, /* br */
1.3 kristaps 86: { NULL, NULL }, /* TH */
1.4 kristaps 87: { man_SH_pre, NULL }, /* SH */
88: { man_SS_pre, NULL }, /* SS */
1.6 kristaps 89: { man_IP_pre, NULL }, /* TP */
1.4 kristaps 90: { man_PP_pre, NULL }, /* LP */
91: { man_PP_pre, NULL }, /* PP */
92: { man_PP_pre, NULL }, /* P */
1.5 kristaps 93: { man_IP_pre, NULL }, /* IP */
1.93 schwarze 94: { man_HP_pre, NULL }, /* HP */
1.8 kristaps 95: { man_SM_pre, NULL }, /* SM */
1.56 kristaps 96: { man_SM_pre, NULL }, /* SB */
1.8 kristaps 97: { man_alt_pre, NULL }, /* BI */
98: { man_alt_pre, NULL }, /* IB */
99: { man_alt_pre, NULL }, /* BR */
100: { man_alt_pre, NULL }, /* RB */
1.3 kristaps 101: { NULL, NULL }, /* R */
1.8 kristaps 102: { man_B_pre, NULL }, /* B */
103: { man_I_pre, NULL }, /* I */
104: { man_alt_pre, NULL }, /* IR */
105: { man_alt_pre, NULL }, /* RI */
1.67 schwarze 106: { man_ign_pre, NULL }, /* na */
1.4 kristaps 107: { man_br_pre, NULL }, /* sp */
1.45 kristaps 108: { man_literal_pre, NULL }, /* nf */
109: { man_literal_pre, NULL }, /* fi */
1.3 kristaps 110: { NULL, NULL }, /* RE */
1.9 kristaps 111: { man_RS_pre, NULL }, /* RS */
1.8 kristaps 112: { man_ign_pre, NULL }, /* DT */
113: { man_ign_pre, NULL }, /* UC */
1.13 kristaps 114: { man_ign_pre, NULL }, /* PD */
1.34 joerg 115: { man_ign_pre, NULL }, /* AT */
1.45 kristaps 116: { man_in_pre, NULL }, /* in */
1.51 kristaps 117: { man_ign_pre, NULL }, /* ft */
1.86 kristaps 118: { man_OP_pre, NULL }, /* OP */
1.88 schwarze 119: { man_literal_pre, NULL }, /* EX */
120: { man_literal_pre, NULL }, /* EE */
1.90 schwarze 121: { man_UR_pre, NULL }, /* UR */
122: { NULL, NULL }, /* UE */
1.92 schwarze 123: { man_ign_pre, NULL }, /* ll */
1.3 kristaps 124: };
125:
1.93 schwarze 126:
1.74 kristaps 127: /*
128: * Printing leading vertical space before a block.
129: * This is used for the paragraph macros.
130: * The rules are pretty simple, since there's very little nesting going
131: * on here. Basically, if we're the first within another block (SS/SH),
132: * then don't emit vertical space. If we are (RS), then do. If not the
133: * first, print it.
134: */
135: static void
136: print_bvspace(struct html *h, const struct man_node *n)
137: {
138:
139: if (n->body && n->body->child)
140: if (MAN_TBL == n->body->child->type)
141: return;
142:
143: if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
144: if (NULL == n->prev)
145: return;
146:
147: print_otag(h, TAG_P, 0, NULL);
148: }
1.1 kristaps 149:
150: void
1.89 schwarze 151: html_man(void *arg, const struct man *man)
1.1 kristaps 152: {
1.45 kristaps 153: struct mhtml mh;
1.3 kristaps 154:
1.45 kristaps 155: memset(&mh, 0, sizeof(struct mhtml));
1.89 schwarze 156: print_man(man_meta(man), man_node(man), &mh, (struct html *)arg);
1.82 kristaps 157: putchar('\n');
1.3 kristaps 158: }
159:
160: static void
1.93 schwarze 161: print_man(MAN_ARGS)
1.3 kristaps 162: {
1.82 kristaps 163: struct tag *t, *tt;
164: struct htmlpair tag;
165:
166: PAIR_CLASS_INIT(&tag, "mandoc");
1.3 kristaps 167:
1.82 kristaps 168: if ( ! (HTML_FRAGMENT & h->oflags)) {
169: print_gen_decls(h);
170: t = print_otag(h, TAG_HTML, 0, NULL);
171: tt = print_otag(h, TAG_HEAD, 0, NULL);
1.89 schwarze 172: print_man_head(man, n, mh, h);
1.82 kristaps 173: print_tagq(h, tt);
174: print_otag(h, TAG_BODY, 0, NULL);
175: print_otag(h, TAG_DIV, 1, &tag);
1.93 schwarze 176: } else
1.82 kristaps 177: t = print_otag(h, TAG_DIV, 1, &tag);
1.53 kristaps 178:
1.89 schwarze 179: print_man_nodelist(man, n, mh, h);
1.3 kristaps 180: print_tagq(h, t);
181: }
182:
183: static void
184: print_man_head(MAN_ARGS)
185: {
186:
187: print_gen_head(h);
1.89 schwarze 188: assert(man->title);
189: assert(man->msec);
190: bufcat_fmt(h, "%s(%s)", man->title, man->msec);
1.3 kristaps 191: print_otag(h, TAG_TITLE, 0, NULL);
192: print_text(h, h->buf);
1.1 kristaps 193: }
1.4 kristaps 194:
195: static void
196: print_man_nodelist(MAN_ARGS)
197: {
198:
1.89 schwarze 199: print_man_node(man, n, mh, h);
1.4 kristaps 200: if (n->next)
1.89 schwarze 201: print_man_nodelist(man, n->next, mh, h);
1.4 kristaps 202: }
203:
204: static void
205: print_man_node(MAN_ARGS)
206: {
207: int child;
208: struct tag *t;
209:
210: child = 1;
1.14 kristaps 211: t = h->tags.head;
1.4 kristaps 212:
213: switch (n->type) {
1.93 schwarze 214: case MAN_ROOT:
1.89 schwarze 215: man_root_pre(man, n, mh, h);
1.4 kristaps 216: break;
1.93 schwarze 217: case MAN_TEXT:
1.65 kristaps 218: /*
219: * If we have a blank line, output a vertical space.
220: * If we have a space as the first character, break
221: * before printing the line's data.
222: */
1.63 kristaps 223: if ('\0' == *n->string) {
224: print_otag(h, TAG_P, 0, NULL);
225: return;
1.78 kristaps 226: }
227:
228: if (' ' == *n->string && MAN_LINE & n->flags)
229: print_otag(h, TAG_BR, 0, NULL);
230: else if (MANH_LITERAL & mh->fl && n->prev)
1.63 kristaps 231: print_otag(h, TAG_BR, 0, NULL);
232:
1.4 kristaps 233: print_text(h, n->string);
1.68 kristaps 234: return;
1.93 schwarze 235: case MAN_EQN:
1.80 kristaps 236: print_eqn(h, n->eqn);
1.69 kristaps 237: break;
1.93 schwarze 238: case MAN_TBL:
1.66 kristaps 239: /*
240: * This will take care of initialising all of the table
241: * state data for the first table, then tearing it down
242: * for the last one.
243: */
1.60 kristaps 244: print_tbl(h, n->span);
1.64 kristaps 245: return;
1.4 kristaps 246: default:
1.93 schwarze 247: /*
1.21 kristaps 248: * Close out scope of font prior to opening a macro
1.66 kristaps 249: * scope.
1.21 kristaps 250: */
1.57 kristaps 251: if (HTMLFONT_NONE != h->metac) {
252: h->metal = h->metac;
253: h->metac = HTMLFONT_NONE;
1.66 kristaps 254: }
255:
256: /*
257: * Close out the current table, if it's open, and unset
258: * the "meta" table state. This will be reopened on the
259: * next table element.
260: */
261: if (h->tblt) {
262: print_tblclose(h);
263: t = h->tags.head;
1.20 kristaps 264: }
1.4 kristaps 265: if (mans[n->tok].pre)
1.89 schwarze 266: child = (*mans[n->tok].pre)(man, n, mh, h);
1.4 kristaps 267: break;
268: }
269:
1.21 kristaps 270: if (child && n->child)
1.89 schwarze 271: print_man_nodelist(man, n->child, mh, h);
1.21 kristaps 272:
1.24 kristaps 273: /* This will automatically close out any font scope. */
1.4 kristaps 274: print_stagq(h, t);
275:
1.61 kristaps 276: switch (n->type) {
1.93 schwarze 277: case MAN_ROOT:
1.89 schwarze 278: man_root_post(man, n, mh, h);
1.69 kristaps 279: break;
1.93 schwarze 280: case MAN_EQN:
1.61 kristaps 281: break;
282: default:
283: if (mans[n->tok].post)
1.89 schwarze 284: (*mans[n->tok].post)(man, n, mh, h);
1.61 kristaps 285: break;
286: }
1.4 kristaps 287: }
288:
1.5 kristaps 289: static int
1.7 kristaps 290: a2width(const struct man_node *n, struct roffsu *su)
1.5 kristaps 291: {
292:
1.6 kristaps 293: if (MAN_TEXT != n->type)
1.7 kristaps 294: return(0);
1.11 kristaps 295: if (a2roffsu(n->string, su, SCALE_BU))
1.7 kristaps 296: return(1);
1.5 kristaps 297:
1.7 kristaps 298: return(0);
1.5 kristaps 299: }
300:
1.65 kristaps 301: static void
1.4 kristaps 302: man_root_pre(MAN_ARGS)
303: {
1.94 ! schwarze 304: char b[BUFSIZ];
1.56 kristaps 305: struct htmlpair tag[3];
1.4 kristaps 306: struct tag *t, *tt;
1.94 ! schwarze 307: char *title;
1.4 kristaps 308:
309: b[0] = 0;
1.89 schwarze 310: if (man->vol)
311: (void)strlcat(b, man->vol, BUFSIZ);
1.4 kristaps 312:
1.89 schwarze 313: assert(man->title);
314: assert(man->msec);
1.94 ! schwarze 315: mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4 kristaps 316:
1.56 kristaps 317: PAIR_SUMMARY_INIT(&tag[0], "Document Header");
318: PAIR_CLASS_INIT(&tag[1], "head");
1.83 schwarze 319: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
320: t = print_otag(h, TAG_TABLE, 3, tag);
321: PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
322: print_otag(h, TAG_COL, 1, tag);
323: print_otag(h, TAG_COL, 1, tag);
324: print_otag(h, TAG_COL, 1, tag);
1.56 kristaps 325:
326: print_otag(h, TAG_TBODY, 0, NULL);
1.15 kristaps 327:
1.4 kristaps 328: tt = print_otag(h, TAG_TR, 0, NULL);
329:
1.55 kristaps 330: PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.4 kristaps 331: print_otag(h, TAG_TD, 1, tag);
332: print_text(h, title);
333: print_stagq(h, tt);
334:
1.55 kristaps 335: PAIR_CLASS_INIT(&tag[0], "head-vol");
1.83 schwarze 336: PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
337: print_otag(h, TAG_TD, 2, tag);
1.4 kristaps 338: print_text(h, b);
339: print_stagq(h, tt);
340:
1.55 kristaps 341: PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.83 schwarze 342: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
343: print_otag(h, TAG_TD, 2, tag);
1.4 kristaps 344: print_text(h, title);
345: print_tagq(h, t);
1.94 ! schwarze 346: free(title);
1.4 kristaps 347: }
348:
349: static void
350: man_root_post(MAN_ARGS)
351: {
1.56 kristaps 352: struct htmlpair tag[3];
1.4 kristaps 353: struct tag *t, *tt;
354:
1.56 kristaps 355: PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
356: PAIR_CLASS_INIT(&tag[1], "foot");
1.83 schwarze 357: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
358: t = print_otag(h, TAG_TABLE, 3, tag);
359: PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
360: print_otag(h, TAG_COL, 1, tag);
361: print_otag(h, TAG_COL, 1, tag);
1.15 kristaps 362:
1.4 kristaps 363: tt = print_otag(h, TAG_TR, 0, NULL);
364:
1.55 kristaps 365: PAIR_CLASS_INIT(&tag[0], "foot-date");
1.4 kristaps 366: print_otag(h, TAG_TD, 1, tag);
1.55 kristaps 367:
1.89 schwarze 368: assert(man->date);
369: print_text(h, man->date);
1.4 kristaps 370: print_stagq(h, tt);
371:
1.55 kristaps 372: PAIR_CLASS_INIT(&tag[0], "foot-os");
1.83 schwarze 373: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
374: print_otag(h, TAG_TD, 2, tag);
1.55 kristaps 375:
1.89 schwarze 376: if (man->source)
377: print_text(h, man->source);
1.4 kristaps 378: print_tagq(h, t);
379: }
380:
381:
382: static int
383: man_br_pre(MAN_ARGS)
384: {
1.7 kristaps 385: struct roffsu su;
386: struct htmlpair tag;
1.4 kristaps 387:
1.7 kristaps 388: SCALE_VS_INIT(&su, 1);
389:
1.49 kristaps 390: if (MAN_sp == n->tok) {
1.75 kristaps 391: if (NULL != (n = n->child))
392: if ( ! a2roffsu(n->string, &su, SCALE_VS))
393: SCALE_VS_INIT(&su, atoi(n->string));
1.49 kristaps 394: } else
1.7 kristaps 395: su.scale = 0;
1.4 kristaps 396:
1.72 kristaps 397: bufinit(h);
1.7 kristaps 398: bufcat_su(h, "height", &su);
399: PAIR_STYLE_INIT(&tag, h);
1.4 kristaps 400: print_otag(h, TAG_DIV, 1, &tag);
1.24 kristaps 401:
1.16 kristaps 402: /* So the div isn't empty: */
403: print_text(h, "\\~");
404:
1.7 kristaps 405: return(0);
1.4 kristaps 406: }
407:
408: static int
409: man_SH_pre(MAN_ARGS)
410: {
1.54 kristaps 411: struct htmlpair tag;
1.4 kristaps 412:
1.54 kristaps 413: if (MAN_BLOCK == n->type) {
1.76 kristaps 414: mh->fl &= ~MANH_LITERAL;
1.54 kristaps 415: PAIR_CLASS_INIT(&tag, "section");
416: print_otag(h, TAG_DIV, 1, &tag);
1.4 kristaps 417: return(1);
1.54 kristaps 418: } else if (MAN_BODY == n->type)
1.4 kristaps 419: return(1);
420:
1.54 kristaps 421: print_otag(h, TAG_H1, 0, NULL);
1.4 kristaps 422: return(1);
423: }
424:
425: static int
1.8 kristaps 426: man_alt_pre(MAN_ARGS)
427: {
428: const struct man_node *nn;
1.78 kristaps 429: int i, savelit;
1.57 kristaps 430: enum htmltag fp;
431: struct tag *t;
1.8 kristaps 432:
1.93 schwarze 433: if ((savelit = mh->fl & MANH_LITERAL))
1.78 kristaps 434: print_otag(h, TAG_BR, 0, NULL);
435:
436: mh->fl &= ~MANH_LITERAL;
437:
1.8 kristaps 438: for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.57 kristaps 439: t = NULL;
1.8 kristaps 440: switch (n->tok) {
1.93 schwarze 441: case MAN_BI:
1.57 kristaps 442: fp = i % 2 ? TAG_I : TAG_B;
1.8 kristaps 443: break;
1.93 schwarze 444: case MAN_IB:
1.57 kristaps 445: fp = i % 2 ? TAG_B : TAG_I;
1.8 kristaps 446: break;
1.93 schwarze 447: case MAN_RI:
1.57 kristaps 448: fp = i % 2 ? TAG_I : TAG_MAX;
1.8 kristaps 449: break;
1.93 schwarze 450: case MAN_IR:
1.57 kristaps 451: fp = i % 2 ? TAG_MAX : TAG_I;
1.8 kristaps 452: break;
1.93 schwarze 453: case MAN_BR:
1.57 kristaps 454: fp = i % 2 ? TAG_MAX : TAG_B;
1.8 kristaps 455: break;
1.93 schwarze 456: case MAN_RB:
1.57 kristaps 457: fp = i % 2 ? TAG_B : TAG_MAX;
1.8 kristaps 458: break;
459: default:
460: abort();
461: /* NOTREACHED */
462: }
463:
464: if (i)
465: h->flags |= HTML_NOSPACE;
466:
1.57 kristaps 467: if (TAG_MAX != fp)
468: t = print_otag(h, fp, 0, NULL);
469:
1.89 schwarze 470: print_man_node(man, nn, mh, h);
1.57 kristaps 471:
472: if (t)
473: print_tagq(h, t);
1.8 kristaps 474: }
475:
1.78 kristaps 476: if (savelit)
477: mh->fl |= MANH_LITERAL;
478:
1.8 kristaps 479: return(0);
480: }
481:
482: static int
1.56 kristaps 483: man_SM_pre(MAN_ARGS)
1.8 kristaps 484: {
1.93 schwarze 485:
1.57 kristaps 486: print_otag(h, TAG_SMALL, 0, NULL);
1.56 kristaps 487: if (MAN_SB == n->tok)
1.57 kristaps 488: print_otag(h, TAG_B, 0, NULL);
1.8 kristaps 489: return(1);
490: }
491:
492: static int
1.4 kristaps 493: man_SS_pre(MAN_ARGS)
494: {
1.54 kristaps 495: struct htmlpair tag;
1.4 kristaps 496:
1.54 kristaps 497: if (MAN_BLOCK == n->type) {
1.76 kristaps 498: mh->fl &= ~MANH_LITERAL;
1.54 kristaps 499: PAIR_CLASS_INIT(&tag, "subsection");
500: print_otag(h, TAG_DIV, 1, &tag);
1.4 kristaps 501: return(1);
1.54 kristaps 502: } else if (MAN_BODY == n->type)
1.4 kristaps 503: return(1);
504:
1.54 kristaps 505: print_otag(h, TAG_H2, 0, NULL);
1.4 kristaps 506: return(1);
507: }
508:
509: static int
510: man_PP_pre(MAN_ARGS)
511: {
512:
1.47 kristaps 513: if (MAN_HEAD == n->type)
514: return(0);
1.74 kristaps 515: else if (MAN_BLOCK == n->type)
516: print_bvspace(h, n);
1.47 kristaps 517:
1.5 kristaps 518: return(1);
519: }
520:
521: static int
522: man_IP_pre(MAN_ARGS)
523: {
524: const struct man_node *nn;
525:
1.93 schwarze 526: if (MAN_BODY == n->type) {
1.77 kristaps 527: print_otag(h, TAG_DD, 0, NULL);
528: return(1);
529: } else if (MAN_HEAD != n->type) {
530: print_otag(h, TAG_DL, 0, NULL);
1.6 kristaps 531: return(1);
532: }
533:
1.78 kristaps 534: /* FIXME: width specification. */
535:
1.77 kristaps 536: print_otag(h, TAG_DT, 0, NULL);
1.6 kristaps 537:
1.59 schwarze 538: /* For IP, only print the first header element. */
1.7 kristaps 539:
1.59 schwarze 540: if (MAN_IP == n->tok && n->child)
1.89 schwarze 541: print_man_node(man, n->child, mh, h);
1.27 kristaps 542:
1.59 schwarze 543: /* For TP, only print next-line header elements. */
1.6 kristaps 544:
1.91 schwarze 545: if (MAN_TP == n->tok) {
546: nn = n->child;
547: while (NULL != nn && 0 == (MAN_LINE & nn->flags))
548: nn = nn->next;
549: while (NULL != nn) {
550: print_man_node(man, nn, mh, h);
551: nn = nn->next;
552: }
553: }
1.6 kristaps 554:
555: return(0);
556: }
557:
558: static int
559: man_HP_pre(MAN_ARGS)
560: {
1.56 kristaps 561: struct htmlpair tag;
562: struct roffsu su;
563: const struct man_node *np;
1.6 kristaps 564:
1.77 kristaps 565: if (MAN_HEAD == n->type)
566: return(0);
567: else if (MAN_BLOCK != n->type)
568: return(1);
1.72 kristaps 569:
1.77 kristaps 570: np = n->head->child;
1.6 kristaps 571:
1.56 kristaps 572: if (NULL == np || ! a2width(np, &su))
573: SCALE_HS_INIT(&su, INDENT);
1.6 kristaps 574:
1.77 kristaps 575: bufinit(h);
1.5 kristaps 576:
1.77 kristaps 577: print_bvspace(h, n);
578: bufcat_su(h, "margin-left", &su);
1.56 kristaps 579: su.scale = -su.scale;
1.7 kristaps 580: bufcat_su(h, "text-indent", &su);
581: PAIR_STYLE_INIT(&tag, h);
1.77 kristaps 582: print_otag(h, TAG_P, 1, &tag);
1.4 kristaps 583: return(1);
584: }
1.86 kristaps 585:
586: static int
587: man_OP_pre(MAN_ARGS)
588: {
589: struct tag *tt;
590: struct htmlpair tag;
591:
592: print_text(h, "[");
593: h->flags |= HTML_NOSPACE;
594: PAIR_CLASS_INIT(&tag, "opt");
595: tt = print_otag(h, TAG_SPAN, 1, &tag);
596:
597: if (NULL != (n = n->child)) {
598: print_otag(h, TAG_B, 0, NULL);
599: print_text(h, n->string);
600: }
601:
602: print_stagq(h, tt);
603:
604: if (NULL != n && NULL != n->next) {
605: print_otag(h, TAG_I, 0, NULL);
606: print_text(h, n->next->string);
607: }
608:
609: print_stagq(h, tt);
610: h->flags |= HTML_NOSPACE;
611: print_text(h, "]");
612: return(0);
613: }
614:
1.8 kristaps 615: static int
616: man_B_pre(MAN_ARGS)
617: {
618:
1.57 kristaps 619: print_otag(h, TAG_B, 0, NULL);
1.8 kristaps 620: return(1);
621: }
622:
623: static int
624: man_I_pre(MAN_ARGS)
625: {
1.93 schwarze 626:
1.57 kristaps 627: print_otag(h, TAG_I, 0, NULL);
1.8 kristaps 628: return(1);
1.45 kristaps 629: }
630:
631: static int
632: man_literal_pre(MAN_ARGS)
633: {
634:
1.88 schwarze 635: if (MAN_fi == n->tok || MAN_EE == n->tok) {
1.45 kristaps 636: print_otag(h, TAG_BR, 0, NULL);
1.78 kristaps 637: mh->fl &= ~MANH_LITERAL;
638: } else
1.45 kristaps 639: mh->fl |= MANH_LITERAL;
640:
1.67 schwarze 641: return(0);
1.45 kristaps 642: }
643:
644: static int
645: man_in_pre(MAN_ARGS)
646: {
647:
648: print_otag(h, TAG_BR, 0, NULL);
649: return(0);
1.8 kristaps 650: }
651:
652: static int
653: man_ign_pre(MAN_ARGS)
654: {
655:
656: return(0);
657: }
1.9 kristaps 658:
659: static int
660: man_RS_pre(MAN_ARGS)
661: {
662: struct htmlpair tag;
663: struct roffsu su;
664:
665: if (MAN_HEAD == n->type)
666: return(0);
667: else if (MAN_BODY == n->type)
668: return(1);
669:
670: SCALE_HS_INIT(&su, INDENT);
1.56 kristaps 671: if (n->head->child)
1.9 kristaps 672: a2width(n->head->child, &su);
673:
1.72 kristaps 674: bufinit(h);
1.56 kristaps 675: bufcat_su(h, "margin-left", &su);
1.9 kristaps 676: PAIR_STYLE_INIT(&tag, h);
677: print_otag(h, TAG_DIV, 1, &tag);
678: return(1);
1.90 schwarze 679: }
680:
681: static int
682: man_UR_pre(MAN_ARGS)
683: {
684: struct htmlpair tag[2];
685:
686: n = n->child;
687: assert(MAN_HEAD == n->type);
688: if (n->nchild) {
689: assert(MAN_TEXT == n->child->type);
690: PAIR_CLASS_INIT(&tag[0], "link-ext");
691: PAIR_HREF_INIT(&tag[1], n->child->string);
692: print_otag(h, TAG_A, 2, tag);
693: }
694:
695: assert(MAN_BODY == n->next->type);
696: if (n->next->nchild)
697: n = n->next;
698:
699: print_man_nodelist(man, n->child, mh, h);
700:
701: return(0);
1.9 kristaps 702: }
CVSweb