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