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