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