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