Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.67
1.67 ! schwarze 1: /* $Id: mdoc_html.c,v 1.66 2012/08/12 06:04:09 matthew 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.25 schwarze 458: if (HTML_KEEP & h->flags) {
459: if (n->prev && n->prev->line != n->line) {
460: h->flags &= ~HTML_KEEP;
461: h->flags |= HTML_PREKEEP;
462: } else if (NULL == n->prev) {
463: if (n->parent && n->parent->line != n->line) {
464: h->flags &= ~HTML_KEEP;
465: h->flags |= HTML_PREKEEP;
466: }
467: }
468: }
469:
1.1 schwarze 470: if (child && n->child)
1.67 ! schwarze 471: print_mdoc_nodelist(meta, n->child, h);
1.1 schwarze 472:
473: print_stagq(h, t);
474:
475: switch (n->type) {
476: case (MDOC_ROOT):
1.67 ! schwarze 477: mdoc_root_post(meta, n, h);
1.55 schwarze 478: break;
479: case (MDOC_EQN):
1.1 schwarze 480: break;
481: default:
1.25 schwarze 482: if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
1.67 ! schwarze 483: (*mdocs[n->tok].post)(meta, n, h);
1.1 schwarze 484: break;
485: }
486: }
487:
488: /* ARGSUSED */
489: static void
490: mdoc_root_post(MDOC_ARGS)
491: {
1.42 schwarze 492: struct htmlpair tag[3];
1.1 schwarze 493: struct tag *t, *tt;
494:
1.42 schwarze 495: PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
496: PAIR_CLASS_INIT(&tag[1], "foot");
1.63 schwarze 497: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
498: t = print_otag(h, TAG_TABLE, 3, tag);
499: PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
500: print_otag(h, TAG_COL, 1, tag);
501: print_otag(h, TAG_COL, 1, tag);
1.42 schwarze 502:
1.64 schwarze 503: print_otag(h, TAG_TBODY, 0, NULL);
1.3 schwarze 504:
1.1 schwarze 505: tt = print_otag(h, TAG_TR, 0, NULL);
506:
1.40 schwarze 507: PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1 schwarze 508: print_otag(h, TAG_TD, 1, tag);
1.67 ! schwarze 509: print_text(h, meta->date);
1.1 schwarze 510: print_stagq(h, tt);
511:
1.40 schwarze 512: PAIR_CLASS_INIT(&tag[0], "foot-os");
1.63 schwarze 513: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
514: print_otag(h, TAG_TD, 2, tag);
1.67 ! schwarze 515: print_text(h, meta->os);
1.1 schwarze 516: print_tagq(h, t);
517: }
518:
519:
520: /* ARGSUSED */
521: static int
522: mdoc_root_pre(MDOC_ARGS)
523: {
1.3 schwarze 524: struct htmlpair tag[3];
1.1 schwarze 525: struct tag *t, *tt;
526: char b[BUFSIZ], title[BUFSIZ];
527:
1.67 ! schwarze 528: strlcpy(b, meta->vol, BUFSIZ);
1.1 schwarze 529:
1.67 ! schwarze 530: if (meta->arch) {
1.40 schwarze 531: strlcat(b, " (", BUFSIZ);
1.67 ! schwarze 532: strlcat(b, meta->arch, BUFSIZ);
1.40 schwarze 533: strlcat(b, ")", BUFSIZ);
1.1 schwarze 534: }
535:
1.67 ! schwarze 536: snprintf(title, BUFSIZ - 1, "%s(%s)", meta->title, meta->msec);
1.1 schwarze 537:
1.42 schwarze 538: PAIR_SUMMARY_INIT(&tag[0], "Document Header");
539: PAIR_CLASS_INIT(&tag[1], "head");
1.63 schwarze 540: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
541: t = print_otag(h, TAG_TABLE, 3, tag);
542: PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
543: print_otag(h, TAG_COL, 1, tag);
544: print_otag(h, TAG_COL, 1, tag);
545: print_otag(h, TAG_COL, 1, tag);
1.42 schwarze 546:
547: print_otag(h, TAG_TBODY, 0, NULL);
1.3 schwarze 548:
1.1 schwarze 549: tt = print_otag(h, TAG_TR, 0, NULL);
550:
1.40 schwarze 551: PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1 schwarze 552: print_otag(h, TAG_TD, 1, tag);
553: print_text(h, title);
554: print_stagq(h, tt);
555:
1.40 schwarze 556: PAIR_CLASS_INIT(&tag[0], "head-vol");
1.63 schwarze 557: PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
558: print_otag(h, TAG_TD, 2, tag);
1.1 schwarze 559: print_text(h, b);
560: print_stagq(h, tt);
561:
1.40 schwarze 562: PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.63 schwarze 563: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
564: print_otag(h, TAG_TD, 2, tag);
1.1 schwarze 565: print_text(h, title);
566: print_tagq(h, t);
567: return(1);
568: }
569:
570:
571: /* ARGSUSED */
572: static int
573: mdoc_sh_pre(MDOC_ARGS)
574: {
1.40 schwarze 575: struct htmlpair tag;
1.1 schwarze 576:
1.40 schwarze 577: if (MDOC_BLOCK == n->type) {
578: PAIR_CLASS_INIT(&tag, "section");
579: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 580: return(1);
1.40 schwarze 581: } else if (MDOC_BODY == n->type)
1.1 schwarze 582: return(1);
583:
1.57 schwarze 584: bufinit(h);
1.59 schwarze 585: bufcat(h, "x");
1.61 schwarze 586:
587: for (n = n->child; n && MDOC_TEXT == n->type; ) {
1.57 schwarze 588: bufcat_id(h, n->string);
1.61 schwarze 589: if (NULL != (n = n->next))
1.57 schwarze 590: bufcat_id(h, " ");
1.1 schwarze 591: }
592:
1.61 schwarze 593: if (NULL == n) {
594: PAIR_ID_INIT(&tag, h->buf);
595: print_otag(h, TAG_H1, 1, &tag);
596: } else
597: print_otag(h, TAG_H1, 0, NULL);
598:
1.1 schwarze 599: return(1);
600: }
601:
602: /* ARGSUSED */
603: static int
604: mdoc_ss_pre(MDOC_ARGS)
605: {
1.40 schwarze 606: struct htmlpair tag;
1.1 schwarze 607:
1.40 schwarze 608: if (MDOC_BLOCK == n->type) {
609: PAIR_CLASS_INIT(&tag, "subsection");
610: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 611: return(1);
1.40 schwarze 612: } else if (MDOC_BODY == n->type)
1.1 schwarze 613: return(1);
614:
1.57 schwarze 615: bufinit(h);
1.59 schwarze 616: bufcat(h, "x");
1.61 schwarze 617:
618: for (n = n->child; n && MDOC_TEXT == n->type; ) {
1.57 schwarze 619: bufcat_id(h, n->string);
1.61 schwarze 620: if (NULL != (n = n->next))
1.57 schwarze 621: bufcat_id(h, " ");
1.1 schwarze 622: }
623:
1.61 schwarze 624: if (NULL == n) {
625: PAIR_ID_INIT(&tag, h->buf);
626: print_otag(h, TAG_H2, 1, &tag);
627: } else
628: print_otag(h, TAG_H2, 0, NULL);
629:
1.1 schwarze 630: return(1);
631: }
632:
633:
634: /* ARGSUSED */
635: static int
636: mdoc_fl_pre(MDOC_ARGS)
637: {
638: struct htmlpair tag;
639:
640: PAIR_CLASS_INIT(&tag, "flag");
1.42 schwarze 641: print_otag(h, TAG_B, 1, &tag);
1.6 schwarze 642:
643: /* `Cm' has no leading hyphen. */
644:
645: if (MDOC_Cm == n->tok)
646: return(1);
647:
648: print_text(h, "\\-");
649:
650: if (n->child)
1.1 schwarze 651: h->flags |= HTML_NOSPACE;
1.11 schwarze 652: else if (n->next && n->next->line == n->line)
653: h->flags |= HTML_NOSPACE;
1.6 schwarze 654:
1.1 schwarze 655: return(1);
656: }
657:
658:
659: /* ARGSUSED */
660: static int
661: mdoc_nd_pre(MDOC_ARGS)
662: {
663: struct htmlpair tag;
664:
665: if (MDOC_BODY != n->type)
666: return(1);
667:
668: /* XXX: this tag in theory can contain block elements. */
669:
670: print_text(h, "\\(em");
1.40 schwarze 671: PAIR_CLASS_INIT(&tag, "desc");
1.1 schwarze 672: print_otag(h, TAG_SPAN, 1, &tag);
673: return(1);
674: }
675:
676:
677: static int
678: mdoc_nm_pre(MDOC_ARGS)
679: {
1.25 schwarze 680: struct htmlpair tag;
681: struct roffsu su;
1.57 schwarze 682: int len;
1.25 schwarze 683:
1.40 schwarze 684: switch (n->type) {
685: case (MDOC_ELEM):
1.25 schwarze 686: synopsis_pre(h, n);
687: PAIR_CLASS_INIT(&tag, "name");
1.42 schwarze 688: print_otag(h, TAG_B, 1, &tag);
1.67 ! schwarze 689: if (NULL == n->child && meta->name)
! 690: print_text(h, meta->name);
1.40 schwarze 691: return(1);
692: case (MDOC_HEAD):
693: print_otag(h, TAG_TD, 0, NULL);
1.67 ! schwarze 694: if (NULL == n->child && meta->name)
! 695: print_text(h, meta->name);
1.40 schwarze 696: return(1);
697: case (MDOC_BODY):
698: print_otag(h, TAG_TD, 0, NULL);
699: return(1);
700: default:
701: break;
702: }
1.25 schwarze 703:
1.40 schwarze 704: synopsis_pre(h, n);
705: PAIR_CLASS_INIT(&tag, "synopsis");
706: print_otag(h, TAG_TABLE, 1, &tag);
1.25 schwarze 707:
1.40 schwarze 708: for (len = 0, n = n->child; n; n = n->next)
709: if (MDOC_TEXT == n->type)
1.57 schwarze 710: len += html_strlen(n->string);
1.25 schwarze 711:
1.67 ! schwarze 712: if (0 == len && meta->name)
! 713: len = html_strlen(meta->name);
1.1 schwarze 714:
1.40 schwarze 715: SCALE_HS_INIT(&su, (double)len);
1.57 schwarze 716: bufinit(h);
1.40 schwarze 717: bufcat_su(h, "width", &su);
718: PAIR_STYLE_INIT(&tag, h);
719: print_otag(h, TAG_COL, 1, &tag);
720: print_otag(h, TAG_COL, 0, NULL);
721: print_otag(h, TAG_TBODY, 0, NULL);
722: print_otag(h, TAG_TR, 0, NULL);
1.1 schwarze 723: return(1);
724: }
725:
726:
727: /* ARGSUSED */
728: static int
729: mdoc_xr_pre(MDOC_ARGS)
730: {
1.56 schwarze 731: struct htmlpair tag[2];
1.9 schwarze 732:
733: if (NULL == n->child)
734: return(0);
1.1 schwarze 735:
736: PAIR_CLASS_INIT(&tag[0], "link-man");
737:
738: if (h->base_man) {
739: buffmt_man(h, n->child->string,
740: n->child->next ?
741: n->child->next->string : NULL);
1.11 schwarze 742: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 743: print_otag(h, TAG_A, 2, tag);
744: } else
745: print_otag(h, TAG_A, 1, tag);
746:
1.56 schwarze 747: n = n->child;
748: print_text(h, n->string);
1.1 schwarze 749:
1.56 schwarze 750: if (NULL == (n = n->next))
1.1 schwarze 751: return(0);
752:
753: h->flags |= HTML_NOSPACE;
754: print_text(h, "(");
755: h->flags |= HTML_NOSPACE;
1.56 schwarze 756: print_text(h, n->string);
1.1 schwarze 757: h->flags |= HTML_NOSPACE;
758: print_text(h, ")");
759: return(0);
760: }
761:
762:
763: /* ARGSUSED */
764: static int
765: mdoc_ns_pre(MDOC_ARGS)
766: {
767:
1.51 schwarze 768: if ( ! (MDOC_LINE & n->flags))
769: h->flags |= HTML_NOSPACE;
1.1 schwarze 770: return(1);
771: }
772:
773:
774: /* ARGSUSED */
775: static int
776: mdoc_ar_pre(MDOC_ARGS)
777: {
778: struct htmlpair tag;
779:
780: PAIR_CLASS_INIT(&tag, "arg");
1.42 schwarze 781: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 782: return(1);
783: }
784:
785:
786: /* ARGSUSED */
787: static int
788: mdoc_xx_pre(MDOC_ARGS)
789: {
790: const char *pp;
791: struct htmlpair tag;
1.52 schwarze 792: int flags;
1.1 schwarze 793:
794: switch (n->tok) {
795: case (MDOC_Bsx):
1.37 schwarze 796: pp = "BSD/OS";
1.1 schwarze 797: break;
798: case (MDOC_Dx):
1.4 schwarze 799: pp = "DragonFly";
1.1 schwarze 800: break;
801: case (MDOC_Fx):
802: pp = "FreeBSD";
803: break;
804: case (MDOC_Nx):
805: pp = "NetBSD";
806: break;
807: case (MDOC_Ox):
808: pp = "OpenBSD";
809: break;
810: case (MDOC_Ux):
811: pp = "UNIX";
812: break;
813: default:
814: return(1);
815: }
816:
817: PAIR_CLASS_INIT(&tag, "unix");
818: print_otag(h, TAG_SPAN, 1, &tag);
1.52 schwarze 819:
1.1 schwarze 820: print_text(h, pp);
1.52 schwarze 821: if (n->child) {
822: flags = h->flags;
823: h->flags |= HTML_KEEP;
824: print_text(h, n->child->string);
825: h->flags = flags;
826: }
827: return(0);
1.1 schwarze 828: }
829:
830:
831: /* ARGSUSED */
832: static int
833: mdoc_bx_pre(MDOC_ARGS)
834: {
1.49 schwarze 835: struct htmlpair tag;
1.1 schwarze 836:
837: PAIR_CLASS_INIT(&tag, "unix");
838: print_otag(h, TAG_SPAN, 1, &tag);
839:
1.49 schwarze 840: if (NULL != (n = n->child)) {
841: print_text(h, n->string);
842: h->flags |= HTML_NOSPACE;
843: print_text(h, "BSD");
844: } else {
845: print_text(h, "BSD");
846: return(0);
847: }
1.1 schwarze 848:
1.49 schwarze 849: if (NULL != (n = n->next)) {
850: h->flags |= HTML_NOSPACE;
851: print_text(h, "-");
1.1 schwarze 852: h->flags |= HTML_NOSPACE;
1.49 schwarze 853: print_text(h, n->string);
854: }
1.1 schwarze 855:
856: return(0);
857: }
858:
1.46 schwarze 859: /* ARGSUSED */
1.1 schwarze 860: static int
1.40 schwarze 861: mdoc_it_pre(MDOC_ARGS)
1.1 schwarze 862: {
1.40 schwarze 863: struct roffsu su;
864: enum mdoc_list type;
865: struct htmlpair tag[2];
866: const struct mdoc_node *bl;
1.1 schwarze 867:
1.40 schwarze 868: bl = n->parent;
869: while (bl && MDOC_Bl != bl->tok)
870: bl = bl->parent;
1.1 schwarze 871:
1.40 schwarze 872: assert(bl);
1.1 schwarze 873:
1.44 schwarze 874: type = bl->norm->Bl.type;
1.1 schwarze 875:
1.40 schwarze 876: assert(lists[type]);
877: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 schwarze 878:
1.57 schwarze 879: bufinit(h);
880:
1.40 schwarze 881: if (MDOC_HEAD == n->type) {
882: switch (type) {
883: case(LIST_bullet):
884: /* FALLTHROUGH */
885: case(LIST_dash):
886: /* FALLTHROUGH */
887: case(LIST_item):
888: /* FALLTHROUGH */
889: case(LIST_hyphen):
890: /* FALLTHROUGH */
891: case(LIST_enum):
892: return(0);
893: case(LIST_diag):
894: /* FALLTHROUGH */
895: case(LIST_hang):
896: /* FALLTHROUGH */
897: case(LIST_inset):
898: /* FALLTHROUGH */
899: case(LIST_ohang):
900: /* FALLTHROUGH */
901: case(LIST_tag):
1.44 schwarze 902: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 903: bufcat_su(h, "margin-top", &su);
904: PAIR_STYLE_INIT(&tag[1], h);
905: print_otag(h, TAG_DT, 2, tag);
1.42 schwarze 906: if (LIST_diag != type)
907: break;
908: PAIR_CLASS_INIT(&tag[0], "diag");
909: print_otag(h, TAG_B, 1, tag);
1.40 schwarze 910: break;
911: case(LIST_column):
912: break;
913: default:
914: break;
915: }
916: } else if (MDOC_BODY == n->type) {
917: switch (type) {
918: case(LIST_bullet):
919: /* FALLTHROUGH */
920: case(LIST_hyphen):
921: /* FALLTHROUGH */
922: case(LIST_dash):
923: /* FALLTHROUGH */
924: case(LIST_enum):
925: /* FALLTHROUGH */
926: case(LIST_item):
1.44 schwarze 927: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 928: bufcat_su(h, "margin-top", &su);
929: PAIR_STYLE_INIT(&tag[1], h);
930: print_otag(h, TAG_LI, 2, tag);
931: break;
932: case(LIST_diag):
933: /* FALLTHROUGH */
934: case(LIST_hang):
935: /* FALLTHROUGH */
936: case(LIST_inset):
937: /* FALLTHROUGH */
938: case(LIST_ohang):
939: /* FALLTHROUGH */
940: case(LIST_tag):
1.44 schwarze 941: if (NULL == bl->norm->Bl.width) {
1.40 schwarze 942: print_otag(h, TAG_DD, 1, tag);
943: break;
944: }
1.44 schwarze 945: a2width(bl->norm->Bl.width, &su);
1.40 schwarze 946: bufcat_su(h, "margin-left", &su);
947: PAIR_STYLE_INIT(&tag[1], h);
948: print_otag(h, TAG_DD, 2, tag);
949: break;
950: case(LIST_column):
1.44 schwarze 951: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40 schwarze 952: bufcat_su(h, "margin-top", &su);
953: PAIR_STYLE_INIT(&tag[1], h);
954: print_otag(h, TAG_TD, 2, tag);
955: break;
956: default:
957: break;
958: }
959: } else {
960: switch (type) {
961: case (LIST_column):
962: print_otag(h, TAG_TR, 1, tag);
963: break;
964: default:
1.1 schwarze 965: break;
1.40 schwarze 966: }
1.1 schwarze 967: }
968:
969: return(1);
970: }
971:
972: /* ARGSUSED */
973: static int
1.40 schwarze 974: mdoc_bl_pre(MDOC_ARGS)
1.1 schwarze 975: {
1.46 schwarze 976: int i;
1.40 schwarze 977: struct htmlpair tag[3];
1.1 schwarze 978: struct roffsu su;
1.42 schwarze 979: char buf[BUFSIZ];
1.1 schwarze 980:
1.40 schwarze 981: if (MDOC_BODY == n->type) {
1.44 schwarze 982: if (LIST_column == n->norm->Bl.type)
1.40 schwarze 983: print_otag(h, TAG_TBODY, 0, NULL);
984: return(1);
1.1 schwarze 985: }
986:
1.40 schwarze 987: if (MDOC_HEAD == n->type) {
1.44 schwarze 988: if (LIST_column != n->norm->Bl.type)
1.40 schwarze 989: return(0);
1.1 schwarze 990:
1.40 schwarze 991: /*
992: * For each column, print out the <COL> tag with our
993: * suggested width. The last column gets min-width, as
994: * in terminal mode it auto-sizes to the width of the
995: * screen and we want to preserve that behaviour.
996: */
1.1 schwarze 997:
1.46 schwarze 998: for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
1.66 matthew 999: bufinit(h);
1.44 schwarze 1000: a2width(n->norm->Bl.cols[i], &su);
1.46 schwarze 1001: if (i < (int)n->norm->Bl.ncols - 1)
1.40 schwarze 1002: bufcat_su(h, "width", &su);
1003: else
1004: bufcat_su(h, "min-width", &su);
1005: PAIR_STYLE_INIT(&tag[0], h);
1006: print_otag(h, TAG_COL, 1, tag);
1007: }
1.1 schwarze 1008:
1.4 schwarze 1009: return(0);
1.1 schwarze 1010: }
1011:
1.40 schwarze 1012: SCALE_VS_INIT(&su, 0);
1.66 matthew 1013: bufinit(h);
1.40 schwarze 1014: bufcat_su(h, "margin-top", &su);
1015: bufcat_su(h, "margin-bottom", &su);
1016: PAIR_STYLE_INIT(&tag[0], h);
1.1 schwarze 1017:
1.44 schwarze 1018: assert(lists[n->norm->Bl.type]);
1.42 schwarze 1019: strlcpy(buf, "list ", BUFSIZ);
1.44 schwarze 1020: strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.42 schwarze 1021: PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1.1 schwarze 1022:
1.40 schwarze 1023: /* Set the block's left-hand margin. */
1.1 schwarze 1024:
1.44 schwarze 1025: if (n->norm->Bl.offs) {
1026: a2offs(n->norm->Bl.offs, &su);
1.40 schwarze 1027: bufcat_su(h, "margin-left", &su);
1028: }
1.1 schwarze 1029:
1.44 schwarze 1030: switch (n->norm->Bl.type) {
1.40 schwarze 1031: case(LIST_bullet):
1.1 schwarze 1032: /* FALLTHROUGH */
1.40 schwarze 1033: case(LIST_dash):
1.1 schwarze 1034: /* FALLTHROUGH */
1.40 schwarze 1035: case(LIST_hyphen):
1.1 schwarze 1036: /* FALLTHROUGH */
1.40 schwarze 1037: case(LIST_item):
1.42 schwarze 1038: print_otag(h, TAG_UL, 2, tag);
1.1 schwarze 1039: break;
1.40 schwarze 1040: case(LIST_enum):
1.42 schwarze 1041: print_otag(h, TAG_OL, 2, tag);
1.1 schwarze 1042: break;
1.40 schwarze 1043: case(LIST_diag):
1044: /* FALLTHROUGH */
1045: case(LIST_hang):
1.4 schwarze 1046: /* FALLTHROUGH */
1.40 schwarze 1047: case(LIST_inset):
1.1 schwarze 1048: /* FALLTHROUGH */
1.40 schwarze 1049: case(LIST_ohang):
1.1 schwarze 1050: /* FALLTHROUGH */
1.40 schwarze 1051: case(LIST_tag):
1.42 schwarze 1052: print_otag(h, TAG_DL, 2, tag);
1.40 schwarze 1053: break;
1054: case(LIST_column):
1.42 schwarze 1055: print_otag(h, TAG_TABLE, 2, tag);
1.1 schwarze 1056: break;
1057: default:
1.40 schwarze 1058: abort();
1059: /* NOTREACHED */
1.1 schwarze 1060: }
1061:
1062: return(1);
1063: }
1064:
1065: /* ARGSUSED */
1066: static int
1067: mdoc_ex_pre(MDOC_ARGS)
1068: {
1.56 schwarze 1069: struct tag *t;
1070: struct htmlpair tag;
1071: int nchild;
1.1 schwarze 1072:
1.40 schwarze 1073: if (n->prev)
1074: print_otag(h, TAG_BR, 0, NULL);
1075:
1.1 schwarze 1076: PAIR_CLASS_INIT(&tag, "utility");
1077:
1078: print_text(h, "The");
1.56 schwarze 1079:
1080: nchild = n->nchild;
1081: for (n = n->child; n; n = n->next) {
1082: assert(MDOC_TEXT == n->type);
1083:
1.42 schwarze 1084: t = print_otag(h, TAG_B, 1, &tag);
1.56 schwarze 1085: print_text(h, n->string);
1.1 schwarze 1086: print_tagq(h, t);
1087:
1.56 schwarze 1088: if (nchild > 2 && n->next) {
1089: h->flags |= HTML_NOSPACE;
1090: print_text(h, ",");
1091: }
1.1 schwarze 1092:
1.56 schwarze 1093: if (n->next && NULL == n->next->next)
1094: print_text(h, "and");
1.1 schwarze 1095: }
1096:
1.56 schwarze 1097: if (nchild > 1)
1.1 schwarze 1098: print_text(h, "utilities exit");
1099: else
1100: print_text(h, "utility exits");
1101:
1102: print_text(h, "0 on success, and >0 if an error occurs.");
1103: return(0);
1104: }
1105:
1106:
1107: /* ARGSUSED */
1108: static int
1109: mdoc_em_pre(MDOC_ARGS)
1110: {
1111: struct htmlpair tag;
1112:
1113: PAIR_CLASS_INIT(&tag, "emph");
1114: print_otag(h, TAG_SPAN, 1, &tag);
1115: return(1);
1116: }
1117:
1118:
1119: /* ARGSUSED */
1120: static int
1121: mdoc_d1_pre(MDOC_ARGS)
1122: {
1123: struct htmlpair tag[2];
1124: struct roffsu su;
1125:
1126: if (MDOC_BLOCK != n->type)
1127: return(1);
1128:
1.40 schwarze 1129: SCALE_VS_INIT(&su, 0);
1.57 schwarze 1130: bufinit(h);
1.40 schwarze 1131: bufcat_su(h, "margin-top", &su);
1132: bufcat_su(h, "margin-bottom", &su);
1133: PAIR_STYLE_INIT(&tag[0], h);
1134: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1135:
1136: /* BLOCKQUOTE needs a block body. */
1.1 schwarze 1137:
1.43 schwarze 1138: PAIR_CLASS_INIT(&tag[0], "display");
1139: print_otag(h, TAG_DIV, 1, tag);
1140:
1141: if (MDOC_Dl == n->tok) {
1142: PAIR_CLASS_INIT(&tag[0], "lit");
1143: print_otag(h, TAG_CODE, 1, tag);
1144: }
1.40 schwarze 1145:
1.1 schwarze 1146: return(1);
1147: }
1148:
1149:
1150: /* ARGSUSED */
1151: static int
1152: mdoc_sx_pre(MDOC_ARGS)
1153: {
1.56 schwarze 1154: struct htmlpair tag[2];
1.1 schwarze 1155:
1.57 schwarze 1156: bufinit(h);
1157: bufcat(h, "#x");
1.61 schwarze 1158:
1159: for (n = n->child; n; ) {
1.57 schwarze 1160: bufcat_id(h, n->string);
1.61 schwarze 1161: if (NULL != (n = n->next))
1.57 schwarze 1162: bufcat_id(h, " ");
1.1 schwarze 1163: }
1164:
1165: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 schwarze 1166: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1167:
1.42 schwarze 1168: print_otag(h, TAG_I, 1, tag);
1.1 schwarze 1169: print_otag(h, TAG_A, 2, tag);
1170: return(1);
1171: }
1172:
1173:
1174: /* ARGSUSED */
1175: static int
1176: mdoc_bd_pre(MDOC_ARGS)
1177: {
1178: struct htmlpair tag[2];
1.50 schwarze 1179: int comp, sv;
1.22 schwarze 1180: const struct mdoc_node *nn;
1.1 schwarze 1181: struct roffsu su;
1182:
1.22 schwarze 1183: if (MDOC_HEAD == n->type)
1.1 schwarze 1184: return(0);
1185:
1186: if (MDOC_BLOCK == n->type) {
1.44 schwarze 1187: comp = n->norm->Bd.comp;
1.1 schwarze 1188: for (nn = n; nn && ! comp; nn = nn->parent) {
1189: if (MDOC_BLOCK != nn->type)
1190: continue;
1191: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1192: comp = 1;
1193: if (nn->prev)
1194: break;
1195: }
1.40 schwarze 1196: if ( ! comp)
1197: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1198: return(1);
1199: }
1200:
1.40 schwarze 1201: SCALE_HS_INIT(&su, 0);
1.44 schwarze 1202: if (n->norm->Bd.offs)
1203: a2offs(n->norm->Bd.offs, &su);
1.57 schwarze 1204:
1205: bufinit(h);
1.40 schwarze 1206: bufcat_su(h, "margin-left", &su);
1207: PAIR_STYLE_INIT(&tag[0], h);
1208:
1.44 schwarze 1209: if (DISP_unfilled != n->norm->Bd.type &&
1210: DISP_literal != n->norm->Bd.type) {
1.40 schwarze 1211: PAIR_CLASS_INIT(&tag[1], "display");
1212: print_otag(h, TAG_DIV, 2, tag);
1.1 schwarze 1213: return(1);
1.40 schwarze 1214: }
1.1 schwarze 1215:
1.40 schwarze 1216: PAIR_CLASS_INIT(&tag[1], "lit display");
1217: print_otag(h, TAG_PRE, 2, tag);
1.1 schwarze 1218:
1.50 schwarze 1219: /* This can be recursive: save & set our literal state. */
1220:
1221: sv = h->flags & HTML_LITERAL;
1222: h->flags |= HTML_LITERAL;
1223:
1.1 schwarze 1224: for (nn = n->child; nn; nn = nn->next) {
1.67 ! schwarze 1225: print_mdoc_node(meta, nn, h);
1.33 schwarze 1226: /*
1227: * If the printed node flushes its own line, then we
1228: * needn't do it here as well. This is hacky, but the
1229: * notion of selective eoln whitespace is pretty dumb
1230: * anyway, so don't sweat it.
1231: */
1232: switch (nn->tok) {
1.36 schwarze 1233: case (MDOC_Sm):
1234: /* FALLTHROUGH */
1.33 schwarze 1235: case (MDOC_br):
1236: /* FALLTHROUGH */
1237: case (MDOC_sp):
1238: /* FALLTHROUGH */
1239: case (MDOC_Bl):
1.39 schwarze 1240: /* FALLTHROUGH */
1241: case (MDOC_D1):
1242: /* FALLTHROUGH */
1243: case (MDOC_Dl):
1.33 schwarze 1244: /* FALLTHROUGH */
1245: case (MDOC_Lp):
1246: /* FALLTHROUGH */
1247: case (MDOC_Pp):
1248: continue;
1249: default:
1250: break;
1251: }
1.28 schwarze 1252: if (nn->next && nn->next->line == nn->line)
1253: continue;
1.40 schwarze 1254: else if (nn->next)
1255: print_text(h, "\n");
1256:
1.28 schwarze 1257: h->flags |= HTML_NOSPACE;
1.1 schwarze 1258: }
1.50 schwarze 1259:
1260: if (0 == sv)
1261: h->flags &= ~HTML_LITERAL;
1.1 schwarze 1262:
1263: return(0);
1264: }
1265:
1266:
1267: /* ARGSUSED */
1268: static int
1269: mdoc_pa_pre(MDOC_ARGS)
1270: {
1271: struct htmlpair tag;
1272:
1273: PAIR_CLASS_INIT(&tag, "file");
1.42 schwarze 1274: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1275: return(1);
1276: }
1277:
1278:
1279: /* ARGSUSED */
1280: static int
1281: mdoc_ad_pre(MDOC_ARGS)
1282: {
1283: struct htmlpair tag;
1284:
1285: PAIR_CLASS_INIT(&tag, "addr");
1.42 schwarze 1286: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1287: return(1);
1288: }
1289:
1290:
1291: /* ARGSUSED */
1292: static int
1293: mdoc_an_pre(MDOC_ARGS)
1294: {
1295: struct htmlpair tag;
1296:
1297: /* TODO: -split and -nosplit (see termp_an_pre()). */
1298:
1299: PAIR_CLASS_INIT(&tag, "author");
1300: print_otag(h, TAG_SPAN, 1, &tag);
1301: return(1);
1302: }
1303:
1304:
1305: /* ARGSUSED */
1306: static int
1307: mdoc_cd_pre(MDOC_ARGS)
1308: {
1309: struct htmlpair tag;
1310:
1.21 schwarze 1311: synopsis_pre(h, n);
1.1 schwarze 1312: PAIR_CLASS_INIT(&tag, "config");
1.42 schwarze 1313: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1314: return(1);
1315: }
1316:
1317:
1318: /* ARGSUSED */
1319: static int
1320: mdoc_dv_pre(MDOC_ARGS)
1321: {
1322: struct htmlpair tag;
1323:
1324: PAIR_CLASS_INIT(&tag, "define");
1325: print_otag(h, TAG_SPAN, 1, &tag);
1326: return(1);
1327: }
1328:
1329:
1330: /* ARGSUSED */
1331: static int
1332: mdoc_ev_pre(MDOC_ARGS)
1333: {
1334: struct htmlpair tag;
1335:
1336: PAIR_CLASS_INIT(&tag, "env");
1337: print_otag(h, TAG_SPAN, 1, &tag);
1338: return(1);
1339: }
1340:
1341:
1342: /* ARGSUSED */
1343: static int
1344: mdoc_er_pre(MDOC_ARGS)
1345: {
1346: struct htmlpair tag;
1347:
1348: PAIR_CLASS_INIT(&tag, "errno");
1349: print_otag(h, TAG_SPAN, 1, &tag);
1350: return(1);
1351: }
1352:
1353:
1354: /* ARGSUSED */
1355: static int
1356: mdoc_fa_pre(MDOC_ARGS)
1357: {
1358: const struct mdoc_node *nn;
1359: struct htmlpair tag;
1360: struct tag *t;
1361:
1362: PAIR_CLASS_INIT(&tag, "farg");
1363: if (n->parent->tok != MDOC_Fo) {
1.42 schwarze 1364: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1365: return(1);
1366: }
1367:
1368: for (nn = n->child; nn; nn = nn->next) {
1.42 schwarze 1369: t = print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1370: print_text(h, nn->string);
1371: print_tagq(h, t);
1.56 schwarze 1372: if (nn->next) {
1373: h->flags |= HTML_NOSPACE;
1.1 schwarze 1374: print_text(h, ",");
1.56 schwarze 1375: }
1.1 schwarze 1376: }
1377:
1.56 schwarze 1378: if (n->child && n->next && n->next->tok == MDOC_Fa) {
1379: h->flags |= HTML_NOSPACE;
1.1 schwarze 1380: print_text(h, ",");
1.56 schwarze 1381: }
1.1 schwarze 1382:
1383: return(0);
1384: }
1385:
1386:
1387: /* ARGSUSED */
1388: static int
1389: mdoc_fd_pre(MDOC_ARGS)
1390: {
1.56 schwarze 1391: struct htmlpair tag[2];
1392: char buf[BUFSIZ];
1393: size_t sz;
1394: int i;
1395: struct tag *t;
1.1 schwarze 1396:
1.21 schwarze 1397: synopsis_pre(h, n);
1398:
1.56 schwarze 1399: if (NULL == (n = n->child))
1400: return(0);
1401:
1402: assert(MDOC_TEXT == n->type);
1403:
1404: if (strcmp(n->string, "#include")) {
1405: PAIR_CLASS_INIT(&tag[0], "macro");
1406: print_otag(h, TAG_B, 1, tag);
1407: return(1);
1408: }
1409:
1410: PAIR_CLASS_INIT(&tag[0], "includes");
1411: print_otag(h, TAG_B, 1, tag);
1412: print_text(h, n->string);
1413:
1414: if (NULL != (n = n->next)) {
1415: assert(MDOC_TEXT == n->type);
1416: strlcpy(buf, '<' == *n->string || '"' == *n->string ?
1417: n->string + 1 : n->string, BUFSIZ);
1418:
1419: sz = strlen(buf);
1420: if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1]))
1421: buf[sz - 1] = '\0';
1422:
1423: PAIR_CLASS_INIT(&tag[0], "link-includes");
1424:
1425: i = 1;
1426: if (h->base_includes) {
1427: buffmt_includes(h, buf);
1428: PAIR_HREF_INIT(&tag[i], h->buf);
1429: i++;
1430: }
1431:
1432: t = print_otag(h, TAG_A, i, tag);
1433: print_text(h, n->string);
1434: print_tagq(h, t);
1435:
1436: n = n->next;
1437: }
1438:
1439: for ( ; n; n = n->next) {
1440: assert(MDOC_TEXT == n->type);
1441: print_text(h, n->string);
1442: }
1443:
1444: return(0);
1.1 schwarze 1445: }
1446:
1447:
1448: /* ARGSUSED */
1449: static int
1450: mdoc_vt_pre(MDOC_ARGS)
1451: {
1452: struct htmlpair tag;
1453:
1.21 schwarze 1454: if (MDOC_BLOCK == n->type) {
1455: synopsis_pre(h, n);
1.7 schwarze 1456: return(1);
1.21 schwarze 1457: } else if (MDOC_ELEM == n->type) {
1458: synopsis_pre(h, n);
1.7 schwarze 1459: } else if (MDOC_HEAD == n->type)
1460: return(0);
1.1 schwarze 1461:
1462: PAIR_CLASS_INIT(&tag, "type");
1463: print_otag(h, TAG_SPAN, 1, &tag);
1464: return(1);
1465: }
1466:
1467:
1468: /* ARGSUSED */
1469: static int
1470: mdoc_ft_pre(MDOC_ARGS)
1471: {
1472: struct htmlpair tag;
1473:
1.21 schwarze 1474: synopsis_pre(h, n);
1.1 schwarze 1475: PAIR_CLASS_INIT(&tag, "ftype");
1.42 schwarze 1476: print_otag(h, TAG_I, 1, &tag);
1.1 schwarze 1477: return(1);
1478: }
1479:
1480:
1481: /* ARGSUSED */
1482: static int
1483: mdoc_fn_pre(MDOC_ARGS)
1484: {
1.56 schwarze 1485: struct tag *t;
1486: struct htmlpair tag[2];
1487: char nbuf[BUFSIZ];
1488: const char *sp, *ep;
1489: int sz, i, pretty;
1.1 schwarze 1490:
1.56 schwarze 1491: pretty = MDOC_SYNPRETTY & n->flags;
1.21 schwarze 1492: synopsis_pre(h, n);
1.1 schwarze 1493:
1494: /* Split apart into type and name. */
1495: assert(n->child->string);
1496: sp = n->child->string;
1497:
1498: ep = strchr(sp, ' ');
1499: if (NULL != ep) {
1500: PAIR_CLASS_INIT(&tag[0], "ftype");
1.42 schwarze 1501: t = print_otag(h, TAG_I, 1, tag);
1.1 schwarze 1502:
1503: while (ep) {
1504: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1505: (void)memcpy(nbuf, sp, (size_t)sz);
1506: nbuf[sz] = '\0';
1507: print_text(h, nbuf);
1508: sp = ++ep;
1509: ep = strchr(sp, ' ');
1510: }
1511: print_tagq(h, t);
1512: }
1513:
1514: PAIR_CLASS_INIT(&tag[0], "fname");
1.11 schwarze 1515:
1516: /*
1517: * FIXME: only refer to IDs that we know exist.
1518: */
1519:
1520: #if 0
1.23 schwarze 1521: if (MDOC_SYNPRETTY & n->flags) {
1.11 schwarze 1522: nbuf[0] = '\0';
1523: html_idcat(nbuf, sp, BUFSIZ);
1524: PAIR_ID_INIT(&tag[1], nbuf);
1525: } else {
1526: strlcpy(nbuf, "#", BUFSIZ);
1527: html_idcat(nbuf, sp, BUFSIZ);
1528: PAIR_HREF_INIT(&tag[1], nbuf);
1529: }
1530: #endif
1531:
1.42 schwarze 1532: t = print_otag(h, TAG_B, 1, tag);
1.1 schwarze 1533:
1534: if (sp) {
1.11 schwarze 1535: strlcpy(nbuf, sp, BUFSIZ);
1.1 schwarze 1536: print_text(h, nbuf);
1537: }
1538:
1539: print_tagq(h, t);
1540:
1541: h->flags |= HTML_NOSPACE;
1542: print_text(h, "(");
1.56 schwarze 1543: h->flags |= HTML_NOSPACE;
1.1 schwarze 1544:
1.57 schwarze 1545: PAIR_CLASS_INIT(&tag[0], "farg");
1.1 schwarze 1546: bufinit(h);
1547: bufcat_style(h, "white-space", "nowrap");
1548: PAIR_STYLE_INIT(&tag[1], h);
1549:
1.56 schwarze 1550: for (n = n->child->next; n; n = n->next) {
1.1 schwarze 1551: i = 1;
1.23 schwarze 1552: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1553: i = 2;
1.42 schwarze 1554: t = print_otag(h, TAG_I, i, tag);
1.56 schwarze 1555: print_text(h, n->string);
1.1 schwarze 1556: print_tagq(h, t);
1.56 schwarze 1557: if (n->next) {
1558: h->flags |= HTML_NOSPACE;
1.1 schwarze 1559: print_text(h, ",");
1.56 schwarze 1560: }
1.1 schwarze 1561: }
1562:
1.56 schwarze 1563: h->flags |= HTML_NOSPACE;
1.1 schwarze 1564: print_text(h, ")");
1.56 schwarze 1565:
1566: if (pretty) {
1567: h->flags |= HTML_NOSPACE;
1.1 schwarze 1568: print_text(h, ";");
1.56 schwarze 1569: }
1.1 schwarze 1570:
1571: return(0);
1572: }
1573:
1574:
1575: /* ARGSUSED */
1576: static int
1.26 schwarze 1577: mdoc_sm_pre(MDOC_ARGS)
1578: {
1579:
1580: assert(n->child && MDOC_TEXT == n->child->type);
1581: if (0 == strcmp("on", n->child->string)) {
1.36 schwarze 1582: /*
1583: * FIXME: no p->col to check. Thus, if we have
1584: * .Bd -literal
1585: * .Sm off
1586: * 1 2
1587: * .Sm on
1588: * 3
1589: * .Ed
1590: * the "3" is preceded by a space.
1591: */
1.26 schwarze 1592: h->flags &= ~HTML_NOSPACE;
1593: h->flags &= ~HTML_NONOSPACE;
1594: } else
1595: h->flags |= HTML_NONOSPACE;
1596:
1597: return(0);
1598: }
1599:
1.40 schwarze 1600: /* ARGSUSED */
1601: static int
1602: mdoc_pp_pre(MDOC_ARGS)
1603: {
1604:
1605: print_otag(h, TAG_P, 0, NULL);
1606: return(0);
1607:
1608: }
1.26 schwarze 1609:
1610: /* ARGSUSED */
1611: static int
1.1 schwarze 1612: mdoc_sp_pre(MDOC_ARGS)
1613: {
1.40 schwarze 1614: struct roffsu su;
1.1 schwarze 1615: struct htmlpair tag;
1616:
1.40 schwarze 1617: SCALE_VS_INIT(&su, 1);
1618:
1619: if (MDOC_sp == n->tok) {
1.59 schwarze 1620: if (NULL != (n = n->child))
1621: if ( ! a2roffsu(n->string, &su, SCALE_VS))
1622: SCALE_VS_INIT(&su, atoi(n->string));
1.40 schwarze 1623: } else
1624: su.scale = 0;
1.1 schwarze 1625:
1.57 schwarze 1626: bufinit(h);
1.1 schwarze 1627: bufcat_su(h, "height", &su);
1628: PAIR_STYLE_INIT(&tag, h);
1629: print_otag(h, TAG_DIV, 1, &tag);
1.40 schwarze 1630:
1.3 schwarze 1631: /* So the div isn't empty: */
1632: print_text(h, "\\~");
1633:
1634: return(0);
1.1 schwarze 1635:
1636: }
1637:
1638: /* ARGSUSED */
1639: static int
1640: mdoc_lk_pre(MDOC_ARGS)
1641: {
1.56 schwarze 1642: struct htmlpair tag[2];
1643:
1644: if (NULL == (n = n->child))
1645: return(0);
1.1 schwarze 1646:
1.56 schwarze 1647: assert(MDOC_TEXT == n->type);
1.1 schwarze 1648:
1649: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.56 schwarze 1650: PAIR_HREF_INIT(&tag[1], n->string);
1651:
1.1 schwarze 1652: print_otag(h, TAG_A, 2, tag);
1653:
1.58 schwarze 1654: if (NULL == n->next)
1655: print_text(h, n->string);
1656:
1657: for (n = n->next; n; n = n->next)
1.56 schwarze 1658: print_text(h, n->string);
1.1 schwarze 1659:
1660: return(0);
1661: }
1662:
1663:
1664: /* ARGSUSED */
1665: static int
1666: mdoc_mt_pre(MDOC_ARGS)
1667: {
1.56 schwarze 1668: struct htmlpair tag[2];
1669: struct tag *t;
1.1 schwarze 1670:
1671: PAIR_CLASS_INIT(&tag[0], "link-mail");
1672:
1.56 schwarze 1673: for (n = n->child; n; n = n->next) {
1674: assert(MDOC_TEXT == n->type);
1675:
1.1 schwarze 1676: bufinit(h);
1677: bufcat(h, "mailto:");
1.56 schwarze 1678: bufcat(h, n->string);
1679:
1.10 schwarze 1680: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1681: t = print_otag(h, TAG_A, 2, tag);
1.56 schwarze 1682: print_text(h, n->string);
1.1 schwarze 1683: print_tagq(h, t);
1684: }
1685:
1686: return(0);
1687: }
1688:
1689:
1690: /* ARGSUSED */
1691: static int
1692: mdoc_fo_pre(MDOC_ARGS)
1693: {
1.20 schwarze 1694: struct htmlpair tag;
1695: struct tag *t;
1.1 schwarze 1696:
1697: if (MDOC_BODY == n->type) {
1698: h->flags |= HTML_NOSPACE;
1699: print_text(h, "(");
1700: h->flags |= HTML_NOSPACE;
1701: return(1);
1.20 schwarze 1702: } else if (MDOC_BLOCK == n->type) {
1.21 schwarze 1703: synopsis_pre(h, n);
1.1 schwarze 1704: return(1);
1.11 schwarze 1705: }
1.1 schwarze 1706:
1.20 schwarze 1707: /* XXX: we drop non-initial arguments as per groff. */
1708:
1709: assert(n->child);
1710: assert(n->child->string);
1711:
1.1 schwarze 1712: PAIR_CLASS_INIT(&tag, "fname");
1.43 schwarze 1713: t = print_otag(h, TAG_B, 1, &tag);
1.20 schwarze 1714: print_text(h, n->child->string);
1715: print_tagq(h, t);
1716: return(0);
1.1 schwarze 1717: }
1718:
1719:
1720: /* ARGSUSED */
1721: static void
1722: mdoc_fo_post(MDOC_ARGS)
1723: {
1.21 schwarze 1724:
1.1 schwarze 1725: if (MDOC_BODY != n->type)
1726: return;
1.56 schwarze 1727: h->flags |= HTML_NOSPACE;
1.1 schwarze 1728: print_text(h, ")");
1.56 schwarze 1729: h->flags |= HTML_NOSPACE;
1.1 schwarze 1730: print_text(h, ";");
1731: }
1732:
1733:
1734: /* ARGSUSED */
1735: static int
1736: mdoc_in_pre(MDOC_ARGS)
1737: {
1.56 schwarze 1738: struct tag *t;
1739: struct htmlpair tag[2];
1740: int i;
1.1 schwarze 1741:
1.21 schwarze 1742: synopsis_pre(h, n);
1743:
1.1 schwarze 1744: PAIR_CLASS_INIT(&tag[0], "includes");
1.42 schwarze 1745: print_otag(h, TAG_B, 1, tag);
1.1 schwarze 1746:
1.56 schwarze 1747: /*
1748: * The first argument of the `In' gets special treatment as
1749: * being a linked value. Subsequent values are printed
1750: * afterward. groff does similarly. This also handles the case
1751: * of no children.
1752: */
1753:
1.23 schwarze 1754: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.1 schwarze 1755: print_text(h, "#include");
1756:
1757: print_text(h, "<");
1758: h->flags |= HTML_NOSPACE;
1759:
1.56 schwarze 1760: if (NULL != (n = n->child)) {
1761: assert(MDOC_TEXT == n->type);
1762:
1.1 schwarze 1763: PAIR_CLASS_INIT(&tag[0], "link-includes");
1.56 schwarze 1764:
1.1 schwarze 1765: i = 1;
1766: if (h->base_includes) {
1.56 schwarze 1767: buffmt_includes(h, n->string);
1.11 schwarze 1768: PAIR_HREF_INIT(&tag[i], h->buf);
1769: i++;
1.56 schwarze 1770: }
1771:
1.1 schwarze 1772: t = print_otag(h, TAG_A, i, tag);
1.56 schwarze 1773: print_text(h, n->string);
1.1 schwarze 1774: print_tagq(h, t);
1.56 schwarze 1775:
1776: n = n->next;
1.1 schwarze 1777: }
1778:
1779: h->flags |= HTML_NOSPACE;
1780: print_text(h, ">");
1.20 schwarze 1781:
1.56 schwarze 1782: for ( ; n; n = n->next) {
1783: assert(MDOC_TEXT == n->type);
1784: print_text(h, n->string);
1785: }
1786:
1.1 schwarze 1787: return(0);
1788: }
1789:
1790:
1791: /* ARGSUSED */
1792: static int
1793: mdoc_ic_pre(MDOC_ARGS)
1794: {
1795: struct htmlpair tag;
1796:
1797: PAIR_CLASS_INIT(&tag, "cmd");
1.42 schwarze 1798: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1799: return(1);
1800: }
1801:
1802:
1803: /* ARGSUSED */
1804: static int
1805: mdoc_rv_pre(MDOC_ARGS)
1806: {
1.56 schwarze 1807: struct htmlpair tag;
1808: struct tag *t;
1809: int nchild;
1.1 schwarze 1810:
1.40 schwarze 1811: if (n->prev)
1812: print_otag(h, TAG_BR, 0, NULL);
1813:
1.56 schwarze 1814: PAIR_CLASS_INIT(&tag, "fname");
1815:
1.1 schwarze 1816: print_text(h, "The");
1817:
1.56 schwarze 1818: nchild = n->nchild;
1819: for (n = n->child; n; n = n->next) {
1820: assert(MDOC_TEXT == n->type);
1821:
1.43 schwarze 1822: t = print_otag(h, TAG_B, 1, &tag);
1.56 schwarze 1823: print_text(h, n->string);
1.1 schwarze 1824: print_tagq(h, t);
1825:
1826: h->flags |= HTML_NOSPACE;
1.56 schwarze 1827: print_text(h, "()");
1828:
1829: if (nchild > 2 && n->next) {
1830: h->flags |= HTML_NOSPACE;
1831: print_text(h, ",");
1832: }
1833:
1834: if (n->next && NULL == n->next->next)
1835: print_text(h, "and");
1.1 schwarze 1836: }
1837:
1.56 schwarze 1838: if (nchild > 1)
1.1 schwarze 1839: print_text(h, "functions return");
1840: else
1841: print_text(h, "function returns");
1842:
1843: print_text(h, "the value 0 if successful; otherwise the value "
1844: "-1 is returned and the global variable");
1845:
1846: PAIR_CLASS_INIT(&tag, "var");
1.42 schwarze 1847: t = print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1848: print_text(h, "errno");
1849: print_tagq(h, t);
1850: print_text(h, "is set to indicate the error.");
1851: return(0);
1852: }
1853:
1854:
1855: /* ARGSUSED */
1856: static int
1857: mdoc_va_pre(MDOC_ARGS)
1858: {
1859: struct htmlpair tag;
1860:
1861: PAIR_CLASS_INIT(&tag, "var");
1.42 schwarze 1862: print_otag(h, TAG_B, 1, &tag);
1.1 schwarze 1863: return(1);
1864: }
1865:
1866:
1867: /* ARGSUSED */
1868: static int
1869: mdoc_ap_pre(MDOC_ARGS)
1870: {
1871:
1872: h->flags |= HTML_NOSPACE;
1873: print_text(h, "\\(aq");
1874: h->flags |= HTML_NOSPACE;
1875: return(1);
1876: }
1877:
1878:
1879: /* ARGSUSED */
1880: static int
1881: mdoc_bf_pre(MDOC_ARGS)
1882: {
1883: struct htmlpair tag[2];
1884: struct roffsu su;
1885:
1886: if (MDOC_HEAD == n->type)
1887: return(0);
1.25 schwarze 1888: else if (MDOC_BODY != n->type)
1.1 schwarze 1889: return(1);
1890:
1.44 schwarze 1891: if (FONT_Em == n->norm->Bf.font)
1.25 schwarze 1892: PAIR_CLASS_INIT(&tag[0], "emph");
1.44 schwarze 1893: else if (FONT_Sy == n->norm->Bf.font)
1.25 schwarze 1894: PAIR_CLASS_INIT(&tag[0], "symb");
1.44 schwarze 1895: else if (FONT_Li == n->norm->Bf.font)
1.25 schwarze 1896: PAIR_CLASS_INIT(&tag[0], "lit");
1897: else
1898: PAIR_CLASS_INIT(&tag[0], "none");
1.1 schwarze 1899:
1.25 schwarze 1900: /*
1901: * We want this to be inline-formatted, but needs to be div to
1902: * accept block children.
1903: */
1.57 schwarze 1904: bufinit(h);
1.1 schwarze 1905: bufcat_style(h, "display", "inline");
1906: SCALE_HS_INIT(&su, 1);
1.25 schwarze 1907: /* Needs a left-margin for spacing. */
1908: bufcat_su(h, "margin-left", &su);
1.1 schwarze 1909: PAIR_STYLE_INIT(&tag[1], h);
1910: print_otag(h, TAG_DIV, 2, tag);
1911: return(1);
1912: }
1913:
1914:
1915: /* ARGSUSED */
1916: static int
1917: mdoc_ms_pre(MDOC_ARGS)
1918: {
1919: struct htmlpair tag;
1920:
1921: PAIR_CLASS_INIT(&tag, "symb");
1922: print_otag(h, TAG_SPAN, 1, &tag);
1923: return(1);
1924: }
1925:
1926:
1927: /* ARGSUSED */
1928: static int
1.34 schwarze 1929: mdoc_igndelim_pre(MDOC_ARGS)
1.1 schwarze 1930: {
1931:
1932: h->flags |= HTML_IGNDELIM;
1933: return(1);
1934: }
1935:
1936:
1937: /* ARGSUSED */
1938: static void
1939: mdoc_pf_post(MDOC_ARGS)
1940: {
1941:
1942: h->flags |= HTML_NOSPACE;
1943: }
1944:
1945:
1946: /* ARGSUSED */
1947: static int
1948: mdoc_rs_pre(MDOC_ARGS)
1949: {
1950: struct htmlpair tag;
1951:
1952: if (MDOC_BLOCK != n->type)
1953: return(1);
1954:
1.40 schwarze 1955: if (n->prev && SEC_SEE_ALSO == n->sec)
1956: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1957:
1958: PAIR_CLASS_INIT(&tag, "ref");
1959: print_otag(h, TAG_SPAN, 1, &tag);
1960: return(1);
1961: }
1962:
1963:
1964:
1965: /* ARGSUSED */
1966: static int
1967: mdoc_li_pre(MDOC_ARGS)
1968: {
1969: struct htmlpair tag;
1970:
1971: PAIR_CLASS_INIT(&tag, "lit");
1.61 schwarze 1972: print_otag(h, TAG_CODE, 1, &tag);
1.1 schwarze 1973: return(1);
1974: }
1975:
1976:
1977: /* ARGSUSED */
1978: static int
1979: mdoc_sy_pre(MDOC_ARGS)
1980: {
1981: struct htmlpair tag;
1982:
1983: PAIR_CLASS_INIT(&tag, "symb");
1984: print_otag(h, TAG_SPAN, 1, &tag);
1985: return(1);
1986: }
1987:
1988:
1989: /* ARGSUSED */
1990: static int
1991: mdoc_bt_pre(MDOC_ARGS)
1992: {
1993:
1994: print_text(h, "is currently in beta test.");
1995: return(0);
1996: }
1997:
1998:
1999: /* ARGSUSED */
2000: static int
2001: mdoc_ud_pre(MDOC_ARGS)
2002: {
2003:
2004: print_text(h, "currently under development.");
2005: return(0);
2006: }
2007:
2008:
2009: /* ARGSUSED */
2010: static int
2011: mdoc_lb_pre(MDOC_ARGS)
2012: {
2013: struct htmlpair tag;
2014:
1.40 schwarze 2015: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
2016: print_otag(h, TAG_BR, 0, NULL);
2017:
1.1 schwarze 2018: PAIR_CLASS_INIT(&tag, "lib");
2019: print_otag(h, TAG_SPAN, 1, &tag);
2020: return(1);
2021: }
2022:
2023:
2024: /* ARGSUSED */
2025: static int
2026: mdoc__x_pre(MDOC_ARGS)
2027: {
1.2 schwarze 2028: struct htmlpair tag[2];
1.42 schwarze 2029: enum htmltag t;
2030:
2031: t = TAG_SPAN;
1.1 schwarze 2032:
2033: switch (n->tok) {
2034: case(MDOC__A):
1.2 schwarze 2035: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.30 schwarze 2036: if (n->prev && MDOC__A == n->prev->tok)
2037: if (NULL == n->next || MDOC__A != n->next->tok)
2038: print_text(h, "and");
1.1 schwarze 2039: break;
2040: case(MDOC__B):
1.2 schwarze 2041: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.42 schwarze 2042: t = TAG_I;
1.1 schwarze 2043: break;
2044: case(MDOC__C):
1.2 schwarze 2045: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1 schwarze 2046: break;
2047: case(MDOC__D):
1.2 schwarze 2048: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1 schwarze 2049: break;
2050: case(MDOC__I):
1.2 schwarze 2051: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.42 schwarze 2052: t = TAG_I;
1.1 schwarze 2053: break;
2054: case(MDOC__J):
1.2 schwarze 2055: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.42 schwarze 2056: t = TAG_I;
1.1 schwarze 2057: break;
2058: case(MDOC__N):
1.2 schwarze 2059: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1 schwarze 2060: break;
2061: case(MDOC__O):
1.2 schwarze 2062: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1 schwarze 2063: break;
2064: case(MDOC__P):
1.2 schwarze 2065: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1 schwarze 2066: break;
2067: case(MDOC__Q):
1.2 schwarze 2068: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1 schwarze 2069: break;
2070: case(MDOC__R):
1.2 schwarze 2071: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1 schwarze 2072: break;
2073: case(MDOC__T):
1.2 schwarze 2074: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1 schwarze 2075: break;
1.2 schwarze 2076: case(MDOC__U):
2077: PAIR_CLASS_INIT(&tag[0], "link-ref");
2078: break;
1.1 schwarze 2079: case(MDOC__V):
1.2 schwarze 2080: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1 schwarze 2081: break;
2082: default:
2083: abort();
2084: /* NOTREACHED */
2085: }
2086:
1.2 schwarze 2087: if (MDOC__U != n->tok) {
1.42 schwarze 2088: print_otag(h, t, 1, tag);
1.2 schwarze 2089: return(1);
2090: }
2091:
2092: PAIR_HREF_INIT(&tag[1], n->child->string);
2093: print_otag(h, TAG_A, 2, tag);
1.30 schwarze 2094:
1.1 schwarze 2095: return(1);
2096: }
2097:
2098:
2099: /* ARGSUSED */
2100: static void
2101: mdoc__x_post(MDOC_ARGS)
2102: {
1.30 schwarze 2103:
2104: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2105: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2106: if (NULL == n->prev || MDOC__A != n->prev->tok)
2107: return;
1.1 schwarze 2108:
1.12 schwarze 2109: /* TODO: %U */
2110:
1.31 schwarze 2111: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2112: return;
2113:
1.56 schwarze 2114: h->flags |= HTML_NOSPACE;
1.1 schwarze 2115: print_text(h, n->next ? "," : ".");
1.25 schwarze 2116: }
2117:
2118:
2119: /* ARGSUSED */
2120: static int
2121: mdoc_bk_pre(MDOC_ARGS)
2122: {
2123:
2124: switch (n->type) {
2125: case (MDOC_BLOCK):
2126: break;
2127: case (MDOC_HEAD):
2128: return(0);
2129: case (MDOC_BODY):
1.41 schwarze 2130: if (n->parent->args || 0 == n->prev->nchild)
2131: h->flags |= HTML_PREKEEP;
1.25 schwarze 2132: break;
2133: default:
2134: abort();
2135: /* NOTREACHED */
2136: }
2137:
2138: return(1);
2139: }
2140:
2141:
2142: /* ARGSUSED */
2143: static void
2144: mdoc_bk_post(MDOC_ARGS)
2145: {
2146:
2147: if (MDOC_BODY == n->type)
2148: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.1 schwarze 2149: }
1.32 schwarze 2150:
2151:
2152: /* ARGSUSED */
2153: static int
2154: mdoc_quote_pre(MDOC_ARGS)
2155: {
2156: struct htmlpair tag;
2157:
2158: if (MDOC_BODY != n->type)
2159: return(1);
2160:
2161: switch (n->tok) {
2162: case (MDOC_Ao):
2163: /* FALLTHROUGH */
2164: case (MDOC_Aq):
2165: print_text(h, "\\(la");
2166: break;
2167: case (MDOC_Bro):
2168: /* FALLTHROUGH */
2169: case (MDOC_Brq):
2170: print_text(h, "\\(lC");
2171: break;
2172: case (MDOC_Bo):
2173: /* FALLTHROUGH */
2174: case (MDOC_Bq):
2175: print_text(h, "\\(lB");
2176: break;
2177: case (MDOC_Oo):
2178: /* FALLTHROUGH */
2179: case (MDOC_Op):
2180: print_text(h, "\\(lB");
1.36 schwarze 2181: h->flags |= HTML_NOSPACE;
1.32 schwarze 2182: PAIR_CLASS_INIT(&tag, "opt");
2183: print_otag(h, TAG_SPAN, 1, &tag);
2184: break;
1.65 schwarze 2185: case (MDOC_Eo):
2186: break;
1.32 schwarze 2187: case (MDOC_Do):
2188: /* FALLTHROUGH */
2189: case (MDOC_Dq):
2190: /* FALLTHROUGH */
2191: case (MDOC_Qo):
2192: /* FALLTHROUGH */
2193: case (MDOC_Qq):
2194: print_text(h, "\\(lq");
2195: break;
2196: case (MDOC_Po):
2197: /* FALLTHROUGH */
2198: case (MDOC_Pq):
2199: print_text(h, "(");
2200: break;
2201: case (MDOC_Ql):
1.61 schwarze 2202: print_text(h, "\\(oq");
2203: h->flags |= HTML_NOSPACE;
2204: PAIR_CLASS_INIT(&tag, "lit");
2205: print_otag(h, TAG_CODE, 1, &tag);
2206: break;
1.32 schwarze 2207: case (MDOC_So):
2208: /* FALLTHROUGH */
2209: case (MDOC_Sq):
2210: print_text(h, "\\(oq");
2211: break;
2212: default:
2213: abort();
2214: /* NOTREACHED */
2215: }
2216:
2217: h->flags |= HTML_NOSPACE;
2218: return(1);
2219: }
2220:
2221:
2222: /* ARGSUSED */
2223: static void
2224: mdoc_quote_post(MDOC_ARGS)
2225: {
2226:
2227: if (MDOC_BODY != n->type)
2228: return;
2229:
2230: h->flags |= HTML_NOSPACE;
2231:
2232: switch (n->tok) {
2233: case (MDOC_Ao):
2234: /* FALLTHROUGH */
2235: case (MDOC_Aq):
2236: print_text(h, "\\(ra");
2237: break;
2238: case (MDOC_Bro):
2239: /* FALLTHROUGH */
2240: case (MDOC_Brq):
2241: print_text(h, "\\(rC");
2242: break;
2243: case (MDOC_Oo):
2244: /* FALLTHROUGH */
2245: case (MDOC_Op):
2246: /* FALLTHROUGH */
2247: case (MDOC_Bo):
2248: /* FALLTHROUGH */
2249: case (MDOC_Bq):
2250: print_text(h, "\\(rB");
1.65 schwarze 2251: break;
2252: case (MDOC_Eo):
1.32 schwarze 2253: break;
2254: case (MDOC_Qo):
2255: /* FALLTHROUGH */
2256: case (MDOC_Qq):
2257: /* FALLTHROUGH */
2258: case (MDOC_Do):
2259: /* FALLTHROUGH */
2260: case (MDOC_Dq):
2261: print_text(h, "\\(rq");
2262: break;
2263: case (MDOC_Po):
2264: /* FALLTHROUGH */
2265: case (MDOC_Pq):
2266: print_text(h, ")");
2267: break;
2268: case (MDOC_Ql):
2269: /* FALLTHROUGH */
2270: case (MDOC_So):
2271: /* FALLTHROUGH */
2272: case (MDOC_Sq):
1.66 matthew 2273: print_text(h, "\\(cq");
1.32 schwarze 2274: break;
2275: default:
2276: abort();
2277: /* NOTREACHED */
2278: }
2279: }
2280:
2281: