Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.32
1.32 ! schwarze 1: /* $Id: mdoc_html.c,v 1.31 2010/09/26 18:23:54 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);
90: static int mdoc_in_pre(MDOC_ARGS);
1.18 schwarze 91: static int mdoc_it_block_pre(MDOC_ARGS, enum mdoc_list,
92: int, struct roffsu *, struct roffsu *);
93: static int mdoc_it_head_pre(MDOC_ARGS, enum mdoc_list,
1.1 schwarze 94: struct roffsu *);
1.20 schwarze 95: static int mdoc_it_body_pre(MDOC_ARGS, enum mdoc_list,
96: struct roffsu *);
1.1 schwarze 97: static int mdoc_it_pre(MDOC_ARGS);
98: static int mdoc_lb_pre(MDOC_ARGS);
99: static int mdoc_li_pre(MDOC_ARGS);
100: static int mdoc_lk_pre(MDOC_ARGS);
101: static int mdoc_mt_pre(MDOC_ARGS);
102: static int mdoc_ms_pre(MDOC_ARGS);
103: static int mdoc_nd_pre(MDOC_ARGS);
104: static int mdoc_nm_pre(MDOC_ARGS);
105: static int mdoc_ns_pre(MDOC_ARGS);
106: static int mdoc_pa_pre(MDOC_ARGS);
107: static void mdoc_pf_post(MDOC_ARGS);
108: static int mdoc_pf_pre(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.1 schwarze 198: {NULL, NULL}, /* No */
199: {mdoc_ns_pre, NULL}, /* Ns */
200: {mdoc_xx_pre, NULL}, /* Nx */
201: {mdoc_xx_pre, NULL}, /* Ox */
202: {NULL, NULL}, /* Pc */
203: {mdoc_pf_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.28 schwarze 1315: if (nn->next && nn->next->line == nn->line)
1316: continue;
1317: print_text(h, "\n");
1318: h->flags |= HTML_NOSPACE;
1.1 schwarze 1319: }
1320:
1321: return(0);
1322: }
1323:
1324:
1325: /* ARGSUSED */
1326: static int
1327: mdoc_pa_pre(MDOC_ARGS)
1328: {
1329: struct htmlpair tag;
1330:
1331: PAIR_CLASS_INIT(&tag, "file");
1332: print_otag(h, TAG_SPAN, 1, &tag);
1333: return(1);
1334: }
1335:
1336:
1337: /* ARGSUSED */
1338: static int
1339: mdoc_ad_pre(MDOC_ARGS)
1340: {
1341: struct htmlpair tag;
1342:
1343: PAIR_CLASS_INIT(&tag, "addr");
1344: print_otag(h, TAG_SPAN, 1, &tag);
1345: return(1);
1346: }
1347:
1348:
1349: /* ARGSUSED */
1350: static int
1351: mdoc_an_pre(MDOC_ARGS)
1352: {
1353: struct htmlpair tag;
1354:
1355: /* TODO: -split and -nosplit (see termp_an_pre()). */
1356:
1357: PAIR_CLASS_INIT(&tag, "author");
1358: print_otag(h, TAG_SPAN, 1, &tag);
1359: return(1);
1360: }
1361:
1362:
1363: /* ARGSUSED */
1364: static int
1365: mdoc_cd_pre(MDOC_ARGS)
1366: {
1367: struct htmlpair tag;
1368:
1.21 schwarze 1369: synopsis_pre(h, n);
1.1 schwarze 1370: PAIR_CLASS_INIT(&tag, "config");
1371: print_otag(h, TAG_SPAN, 1, &tag);
1372: return(1);
1373: }
1374:
1375:
1376: /* ARGSUSED */
1377: static int
1378: mdoc_dv_pre(MDOC_ARGS)
1379: {
1380: struct htmlpair tag;
1381:
1382: PAIR_CLASS_INIT(&tag, "define");
1383: print_otag(h, TAG_SPAN, 1, &tag);
1384: return(1);
1385: }
1386:
1387:
1388: /* ARGSUSED */
1389: static int
1390: mdoc_ev_pre(MDOC_ARGS)
1391: {
1392: struct htmlpair tag;
1393:
1394: PAIR_CLASS_INIT(&tag, "env");
1395: print_otag(h, TAG_SPAN, 1, &tag);
1396: return(1);
1397: }
1398:
1399:
1400: /* ARGSUSED */
1401: static int
1402: mdoc_er_pre(MDOC_ARGS)
1403: {
1404: struct htmlpair tag;
1405:
1406: PAIR_CLASS_INIT(&tag, "errno");
1407: print_otag(h, TAG_SPAN, 1, &tag);
1408: return(1);
1409: }
1410:
1411:
1412: /* ARGSUSED */
1413: static int
1414: mdoc_fa_pre(MDOC_ARGS)
1415: {
1416: const struct mdoc_node *nn;
1417: struct htmlpair tag;
1418: struct tag *t;
1419:
1420: PAIR_CLASS_INIT(&tag, "farg");
1421: if (n->parent->tok != MDOC_Fo) {
1422: print_otag(h, TAG_SPAN, 1, &tag);
1423: return(1);
1424: }
1425:
1426: for (nn = n->child; nn; nn = nn->next) {
1427: t = print_otag(h, TAG_SPAN, 1, &tag);
1428: print_text(h, nn->string);
1429: print_tagq(h, t);
1430: if (nn->next)
1431: print_text(h, ",");
1432: }
1433:
1434: if (n->child && n->next && n->next->tok == MDOC_Fa)
1435: print_text(h, ",");
1436:
1437: return(0);
1438: }
1439:
1440:
1441: /* ARGSUSED */
1442: static int
1443: mdoc_fd_pre(MDOC_ARGS)
1444: {
1445: struct htmlpair tag;
1446:
1.21 schwarze 1447: synopsis_pre(h, n);
1448:
1.1 schwarze 1449: PAIR_CLASS_INIT(&tag, "macro");
1450: print_otag(h, TAG_SPAN, 1, &tag);
1451: return(1);
1452: }
1453:
1454:
1455: /* ARGSUSED */
1456: static int
1457: mdoc_vt_pre(MDOC_ARGS)
1458: {
1459: struct htmlpair tag;
1460:
1.21 schwarze 1461: if (MDOC_BLOCK == n->type) {
1462: synopsis_pre(h, n);
1.7 schwarze 1463: return(1);
1.21 schwarze 1464: } else if (MDOC_ELEM == n->type) {
1465: synopsis_pre(h, n);
1.7 schwarze 1466: } else if (MDOC_HEAD == n->type)
1467: return(0);
1.1 schwarze 1468:
1469: PAIR_CLASS_INIT(&tag, "type");
1470: print_otag(h, TAG_SPAN, 1, &tag);
1471: return(1);
1472: }
1473:
1474:
1475: /* ARGSUSED */
1476: static int
1477: mdoc_ft_pre(MDOC_ARGS)
1478: {
1479: struct htmlpair tag;
1480:
1.21 schwarze 1481: synopsis_pre(h, n);
1.1 schwarze 1482: PAIR_CLASS_INIT(&tag, "ftype");
1483: print_otag(h, TAG_SPAN, 1, &tag);
1484: return(1);
1485: }
1486:
1487:
1488: /* ARGSUSED */
1489: static int
1490: mdoc_fn_pre(MDOC_ARGS)
1491: {
1492: struct tag *t;
1493: struct htmlpair tag[2];
1494: const struct mdoc_node *nn;
1495: char nbuf[BUFSIZ];
1496: const char *sp, *ep;
1497: int sz, i;
1498:
1.21 schwarze 1499: synopsis_pre(h, n);
1.1 schwarze 1500:
1501: /* Split apart into type and name. */
1502: assert(n->child->string);
1503: sp = n->child->string;
1504:
1505: ep = strchr(sp, ' ');
1506: if (NULL != ep) {
1507: PAIR_CLASS_INIT(&tag[0], "ftype");
1508: t = print_otag(h, TAG_SPAN, 1, tag);
1509:
1510: while (ep) {
1511: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1512: (void)memcpy(nbuf, sp, (size_t)sz);
1513: nbuf[sz] = '\0';
1514: print_text(h, nbuf);
1515: sp = ++ep;
1516: ep = strchr(sp, ' ');
1517: }
1518: print_tagq(h, t);
1519: }
1520:
1521: PAIR_CLASS_INIT(&tag[0], "fname");
1.11 schwarze 1522:
1523: /*
1524: * FIXME: only refer to IDs that we know exist.
1525: */
1526:
1527: #if 0
1.23 schwarze 1528: if (MDOC_SYNPRETTY & n->flags) {
1.11 schwarze 1529: nbuf[0] = '\0';
1530: html_idcat(nbuf, sp, BUFSIZ);
1531: PAIR_ID_INIT(&tag[1], nbuf);
1532: } else {
1533: strlcpy(nbuf, "#", BUFSIZ);
1534: html_idcat(nbuf, sp, BUFSIZ);
1535: PAIR_HREF_INIT(&tag[1], nbuf);
1536: }
1537: #endif
1538:
1.1 schwarze 1539: t = print_otag(h, TAG_SPAN, 1, tag);
1540:
1541: if (sp) {
1.11 schwarze 1542: strlcpy(nbuf, sp, BUFSIZ);
1.1 schwarze 1543: print_text(h, nbuf);
1544: }
1545:
1546: print_tagq(h, t);
1547:
1548: h->flags |= HTML_NOSPACE;
1549: print_text(h, "(");
1550:
1551: bufinit(h);
1552: PAIR_CLASS_INIT(&tag[0], "farg");
1553: bufcat_style(h, "white-space", "nowrap");
1554: PAIR_STYLE_INIT(&tag[1], h);
1555:
1556: for (nn = n->child->next; nn; nn = nn->next) {
1557: i = 1;
1.23 schwarze 1558: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1559: i = 2;
1560: t = print_otag(h, TAG_SPAN, i, tag);
1561: print_text(h, nn->string);
1562: print_tagq(h, t);
1563: if (nn->next)
1564: print_text(h, ",");
1565: }
1566:
1567: print_text(h, ")");
1.23 schwarze 1568: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1569: print_text(h, ";");
1570:
1571: return(0);
1572: }
1573:
1574:
1575: /* ARGSUSED */
1576: static int
1.26 schwarze 1577: mdoc_sm_pre(MDOC_ARGS)
1578: {
1579:
1580: assert(n->child && MDOC_TEXT == n->child->type);
1581: if (0 == strcmp("on", n->child->string)) {
1582: /* FIXME: no p->col to check... */
1583: h->flags &= ~HTML_NOSPACE;
1584: h->flags &= ~HTML_NONOSPACE;
1585: } else
1586: h->flags |= HTML_NONOSPACE;
1587:
1588: return(0);
1589: }
1590:
1591:
1592: /* ARGSUSED */
1593: static int
1.1 schwarze 1594: mdoc_sp_pre(MDOC_ARGS)
1595: {
1596: int len;
1597: struct htmlpair tag;
1598: struct roffsu su;
1599:
1600: switch (n->tok) {
1601: case (MDOC_sp):
1602: /* FIXME: can this have a scaling indicator? */
1603: len = n->child ? atoi(n->child->string) : 1;
1604: break;
1605: case (MDOC_br):
1606: len = 0;
1607: break;
1608: default:
1.26 schwarze 1609: assert(n->parent);
1610: if ((NULL == n->next || NULL == n->prev) &&
1611: (MDOC_Ss == n->parent->tok ||
1612: MDOC_Sh == n->parent->tok))
1613: return(0);
1.1 schwarze 1614: len = 1;
1615: break;
1616: }
1617:
1618: SCALE_VS_INIT(&su, len);
1619: bufcat_su(h, "height", &su);
1620: PAIR_STYLE_INIT(&tag, h);
1621: print_otag(h, TAG_DIV, 1, &tag);
1.3 schwarze 1622: /* So the div isn't empty: */
1623: print_text(h, "\\~");
1624:
1625: return(0);
1.1 schwarze 1626:
1627: }
1628:
1629:
1630: /* ARGSUSED */
1631: static int
1632: mdoc_lk_pre(MDOC_ARGS)
1633: {
1634: const struct mdoc_node *nn;
1635: struct htmlpair tag[2];
1636:
1637: nn = n->child;
1638:
1639: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.11 schwarze 1640: PAIR_HREF_INIT(&tag[1], nn->string);
1.1 schwarze 1641: print_otag(h, TAG_A, 2, tag);
1642:
1.2 schwarze 1643: if (NULL == nn->next)
1644: return(1);
1645:
1.1 schwarze 1646: for (nn = nn->next; nn; nn = nn->next)
1647: print_text(h, nn->string);
1648:
1649: return(0);
1650: }
1651:
1652:
1653: /* ARGSUSED */
1654: static int
1655: mdoc_mt_pre(MDOC_ARGS)
1656: {
1657: struct htmlpair tag[2];
1658: struct tag *t;
1659: const struct mdoc_node *nn;
1660:
1661: PAIR_CLASS_INIT(&tag[0], "link-mail");
1662:
1663: for (nn = n->child; nn; nn = nn->next) {
1664: bufinit(h);
1665: bufcat(h, "mailto:");
1666: bufcat(h, nn->string);
1.10 schwarze 1667: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1668: t = print_otag(h, TAG_A, 2, tag);
1669: print_text(h, nn->string);
1670: print_tagq(h, t);
1671: }
1672:
1673: return(0);
1674: }
1675:
1676:
1677: /* ARGSUSED */
1678: static int
1679: mdoc_fo_pre(MDOC_ARGS)
1680: {
1.20 schwarze 1681: struct htmlpair tag;
1682: struct tag *t;
1.1 schwarze 1683:
1684: if (MDOC_BODY == n->type) {
1685: h->flags |= HTML_NOSPACE;
1686: print_text(h, "(");
1687: h->flags |= HTML_NOSPACE;
1688: return(1);
1.20 schwarze 1689: } else if (MDOC_BLOCK == n->type) {
1.21 schwarze 1690: synopsis_pre(h, n);
1.1 schwarze 1691: return(1);
1.11 schwarze 1692: }
1.1 schwarze 1693:
1.20 schwarze 1694: /* XXX: we drop non-initial arguments as per groff. */
1695:
1696: assert(n->child);
1697: assert(n->child->string);
1698:
1.1 schwarze 1699: PAIR_CLASS_INIT(&tag, "fname");
1.20 schwarze 1700: t = print_otag(h, TAG_SPAN, 1, &tag);
1701: print_text(h, n->child->string);
1702: print_tagq(h, t);
1703: return(0);
1.1 schwarze 1704: }
1705:
1706:
1707: /* ARGSUSED */
1708: static void
1709: mdoc_fo_post(MDOC_ARGS)
1710: {
1.21 schwarze 1711:
1.1 schwarze 1712: if (MDOC_BODY != n->type)
1713: return;
1714: print_text(h, ")");
1715: print_text(h, ";");
1716: }
1717:
1718:
1719: /* ARGSUSED */
1720: static int
1721: mdoc_in_pre(MDOC_ARGS)
1722: {
1723: const struct mdoc_node *nn;
1724: struct tag *t;
1725: struct htmlpair tag[2];
1726: int i;
1727:
1.21 schwarze 1728: synopsis_pre(h, n);
1729:
1.1 schwarze 1730: PAIR_CLASS_INIT(&tag[0], "includes");
1731: print_otag(h, TAG_SPAN, 1, tag);
1732:
1.23 schwarze 1733: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.1 schwarze 1734: print_text(h, "#include");
1735:
1736: print_text(h, "<");
1737: h->flags |= HTML_NOSPACE;
1738:
1739: for (nn = n->child; nn; nn = nn->next) {
1740: PAIR_CLASS_INIT(&tag[0], "link-includes");
1741: i = 1;
1.3 schwarze 1742: bufinit(h);
1.1 schwarze 1743: if (h->base_includes) {
1744: buffmt_includes(h, nn->string);
1.11 schwarze 1745: PAIR_HREF_INIT(&tag[i], h->buf);
1746: i++;
1.1 schwarze 1747: }
1748: t = print_otag(h, TAG_A, i, tag);
1749: print_mdoc_node(m, nn, h);
1750: print_tagq(h, t);
1751: }
1752:
1753: h->flags |= HTML_NOSPACE;
1754: print_text(h, ">");
1.20 schwarze 1755:
1.1 schwarze 1756: return(0);
1757: }
1758:
1759:
1760: /* ARGSUSED */
1761: static int
1762: mdoc_ic_pre(MDOC_ARGS)
1763: {
1764: struct htmlpair tag;
1765:
1766: PAIR_CLASS_INIT(&tag, "cmd");
1767: print_otag(h, TAG_SPAN, 1, &tag);
1768: return(1);
1769: }
1770:
1771:
1772: /* ARGSUSED */
1773: static int
1774: mdoc_rv_pre(MDOC_ARGS)
1775: {
1776: const struct mdoc_node *nn;
1777: struct htmlpair tag;
1778: struct tag *t;
1779:
1780: print_otag(h, TAG_DIV, 0, NULL);
1781: print_text(h, "The");
1782:
1783: for (nn = n->child; nn; nn = nn->next) {
1784: PAIR_CLASS_INIT(&tag, "fname");
1785: t = print_otag(h, TAG_SPAN, 1, &tag);
1786: print_text(h, nn->string);
1787: print_tagq(h, t);
1788:
1789: h->flags |= HTML_NOSPACE;
1790: if (nn->next && NULL == nn->next->next)
1791: print_text(h, "(), and");
1792: else if (nn->next)
1793: print_text(h, "(),");
1794: else
1795: print_text(h, "()");
1796: }
1797:
1.17 schwarze 1798: if (n->child && n->child->next)
1.1 schwarze 1799: print_text(h, "functions return");
1800: else
1801: print_text(h, "function returns");
1802:
1803: print_text(h, "the value 0 if successful; otherwise the value "
1804: "-1 is returned and the global variable");
1805:
1806: PAIR_CLASS_INIT(&tag, "var");
1807: t = print_otag(h, TAG_SPAN, 1, &tag);
1808: print_text(h, "errno");
1809: print_tagq(h, t);
1810: print_text(h, "is set to indicate the error.");
1811: return(0);
1812: }
1813:
1814:
1815: /* ARGSUSED */
1816: static int
1817: mdoc_va_pre(MDOC_ARGS)
1818: {
1819: struct htmlpair tag;
1820:
1821: PAIR_CLASS_INIT(&tag, "var");
1822: print_otag(h, TAG_SPAN, 1, &tag);
1823: return(1);
1824: }
1825:
1826:
1827: /* ARGSUSED */
1828: static int
1829: mdoc_ap_pre(MDOC_ARGS)
1830: {
1831:
1832: h->flags |= HTML_NOSPACE;
1833: print_text(h, "\\(aq");
1834: h->flags |= HTML_NOSPACE;
1835: return(1);
1836: }
1837:
1838:
1839: /* ARGSUSED */
1840: static int
1841: mdoc_bf_pre(MDOC_ARGS)
1842: {
1843: struct htmlpair tag[2];
1844: struct roffsu su;
1845:
1846: if (MDOC_HEAD == n->type)
1847: return(0);
1.25 schwarze 1848: else if (MDOC_BODY != n->type)
1.1 schwarze 1849: return(1);
1850:
1.25 schwarze 1851: assert(n->data.Bf);
1.1 schwarze 1852:
1.25 schwarze 1853: if (FONT_Em == n->data.Bf->font)
1854: PAIR_CLASS_INIT(&tag[0], "emph");
1855: else if (FONT_Sy == n->data.Bf->font)
1856: PAIR_CLASS_INIT(&tag[0], "symb");
1857: else if (FONT_Li == n->data.Bf->font)
1858: PAIR_CLASS_INIT(&tag[0], "lit");
1859: else
1860: PAIR_CLASS_INIT(&tag[0], "none");
1.1 schwarze 1861:
1.25 schwarze 1862: /*
1863: * We want this to be inline-formatted, but needs to be div to
1864: * accept block children.
1865: */
1.1 schwarze 1866: bufcat_style(h, "display", "inline");
1867: SCALE_HS_INIT(&su, 1);
1.25 schwarze 1868: /* Needs a left-margin for spacing. */
1869: bufcat_su(h, "margin-left", &su);
1.1 schwarze 1870: PAIR_STYLE_INIT(&tag[1], h);
1871: print_otag(h, TAG_DIV, 2, tag);
1872: return(1);
1873: }
1874:
1875:
1876: /* ARGSUSED */
1877: static int
1878: mdoc_ms_pre(MDOC_ARGS)
1879: {
1880: struct htmlpair tag;
1881:
1882: PAIR_CLASS_INIT(&tag, "symb");
1883: print_otag(h, TAG_SPAN, 1, &tag);
1884: return(1);
1885: }
1886:
1887:
1888: /* ARGSUSED */
1889: static int
1890: mdoc_pf_pre(MDOC_ARGS)
1891: {
1892:
1893: h->flags |= HTML_IGNDELIM;
1894: return(1);
1895: }
1896:
1897:
1898: /* ARGSUSED */
1899: static void
1900: mdoc_pf_post(MDOC_ARGS)
1901: {
1902:
1903: h->flags &= ~HTML_IGNDELIM;
1904: h->flags |= HTML_NOSPACE;
1905: }
1906:
1907:
1908: /* ARGSUSED */
1909: static int
1910: mdoc_rs_pre(MDOC_ARGS)
1911: {
1912: struct htmlpair tag;
1913:
1914: if (MDOC_BLOCK != n->type)
1915: return(1);
1916:
1917: if (n->prev && SEC_SEE_ALSO == n->sec) {
1.31 schwarze 1918: print_otag(h, TAG_BR, 0, NULL);
1919: print_otag(h, TAG_BR, 0, NULL);
1920: }
1.1 schwarze 1921:
1922: PAIR_CLASS_INIT(&tag, "ref");
1923: print_otag(h, TAG_SPAN, 1, &tag);
1924: return(1);
1925: }
1926:
1927:
1928:
1929: /* ARGSUSED */
1930: static int
1931: mdoc_li_pre(MDOC_ARGS)
1932: {
1933: struct htmlpair tag;
1934:
1935: PAIR_CLASS_INIT(&tag, "lit");
1936: print_otag(h, TAG_SPAN, 1, &tag);
1937: return(1);
1938: }
1939:
1940:
1941: /* ARGSUSED */
1942: static int
1943: mdoc_sy_pre(MDOC_ARGS)
1944: {
1945: struct htmlpair tag;
1946:
1947: PAIR_CLASS_INIT(&tag, "symb");
1948: print_otag(h, TAG_SPAN, 1, &tag);
1949: return(1);
1950: }
1951:
1952:
1953: /* ARGSUSED */
1954: static int
1955: mdoc_bt_pre(MDOC_ARGS)
1956: {
1957:
1958: print_text(h, "is currently in beta test.");
1959: return(0);
1960: }
1961:
1962:
1963: /* ARGSUSED */
1964: static int
1965: mdoc_ud_pre(MDOC_ARGS)
1966: {
1967:
1968: print_text(h, "currently under development.");
1969: return(0);
1970: }
1971:
1972:
1973: /* ARGSUSED */
1974: static int
1975: mdoc_lb_pre(MDOC_ARGS)
1976: {
1977: struct htmlpair tag;
1978:
1.13 schwarze 1979: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.1 schwarze 1980: print_otag(h, TAG_DIV, 0, NULL);
1981: PAIR_CLASS_INIT(&tag, "lib");
1982: print_otag(h, TAG_SPAN, 1, &tag);
1983: return(1);
1984: }
1985:
1986:
1987: /* ARGSUSED */
1988: static int
1989: mdoc__x_pre(MDOC_ARGS)
1990: {
1.2 schwarze 1991: struct htmlpair tag[2];
1.1 schwarze 1992:
1993: switch (n->tok) {
1994: case(MDOC__A):
1.2 schwarze 1995: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.30 schwarze 1996: if (n->prev && MDOC__A == n->prev->tok)
1997: if (NULL == n->next || MDOC__A != n->next->tok)
1998: print_text(h, "and");
1.1 schwarze 1999: break;
2000: case(MDOC__B):
1.2 schwarze 2001: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.1 schwarze 2002: break;
2003: case(MDOC__C):
1.2 schwarze 2004: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1 schwarze 2005: break;
2006: case(MDOC__D):
1.2 schwarze 2007: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1 schwarze 2008: break;
2009: case(MDOC__I):
1.2 schwarze 2010: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.1 schwarze 2011: break;
2012: case(MDOC__J):
1.2 schwarze 2013: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.1 schwarze 2014: break;
2015: case(MDOC__N):
1.2 schwarze 2016: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1 schwarze 2017: break;
2018: case(MDOC__O):
1.2 schwarze 2019: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1 schwarze 2020: break;
2021: case(MDOC__P):
1.2 schwarze 2022: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1 schwarze 2023: break;
2024: case(MDOC__Q):
1.2 schwarze 2025: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1 schwarze 2026: break;
2027: case(MDOC__R):
1.2 schwarze 2028: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1 schwarze 2029: break;
2030: case(MDOC__T):
1.2 schwarze 2031: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1 schwarze 2032: break;
1.2 schwarze 2033: case(MDOC__U):
2034: PAIR_CLASS_INIT(&tag[0], "link-ref");
2035: break;
1.1 schwarze 2036: case(MDOC__V):
1.2 schwarze 2037: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1 schwarze 2038: break;
2039: default:
2040: abort();
2041: /* NOTREACHED */
2042: }
2043:
1.2 schwarze 2044: if (MDOC__U != n->tok) {
2045: print_otag(h, TAG_SPAN, 1, tag);
2046: return(1);
2047: }
2048:
2049: PAIR_HREF_INIT(&tag[1], n->child->string);
2050: print_otag(h, TAG_A, 2, tag);
1.30 schwarze 2051:
1.1 schwarze 2052: return(1);
2053: }
2054:
2055:
2056: /* ARGSUSED */
2057: static void
2058: mdoc__x_post(MDOC_ARGS)
2059: {
1.30 schwarze 2060:
2061: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2062: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2063: if (NULL == n->prev || MDOC__A != n->prev->tok)
2064: return;
1.1 schwarze 2065:
1.12 schwarze 2066: /* TODO: %U */
2067:
1.31 schwarze 2068: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2069: return;
2070:
1.1 schwarze 2071: print_text(h, n->next ? "," : ".");
1.25 schwarze 2072: }
2073:
2074:
2075: /* ARGSUSED */
2076: static int
2077: mdoc_bk_pre(MDOC_ARGS)
2078: {
2079:
2080: switch (n->type) {
2081: case (MDOC_BLOCK):
2082: break;
2083: case (MDOC_HEAD):
2084: return(0);
2085: case (MDOC_BODY):
2086: h->flags |= HTML_PREKEEP;
2087: break;
2088: default:
2089: abort();
2090: /* NOTREACHED */
2091: }
2092:
2093: return(1);
2094: }
2095:
2096:
2097: /* ARGSUSED */
2098: static void
2099: mdoc_bk_post(MDOC_ARGS)
2100: {
2101:
2102: if (MDOC_BODY == n->type)
2103: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.1 schwarze 2104: }
1.32 ! schwarze 2105:
! 2106:
! 2107: /* ARGSUSED */
! 2108: static int
! 2109: mdoc_quote_pre(MDOC_ARGS)
! 2110: {
! 2111: struct htmlpair tag;
! 2112:
! 2113: if (MDOC_BODY != n->type)
! 2114: return(1);
! 2115:
! 2116: switch (n->tok) {
! 2117: case (MDOC_Ao):
! 2118: /* FALLTHROUGH */
! 2119: case (MDOC_Aq):
! 2120: print_text(h, "\\(la");
! 2121: break;
! 2122: case (MDOC_Bro):
! 2123: /* FALLTHROUGH */
! 2124: case (MDOC_Brq):
! 2125: print_text(h, "\\(lC");
! 2126: break;
! 2127: case (MDOC_Bo):
! 2128: /* FALLTHROUGH */
! 2129: case (MDOC_Bq):
! 2130: print_text(h, "\\(lB");
! 2131: break;
! 2132: case (MDOC_Oo):
! 2133: /* FALLTHROUGH */
! 2134: case (MDOC_Op):
! 2135: print_text(h, "\\(lB");
! 2136: PAIR_CLASS_INIT(&tag, "opt");
! 2137: print_otag(h, TAG_SPAN, 1, &tag);
! 2138: break;
! 2139: case (MDOC_Do):
! 2140: /* FALLTHROUGH */
! 2141: case (MDOC_Dq):
! 2142: /* FALLTHROUGH */
! 2143: case (MDOC_Qo):
! 2144: /* FALLTHROUGH */
! 2145: case (MDOC_Qq):
! 2146: print_text(h, "\\(lq");
! 2147: break;
! 2148: case (MDOC_Po):
! 2149: /* FALLTHROUGH */
! 2150: case (MDOC_Pq):
! 2151: print_text(h, "(");
! 2152: break;
! 2153: case (MDOC_Ql):
! 2154: /* FALLTHROUGH */
! 2155: case (MDOC_So):
! 2156: /* FALLTHROUGH */
! 2157: case (MDOC_Sq):
! 2158: print_text(h, "\\(oq");
! 2159: break;
! 2160: default:
! 2161: abort();
! 2162: /* NOTREACHED */
! 2163: }
! 2164:
! 2165: h->flags |= HTML_NOSPACE;
! 2166: return(1);
! 2167: }
! 2168:
! 2169:
! 2170: /* ARGSUSED */
! 2171: static void
! 2172: mdoc_quote_post(MDOC_ARGS)
! 2173: {
! 2174:
! 2175: if (MDOC_BODY != n->type)
! 2176: return;
! 2177:
! 2178: h->flags |= HTML_NOSPACE;
! 2179:
! 2180: switch (n->tok) {
! 2181: case (MDOC_Ao):
! 2182: /* FALLTHROUGH */
! 2183: case (MDOC_Aq):
! 2184: print_text(h, "\\(ra");
! 2185: break;
! 2186: case (MDOC_Bro):
! 2187: /* FALLTHROUGH */
! 2188: case (MDOC_Brq):
! 2189: print_text(h, "\\(rC");
! 2190: break;
! 2191: case (MDOC_Oo):
! 2192: /* FALLTHROUGH */
! 2193: case (MDOC_Op):
! 2194: /* FALLTHROUGH */
! 2195: case (MDOC_Bo):
! 2196: /* FALLTHROUGH */
! 2197: case (MDOC_Bq):
! 2198: print_text(h, "\\(rB");
! 2199: break;
! 2200: case (MDOC_Qo):
! 2201: /* FALLTHROUGH */
! 2202: case (MDOC_Qq):
! 2203: /* FALLTHROUGH */
! 2204: case (MDOC_Do):
! 2205: /* FALLTHROUGH */
! 2206: case (MDOC_Dq):
! 2207: print_text(h, "\\(rq");
! 2208: break;
! 2209: case (MDOC_Po):
! 2210: /* FALLTHROUGH */
! 2211: case (MDOC_Pq):
! 2212: print_text(h, ")");
! 2213: break;
! 2214: case (MDOC_Ql):
! 2215: /* FALLTHROUGH */
! 2216: case (MDOC_So):
! 2217: /* FALLTHROUGH */
! 2218: case (MDOC_Sq):
! 2219: print_text(h, "\\(aq");
! 2220: break;
! 2221: default:
! 2222: abort();
! 2223: /* NOTREACHED */
! 2224: }
! 2225: }
! 2226:
! 2227: