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