Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.69
1.69 ! schwarze 1: /* $Id: mdoc_html.c,v 1.68 2013/12/24 19:10:34 schwarze Exp $ */
1.1 schwarze 2: /*
1.48 schwarze 3: * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 schwarze 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: */
17: #include <sys/types.h>
18:
19: #include <assert.h>
20: #include <ctype.h>
21: #include <stdio.h>
22: #include <stdlib.h>
23: #include <string.h>
24: #include <unistd.h>
25:
1.17 schwarze 26: #include "mandoc.h"
1.1 schwarze 27: #include "out.h"
28: #include "html.h"
29: #include "mdoc.h"
30: #include "main.h"
31:
32: #define INDENT 5
33:
1.67 schwarze 34: #define MDOC_ARGS const struct mdoc_meta *meta, \
1.1 schwarze 35: const struct mdoc_node *n, \
36: struct html *h
37:
1.6 schwarze 38: #ifndef MIN
39: #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
40: #endif
41:
1.1 schwarze 42: struct htmlmdoc {
43: int (*pre)(MDOC_ARGS);
44: void (*post)(MDOC_ARGS);
45: };
46:
47: static void print_mdoc(MDOC_ARGS);
48: static void print_mdoc_head(MDOC_ARGS);
49: static void print_mdoc_node(MDOC_ARGS);
50: static void print_mdoc_nodelist(MDOC_ARGS);
1.21 schwarze 51: static void synopsis_pre(struct html *,
52: const struct mdoc_node *);
1.1 schwarze 53:
54: static void a2width(const char *, struct roffsu *);
55: static void a2offs(const char *, struct roffsu *);
56:
57: static void mdoc_root_post(MDOC_ARGS);
58: static int mdoc_root_pre(MDOC_ARGS);
59:
60: static void mdoc__x_post(MDOC_ARGS);
61: static int mdoc__x_pre(MDOC_ARGS);
62: static int mdoc_ad_pre(MDOC_ARGS);
63: static int mdoc_an_pre(MDOC_ARGS);
64: static int mdoc_ap_pre(MDOC_ARGS);
65: static int mdoc_ar_pre(MDOC_ARGS);
66: static int mdoc_bd_pre(MDOC_ARGS);
67: static int mdoc_bf_pre(MDOC_ARGS);
1.25 schwarze 68: static void mdoc_bk_post(MDOC_ARGS);
69: static int mdoc_bk_pre(MDOC_ARGS);
1.1 schwarze 70: static int mdoc_bl_pre(MDOC_ARGS);
71: static int mdoc_bt_pre(MDOC_ARGS);
72: static int mdoc_bx_pre(MDOC_ARGS);
73: static int mdoc_cd_pre(MDOC_ARGS);
74: static int mdoc_d1_pre(MDOC_ARGS);
75: static int mdoc_dv_pre(MDOC_ARGS);
76: static int mdoc_fa_pre(MDOC_ARGS);
77: static int mdoc_fd_pre(MDOC_ARGS);
78: static int mdoc_fl_pre(MDOC_ARGS);
79: static int mdoc_fn_pre(MDOC_ARGS);
80: static int mdoc_ft_pre(MDOC_ARGS);
81: static int mdoc_em_pre(MDOC_ARGS);
82: static int mdoc_er_pre(MDOC_ARGS);
83: static int mdoc_ev_pre(MDOC_ARGS);
84: static int mdoc_ex_pre(MDOC_ARGS);
85: static void mdoc_fo_post(MDOC_ARGS);
86: static int mdoc_fo_pre(MDOC_ARGS);
87: static int mdoc_ic_pre(MDOC_ARGS);
1.34 schwarze 88: static int mdoc_igndelim_pre(MDOC_ARGS);
1.1 schwarze 89: static int mdoc_in_pre(MDOC_ARGS);
90: static int mdoc_it_pre(MDOC_ARGS);
91: static int mdoc_lb_pre(MDOC_ARGS);
92: static int mdoc_li_pre(MDOC_ARGS);
93: static int mdoc_lk_pre(MDOC_ARGS);
94: static int mdoc_mt_pre(MDOC_ARGS);
95: static int mdoc_ms_pre(MDOC_ARGS);
96: static int mdoc_nd_pre(MDOC_ARGS);
97: static int mdoc_nm_pre(MDOC_ARGS);
98: static int mdoc_ns_pre(MDOC_ARGS);
99: static int mdoc_pa_pre(MDOC_ARGS);
100: static void mdoc_pf_post(MDOC_ARGS);
1.40 schwarze 101: static int mdoc_pp_pre(MDOC_ARGS);
1.32 schwarze 102: static void mdoc_quote_post(MDOC_ARGS);
103: static int mdoc_quote_pre(MDOC_ARGS);
1.1 schwarze 104: static int mdoc_rs_pre(MDOC_ARGS);
105: static int mdoc_rv_pre(MDOC_ARGS);
106: static int mdoc_sh_pre(MDOC_ARGS);
1.26 schwarze 107: static int mdoc_sm_pre(MDOC_ARGS);
1.1 schwarze 108: static int mdoc_sp_pre(MDOC_ARGS);
109: static int mdoc_ss_pre(MDOC_ARGS);
110: static int mdoc_sx_pre(MDOC_ARGS);
111: static int mdoc_sy_pre(MDOC_ARGS);
112: static int mdoc_ud_pre(MDOC_ARGS);
113: static int mdoc_va_pre(MDOC_ARGS);
114: static int mdoc_vt_pre(MDOC_ARGS);
115: static int mdoc_xr_pre(MDOC_ARGS);
116: static int mdoc_xx_pre(MDOC_ARGS);
117:
118: static const struct htmlmdoc mdocs[MDOC_MAX] = {
119: {mdoc_ap_pre, NULL}, /* Ap */
120: {NULL, NULL}, /* Dd */
121: {NULL, NULL}, /* Dt */
122: {NULL, NULL}, /* Os */
123: {mdoc_sh_pre, NULL }, /* Sh */
124: {mdoc_ss_pre, NULL }, /* Ss */
1.40 schwarze 125: {mdoc_pp_pre, NULL}, /* Pp */
1.1 schwarze 126: {mdoc_d1_pre, NULL}, /* D1 */
127: {mdoc_d1_pre, NULL}, /* Dl */
128: {mdoc_bd_pre, NULL}, /* Bd */
129: {NULL, NULL}, /* Ed */
1.40 schwarze 130: {mdoc_bl_pre, NULL}, /* Bl */
1.1 schwarze 131: {NULL, NULL}, /* El */
132: {mdoc_it_pre, NULL}, /* It */
133: {mdoc_ad_pre, NULL}, /* Ad */
134: {mdoc_an_pre, NULL}, /* An */
135: {mdoc_ar_pre, NULL}, /* Ar */
136: {mdoc_cd_pre, NULL}, /* Cd */
137: {mdoc_fl_pre, NULL}, /* Cm */
138: {mdoc_dv_pre, NULL}, /* Dv */
139: {mdoc_er_pre, NULL}, /* Er */
140: {mdoc_ev_pre, NULL}, /* Ev */
141: {mdoc_ex_pre, NULL}, /* Ex */
142: {mdoc_fa_pre, NULL}, /* Fa */
1.21 schwarze 143: {mdoc_fd_pre, NULL}, /* Fd */
1.1 schwarze 144: {mdoc_fl_pre, NULL}, /* Fl */
145: {mdoc_fn_pre, NULL}, /* Fn */
146: {mdoc_ft_pre, NULL}, /* Ft */
147: {mdoc_ic_pre, NULL}, /* Ic */
148: {mdoc_in_pre, NULL}, /* In */
149: {mdoc_li_pre, NULL}, /* Li */
150: {mdoc_nd_pre, NULL}, /* Nd */
151: {mdoc_nm_pre, NULL}, /* Nm */
1.32 schwarze 152: {mdoc_quote_pre, mdoc_quote_post}, /* Op */
1.1 schwarze 153: {NULL, NULL}, /* Ot */
154: {mdoc_pa_pre, NULL}, /* Pa */
155: {mdoc_rv_pre, NULL}, /* Rv */
156: {NULL, NULL}, /* St */
157: {mdoc_va_pre, NULL}, /* Va */
158: {mdoc_vt_pre, NULL}, /* Vt */
159: {mdoc_xr_pre, NULL}, /* Xr */
160: {mdoc__x_pre, mdoc__x_post}, /* %A */
161: {mdoc__x_pre, mdoc__x_post}, /* %B */
162: {mdoc__x_pre, mdoc__x_post}, /* %D */
163: {mdoc__x_pre, mdoc__x_post}, /* %I */
164: {mdoc__x_pre, mdoc__x_post}, /* %J */
165: {mdoc__x_pre, mdoc__x_post}, /* %N */
166: {mdoc__x_pre, mdoc__x_post}, /* %O */
167: {mdoc__x_pre, mdoc__x_post}, /* %P */
168: {mdoc__x_pre, mdoc__x_post}, /* %R */
169: {mdoc__x_pre, mdoc__x_post}, /* %T */
170: {mdoc__x_pre, mdoc__x_post}, /* %V */
171: {NULL, NULL}, /* Ac */
1.32 schwarze 172: {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
173: {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
1.1 schwarze 174: {NULL, NULL}, /* At */
175: {NULL, NULL}, /* Bc */
176: {mdoc_bf_pre, NULL}, /* Bf */
1.32 schwarze 177: {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
178: {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
1.1 schwarze 179: {mdoc_xx_pre, NULL}, /* Bsx */
180: {mdoc_bx_pre, NULL}, /* Bx */
181: {NULL, NULL}, /* Db */
182: {NULL, NULL}, /* Dc */
1.32 schwarze 183: {mdoc_quote_pre, mdoc_quote_post}, /* Do */
184: {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
1.11 schwarze 185: {NULL, NULL}, /* Ec */ /* FIXME: no space */
1.1 schwarze 186: {NULL, NULL}, /* Ef */
187: {mdoc_em_pre, NULL}, /* Em */
1.65 schwarze 188: {mdoc_quote_pre, mdoc_quote_post}, /* Eo */
1.1 schwarze 189: {mdoc_xx_pre, NULL}, /* Fx */
1.26 schwarze 190: {mdoc_ms_pre, NULL}, /* Ms */
1.34 schwarze 191: {mdoc_igndelim_pre, NULL}, /* No */
1.1 schwarze 192: {mdoc_ns_pre, NULL}, /* Ns */
193: {mdoc_xx_pre, NULL}, /* Nx */
194: {mdoc_xx_pre, NULL}, /* Ox */
195: {NULL, NULL}, /* Pc */
1.34 schwarze 196: {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
1.32 schwarze 197: {mdoc_quote_pre, mdoc_quote_post}, /* Po */
198: {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
1.1 schwarze 199: {NULL, NULL}, /* Qc */
1.32 schwarze 200: {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
201: {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
202: {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
1.1 schwarze 203: {NULL, NULL}, /* Re */
204: {mdoc_rs_pre, NULL}, /* Rs */
205: {NULL, NULL}, /* Sc */
1.32 schwarze 206: {mdoc_quote_pre, mdoc_quote_post}, /* So */
207: {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
1.26 schwarze 208: {mdoc_sm_pre, NULL}, /* Sm */
1.1 schwarze 209: {mdoc_sx_pre, NULL}, /* Sx */
210: {mdoc_sy_pre, NULL}, /* Sy */
211: {NULL, NULL}, /* Tn */
212: {mdoc_xx_pre, NULL}, /* Ux */
213: {NULL, NULL}, /* Xc */
214: {NULL, NULL}, /* Xo */
215: {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
216: {NULL, NULL}, /* Fc */
1.32 schwarze 217: {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
1.1 schwarze 218: {NULL, NULL}, /* Oc */
1.25 schwarze 219: {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
1.1 schwarze 220: {NULL, NULL}, /* Ek */
221: {mdoc_bt_pre, NULL}, /* Bt */
222: {NULL, NULL}, /* Hf */
223: {NULL, NULL}, /* Fr */
224: {mdoc_ud_pre, NULL}, /* Ud */
225: {mdoc_lb_pre, NULL}, /* Lb */
1.40 schwarze 226: {mdoc_pp_pre, NULL}, /* Lp */
1.1 schwarze 227: {mdoc_lk_pre, NULL}, /* Lk */
228: {mdoc_mt_pre, NULL}, /* Mt */
1.32 schwarze 229: {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
230: {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
1.1 schwarze 231: {NULL, NULL}, /* Brc */
232: {mdoc__x_pre, mdoc__x_post}, /* %C */
233: {NULL, NULL}, /* Es */ /* TODO */
234: {NULL, NULL}, /* En */ /* TODO */
235: {mdoc_xx_pre, NULL}, /* Dx */
236: {mdoc__x_pre, mdoc__x_post}, /* %Q */
237: {mdoc_sp_pre, NULL}, /* br */
238: {mdoc_sp_pre, NULL}, /* sp */
1.2 schwarze 239: {mdoc__x_pre, mdoc__x_post}, /* %U */
1.20 schwarze 240: {NULL, NULL}, /* Ta */
1.1 schwarze 241: };
242:
1.40 schwarze 243: static const char * const lists[LIST_MAX] = {
244: NULL,
245: "list-bul",
246: "list-col",
247: "list-dash",
248: "list-diag",
249: "list-enum",
250: "list-hang",
251: "list-hyph",
252: "list-inset",
253: "list-item",
254: "list-ohang",
255: "list-tag"
256: };
1.1 schwarze 257:
258: void
1.67 schwarze 259: html_mdoc(void *arg, const struct mdoc *mdoc)
1.1 schwarze 260: {
261:
1.67 schwarze 262: print_mdoc(mdoc_meta(mdoc), mdoc_node(mdoc),
263: (struct html *)arg);
1.62 schwarze 264: putchar('\n');
1.1 schwarze 265: }
266:
267:
268: /*
269: * Calculate the scaling unit passed in a `-width' argument. This uses
270: * either a native scaling unit (e.g., 1i, 2m) or the string length of
271: * the value.
272: */
273: static void
274: a2width(const char *p, struct roffsu *su)
275: {
276:
277: if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.40 schwarze 278: su->unit = SCALE_BU;
1.57 schwarze 279: su->scale = html_strlen(p);
1.1 schwarze 280: }
281: }
282:
283:
284: /*
1.21 schwarze 285: * See the same function in mdoc_term.c for documentation.
286: */
287: static void
288: synopsis_pre(struct html *h, const struct mdoc_node *n)
289: {
290:
1.23 schwarze 291: if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.21 schwarze 292: return;
293:
294: if (n->prev->tok == n->tok &&
295: MDOC_Fo != n->tok &&
296: MDOC_Ft != n->tok &&
297: MDOC_Fn != n->tok) {
1.40 schwarze 298: print_otag(h, TAG_BR, 0, NULL);
1.21 schwarze 299: return;
300: }
301:
302: switch (n->prev->tok) {
303: case (MDOC_Fd):
304: /* FALLTHROUGH */
305: case (MDOC_Fn):
306: /* FALLTHROUGH */
307: case (MDOC_Fo):
308: /* FALLTHROUGH */
309: case (MDOC_In):
310: /* FALLTHROUGH */
311: case (MDOC_Vt):
1.40 schwarze 312: print_otag(h, TAG_P, 0, NULL);
1.21 schwarze 313: break;
314: case (MDOC_Ft):
315: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1.40 schwarze 316: print_otag(h, TAG_P, 0, NULL);
1.21 schwarze 317: break;
318: }
319: /* FALLTHROUGH */
320: default:
1.40 schwarze 321: print_otag(h, TAG_BR, 0, NULL);
1.21 schwarze 322: break;
323: }
324: }
325:
326:
327: /*
1.1 schwarze 328: * Calculate the scaling unit passed in an `-offset' argument. This
329: * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
330: * predefined strings (indent, etc.), or the string length of the value.
331: */
332: static void
333: a2offs(const char *p, struct roffsu *su)
334: {
335:
336: /* FIXME: "right"? */
337:
338: if (0 == strcmp(p, "left"))
339: SCALE_HS_INIT(su, 0);
340: else if (0 == strcmp(p, "indent"))
341: SCALE_HS_INIT(su, INDENT);
342: else if (0 == strcmp(p, "indent-two"))
343: SCALE_HS_INIT(su, INDENT * 2);
1.61 schwarze 344: else if ( ! a2roffsu(p, su, SCALE_MAX))
345: SCALE_HS_INIT(su, html_strlen(p));
1.1 schwarze 346: }
347:
348:
349: static void
350: print_mdoc(MDOC_ARGS)
351: {
1.62 schwarze 352: struct tag *t, *tt;
353: struct htmlpair tag;
354:
355: PAIR_CLASS_INIT(&tag, "mandoc");
1.1 schwarze 356:
1.62 schwarze 357: if ( ! (HTML_FRAGMENT & h->oflags)) {
358: print_gen_decls(h);
359: t = print_otag(h, TAG_HTML, 0, NULL);
360: tt = print_otag(h, TAG_HEAD, 0, NULL);
1.67 schwarze 361: print_mdoc_head(meta, n, h);
1.62 schwarze 362: print_tagq(h, tt);
363: print_otag(h, TAG_BODY, 0, NULL);
364: print_otag(h, TAG_DIV, 1, &tag);
365: } else
366: t = print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 367:
1.67 schwarze 368: print_mdoc_nodelist(meta, n, h);
1.1 schwarze 369: print_tagq(h, t);
370: }
371:
372:
373: /* ARGSUSED */
374: static void
375: print_mdoc_head(MDOC_ARGS)
376: {
377:
378: print_gen_head(h);
379: bufinit(h);
1.67 schwarze 380: bufcat_fmt(h, "%s(%s)", meta->title, meta->msec);
1.1 schwarze 381:
1.67 schwarze 382: if (meta->arch)
383: bufcat_fmt(h, " (%s)", meta->arch);
1.1 schwarze 384:
385: print_otag(h, TAG_TITLE, 0, NULL);
386: print_text(h, h->buf);
387: }
388:
389:
390: static void
391: print_mdoc_nodelist(MDOC_ARGS)
392: {
393:
1.67 schwarze 394: print_mdoc_node(meta, n, h);
1.1 schwarze 395: if (n->next)
1.67 schwarze 396: print_mdoc_nodelist(meta, n->next, h);
1.1 schwarze 397: }
398:
399:
400: static void
401: print_mdoc_node(MDOC_ARGS)
402: {
403: int child;
404: struct tag *t;
405:
406: child = 1;
1.2 schwarze 407: t = h->tags.head;
1.1 schwarze 408:
409: switch (n->type) {
410: case (MDOC_ROOT):
1.67 schwarze 411: child = mdoc_root_pre(meta, n, h);
1.1 schwarze 412: break;
413: case (MDOC_TEXT):
1.48 schwarze 414: /* No tables in this mode... */
415: assert(NULL == h->tblt);
1.50 schwarze 416:
417: /*
418: * Make sure that if we're in a literal mode already
419: * (i.e., within a <PRE>) don't print the newline.
420: */
1.47 schwarze 421: if (' ' == *n->string && MDOC_LINE & n->flags)
1.50 schwarze 422: if ( ! (HTML_LITERAL & h->flags))
423: print_otag(h, TAG_BR, 0, NULL);
1.56 schwarze 424: if (MDOC_DELIMC & n->flags)
425: h->flags |= HTML_NOSPACE;
1.1 schwarze 426: print_text(h, n->string);
1.56 schwarze 427: if (MDOC_DELIMO & n->flags)
428: h->flags |= HTML_NOSPACE;
1.54 schwarze 429: return;
430: case (MDOC_EQN):
1.60 schwarze 431: print_eqn(h, n->eqn);
1.55 schwarze 432: break;
1.45 schwarze 433: case (MDOC_TBL):
1.48 schwarze 434: /*
435: * This will take care of initialising all of the table
436: * state data for the first table, then tearing it down
437: * for the last one.
438: */
1.45 schwarze 439: print_tbl(h, n->span);
1.48 schwarze 440: return;
1.1 schwarze 441: default:
1.48 schwarze 442: /*
443: * Close out the current table, if it's open, and unset
444: * the "meta" table state. This will be reopened on the
445: * next table element.
446: */
447: if (h->tblt) {
448: print_tblclose(h);
449: t = h->tags.head;
450: }
451:
452: assert(NULL == h->tblt);
1.25 schwarze 453: if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
1.67 schwarze 454: child = (*mdocs[n->tok].pre)(meta, n, h);
1.1 schwarze 455: break;
456: }
457:
1.69 ! schwarze 458: if (HTML_KEEP & h->flags) {
1.68 schwarze 459: if (n->prev ? (n->prev->lastline != n->line) :
460: (n->parent && n->parent->line != n->line)) {
1.25 schwarze 461: h->flags &= ~HTML_KEEP;
462: h->flags |= HTML_PREKEEP;
463: }
464: }
465:
1.1 schwarze 466: if (child && n->child)
1.67 schwarze 467: print_mdoc_nodelist(meta, n->child, h);
1.1 schwarze 468:
469: print_stagq(h, t);
470:
471: switch (n->type) {
472: case (MDOC_ROOT):
1.67 schwarze 473: mdoc_root_post(meta, n, h);
1.55 schwarze 474: break;
475: case (MDOC_EQN):
1.1 schwarze 476: break;
477: default:
1.25 schwarze 478: if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
1.67 schwarze 479: (*mdocs[n->tok].post)(meta, n, h);
1.1 schwarze 480: break;
481: }
482: }
483:
484: /* ARGSUSED */
485: static void
486: mdoc_root_post(MDOC_ARGS)
487: {
1.42 schwarze 488: struct htmlpair tag[3];
1.1 schwarze 489: struct tag *t, *tt;
490:
1.42 schwarze 491: PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
492: PAIR_CLASS_INIT(&tag[1], "foot");
1.63 schwarze 493: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
494: t = print_otag(h, TAG_TABLE, 3, tag);
495: PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
496: print_otag(h, TAG_COL, 1, tag);
497: print_otag(h, TAG_COL, 1, tag);
1.42 schwarze 498:
1.64 schwarze 499: print_otag(h, TAG_TBODY, 0, NULL);
1.3 schwarze 500:
1.1 schwarze 501: tt = print_otag(h, TAG_TR, 0, NULL);
502:
1.40 schwarze 503: PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1 schwarze 504: print_otag(h, TAG_TD, 1, tag);
1.67 schwarze 505: print_text(h, meta->date);
1.1 schwarze 506: print_stagq(h, tt);
507:
1.40 schwarze 508: PAIR_CLASS_INIT(&tag[0], "foot-os");
1.63 schwarze 509: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
510: print_otag(h, TAG_TD, 2, tag);
1.67 schwarze 511: print_text(h, meta->os);
1.1 schwarze 512: print_tagq(h, t);
513: }
514:
515:
516: /* ARGSUSED */
517: static int
518: mdoc_root_pre(MDOC_ARGS)
519: {
1.3 schwarze 520: struct htmlpair tag[3];
1.1 schwarze 521: struct tag *t, *tt;
522: char b[BUFSIZ], title[BUFSIZ];
523:
1.67 schwarze 524: strlcpy(b, meta->vol, BUFSIZ);
1.1 schwarze 525:
1.67 schwarze 526: if (meta->arch) {
1.40 schwarze 527: strlcat(b, " (", BUFSIZ);
1.67 schwarze 528: strlcat(b, meta->arch, BUFSIZ);
1.40 schwarze 529: strlcat(b, ")", BUFSIZ);
1.1 schwarze 530: }
531:
1.67 schwarze 532: snprintf(title, BUFSIZ - 1, "%s(%s)", meta->title, meta->msec);
1.1 schwarze 533:
1.42 schwarze 534: PAIR_SUMMARY_INIT(&tag[0], "Document Header");
535: PAIR_CLASS_INIT(&tag[1], "head");
1.63 schwarze 536: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
537: t = print_otag(h, TAG_TABLE, 3, tag);
538: PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
539: print_otag(h, TAG_COL, 1, tag);
540: print_otag(h, TAG_COL, 1, tag);
541: print_otag(h, TAG_COL, 1, tag);
1.42 schwarze 542:
543: print_otag(h, TAG_TBODY, 0, NULL);
1.3 schwarze 544:
1.1 schwarze 545: tt = print_otag(h, TAG_TR, 0, NULL);
546:
1.40 schwarze 547: PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1 schwarze 548: print_otag(h, TAG_TD, 1, tag);
549: print_text(h, title);
550: print_stagq(h, tt);
551:
1.40 schwarze 552: PAIR_CLASS_INIT(&tag[0], "head-vol");
1.63 schwarze 553: PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
554: print_otag(h, TAG_TD, 2, tag);
1.1 schwarze 555: print_text(h, b);
556: print_stagq(h, tt);
557:
1.40 schwarze 558: PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.63 schwarze 559: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
560: print_otag(h, TAG_TD, 2, tag);
1.1 schwarze 561: print_text(h, title);
562: print_tagq(h, t);
563: return(1);
564: }
565:
566:
567: /* ARGSUSED */
568: static int
569: mdoc_sh_pre(MDOC_ARGS)
570: {
1.40 schwarze 571: struct htmlpair tag;
1.1 schwarze 572:
1.40 schwarze 573: if (MDOC_BLOCK == n->type) {
574: PAIR_CLASS_INIT(&tag, "section");
575: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 576: return(1);
1.40 schwarze 577: } else if (MDOC_BODY == n->type)
1.1 schwarze 578: return(1);
579:
1.57 schwarze 580: bufinit(h);
1.59 schwarze 581: bufcat(h, "x");
1.61 schwarze 582:
583: for (n = n->child; n && MDOC_TEXT == n->type; ) {
1.57 schwarze 584: bufcat_id(h, n->string);
1.61 schwarze 585: if (NULL != (n = n->next))
1.57 schwarze 586: bufcat_id(h, " ");
1.1 schwarze 587: }
588:
1.61 schwarze 589: if (NULL == n) {
590: PAIR_ID_INIT(&tag, h->buf);
591: print_otag(h, TAG_H1, 1, &tag);
592: } else
593: print_otag(h, TAG_H1, 0, NULL);
594:
1.1 schwarze 595: return(1);
596: }
597:
598: /* ARGSUSED */
599: static int
600: mdoc_ss_pre(MDOC_ARGS)
601: {
1.40 schwarze 602: struct htmlpair tag;
1.1 schwarze 603:
1.40 schwarze 604: if (MDOC_BLOCK == n->type) {
605: PAIR_CLASS_INIT(&tag, "subsection");
606: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 607: return(1);
1.40 schwarze 608: } else if (MDOC_BODY == n->type)
1.1 schwarze 609: return(1);
610:
1.57 schwarze 611: bufinit(h);
1.59 schwarze 612: bufcat(h, "x");
1.61 schwarze 613:
614: for (n = n->child; n && MDOC_TEXT == n->type; ) {
1.57 schwarze 615: bufcat_id(h, n->string);
1.61 schwarze 616: if (NULL != (n = n->next))
1.57 schwarze 617: bufcat_id(h, " ");
1.1 schwarze 618: }
619:
1.61 schwarze 620: if (NULL == n) {
621: PAIR_ID_INIT(&tag, h->buf);
622: print_otag(h, TAG_H2, 1, &tag);
623: } else
624: print_otag(h, TAG_H2, 0, NULL);
625:
1.1 schwarze 626: return(1);
627: }
628:
629:
630: /* ARGSUSED */
631: static int
632: mdoc_fl_pre(MDOC_ARGS)
633: {
634: struct htmlpair tag;
635:
636: PAIR_CLASS_INIT(&tag, "flag");
1.42 schwarze 637: print_otag(h, TAG_B, 1, &tag);
1.6 schwarze 638:
639: /* `Cm' has no leading hyphen. */
640:
641: if (MDOC_Cm == n->tok)
642: return(1);
643:
644: print_text(h, "\\-");
645:
646: if (n->child)
1.1 schwarze 647: h->flags |= HTML_NOSPACE;
1.11 schwarze 648: else if (n->next && n->next->line == n->line)
649: h->flags |= HTML_NOSPACE;
1.6 schwarze 650:
1.1 schwarze 651: return(1);
652: }
653:
654:
655: /* ARGSUSED */
656: static int
657: mdoc_nd_pre(MDOC_ARGS)
658: {
659: struct htmlpair tag;
660:
661: if (MDOC_BODY != n->type)
662: return(1);
663:
664: /* XXX: this tag in theory can contain block elements. */
665:
666: print_text(h, "\\(em");
1.40 schwarze 667: PAIR_CLASS_INIT(&tag, "desc");
1.1 schwarze 668: print_otag(h, TAG_SPAN, 1, &tag);
669: return(1);
670: }
671:
672:
673: static int
674: mdoc_nm_pre(MDOC_ARGS)
675: {
1.25 schwarze 676: struct htmlpair tag;
677: struct roffsu su;
1.57 schwarze 678: int len;
1.25 schwarze 679:
1.40 schwarze 680: switch (n->type) {
681: case (MDOC_ELEM):
1.25 schwarze 682: synopsis_pre(h, n);
683: PAIR_CLASS_INIT(&tag, "name");
1.42 schwarze 684: print_otag(h, TAG_B, 1, &tag);
1.67 schwarze 685: if (NULL == n->child && meta->name)
686: print_text(h, meta->name);
1.40 schwarze 687: return(1);
688: case (MDOC_HEAD):
689: print_otag(h, TAG_TD, 0, NULL);
1.67 schwarze 690: if (NULL == n->child && meta->name)
691: print_text(h, meta->name);
1.40 schwarze 692: return(1);
693: case (MDOC_BODY):
694: print_otag(h, TAG_TD, 0, NULL);
695: return(1);
696: default:
697: break;
698: }
1.25 schwarze 699:
1.40 schwarze 700: synopsis_pre(h, n);
701: PAIR_CLASS_INIT(&tag, "synopsis");
702: print_otag(h, TAG_TABLE, 1, &tag);
1.25 schwarze 703:
1.40 schwarze 704: for (len = 0, n = n->child; n; n = n->next)
705: if (MDOC_TEXT == n->type)
1.57 schwarze 706: len += html_strlen(n->string);
1.25 schwarze 707:
1.67 schwarze 708: if (0 == len && meta->name)
709: len = html_strlen(meta->name);
1.1 schwarze 710:
1.40 schwarze 711: SCALE_HS_INIT(&su, (double)len);
1.57 schwarze 712: bufinit(h);
1.40 schwarze 713: bufcat_su(h, "width", &su);
714: PAIR_STYLE_INIT(&tag, h);
715: print_otag(h, TAG_COL, 1, &tag);
716: print_otag(h, TAG_COL, 0, NULL);
717: print_otag(h, TAG_TBODY, 0, NULL);
718: print_otag(h, TAG_TR, 0, NULL);
1.1 schwarze 719: return(1);
720: }
721:
722:
723: /* ARGSUSED */
724: static int
725: mdoc_xr_pre(MDOC_ARGS)
726: {
1.56 schwarze 727: struct htmlpair tag[2];
1.9 schwarze 728:
729: if (NULL == n->child)
730: return(0);
1.1 schwarze 731:
732: PAIR_CLASS_INIT(&tag[0], "link-man");
733:
734: if (h->base_man) {
735: buffmt_man(h, n->child->string,
736: n->child->next ?
737: n->child->next->string : NULL);
1.11 schwarze 738: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 739: print_otag(h, TAG_A, 2, tag);
740: } else
741: print_otag(h, TAG_A, 1, tag);
742:
1.56 schwarze 743: n = n->child;
744: print_text(h, n->string);
1.1 schwarze 745:
1.56 schwarze 746: if (NULL == (n = n->next))
1.1 schwarze 747: return(0);
748:
749: h->flags |= HTML_NOSPACE;
750: print_text(h, "(");
751: h->flags |= HTML_NOSPACE;
1.56 schwarze 752: print_text(h, n->string);
1.1 schwarze 753: h->flags |= HTML_NOSPACE;
754: print_text(h, ")");
755: return(0);
756: }
757:
758:
759: /* ARGSUSED */
760: static int
761: mdoc_ns_pre(MDOC_ARGS)
762: {
763:
1.51 schwarze 764: if ( ! (MDOC_LINE & n->flags))
765: h->flags |= HTML_NOSPACE;
1.1 schwarze 766: return(1);
767: }
768:
769:
770: /* ARGSUSED */
771: static int
772: mdoc_ar_pre(MDOC_ARGS)
773: {
774: struct htmlpair tag;
775:
776: PAIR_CLASS_INIT(&tag, "arg");
1.42 schwarze 777: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 778: return(1);
779: }
780:
781:
782: /* ARGSUSED */
783: static int
784: mdoc_xx_pre(MDOC_ARGS)
785: {
786: const char *pp;
787: struct htmlpair tag;
1.52 schwarze 788: int flags;
1.1 schwarze 789:
790: switch (n->tok) {
791: case (MDOC_Bsx):
1.37 schwarze 792: pp = "BSD/OS";
1.1 schwarze 793: break;
794: case (MDOC_Dx):
1.4 schwarze 795: pp = "DragonFly";
1.1 schwarze 796: break;
797: case (MDOC_Fx):
798: pp = "FreeBSD";
799: break;
800: case (MDOC_Nx):
801: pp = "NetBSD";
802: break;
803: case (MDOC_Ox):
804: pp = "OpenBSD";
805: break;
806: case (MDOC_Ux):
807: pp = "UNIX";
808: break;
809: default:
810: return(1);
811: }
812:
813: PAIR_CLASS_INIT(&tag, "unix");
814: print_otag(h, TAG_SPAN, 1, &tag);
1.52 schwarze 815:
1.1 schwarze 816: print_text(h, pp);
1.52 schwarze 817: if (n->child) {
818: flags = h->flags;
819: h->flags |= HTML_KEEP;
820: print_text(h, n->child->string);
821: h->flags = flags;
822: }
823: return(0);
1.1 schwarze 824: }
825:
826:
827: /* ARGSUSED */
828: static int
829: mdoc_bx_pre(MDOC_ARGS)
830: {
1.49 schwarze 831: struct htmlpair tag;
1.1 schwarze 832:
833: PAIR_CLASS_INIT(&tag, "unix");
834: print_otag(h, TAG_SPAN, 1, &tag);
835:
1.49 schwarze 836: if (NULL != (n = n->child)) {
837: print_text(h, n->string);
838: h->flags |= HTML_NOSPACE;
839: print_text(h, "BSD");
840: } else {
841: print_text(h, "BSD");
842: return(0);
843: }
1.1 schwarze 844:
1.49 schwarze 845: if (NULL != (n = n->next)) {
846: h->flags |= HTML_NOSPACE;
847: print_text(h, "-");
1.1 schwarze 848: h->flags |= HTML_NOSPACE;
1.49 schwarze 849: print_text(h, n->string);
850: }
1.1 schwarze 851:
852: return(0);
853: }
854:
1.46 schwarze 855: /* ARGSUSED */
1.1 schwarze 856: static int
1.40 schwarze 857: mdoc_it_pre(MDOC_ARGS)
1.1 schwarze 858: {
1.40 schwarze 859: struct roffsu su;
860: enum mdoc_list type;
861: struct htmlpair tag[2];
862: const struct mdoc_node *bl;
1.1 schwarze 863:
1.40 schwarze 864: bl = n->parent;
865: while (bl && MDOC_Bl != bl->tok)
866: bl = bl->parent;
1.1 schwarze 867:
1.40 schwarze 868: assert(bl);
1.1 schwarze 869:
1.44 schwarze 870: type = bl->norm->Bl.type;
1.1 schwarze 871:
1.40 schwarze 872: assert(lists[type]);
873: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 schwarze 874:
1.57 schwarze 875: bufinit(h);
876:
1.40 schwarze 877: if (MDOC_HEAD == n->type) {
878: switch (type) {
879: case(LIST_bullet):
880: /* FALLTHROUGH */
881: case(LIST_dash):
882: /* FALLTHROUGH */
883: case(LIST_item):
884: /* FALLTHROUGH */
885: case(LIST_hyphen):
886: /* FALLTHROUGH */
887: case(LIST_enum):
888: return(0);
889: case(LIST_diag):
890: /* FALLTHROUGH */
891: case(LIST_hang):
892: /* FALLTHROUGH */
893: case(LIST_inset):
894: /* FALLTHROUGH */
895: case(LIST_ohang):
896: /* FALLTHROUGH */
897: case(LIST_tag):
1.44 schwarze 898: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 899: bufcat_su(h, "margin-top", &su);
900: PAIR_STYLE_INIT(&tag[1], h);
901: print_otag(h, TAG_DT, 2, tag);
1.42 schwarze 902: if (LIST_diag != type)
903: break;
904: PAIR_CLASS_INIT(&tag[0], "diag");
905: print_otag(h, TAG_B, 1, tag);
1.40 schwarze 906: break;
907: case(LIST_column):
908: break;
909: default:
910: break;
911: }
912: } else if (MDOC_BODY == n->type) {
913: switch (type) {
914: case(LIST_bullet):
915: /* FALLTHROUGH */
916: case(LIST_hyphen):
917: /* FALLTHROUGH */
918: case(LIST_dash):
919: /* FALLTHROUGH */
920: case(LIST_enum):
921: /* FALLTHROUGH */
922: case(LIST_item):
1.44 schwarze 923: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 924: bufcat_su(h, "margin-top", &su);
925: PAIR_STYLE_INIT(&tag[1], h);
926: print_otag(h, TAG_LI, 2, tag);
927: break;
928: case(LIST_diag):
929: /* FALLTHROUGH */
930: case(LIST_hang):
931: /* FALLTHROUGH */
932: case(LIST_inset):
933: /* FALLTHROUGH */
934: case(LIST_ohang):
935: /* FALLTHROUGH */
936: case(LIST_tag):
1.44 schwarze 937: if (NULL == bl->norm->Bl.width) {
1.40 schwarze 938: print_otag(h, TAG_DD, 1, tag);
939: break;
940: }
1.44 schwarze 941: a2width(bl->norm->Bl.width, &su);
1.40 schwarze 942: bufcat_su(h, "margin-left", &su);
943: PAIR_STYLE_INIT(&tag[1], h);
944: print_otag(h, TAG_DD, 2, tag);
945: break;
946: case(LIST_column):
1.44 schwarze 947: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 948: bufcat_su(h, "margin-top", &su);
949: PAIR_STYLE_INIT(&tag[1], h);
950: print_otag(h, TAG_TD, 2, tag);
951: break;
952: default:
953: break;
954: }
955: } else {
956: switch (type) {
957: case (LIST_column):
958: print_otag(h, TAG_TR, 1, tag);
959: break;
960: default:
1.1 schwarze 961: break;
1.40 schwarze 962: }
1.1 schwarze 963: }
964:
965: return(1);
966: }
967:
968: /* ARGSUSED */
969: static int
1.40 schwarze 970: mdoc_bl_pre(MDOC_ARGS)
1.1 schwarze 971: {
1.46 schwarze 972: int i;
1.40 schwarze 973: struct htmlpair tag[3];
1.1 schwarze 974: struct roffsu su;
1.42 schwarze 975: char buf[BUFSIZ];
1.1 schwarze 976:
1.40 schwarze 977: if (MDOC_BODY == n->type) {
1.44 schwarze 978: if (LIST_column == n->norm->Bl.type)
1.40 schwarze 979: print_otag(h, TAG_TBODY, 0, NULL);
980: return(1);
1.1 schwarze 981: }
982:
1.40 schwarze 983: if (MDOC_HEAD == n->type) {
1.44 schwarze 984: if (LIST_column != n->norm->Bl.type)
1.40 schwarze 985: return(0);
1.1 schwarze 986:
1.40 schwarze 987: /*
988: * For each column, print out the <COL> tag with our
989: * suggested width. The last column gets min-width, as
990: * in terminal mode it auto-sizes to the width of the
991: * screen and we want to preserve that behaviour.
992: */
1.1 schwarze 993:
1.46 schwarze 994: for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
1.66 matthew 995: bufinit(h);
1.44 schwarze 996: a2width(n->norm->Bl.cols[i], &su);
1.46 schwarze 997: if (i < (int)n->norm->Bl.ncols - 1)
1.40 schwarze 998: bufcat_su(h, "width", &su);
999: else
1000: bufcat_su(h, "min-width", &su);
1001: PAIR_STYLE_INIT(&tag[0], h);
1002: print_otag(h, TAG_COL, 1, tag);
1003: }
1.1 schwarze 1004:
1.4 schwarze 1005: return(0);
1.1 schwarze 1006: }
1007:
1.40 schwarze 1008: SCALE_VS_INIT(&su, 0);
1.66 matthew 1009: bufinit(h);
1.40 schwarze 1010: bufcat_su(h, "margin-top", &su);
1011: bufcat_su(h, "margin-bottom", &su);
1012: PAIR_STYLE_INIT(&tag[0], h);
1.1 schwarze 1013:
1.44 schwarze 1014: assert(lists[n->norm->Bl.type]);
1.42 schwarze 1015: strlcpy(buf, "list ", BUFSIZ);
1.44 schwarze 1016: strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.42 schwarze 1017: PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1.1 schwarze 1018:
1.40 schwarze 1019: /* Set the block's left-hand margin. */
1.1 schwarze 1020:
1.44 schwarze 1021: if (n->norm->Bl.offs) {
1022: a2offs(n->norm->Bl.offs, &su);
1.40 schwarze 1023: bufcat_su(h, "margin-left", &su);
1024: }
1.1 schwarze 1025:
1.44 schwarze 1026: switch (n->norm->Bl.type) {
1.40 schwarze 1027: case(LIST_bullet):
1.1 schwarze 1028: /* FALLTHROUGH */
1.40 schwarze 1029: case(LIST_dash):
1.1 schwarze 1030: /* FALLTHROUGH */
1.40 schwarze 1031: case(LIST_hyphen):
1.1 schwarze 1032: /* FALLTHROUGH */
1.40 schwarze 1033: case(LIST_item):
1.42 schwarze 1034: print_otag(h, TAG_UL, 2, tag);
1.1 schwarze 1035: break;
1.40 schwarze 1036: case(LIST_enum):
1.42 schwarze 1037: print_otag(h, TAG_OL, 2, tag);
1.1 schwarze 1038: break;
1.40 schwarze 1039: case(LIST_diag):
1040: /* FALLTHROUGH */
1041: case(LIST_hang):
1.4 schwarze 1042: /* FALLTHROUGH */
1.40 schwarze 1043: case(LIST_inset):
1.1 schwarze 1044: /* FALLTHROUGH */
1.40 schwarze 1045: case(LIST_ohang):
1.1 schwarze 1046: /* FALLTHROUGH */
1.40 schwarze 1047: case(LIST_tag):
1.42 schwarze 1048: print_otag(h, TAG_DL, 2, tag);
1.40 schwarze 1049: break;
1050: case(LIST_column):
1.42 schwarze 1051: print_otag(h, TAG_TABLE, 2, tag);
1.1 schwarze 1052: break;
1053: default:
1.40 schwarze 1054: abort();
1055: /* NOTREACHED */
1.1 schwarze 1056: }
1057:
1058: return(1);
1059: }
1060:
1061: /* ARGSUSED */
1062: static int
1063: mdoc_ex_pre(MDOC_ARGS)
1064: {
1.56 schwarze 1065: struct tag *t;
1066: struct htmlpair tag;
1067: int nchild;
1.1 schwarze 1068:
1.40 schwarze 1069: if (n->prev)
1070: print_otag(h, TAG_BR, 0, NULL);
1071:
1.1 schwarze 1072: PAIR_CLASS_INIT(&tag, "utility");
1073:
1074: print_text(h, "The");
1.56 schwarze 1075:
1076: nchild = n->nchild;
1077: for (n = n->child; n; n = n->next) {
1078: assert(MDOC_TEXT == n->type);
1079:
1.42 schwarze 1080: t = print_otag(h, TAG_B, 1, &tag);
1.56 schwarze 1081: print_text(h, n->string);
1.1 schwarze 1082: print_tagq(h, t);
1083:
1.56 schwarze 1084: if (nchild > 2 && n->next) {
1085: h->flags |= HTML_NOSPACE;
1086: print_text(h, ",");
1087: }
1.1 schwarze 1088:
1.56 schwarze 1089: if (n->next && NULL == n->next->next)
1090: print_text(h, "and");
1.1 schwarze 1091: }
1092:
1.56 schwarze 1093: if (nchild > 1)
1.1 schwarze 1094: print_text(h, "utilities exit");
1095: else
1096: print_text(h, "utility exits");
1097:
1098: print_text(h, "0 on success, and >0 if an error occurs.");
1099: return(0);
1100: }
1101:
1102:
1103: /* ARGSUSED */
1104: static int
1105: mdoc_em_pre(MDOC_ARGS)
1106: {
1107: struct htmlpair tag;
1108:
1109: PAIR_CLASS_INIT(&tag, "emph");
1110: print_otag(h, TAG_SPAN, 1, &tag);
1111: return(1);
1112: }
1113:
1114:
1115: /* ARGSUSED */
1116: static int
1117: mdoc_d1_pre(MDOC_ARGS)
1118: {
1119: struct htmlpair tag[2];
1120: struct roffsu su;
1121:
1122: if (MDOC_BLOCK != n->type)
1123: return(1);
1124:
1.40 schwarze 1125: SCALE_VS_INIT(&su, 0);
1.57 schwarze 1126: bufinit(h);
1.40 schwarze 1127: bufcat_su(h, "margin-top", &su);
1128: bufcat_su(h, "margin-bottom", &su);
1129: PAIR_STYLE_INIT(&tag[0], h);
1130: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1131:
1132: /* BLOCKQUOTE needs a block body. */
1.1 schwarze 1133:
1.43 schwarze 1134: PAIR_CLASS_INIT(&tag[0], "display");
1135: print_otag(h, TAG_DIV, 1, tag);
1136:
1137: if (MDOC_Dl == n->tok) {
1138: PAIR_CLASS_INIT(&tag[0], "lit");
1139: print_otag(h, TAG_CODE, 1, tag);
1140: }
1.40 schwarze 1141:
1.1 schwarze 1142: return(1);
1143: }
1144:
1145:
1146: /* ARGSUSED */
1147: static int
1148: mdoc_sx_pre(MDOC_ARGS)
1149: {
1.56 schwarze 1150: struct htmlpair tag[2];
1.1 schwarze 1151:
1.57 schwarze 1152: bufinit(h);
1153: bufcat(h, "#x");
1.61 schwarze 1154:
1155: for (n = n->child; n; ) {
1.57 schwarze 1156: bufcat_id(h, n->string);
1.61 schwarze 1157: if (NULL != (n = n->next))
1.57 schwarze 1158: bufcat_id(h, " ");
1.1 schwarze 1159: }
1160:
1161: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 schwarze 1162: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1163:
1.42 schwarze 1164: print_otag(h, TAG_I, 1, tag);
1.1 schwarze 1165: print_otag(h, TAG_A, 2, tag);
1166: return(1);
1167: }
1168:
1169:
1170: /* ARGSUSED */
1171: static int
1172: mdoc_bd_pre(MDOC_ARGS)
1173: {
1174: struct htmlpair tag[2];
1.50 schwarze 1175: int comp, sv;
1.22 schwarze 1176: const struct mdoc_node *nn;
1.1 schwarze 1177: struct roffsu su;
1178:
1.22 schwarze 1179: if (MDOC_HEAD == n->type)
1.1 schwarze 1180: return(0);
1181:
1182: if (MDOC_BLOCK == n->type) {
1.44 schwarze 1183: comp = n->norm->Bd.comp;
1.1 schwarze 1184: for (nn = n; nn && ! comp; nn = nn->parent) {
1185: if (MDOC_BLOCK != nn->type)
1186: continue;
1187: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1188: comp = 1;
1189: if (nn->prev)
1190: break;
1191: }
1.40 schwarze 1192: if ( ! comp)
1193: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1194: return(1);
1195: }
1196:
1.40 schwarze 1197: SCALE_HS_INIT(&su, 0);
1.44 schwarze 1198: if (n->norm->Bd.offs)
1199: a2offs(n->norm->Bd.offs, &su);
1.57 schwarze 1200:
1201: bufinit(h);
1.40 schwarze 1202: bufcat_su(h, "margin-left", &su);
1203: PAIR_STYLE_INIT(&tag[0], h);
1204:
1.44 schwarze 1205: if (DISP_unfilled != n->norm->Bd.type &&
1206: DISP_literal != n->norm->Bd.type) {
1.40 schwarze 1207: PAIR_CLASS_INIT(&tag[1], "display");
1208: print_otag(h, TAG_DIV, 2, tag);
1.1 schwarze 1209: return(1);
1.40 schwarze 1210: }
1.1 schwarze 1211:
1.40 schwarze 1212: PAIR_CLASS_INIT(&tag[1], "lit display");
1213: print_otag(h, TAG_PRE, 2, tag);
1.1 schwarze 1214:
1.50 schwarze 1215: /* This can be recursive: save & set our literal state. */
1216:
1217: sv = h->flags & HTML_LITERAL;
1218: h->flags |= HTML_LITERAL;
1219:
1.1 schwarze 1220: for (nn = n->child; nn; nn = nn->next) {
1.67 schwarze 1221: print_mdoc_node(meta, nn, h);
1.33 schwarze 1222: /*
1223: * If the printed node flushes its own line, then we
1224: * needn't do it here as well. This is hacky, but the
1225: * notion of selective eoln whitespace is pretty dumb
1226: * anyway, so don't sweat it.
1227: */
1228: switch (nn->tok) {
1.36 schwarze 1229: case (MDOC_Sm):
1230: /* FALLTHROUGH */
1.33 schwarze 1231: case (MDOC_br):
1232: /* FALLTHROUGH */
1233: case (MDOC_sp):
1234: /* FALLTHROUGH */
1235: case (MDOC_Bl):
1.39 schwarze 1236: /* FALLTHROUGH */
1237: case (MDOC_D1):
1238: /* FALLTHROUGH */
1239: case (MDOC_Dl):
1.33 schwarze 1240: /* FALLTHROUGH */
1241: case (MDOC_Lp):
1242: /* FALLTHROUGH */
1243: case (MDOC_Pp):
1244: continue;
1245: default:
1246: break;
1247: }
1.28 schwarze 1248: if (nn->next && nn->next->line == nn->line)
1249: continue;
1.40 schwarze 1250: else if (nn->next)
1251: print_text(h, "\n");
1252:
1.28 schwarze 1253: h->flags |= HTML_NOSPACE;
1.1 schwarze 1254: }
1.50 schwarze 1255:
1256: if (0 == sv)
1257: h->flags &= ~HTML_LITERAL;
1.1 schwarze 1258:
1259: return(0);
1260: }
1261:
1262:
1263: /* ARGSUSED */
1264: static int
1265: mdoc_pa_pre(MDOC_ARGS)
1266: {
1267: struct htmlpair tag;
1268:
1269: PAIR_CLASS_INIT(&tag, "file");
1.42 schwarze 1270: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1271: return(1);
1272: }
1273:
1274:
1275: /* ARGSUSED */
1276: static int
1277: mdoc_ad_pre(MDOC_ARGS)
1278: {
1279: struct htmlpair tag;
1280:
1281: PAIR_CLASS_INIT(&tag, "addr");
1.42 schwarze 1282: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1283: return(1);
1284: }
1285:
1286:
1287: /* ARGSUSED */
1288: static int
1289: mdoc_an_pre(MDOC_ARGS)
1290: {
1291: struct htmlpair tag;
1292:
1293: /* TODO: -split and -nosplit (see termp_an_pre()). */
1294:
1295: PAIR_CLASS_INIT(&tag, "author");
1296: print_otag(h, TAG_SPAN, 1, &tag);
1297: return(1);
1298: }
1299:
1300:
1301: /* ARGSUSED */
1302: static int
1303: mdoc_cd_pre(MDOC_ARGS)
1304: {
1305: struct htmlpair tag;
1306:
1.21 schwarze 1307: synopsis_pre(h, n);
1.1 schwarze 1308: PAIR_CLASS_INIT(&tag, "config");
1.42 schwarze 1309: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1310: return(1);
1311: }
1312:
1313:
1314: /* ARGSUSED */
1315: static int
1316: mdoc_dv_pre(MDOC_ARGS)
1317: {
1318: struct htmlpair tag;
1319:
1320: PAIR_CLASS_INIT(&tag, "define");
1321: print_otag(h, TAG_SPAN, 1, &tag);
1322: return(1);
1323: }
1324:
1325:
1326: /* ARGSUSED */
1327: static int
1328: mdoc_ev_pre(MDOC_ARGS)
1329: {
1330: struct htmlpair tag;
1331:
1332: PAIR_CLASS_INIT(&tag, "env");
1333: print_otag(h, TAG_SPAN, 1, &tag);
1334: return(1);
1335: }
1336:
1337:
1338: /* ARGSUSED */
1339: static int
1340: mdoc_er_pre(MDOC_ARGS)
1341: {
1342: struct htmlpair tag;
1343:
1344: PAIR_CLASS_INIT(&tag, "errno");
1345: print_otag(h, TAG_SPAN, 1, &tag);
1346: return(1);
1347: }
1348:
1349:
1350: /* ARGSUSED */
1351: static int
1352: mdoc_fa_pre(MDOC_ARGS)
1353: {
1354: const struct mdoc_node *nn;
1355: struct htmlpair tag;
1356: struct tag *t;
1357:
1358: PAIR_CLASS_INIT(&tag, "farg");
1359: if (n->parent->tok != MDOC_Fo) {
1.42 schwarze 1360: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1361: return(1);
1362: }
1363:
1364: for (nn = n->child; nn; nn = nn->next) {
1.42 schwarze 1365: t = print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1366: print_text(h, nn->string);
1367: print_tagq(h, t);
1.56 schwarze 1368: if (nn->next) {
1369: h->flags |= HTML_NOSPACE;
1.1 schwarze 1370: print_text(h, ",");
1.56 schwarze 1371: }
1.1 schwarze 1372: }
1373:
1.56 schwarze 1374: if (n->child && n->next && n->next->tok == MDOC_Fa) {
1375: h->flags |= HTML_NOSPACE;
1.1 schwarze 1376: print_text(h, ",");
1.56 schwarze 1377: }
1.1 schwarze 1378:
1379: return(0);
1380: }
1381:
1382:
1383: /* ARGSUSED */
1384: static int
1385: mdoc_fd_pre(MDOC_ARGS)
1386: {
1.56 schwarze 1387: struct htmlpair tag[2];
1388: char buf[BUFSIZ];
1389: size_t sz;
1390: int i;
1391: struct tag *t;
1.1 schwarze 1392:
1.21 schwarze 1393: synopsis_pre(h, n);
1394:
1.56 schwarze 1395: if (NULL == (n = n->child))
1396: return(0);
1397:
1398: assert(MDOC_TEXT == n->type);
1399:
1400: if (strcmp(n->string, "#include")) {
1401: PAIR_CLASS_INIT(&tag[0], "macro");
1402: print_otag(h, TAG_B, 1, tag);
1403: return(1);
1404: }
1405:
1406: PAIR_CLASS_INIT(&tag[0], "includes");
1407: print_otag(h, TAG_B, 1, tag);
1408: print_text(h, n->string);
1409:
1410: if (NULL != (n = n->next)) {
1411: assert(MDOC_TEXT == n->type);
1412: strlcpy(buf, '<' == *n->string || '"' == *n->string ?
1413: n->string + 1 : n->string, BUFSIZ);
1414:
1415: sz = strlen(buf);
1416: if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1]))
1417: buf[sz - 1] = '\0';
1418:
1419: PAIR_CLASS_INIT(&tag[0], "link-includes");
1420:
1421: i = 1;
1422: if (h->base_includes) {
1423: buffmt_includes(h, buf);
1424: PAIR_HREF_INIT(&tag[i], h->buf);
1425: i++;
1426: }
1427:
1428: t = print_otag(h, TAG_A, i, tag);
1429: print_text(h, n->string);
1430: print_tagq(h, t);
1431:
1432: n = n->next;
1433: }
1434:
1435: for ( ; n; n = n->next) {
1436: assert(MDOC_TEXT == n->type);
1437: print_text(h, n->string);
1438: }
1439:
1440: return(0);
1.1 schwarze 1441: }
1442:
1443:
1444: /* ARGSUSED */
1445: static int
1446: mdoc_vt_pre(MDOC_ARGS)
1447: {
1448: struct htmlpair tag;
1449:
1.21 schwarze 1450: if (MDOC_BLOCK == n->type) {
1451: synopsis_pre(h, n);
1.7 schwarze 1452: return(1);
1.21 schwarze 1453: } else if (MDOC_ELEM == n->type) {
1454: synopsis_pre(h, n);
1.7 schwarze 1455: } else if (MDOC_HEAD == n->type)
1456: return(0);
1.1 schwarze 1457:
1458: PAIR_CLASS_INIT(&tag, "type");
1459: print_otag(h, TAG_SPAN, 1, &tag);
1460: return(1);
1461: }
1462:
1463:
1464: /* ARGSUSED */
1465: static int
1466: mdoc_ft_pre(MDOC_ARGS)
1467: {
1468: struct htmlpair tag;
1469:
1.21 schwarze 1470: synopsis_pre(h, n);
1.1 schwarze 1471: PAIR_CLASS_INIT(&tag, "ftype");
1.42 schwarze 1472: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1473: return(1);
1474: }
1475:
1476:
1477: /* ARGSUSED */
1478: static int
1479: mdoc_fn_pre(MDOC_ARGS)
1480: {
1.56 schwarze 1481: struct tag *t;
1482: struct htmlpair tag[2];
1483: char nbuf[BUFSIZ];
1484: const char *sp, *ep;
1485: int sz, i, pretty;
1.1 schwarze 1486:
1.56 schwarze 1487: pretty = MDOC_SYNPRETTY & n->flags;
1.21 schwarze 1488: synopsis_pre(h, n);
1.1 schwarze 1489:
1490: /* Split apart into type and name. */
1491: assert(n->child->string);
1492: sp = n->child->string;
1493:
1494: ep = strchr(sp, ' ');
1495: if (NULL != ep) {
1496: PAIR_CLASS_INIT(&tag[0], "ftype");
1.42 schwarze 1497: t = print_otag(h, TAG_I, 1, tag);
1.1 schwarze 1498:
1499: while (ep) {
1500: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1501: (void)memcpy(nbuf, sp, (size_t)sz);
1502: nbuf[sz] = '\0';
1503: print_text(h, nbuf);
1504: sp = ++ep;
1505: ep = strchr(sp, ' ');
1506: }
1507: print_tagq(h, t);
1508: }
1509:
1510: PAIR_CLASS_INIT(&tag[0], "fname");
1.11 schwarze 1511:
1512: /*
1513: * FIXME: only refer to IDs that we know exist.
1514: */
1515:
1516: #if 0
1.23 schwarze 1517: if (MDOC_SYNPRETTY & n->flags) {
1.11 schwarze 1518: nbuf[0] = '\0';
1519: html_idcat(nbuf, sp, BUFSIZ);
1520: PAIR_ID_INIT(&tag[1], nbuf);
1521: } else {
1522: strlcpy(nbuf, "#", BUFSIZ);
1523: html_idcat(nbuf, sp, BUFSIZ);
1524: PAIR_HREF_INIT(&tag[1], nbuf);
1525: }
1526: #endif
1527:
1.42 schwarze 1528: t = print_otag(h, TAG_B, 1, tag);
1.1 schwarze 1529:
1530: if (sp) {
1.11 schwarze 1531: strlcpy(nbuf, sp, BUFSIZ);
1.1 schwarze 1532: print_text(h, nbuf);
1533: }
1534:
1535: print_tagq(h, t);
1536:
1537: h->flags |= HTML_NOSPACE;
1538: print_text(h, "(");
1.56 schwarze 1539: h->flags |= HTML_NOSPACE;
1.1 schwarze 1540:
1.57 schwarze 1541: PAIR_CLASS_INIT(&tag[0], "farg");
1.1 schwarze 1542: bufinit(h);
1543: bufcat_style(h, "white-space", "nowrap");
1544: PAIR_STYLE_INIT(&tag[1], h);
1545:
1.56 schwarze 1546: for (n = n->child->next; n; n = n->next) {
1.1 schwarze 1547: i = 1;
1.23 schwarze 1548: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1549: i = 2;
1.42 schwarze 1550: t = print_otag(h, TAG_I, i, tag);
1.56 schwarze 1551: print_text(h, n->string);
1.1 schwarze 1552: print_tagq(h, t);
1.56 schwarze 1553: if (n->next) {
1554: h->flags |= HTML_NOSPACE;
1.1 schwarze 1555: print_text(h, ",");
1.56 schwarze 1556: }
1.1 schwarze 1557: }
1558:
1.56 schwarze 1559: h->flags |= HTML_NOSPACE;
1.1 schwarze 1560: print_text(h, ")");
1.56 schwarze 1561:
1562: if (pretty) {
1563: h->flags |= HTML_NOSPACE;
1.1 schwarze 1564: print_text(h, ";");
1.56 schwarze 1565: }
1.1 schwarze 1566:
1567: return(0);
1568: }
1569:
1570:
1571: /* ARGSUSED */
1572: static int
1.26 schwarze 1573: mdoc_sm_pre(MDOC_ARGS)
1574: {
1575:
1576: assert(n->child && MDOC_TEXT == n->child->type);
1577: if (0 == strcmp("on", n->child->string)) {
1.36 schwarze 1578: /*
1579: * FIXME: no p->col to check. Thus, if we have
1580: * .Bd -literal
1581: * .Sm off
1582: * 1 2
1583: * .Sm on
1584: * 3
1585: * .Ed
1586: * the "3" is preceded by a space.
1587: */
1.26 schwarze 1588: h->flags &= ~HTML_NOSPACE;
1589: h->flags &= ~HTML_NONOSPACE;
1590: } else
1591: h->flags |= HTML_NONOSPACE;
1592:
1593: return(0);
1594: }
1595:
1.40 schwarze 1596: /* ARGSUSED */
1597: static int
1598: mdoc_pp_pre(MDOC_ARGS)
1599: {
1600:
1601: print_otag(h, TAG_P, 0, NULL);
1602: return(0);
1603:
1604: }
1.26 schwarze 1605:
1606: /* ARGSUSED */
1607: static int
1.1 schwarze 1608: mdoc_sp_pre(MDOC_ARGS)
1609: {
1.40 schwarze 1610: struct roffsu su;
1.1 schwarze 1611: struct htmlpair tag;
1612:
1.40 schwarze 1613: SCALE_VS_INIT(&su, 1);
1614:
1615: if (MDOC_sp == n->tok) {
1.59 schwarze 1616: if (NULL != (n = n->child))
1617: if ( ! a2roffsu(n->string, &su, SCALE_VS))
1618: SCALE_VS_INIT(&su, atoi(n->string));
1.40 schwarze 1619: } else
1620: su.scale = 0;
1.1 schwarze 1621:
1.57 schwarze 1622: bufinit(h);
1.1 schwarze 1623: bufcat_su(h, "height", &su);
1624: PAIR_STYLE_INIT(&tag, h);
1625: print_otag(h, TAG_DIV, 1, &tag);
1.40 schwarze 1626:
1.3 schwarze 1627: /* So the div isn't empty: */
1628: print_text(h, "\\~");
1629:
1630: return(0);
1.1 schwarze 1631:
1632: }
1633:
1634: /* ARGSUSED */
1635: static int
1636: mdoc_lk_pre(MDOC_ARGS)
1637: {
1.56 schwarze 1638: struct htmlpair tag[2];
1639:
1640: if (NULL == (n = n->child))
1641: return(0);
1.1 schwarze 1642:
1.56 schwarze 1643: assert(MDOC_TEXT == n->type);
1.1 schwarze 1644:
1645: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.56 schwarze 1646: PAIR_HREF_INIT(&tag[1], n->string);
1647:
1.1 schwarze 1648: print_otag(h, TAG_A, 2, tag);
1649:
1.58 schwarze 1650: if (NULL == n->next)
1651: print_text(h, n->string);
1652:
1653: for (n = n->next; n; n = n->next)
1.56 schwarze 1654: print_text(h, n->string);
1.1 schwarze 1655:
1656: return(0);
1657: }
1658:
1659:
1660: /* ARGSUSED */
1661: static int
1662: mdoc_mt_pre(MDOC_ARGS)
1663: {
1.56 schwarze 1664: struct htmlpair tag[2];
1665: struct tag *t;
1.1 schwarze 1666:
1667: PAIR_CLASS_INIT(&tag[0], "link-mail");
1668:
1.56 schwarze 1669: for (n = n->child; n; n = n->next) {
1670: assert(MDOC_TEXT == n->type);
1671:
1.1 schwarze 1672: bufinit(h);
1673: bufcat(h, "mailto:");
1.56 schwarze 1674: bufcat(h, n->string);
1675:
1.10 schwarze 1676: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1677: t = print_otag(h, TAG_A, 2, tag);
1.56 schwarze 1678: print_text(h, n->string);
1.1 schwarze 1679: print_tagq(h, t);
1680: }
1681:
1682: return(0);
1683: }
1684:
1685:
1686: /* ARGSUSED */
1687: static int
1688: mdoc_fo_pre(MDOC_ARGS)
1689: {
1.20 schwarze 1690: struct htmlpair tag;
1691: struct tag *t;
1.1 schwarze 1692:
1693: if (MDOC_BODY == n->type) {
1694: h->flags |= HTML_NOSPACE;
1695: print_text(h, "(");
1696: h->flags |= HTML_NOSPACE;
1697: return(1);
1.20 schwarze 1698: } else if (MDOC_BLOCK == n->type) {
1.21 schwarze 1699: synopsis_pre(h, n);
1.1 schwarze 1700: return(1);
1.11 schwarze 1701: }
1.1 schwarze 1702:
1.20 schwarze 1703: /* XXX: we drop non-initial arguments as per groff. */
1704:
1705: assert(n->child);
1706: assert(n->child->string);
1707:
1.1 schwarze 1708: PAIR_CLASS_INIT(&tag, "fname");
1.43 schwarze 1709: t = print_otag(h, TAG_B, 1, &tag);
1.20 schwarze 1710: print_text(h, n->child->string);
1711: print_tagq(h, t);
1712: return(0);
1.1 schwarze 1713: }
1714:
1715:
1716: /* ARGSUSED */
1717: static void
1718: mdoc_fo_post(MDOC_ARGS)
1719: {
1.21 schwarze 1720:
1.1 schwarze 1721: if (MDOC_BODY != n->type)
1722: return;
1.56 schwarze 1723: h->flags |= HTML_NOSPACE;
1.1 schwarze 1724: print_text(h, ")");
1.56 schwarze 1725: h->flags |= HTML_NOSPACE;
1.1 schwarze 1726: print_text(h, ";");
1727: }
1728:
1729:
1730: /* ARGSUSED */
1731: static int
1732: mdoc_in_pre(MDOC_ARGS)
1733: {
1.56 schwarze 1734: struct tag *t;
1735: struct htmlpair tag[2];
1736: int i;
1.1 schwarze 1737:
1.21 schwarze 1738: synopsis_pre(h, n);
1739:
1.1 schwarze 1740: PAIR_CLASS_INIT(&tag[0], "includes");
1.42 schwarze 1741: print_otag(h, TAG_B, 1, tag);
1.1 schwarze 1742:
1.56 schwarze 1743: /*
1744: * The first argument of the `In' gets special treatment as
1745: * being a linked value. Subsequent values are printed
1746: * afterward. groff does similarly. This also handles the case
1747: * of no children.
1748: */
1749:
1.23 schwarze 1750: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.1 schwarze 1751: print_text(h, "#include");
1752:
1753: print_text(h, "<");
1754: h->flags |= HTML_NOSPACE;
1755:
1.56 schwarze 1756: if (NULL != (n = n->child)) {
1757: assert(MDOC_TEXT == n->type);
1758:
1.1 schwarze 1759: PAIR_CLASS_INIT(&tag[0], "link-includes");
1.56 schwarze 1760:
1.1 schwarze 1761: i = 1;
1762: if (h->base_includes) {
1.56 schwarze 1763: buffmt_includes(h, n->string);
1.11 schwarze 1764: PAIR_HREF_INIT(&tag[i], h->buf);
1765: i++;
1.56 schwarze 1766: }
1767:
1.1 schwarze 1768: t = print_otag(h, TAG_A, i, tag);
1.56 schwarze 1769: print_text(h, n->string);
1.1 schwarze 1770: print_tagq(h, t);
1.56 schwarze 1771:
1772: n = n->next;
1.1 schwarze 1773: }
1774:
1775: h->flags |= HTML_NOSPACE;
1776: print_text(h, ">");
1.20 schwarze 1777:
1.56 schwarze 1778: for ( ; n; n = n->next) {
1779: assert(MDOC_TEXT == n->type);
1780: print_text(h, n->string);
1781: }
1782:
1.1 schwarze 1783: return(0);
1784: }
1785:
1786:
1787: /* ARGSUSED */
1788: static int
1789: mdoc_ic_pre(MDOC_ARGS)
1790: {
1791: struct htmlpair tag;
1792:
1793: PAIR_CLASS_INIT(&tag, "cmd");
1.42 schwarze 1794: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1795: return(1);
1796: }
1797:
1798:
1799: /* ARGSUSED */
1800: static int
1801: mdoc_rv_pre(MDOC_ARGS)
1802: {
1.56 schwarze 1803: struct htmlpair tag;
1804: struct tag *t;
1805: int nchild;
1.1 schwarze 1806:
1.40 schwarze 1807: if (n->prev)
1808: print_otag(h, TAG_BR, 0, NULL);
1809:
1.56 schwarze 1810: PAIR_CLASS_INIT(&tag, "fname");
1811:
1.1 schwarze 1812: print_text(h, "The");
1813:
1.56 schwarze 1814: nchild = n->nchild;
1815: for (n = n->child; n; n = n->next) {
1816: assert(MDOC_TEXT == n->type);
1817:
1.43 schwarze 1818: t = print_otag(h, TAG_B, 1, &tag);
1.56 schwarze 1819: print_text(h, n->string);
1.1 schwarze 1820: print_tagq(h, t);
1821:
1822: h->flags |= HTML_NOSPACE;
1.56 schwarze 1823: print_text(h, "()");
1824:
1825: if (nchild > 2 && n->next) {
1826: h->flags |= HTML_NOSPACE;
1827: print_text(h, ",");
1828: }
1829:
1830: if (n->next && NULL == n->next->next)
1831: print_text(h, "and");
1.1 schwarze 1832: }
1833:
1.56 schwarze 1834: if (nchild > 1)
1.1 schwarze 1835: print_text(h, "functions return");
1836: else
1837: print_text(h, "function returns");
1838:
1839: print_text(h, "the value 0 if successful; otherwise the value "
1840: "-1 is returned and the global variable");
1841:
1842: PAIR_CLASS_INIT(&tag, "var");
1.42 schwarze 1843: t = print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1844: print_text(h, "errno");
1845: print_tagq(h, t);
1846: print_text(h, "is set to indicate the error.");
1847: return(0);
1848: }
1849:
1850:
1851: /* ARGSUSED */
1852: static int
1853: mdoc_va_pre(MDOC_ARGS)
1854: {
1855: struct htmlpair tag;
1856:
1857: PAIR_CLASS_INIT(&tag, "var");
1.42 schwarze 1858: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1859: return(1);
1860: }
1861:
1862:
1863: /* ARGSUSED */
1864: static int
1865: mdoc_ap_pre(MDOC_ARGS)
1866: {
1867:
1868: h->flags |= HTML_NOSPACE;
1869: print_text(h, "\\(aq");
1870: h->flags |= HTML_NOSPACE;
1871: return(1);
1872: }
1873:
1874:
1875: /* ARGSUSED */
1876: static int
1877: mdoc_bf_pre(MDOC_ARGS)
1878: {
1879: struct htmlpair tag[2];
1880: struct roffsu su;
1881:
1882: if (MDOC_HEAD == n->type)
1883: return(0);
1.25 schwarze 1884: else if (MDOC_BODY != n->type)
1.1 schwarze 1885: return(1);
1886:
1.44 schwarze 1887: if (FONT_Em == n->norm->Bf.font)
1.25 schwarze 1888: PAIR_CLASS_INIT(&tag[0], "emph");
1.44 schwarze 1889: else if (FONT_Sy == n->norm->Bf.font)
1.25 schwarze 1890: PAIR_CLASS_INIT(&tag[0], "symb");
1.44 schwarze 1891: else if (FONT_Li == n->norm->Bf.font)
1.25 schwarze 1892: PAIR_CLASS_INIT(&tag[0], "lit");
1893: else
1894: PAIR_CLASS_INIT(&tag[0], "none");
1.1 schwarze 1895:
1.25 schwarze 1896: /*
1897: * We want this to be inline-formatted, but needs to be div to
1898: * accept block children.
1899: */
1.57 schwarze 1900: bufinit(h);
1.1 schwarze 1901: bufcat_style(h, "display", "inline");
1902: SCALE_HS_INIT(&su, 1);
1.25 schwarze 1903: /* Needs a left-margin for spacing. */
1904: bufcat_su(h, "margin-left", &su);
1.1 schwarze 1905: PAIR_STYLE_INIT(&tag[1], h);
1906: print_otag(h, TAG_DIV, 2, tag);
1907: return(1);
1908: }
1909:
1910:
1911: /* ARGSUSED */
1912: static int
1913: mdoc_ms_pre(MDOC_ARGS)
1914: {
1915: struct htmlpair tag;
1916:
1917: PAIR_CLASS_INIT(&tag, "symb");
1918: print_otag(h, TAG_SPAN, 1, &tag);
1919: return(1);
1920: }
1921:
1922:
1923: /* ARGSUSED */
1924: static int
1.34 schwarze 1925: mdoc_igndelim_pre(MDOC_ARGS)
1.1 schwarze 1926: {
1927:
1928: h->flags |= HTML_IGNDELIM;
1929: return(1);
1930: }
1931:
1932:
1933: /* ARGSUSED */
1934: static void
1935: mdoc_pf_post(MDOC_ARGS)
1936: {
1937:
1938: h->flags |= HTML_NOSPACE;
1939: }
1940:
1941:
1942: /* ARGSUSED */
1943: static int
1944: mdoc_rs_pre(MDOC_ARGS)
1945: {
1946: struct htmlpair tag;
1947:
1948: if (MDOC_BLOCK != n->type)
1949: return(1);
1950:
1.40 schwarze 1951: if (n->prev && SEC_SEE_ALSO == n->sec)
1952: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1953:
1954: PAIR_CLASS_INIT(&tag, "ref");
1955: print_otag(h, TAG_SPAN, 1, &tag);
1956: return(1);
1957: }
1958:
1959:
1960:
1961: /* ARGSUSED */
1962: static int
1963: mdoc_li_pre(MDOC_ARGS)
1964: {
1965: struct htmlpair tag;
1966:
1967: PAIR_CLASS_INIT(&tag, "lit");
1.61 schwarze 1968: print_otag(h, TAG_CODE, 1, &tag);
1.1 schwarze 1969: return(1);
1970: }
1971:
1972:
1973: /* ARGSUSED */
1974: static int
1975: mdoc_sy_pre(MDOC_ARGS)
1976: {
1977: struct htmlpair tag;
1978:
1979: PAIR_CLASS_INIT(&tag, "symb");
1980: print_otag(h, TAG_SPAN, 1, &tag);
1981: return(1);
1982: }
1983:
1984:
1985: /* ARGSUSED */
1986: static int
1987: mdoc_bt_pre(MDOC_ARGS)
1988: {
1989:
1990: print_text(h, "is currently in beta test.");
1991: return(0);
1992: }
1993:
1994:
1995: /* ARGSUSED */
1996: static int
1997: mdoc_ud_pre(MDOC_ARGS)
1998: {
1999:
2000: print_text(h, "currently under development.");
2001: return(0);
2002: }
2003:
2004:
2005: /* ARGSUSED */
2006: static int
2007: mdoc_lb_pre(MDOC_ARGS)
2008: {
2009: struct htmlpair tag;
2010:
1.40 schwarze 2011: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
2012: print_otag(h, TAG_BR, 0, NULL);
2013:
1.1 schwarze 2014: PAIR_CLASS_INIT(&tag, "lib");
2015: print_otag(h, TAG_SPAN, 1, &tag);
2016: return(1);
2017: }
2018:
2019:
2020: /* ARGSUSED */
2021: static int
2022: mdoc__x_pre(MDOC_ARGS)
2023: {
1.2 schwarze 2024: struct htmlpair tag[2];
1.42 schwarze 2025: enum htmltag t;
2026:
2027: t = TAG_SPAN;
1.1 schwarze 2028:
2029: switch (n->tok) {
2030: case(MDOC__A):
1.2 schwarze 2031: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.30 schwarze 2032: if (n->prev && MDOC__A == n->prev->tok)
2033: if (NULL == n->next || MDOC__A != n->next->tok)
2034: print_text(h, "and");
1.1 schwarze 2035: break;
2036: case(MDOC__B):
1.2 schwarze 2037: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.42 schwarze 2038: t = TAG_I;
1.1 schwarze 2039: break;
2040: case(MDOC__C):
1.2 schwarze 2041: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1 schwarze 2042: break;
2043: case(MDOC__D):
1.2 schwarze 2044: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1 schwarze 2045: break;
2046: case(MDOC__I):
1.2 schwarze 2047: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.42 schwarze 2048: t = TAG_I;
1.1 schwarze 2049: break;
2050: case(MDOC__J):
1.2 schwarze 2051: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.42 schwarze 2052: t = TAG_I;
1.1 schwarze 2053: break;
2054: case(MDOC__N):
1.2 schwarze 2055: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1 schwarze 2056: break;
2057: case(MDOC__O):
1.2 schwarze 2058: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1 schwarze 2059: break;
2060: case(MDOC__P):
1.2 schwarze 2061: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1 schwarze 2062: break;
2063: case(MDOC__Q):
1.2 schwarze 2064: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1 schwarze 2065: break;
2066: case(MDOC__R):
1.2 schwarze 2067: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1 schwarze 2068: break;
2069: case(MDOC__T):
1.2 schwarze 2070: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1 schwarze 2071: break;
1.2 schwarze 2072: case(MDOC__U):
2073: PAIR_CLASS_INIT(&tag[0], "link-ref");
2074: break;
1.1 schwarze 2075: case(MDOC__V):
1.2 schwarze 2076: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1 schwarze 2077: break;
2078: default:
2079: abort();
2080: /* NOTREACHED */
2081: }
2082:
1.2 schwarze 2083: if (MDOC__U != n->tok) {
1.42 schwarze 2084: print_otag(h, t, 1, tag);
1.2 schwarze 2085: return(1);
2086: }
2087:
2088: PAIR_HREF_INIT(&tag[1], n->child->string);
2089: print_otag(h, TAG_A, 2, tag);
1.30 schwarze 2090:
1.1 schwarze 2091: return(1);
2092: }
2093:
2094:
2095: /* ARGSUSED */
2096: static void
2097: mdoc__x_post(MDOC_ARGS)
2098: {
1.30 schwarze 2099:
2100: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2101: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2102: if (NULL == n->prev || MDOC__A != n->prev->tok)
2103: return;
1.1 schwarze 2104:
1.12 schwarze 2105: /* TODO: %U */
2106:
1.31 schwarze 2107: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2108: return;
2109:
1.56 schwarze 2110: h->flags |= HTML_NOSPACE;
1.1 schwarze 2111: print_text(h, n->next ? "," : ".");
1.25 schwarze 2112: }
2113:
2114:
2115: /* ARGSUSED */
2116: static int
2117: mdoc_bk_pre(MDOC_ARGS)
2118: {
2119:
2120: switch (n->type) {
2121: case (MDOC_BLOCK):
2122: break;
2123: case (MDOC_HEAD):
2124: return(0);
2125: case (MDOC_BODY):
1.41 schwarze 2126: if (n->parent->args || 0 == n->prev->nchild)
2127: h->flags |= HTML_PREKEEP;
1.25 schwarze 2128: break;
2129: default:
2130: abort();
2131: /* NOTREACHED */
2132: }
2133:
2134: return(1);
2135: }
2136:
2137:
2138: /* ARGSUSED */
2139: static void
2140: mdoc_bk_post(MDOC_ARGS)
2141: {
2142:
2143: if (MDOC_BODY == n->type)
2144: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.1 schwarze 2145: }
1.32 schwarze 2146:
2147:
2148: /* ARGSUSED */
2149: static int
2150: mdoc_quote_pre(MDOC_ARGS)
2151: {
2152: struct htmlpair tag;
2153:
2154: if (MDOC_BODY != n->type)
2155: return(1);
2156:
2157: switch (n->tok) {
2158: case (MDOC_Ao):
2159: /* FALLTHROUGH */
2160: case (MDOC_Aq):
2161: print_text(h, "\\(la");
2162: break;
2163: case (MDOC_Bro):
2164: /* FALLTHROUGH */
2165: case (MDOC_Brq):
2166: print_text(h, "\\(lC");
2167: break;
2168: case (MDOC_Bo):
2169: /* FALLTHROUGH */
2170: case (MDOC_Bq):
2171: print_text(h, "\\(lB");
2172: break;
2173: case (MDOC_Oo):
2174: /* FALLTHROUGH */
2175: case (MDOC_Op):
2176: print_text(h, "\\(lB");
1.36 schwarze 2177: h->flags |= HTML_NOSPACE;
1.32 schwarze 2178: PAIR_CLASS_INIT(&tag, "opt");
2179: print_otag(h, TAG_SPAN, 1, &tag);
2180: break;
1.65 schwarze 2181: case (MDOC_Eo):
2182: break;
1.32 schwarze 2183: case (MDOC_Do):
2184: /* FALLTHROUGH */
2185: case (MDOC_Dq):
2186: /* FALLTHROUGH */
2187: case (MDOC_Qo):
2188: /* FALLTHROUGH */
2189: case (MDOC_Qq):
2190: print_text(h, "\\(lq");
2191: break;
2192: case (MDOC_Po):
2193: /* FALLTHROUGH */
2194: case (MDOC_Pq):
2195: print_text(h, "(");
2196: break;
2197: case (MDOC_Ql):
1.61 schwarze 2198: print_text(h, "\\(oq");
2199: h->flags |= HTML_NOSPACE;
2200: PAIR_CLASS_INIT(&tag, "lit");
2201: print_otag(h, TAG_CODE, 1, &tag);
2202: break;
1.32 schwarze 2203: case (MDOC_So):
2204: /* FALLTHROUGH */
2205: case (MDOC_Sq):
2206: print_text(h, "\\(oq");
2207: break;
2208: default:
2209: abort();
2210: /* NOTREACHED */
2211: }
2212:
2213: h->flags |= HTML_NOSPACE;
2214: return(1);
2215: }
2216:
2217:
2218: /* ARGSUSED */
2219: static void
2220: mdoc_quote_post(MDOC_ARGS)
2221: {
2222:
2223: if (MDOC_BODY != n->type)
2224: return;
2225:
2226: h->flags |= HTML_NOSPACE;
2227:
2228: switch (n->tok) {
2229: case (MDOC_Ao):
2230: /* FALLTHROUGH */
2231: case (MDOC_Aq):
2232: print_text(h, "\\(ra");
2233: break;
2234: case (MDOC_Bro):
2235: /* FALLTHROUGH */
2236: case (MDOC_Brq):
2237: print_text(h, "\\(rC");
2238: break;
2239: case (MDOC_Oo):
2240: /* FALLTHROUGH */
2241: case (MDOC_Op):
2242: /* FALLTHROUGH */
2243: case (MDOC_Bo):
2244: /* FALLTHROUGH */
2245: case (MDOC_Bq):
2246: print_text(h, "\\(rB");
1.65 schwarze 2247: break;
2248: case (MDOC_Eo):
1.32 schwarze 2249: break;
2250: case (MDOC_Qo):
2251: /* FALLTHROUGH */
2252: case (MDOC_Qq):
2253: /* FALLTHROUGH */
2254: case (MDOC_Do):
2255: /* FALLTHROUGH */
2256: case (MDOC_Dq):
2257: print_text(h, "\\(rq");
2258: break;
2259: case (MDOC_Po):
2260: /* FALLTHROUGH */
2261: case (MDOC_Pq):
2262: print_text(h, ")");
2263: break;
2264: case (MDOC_Ql):
2265: /* FALLTHROUGH */
2266: case (MDOC_So):
2267: /* FALLTHROUGH */
2268: case (MDOC_Sq):
1.66 matthew 2269: print_text(h, "\\(cq");
1.32 schwarze 2270: break;
2271: default:
2272: abort();
2273: /* NOTREACHED */
2274: }
2275: }
2276:
2277: