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