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