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