Annotation of mandoc/man_html.c, Revision 1.49
1.49 ! kristaps 1: /* $Id: man_html.c,v 1.48 2010/12/06 14:07:01 kristaps Exp $ */
1.1 kristaps 2: /*
1.42 schwarze 3: * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
1.25 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
20:
1.1 kristaps 21: #include <sys/types.h>
22:
1.5 kristaps 23: #include <assert.h>
24: #include <ctype.h>
1.2 kristaps 25: #include <stdio.h>
1.1 kristaps 26: #include <stdlib.h>
1.4 kristaps 27: #include <string.h>
1.1 kristaps 28:
1.35 kristaps 29: #include "mandoc.h"
1.7 kristaps 30: #include "out.h"
1.1 kristaps 31: #include "html.h"
32: #include "man.h"
1.10 kristaps 33: #include "main.h"
1.1 kristaps 34:
1.6 kristaps 35: /* TODO: preserve ident widths. */
1.13 kristaps 36: /* FIXME: have PD set the default vspace width. */
1.6 kristaps 37:
38: #define INDENT 5
1.4 kristaps 39: #define HALFINDENT 3
40:
1.3 kristaps 41: #define MAN_ARGS const struct man_meta *m, \
42: const struct man_node *n, \
1.45 kristaps 43: struct mhtml *mh, \
1.3 kristaps 44: struct html *h
45:
1.45 kristaps 46: struct mhtml {
47: int fl;
48: #define MANH_LITERAL (1 << 0) /* literal context */
49: };
50:
1.3 kristaps 51: struct htmlman {
52: int (*pre)(MAN_ARGS);
53: int (*post)(MAN_ARGS);
54: };
55:
56: static void print_man(MAN_ARGS);
57: static void print_man_head(MAN_ARGS);
1.4 kristaps 58: static void print_man_nodelist(MAN_ARGS);
59: static void print_man_node(MAN_ARGS);
1.3 kristaps 60:
1.7 kristaps 61: static int a2width(const struct man_node *,
62: struct roffsu *);
1.5 kristaps 63:
1.8 kristaps 64: static int man_alt_pre(MAN_ARGS);
1.4 kristaps 65: static int man_br_pre(MAN_ARGS);
1.8 kristaps 66: static int man_ign_pre(MAN_ARGS);
1.45 kristaps 67: static int man_in_pre(MAN_ARGS);
68: static int man_literal_pre(MAN_ARGS);
1.8 kristaps 69: static void man_root_post(MAN_ARGS);
70: static int man_root_pre(MAN_ARGS);
71: static int man_B_pre(MAN_ARGS);
1.6 kristaps 72: static int man_HP_pre(MAN_ARGS);
1.8 kristaps 73: static int man_I_pre(MAN_ARGS);
1.5 kristaps 74: static int man_IP_pre(MAN_ARGS);
1.4 kristaps 75: static int man_PP_pre(MAN_ARGS);
1.9 kristaps 76: static int man_RS_pre(MAN_ARGS);
1.8 kristaps 77: static int man_SB_pre(MAN_ARGS);
1.4 kristaps 78: static int man_SH_pre(MAN_ARGS);
1.8 kristaps 79: static int man_SM_pre(MAN_ARGS);
1.4 kristaps 80: static int man_SS_pre(MAN_ARGS);
81:
1.3 kristaps 82: static const struct htmlman mans[MAN_MAX] = {
1.4 kristaps 83: { man_br_pre, NULL }, /* br */
1.3 kristaps 84: { NULL, NULL }, /* TH */
1.4 kristaps 85: { man_SH_pre, NULL }, /* SH */
86: { man_SS_pre, NULL }, /* SS */
1.6 kristaps 87: { man_IP_pre, NULL }, /* TP */
1.4 kristaps 88: { man_PP_pre, NULL }, /* LP */
89: { man_PP_pre, NULL }, /* PP */
90: { man_PP_pre, NULL }, /* P */
1.5 kristaps 91: { man_IP_pre, NULL }, /* IP */
1.6 kristaps 92: { man_HP_pre, NULL }, /* HP */
1.8 kristaps 93: { man_SM_pre, NULL }, /* SM */
94: { man_SB_pre, NULL }, /* SB */
95: { man_alt_pre, NULL }, /* BI */
96: { man_alt_pre, NULL }, /* IB */
97: { man_alt_pre, NULL }, /* BR */
98: { man_alt_pre, NULL }, /* RB */
1.3 kristaps 99: { NULL, NULL }, /* R */
1.8 kristaps 100: { man_B_pre, NULL }, /* B */
101: { man_I_pre, NULL }, /* I */
102: { man_alt_pre, NULL }, /* IR */
103: { man_alt_pre, NULL }, /* RI */
1.3 kristaps 104: { NULL, NULL }, /* na */
105: { NULL, NULL }, /* i */
1.4 kristaps 106: { man_br_pre, NULL }, /* sp */
1.45 kristaps 107: { man_literal_pre, NULL }, /* nf */
108: { man_literal_pre, NULL }, /* fi */
1.3 kristaps 109: { NULL, NULL }, /* r */
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.3 kristaps 117: };
118:
1.1 kristaps 119:
120: void
121: html_man(void *arg, const struct man *m)
122: {
1.3 kristaps 123: struct html *h;
124: struct tag *t;
1.45 kristaps 125: struct mhtml mh;
1.3 kristaps 126:
127: h = (struct html *)arg;
128:
1.26 kristaps 129: print_gen_decls(h);
1.3 kristaps 130:
1.45 kristaps 131: memset(&mh, 0, sizeof(struct mhtml));
132:
1.3 kristaps 133: t = print_otag(h, TAG_HTML, 0, NULL);
1.45 kristaps 134: print_man(man_meta(m), man_node(m), &mh, h);
1.3 kristaps 135: print_tagq(h, t);
136:
137: printf("\n");
138: }
139:
140:
141: static void
142: print_man(MAN_ARGS)
143: {
144: struct tag *t;
145: struct htmlpair tag;
146:
147: t = print_otag(h, TAG_HEAD, 0, NULL);
148:
1.45 kristaps 149: print_man_head(m, n, mh, h);
1.3 kristaps 150: print_tagq(h, t);
151: t = print_otag(h, TAG_BODY, 0, NULL);
152:
153: tag.key = ATTR_CLASS;
154: tag.val = "body";
155: print_otag(h, TAG_DIV, 1, &tag);
156:
1.45 kristaps 157: print_man_nodelist(m, n, mh, h);
1.3 kristaps 158:
159: print_tagq(h, t);
160: }
161:
162:
163: /* ARGSUSED */
164: static void
165: print_man_head(MAN_ARGS)
166: {
167:
168: print_gen_head(h);
169: bufinit(h);
1.31 kristaps 170: buffmt(h, "%s(%s)", m->title, m->msec);
1.3 kristaps 171:
172: print_otag(h, TAG_TITLE, 0, NULL);
173: print_text(h, h->buf);
1.1 kristaps 174: }
1.4 kristaps 175:
176:
177: static void
178: print_man_nodelist(MAN_ARGS)
179: {
180:
1.45 kristaps 181: print_man_node(m, n, mh, h);
1.4 kristaps 182: if (n->next)
1.45 kristaps 183: print_man_nodelist(m, n->next, mh, h);
1.4 kristaps 184: }
185:
186:
187: static void
188: print_man_node(MAN_ARGS)
189: {
190: int child;
191: struct tag *t;
192:
193: child = 1;
1.14 kristaps 194: t = h->tags.head;
1.4 kristaps 195:
196: bufinit(h);
197:
1.28 kristaps 198: /*
199: * FIXME: embedded elements within next-line scopes (e.g., `br'
200: * within an empty `B') will cause formatting to be forgotten
201: * due to scope closing out.
202: */
203:
1.4 kristaps 204: switch (n->type) {
205: case (MAN_ROOT):
1.45 kristaps 206: child = man_root_pre(m, n, mh, h);
1.4 kristaps 207: break;
208: case (MAN_TEXT):
209: print_text(h, n->string);
1.45 kristaps 210:
211: if (MANH_LITERAL & mh->fl)
212: print_otag(h, TAG_BR, 0, NULL);
213:
1.19 kristaps 214: return;
1.4 kristaps 215: default:
1.21 kristaps 216: /*
217: * Close out scope of font prior to opening a macro
218: * scope. Assert that the metafont is on the top of the
219: * stack (it's never nested).
220: */
1.20 kristaps 221: if (h->metaf) {
222: assert(h->metaf == t);
223: print_tagq(h, h->metaf);
1.21 kristaps 224: assert(NULL == h->metaf);
1.20 kristaps 225: t = h->tags.head;
226: }
1.4 kristaps 227: if (mans[n->tok].pre)
1.45 kristaps 228: child = (*mans[n->tok].pre)(m, n, mh, h);
1.4 kristaps 229: break;
230: }
231:
1.21 kristaps 232: if (child && n->child)
1.45 kristaps 233: print_man_nodelist(m, n->child, mh, h);
1.21 kristaps 234:
1.24 kristaps 235: /* This will automatically close out any font scope. */
1.4 kristaps 236: print_stagq(h, t);
237:
238: bufinit(h);
239:
240: switch (n->type) {
241: case (MAN_ROOT):
1.45 kristaps 242: man_root_post(m, n, mh, h);
1.4 kristaps 243: break;
244: case (MAN_TEXT):
245: break;
246: default:
247: if (mans[n->tok].post)
1.45 kristaps 248: (*mans[n->tok].post)(m, n, mh, h);
1.4 kristaps 249: break;
250: }
251: }
252:
253:
1.5 kristaps 254: static int
1.7 kristaps 255: a2width(const struct man_node *n, struct roffsu *su)
1.5 kristaps 256: {
257:
1.6 kristaps 258: if (MAN_TEXT != n->type)
1.7 kristaps 259: return(0);
1.11 kristaps 260: if (a2roffsu(n->string, su, SCALE_BU))
1.7 kristaps 261: return(1);
1.5 kristaps 262:
1.7 kristaps 263: return(0);
1.5 kristaps 264: }
265:
266:
1.40 kristaps 267: /* ARGSUSED */
1.4 kristaps 268: static int
269: man_root_pre(MAN_ARGS)
270: {
1.15 kristaps 271: struct htmlpair tag[3];
1.4 kristaps 272: struct tag *t, *tt;
273: char b[BUFSIZ], title[BUFSIZ];
274:
275: b[0] = 0;
276: if (m->vol)
277: (void)strlcat(b, m->vol, BUFSIZ);
278:
1.31 kristaps 279: snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.4 kristaps 280:
1.7 kristaps 281: PAIR_CLASS_INIT(&tag[0], "header");
282: bufcat_style(h, "width", "100%");
283: PAIR_STYLE_INIT(&tag[1], h);
1.15 kristaps 284: PAIR_SUMMARY_INIT(&tag[2], "header");
285:
286: t = print_otag(h, TAG_TABLE, 3, tag);
1.4 kristaps 287: tt = print_otag(h, TAG_TR, 0, NULL);
288:
1.7 kristaps 289: bufinit(h);
290: bufcat_style(h, "width", "10%");
291: PAIR_STYLE_INIT(&tag[0], h);
1.4 kristaps 292: print_otag(h, TAG_TD, 1, tag);
293: print_text(h, title);
294: print_stagq(h, tt);
295:
1.7 kristaps 296: bufinit(h);
297: bufcat_style(h, "width", "80%");
298: bufcat_style(h, "white-space", "nowrap");
299: bufcat_style(h, "text-align", "center");
300: PAIR_STYLE_INIT(&tag[0], h);
1.4 kristaps 301: print_otag(h, TAG_TD, 1, tag);
302: print_text(h, b);
303: print_stagq(h, tt);
304:
1.7 kristaps 305: bufinit(h);
306: bufcat_style(h, "width", "10%");
307: bufcat_style(h, "text-align", "right");
308: PAIR_STYLE_INIT(&tag[0], h);
1.4 kristaps 309: print_otag(h, TAG_TD, 1, tag);
310: print_text(h, title);
311: print_tagq(h, t);
312: return(1);
313: }
314:
315:
316: /* ARGSUSED */
317: static void
318: man_root_post(MAN_ARGS)
319: {
1.15 kristaps 320: struct htmlpair tag[3];
1.4 kristaps 321: struct tag *t, *tt;
1.12 kristaps 322: char b[DATESIZ];
1.4 kristaps 323:
1.36 kristaps 324: if (m->rawdate)
325: strlcpy(b, m->rawdate, DATESIZ);
326: else
327: time2a(m->date, b, DATESIZ);
1.4 kristaps 328:
1.7 kristaps 329: PAIR_CLASS_INIT(&tag[0], "footer");
330: bufcat_style(h, "width", "100%");
331: PAIR_STYLE_INIT(&tag[1], h);
1.15 kristaps 332: PAIR_SUMMARY_INIT(&tag[2], "footer");
333:
334: t = print_otag(h, TAG_TABLE, 3, tag);
1.4 kristaps 335: tt = print_otag(h, TAG_TR, 0, NULL);
336:
1.7 kristaps 337: bufinit(h);
338: bufcat_style(h, "width", "50%");
339: PAIR_STYLE_INIT(&tag[0], h);
1.4 kristaps 340: print_otag(h, TAG_TD, 1, tag);
341: print_text(h, b);
342: print_stagq(h, tt);
343:
1.7 kristaps 344: bufinit(h);
345: bufcat_style(h, "width", "50%");
346: bufcat_style(h, "text-align", "right");
347: PAIR_STYLE_INIT(&tag[0], h);
1.4 kristaps 348: print_otag(h, TAG_TD, 1, tag);
349: if (m->source)
350: print_text(h, m->source);
351: print_tagq(h, t);
352: }
353:
354:
355:
356: /* ARGSUSED */
357: static int
358: man_br_pre(MAN_ARGS)
359: {
1.7 kristaps 360: struct roffsu su;
361: struct htmlpair tag;
1.4 kristaps 362:
1.7 kristaps 363: SCALE_VS_INIT(&su, 1);
364:
1.49 ! kristaps 365: if (MAN_sp == n->tok) {
1.29 kristaps 366: if (n->child)
367: a2roffsu(n->child->string, &su, SCALE_VS);
1.49 ! kristaps 368: } else
1.7 kristaps 369: su.scale = 0;
1.4 kristaps 370:
1.7 kristaps 371: bufcat_su(h, "height", &su);
372: PAIR_STYLE_INIT(&tag, h);
1.4 kristaps 373: print_otag(h, TAG_DIV, 1, &tag);
1.24 kristaps 374:
1.16 kristaps 375: /* So the div isn't empty: */
376: print_text(h, "\\~");
377:
1.7 kristaps 378: return(0);
1.4 kristaps 379: }
380:
381:
382: /* ARGSUSED */
383: static int
384: man_SH_pre(MAN_ARGS)
385: {
1.7 kristaps 386: struct htmlpair tag[2];
387: struct roffsu su;
1.4 kristaps 388:
389: if (MAN_BODY == n->type) {
1.7 kristaps 390: SCALE_HS_INIT(&su, INDENT);
391: bufcat_su(h, "margin-left", &su);
392: PAIR_CLASS_INIT(&tag[0], "sec-body");
393: PAIR_STYLE_INIT(&tag[1], h);
1.4 kristaps 394: print_otag(h, TAG_DIV, 2, tag);
395: return(1);
396: } else if (MAN_BLOCK == n->type) {
1.7 kristaps 397: PAIR_CLASS_INIT(&tag[0], "sec-block");
1.4 kristaps 398: if (n->prev && MAN_SH == n->prev->tok)
399: if (NULL == n->prev->body->child) {
400: print_otag(h, TAG_DIV, 1, tag);
401: return(1);
402: }
403:
1.7 kristaps 404: SCALE_VS_INIT(&su, 1);
405: bufcat_su(h, "margin-top", &su);
1.4 kristaps 406: if (NULL == n->next)
1.7 kristaps 407: bufcat_su(h, "margin-bottom", &su);
408: PAIR_STYLE_INIT(&tag[1], h);
1.4 kristaps 409: print_otag(h, TAG_DIV, 2, tag);
410: return(1);
411: }
412:
1.7 kristaps 413: PAIR_CLASS_INIT(&tag[0], "sec-head");
1.4 kristaps 414: print_otag(h, TAG_DIV, 1, tag);
415: return(1);
416: }
417:
418:
419: /* ARGSUSED */
420: static int
1.8 kristaps 421: man_alt_pre(MAN_ARGS)
422: {
423: const struct man_node *nn;
424: struct tag *t;
425: int i;
1.23 kristaps 426: enum htmlfont fp;
1.8 kristaps 427:
428: for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
429: switch (n->tok) {
430: case (MAN_BI):
1.23 kristaps 431: fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_BOLD;
1.8 kristaps 432: break;
433: case (MAN_IB):
1.23 kristaps 434: fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_ITALIC;
1.8 kristaps 435: break;
436: case (MAN_RI):
1.23 kristaps 437: fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_NONE;
1.8 kristaps 438: break;
439: case (MAN_IR):
1.23 kristaps 440: fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_ITALIC;
1.8 kristaps 441: break;
442: case (MAN_BR):
1.23 kristaps 443: fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_BOLD;
1.8 kristaps 444: break;
445: case (MAN_RB):
1.23 kristaps 446: fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_NONE;
1.8 kristaps 447: break;
448: default:
449: abort();
450: /* NOTREACHED */
451: }
452:
453: if (i)
454: h->flags |= HTML_NOSPACE;
455:
1.24 kristaps 456: /*
457: * Open and close the scope with each argument, so that
458: * internal \f escapes, which are common, are also
459: * closed out with the scope.
460: */
1.23 kristaps 461: t = print_ofont(h, fp);
1.45 kristaps 462: print_man_node(m, nn, mh, h);
1.21 kristaps 463: print_tagq(h, t);
1.8 kristaps 464: }
465:
466: return(0);
467: }
468:
469:
470: /* ARGSUSED */
471: static int
472: man_SB_pre(MAN_ARGS)
473: {
474: struct htmlpair tag;
475:
1.23 kristaps 476: /* FIXME: print_ofont(). */
1.8 kristaps 477: PAIR_CLASS_INIT(&tag, "small bold");
478: print_otag(h, TAG_SPAN, 1, &tag);
479: return(1);
480: }
481:
482:
483: /* ARGSUSED */
484: static int
485: man_SM_pre(MAN_ARGS)
486: {
487: struct htmlpair tag;
488:
489: PAIR_CLASS_INIT(&tag, "small");
490: print_otag(h, TAG_SPAN, 1, &tag);
491: return(1);
492: }
493:
494:
495: /* ARGSUSED */
496: static int
1.4 kristaps 497: man_SS_pre(MAN_ARGS)
498: {
499: struct htmlpair tag[3];
1.7 kristaps 500: struct roffsu su;
1.4 kristaps 501:
1.7 kristaps 502: SCALE_VS_INIT(&su, 1);
1.4 kristaps 503:
504: if (MAN_BODY == n->type) {
1.7 kristaps 505: PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.4 kristaps 506: if (n->parent->next && n->child) {
1.7 kristaps 507: bufcat_su(h, "margin-bottom", &su);
508: PAIR_STYLE_INIT(&tag[1], h);
509: print_otag(h, TAG_DIV, 2, tag);
510: return(1);
1.4 kristaps 511: }
512:
1.7 kristaps 513: print_otag(h, TAG_DIV, 1, tag);
1.4 kristaps 514: return(1);
515: } else if (MAN_BLOCK == n->type) {
1.7 kristaps 516: PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.4 kristaps 517: if (n->prev && MAN_SS == n->prev->tok)
518: if (n->prev->body->child) {
1.7 kristaps 519: bufcat_su(h, "margin-top", &su);
520: PAIR_STYLE_INIT(&tag[1], h);
521: print_otag(h, TAG_DIV, 2, tag);
522: return(1);
1.4 kristaps 523: }
524:
1.7 kristaps 525: print_otag(h, TAG_DIV, 1, tag);
1.4 kristaps 526: return(1);
527: }
528:
1.7 kristaps 529: SCALE_HS_INIT(&su, INDENT - HALFINDENT);
530: bufcat_su(h, "margin-left", &su);
531: PAIR_CLASS_INIT(&tag[0], "ssec-head");
532: PAIR_STYLE_INIT(&tag[1], h);
1.4 kristaps 533: print_otag(h, TAG_DIV, 2, tag);
534: return(1);
535: }
536:
537:
538: /* ARGSUSED */
539: static int
540: man_PP_pre(MAN_ARGS)
541: {
1.5 kristaps 542: struct htmlpair tag;
1.7 kristaps 543: struct roffsu su;
1.5 kristaps 544: int i;
1.4 kristaps 545:
1.47 kristaps 546: if (MAN_BODY == n->type)
1.4 kristaps 547: return(1);
1.47 kristaps 548: if (MAN_HEAD == n->type)
549: return(0);
1.4 kristaps 550:
1.5 kristaps 551: i = 0;
552:
1.22 kristaps 553: if (MAN_ROOT == n->parent->type) {
1.7 kristaps 554: SCALE_HS_INIT(&su, INDENT);
555: bufcat_su(h, "margin-left", &su);
1.22 kristaps 556: i = 1;
1.5 kristaps 557: }
1.22 kristaps 558: if (n->prev) {
1.7 kristaps 559: SCALE_VS_INIT(&su, 1);
1.22 kristaps 560: bufcat_su(h, "margin-top", &su);
561: i = 1;
1.5 kristaps 562: }
1.4 kristaps 563:
1.7 kristaps 564: PAIR_STYLE_INIT(&tag, h);
1.22 kristaps 565: print_otag(h, TAG_DIV, i, &tag);
1.47 kristaps 566:
1.5 kristaps 567: return(1);
568: }
569:
570:
571: /* ARGSUSED */
572: static int
573: man_IP_pre(MAN_ARGS)
574: {
1.7 kristaps 575: struct roffsu su;
1.5 kristaps 576: struct htmlpair tag;
577: const struct man_node *nn;
1.7 kristaps 578: int width;
1.5 kristaps 579:
1.7 kristaps 580: /*
581: * This scattering of 1-BU margins and pads is to make sure that
582: * when text overruns its box, the subsequent text isn't flush
583: * up against it. However, the rest of the right-hand box must
584: * also be adjusted in consideration of this 1-BU space.
585: */
586:
587: if (MAN_BODY == n->type) {
588: SCALE_HS_INIT(&su, INDENT);
589: bufcat_su(h, "margin-left", &su);
590: PAIR_STYLE_INIT(&tag, h);
591: print_otag(h, TAG_DIV, 1, &tag);
1.6 kristaps 592: return(1);
593: }
594:
595: nn = MAN_BLOCK == n->type ?
596: n->head->child : n->parent->head->child;
597:
1.7 kristaps 598: SCALE_HS_INIT(&su, INDENT);
599: width = 0;
1.6 kristaps 600:
1.28 kristaps 601: /* Width is the last token. */
602:
1.7 kristaps 603: if (MAN_IP == n->tok && NULL != nn)
1.5 kristaps 604: if (NULL != (nn = nn->next)) {
605: for ( ; nn->next; nn = nn->next)
606: /* Do nothing. */ ;
1.7 kristaps 607: width = a2width(nn, &su);
1.5 kristaps 608: }
609:
1.28 kristaps 610: /* Width is the first token. */
611:
1.27 kristaps 612: if (MAN_TP == n->tok && NULL != nn) {
1.28 kristaps 613: /* Skip past non-text children. */
1.27 kristaps 614: while (nn && MAN_TEXT != nn->type)
615: nn = nn->next;
1.28 kristaps 616: if (nn)
617: width = a2width(nn, &su);
1.27 kristaps 618: }
1.7 kristaps 619:
1.5 kristaps 620: if (MAN_BLOCK == n->type) {
1.7 kristaps 621: bufcat_su(h, "margin-left", &su);
1.9 kristaps 622: SCALE_VS_INIT(&su, 1);
623: bufcat_su(h, "margin-top", &su);
1.7 kristaps 624: bufcat_style(h, "clear", "both");
625: PAIR_STYLE_INIT(&tag, h);
1.5 kristaps 626: print_otag(h, TAG_DIV, 1, &tag);
627: return(1);
1.6 kristaps 628: }
629:
1.7 kristaps 630: bufcat_su(h, "min-width", &su);
631: SCALE_INVERT(&su);
632: bufcat_su(h, "margin-left", &su);
633: SCALE_HS_INIT(&su, 1);
634: bufcat_su(h, "margin-right", &su);
635: bufcat_style(h, "clear", "left");
1.6 kristaps 636:
637: if (n->next && n->next->child)
1.7 kristaps 638: bufcat_style(h, "float", "left");
1.6 kristaps 639:
1.7 kristaps 640: PAIR_STYLE_INIT(&tag, h);
1.6 kristaps 641: print_otag(h, TAG_DIV, 1, &tag);
642:
1.28 kristaps 643: /*
644: * Without a length string, we can print all of our children.
645: */
1.7 kristaps 646:
647: if ( ! width)
1.6 kristaps 648: return(1);
1.27 kristaps 649:
1.28 kristaps 650: /*
651: * When a length has been specified, we need to carefully print
652: * our child context: IP gets all children printed but the last
653: * (the width), while TP gets all children printed but the first
654: * (the width).
655: */
1.6 kristaps 656:
1.7 kristaps 657: if (MAN_IP == n->tok)
658: for (nn = n->child; nn->next; nn = nn->next)
1.45 kristaps 659: print_man_node(m, nn, mh, h);
1.7 kristaps 660: if (MAN_TP == n->tok)
661: for (nn = n->child->next; nn; nn = nn->next)
1.45 kristaps 662: print_man_node(m, nn, mh, h);
1.6 kristaps 663:
664: return(0);
665: }
666:
667:
668: /* ARGSUSED */
669: static int
670: man_HP_pre(MAN_ARGS)
671: {
672: const struct man_node *nn;
673: struct htmlpair tag;
1.7 kristaps 674: struct roffsu su;
1.6 kristaps 675:
676: if (MAN_HEAD == n->type)
677: return(0);
678:
679: nn = MAN_BLOCK == n->type ?
680: n->head->child : n->parent->head->child;
681:
1.7 kristaps 682: SCALE_HS_INIT(&su, INDENT);
1.6 kristaps 683:
684: if (NULL != nn)
1.7 kristaps 685: (void)a2width(nn, &su);
1.6 kristaps 686:
687: if (MAN_BLOCK == n->type) {
1.7 kristaps 688: bufcat_su(h, "margin-left", &su);
1.9 kristaps 689: SCALE_VS_INIT(&su, 1);
690: bufcat_su(h, "margin-top", &su);
1.7 kristaps 691: bufcat_style(h, "clear", "both");
692: PAIR_STYLE_INIT(&tag, h);
1.5 kristaps 693: print_otag(h, TAG_DIV, 1, &tag);
1.6 kristaps 694: return(1);
695: }
1.5 kristaps 696:
1.7 kristaps 697: bufcat_su(h, "margin-left", &su);
698: SCALE_INVERT(&su);
699: bufcat_su(h, "text-indent", &su);
1.5 kristaps 700:
1.7 kristaps 701: PAIR_STYLE_INIT(&tag, h);
1.6 kristaps 702: print_otag(h, TAG_DIV, 1, &tag);
1.4 kristaps 703: return(1);
704: }
1.6 kristaps 705:
1.8 kristaps 706:
707: /* ARGSUSED */
708: static int
709: man_B_pre(MAN_ARGS)
710: {
711:
1.23 kristaps 712: print_ofont(h, HTMLFONT_BOLD);
1.8 kristaps 713: return(1);
714: }
715:
716:
717: /* ARGSUSED */
718: static int
719: man_I_pre(MAN_ARGS)
720: {
1.23 kristaps 721:
722: print_ofont(h, HTMLFONT_ITALIC);
1.8 kristaps 723: return(1);
1.45 kristaps 724: }
725:
726:
727: /* ARGSUSED */
728: static int
729: man_literal_pre(MAN_ARGS)
730: {
731:
1.48 kristaps 732: if (MAN_nf == n->tok) {
1.45 kristaps 733: print_otag(h, TAG_BR, 0, NULL);
734: mh->fl |= MANH_LITERAL;
1.48 kristaps 735: } else
1.45 kristaps 736: mh->fl &= ~MANH_LITERAL;
737:
738: return(1);
739: }
740:
741:
742: /* ARGSUSED */
743: static int
744: man_in_pre(MAN_ARGS)
745: {
746:
747: print_otag(h, TAG_BR, 0, NULL);
748: return(0);
1.8 kristaps 749: }
750:
751:
752: /* ARGSUSED */
753: static int
754: man_ign_pre(MAN_ARGS)
755: {
756:
757: return(0);
758: }
1.9 kristaps 759:
760:
761: /* ARGSUSED */
762: static int
763: man_RS_pre(MAN_ARGS)
764: {
765: struct htmlpair tag;
766: struct roffsu su;
767:
768: if (MAN_HEAD == n->type)
769: return(0);
770: else if (MAN_BODY == n->type)
771: return(1);
772:
773: SCALE_HS_INIT(&su, INDENT);
774: bufcat_su(h, "margin-left", &su);
775:
776: if (n->head->child) {
777: SCALE_VS_INIT(&su, 1);
778: a2width(n->head->child, &su);
779: bufcat_su(h, "margin-top", &su);
780: }
781:
782: PAIR_STYLE_INIT(&tag, h);
783: print_otag(h, TAG_DIV, 1, &tag);
784: return(1);
785: }
CVSweb