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