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