Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.40
1.40 ! schwarze 1: /* $Id: mdoc_html.c,v 1.39 2010/12/06 22:10:13 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.40 ! schwarze 462: struct htmlpair tag[2];
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.40 ! schwarze 468: PAIR_CLASS_INIT(&tag[0], "foot");
! 469: PAIR_SUMMARY_INIT(&tag[1], "Document Footer");
! 470: t = print_otag(h, TAG_TABLE, 2, tag);
1.3 schwarze 471:
1.1 schwarze 472: tt = print_otag(h, TAG_TR, 0, NULL);
473:
1.40 ! schwarze 474: PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1 schwarze 475: print_otag(h, TAG_TD, 1, tag);
1.40 ! schwarze 476:
1.1 schwarze 477: print_text(h, b);
478: print_stagq(h, tt);
479:
1.40 ! schwarze 480: PAIR_CLASS_INIT(&tag[0], "foot-os");
1.1 schwarze 481: print_otag(h, TAG_TD, 1, tag);
1.40 ! schwarze 482:
1.1 schwarze 483: print_text(h, m->os);
484: print_tagq(h, t);
485: }
486:
487:
488: /* ARGSUSED */
489: static int
490: mdoc_root_pre(MDOC_ARGS)
491: {
1.3 schwarze 492: struct htmlpair tag[3];
1.1 schwarze 493: struct tag *t, *tt;
494: char b[BUFSIZ], title[BUFSIZ];
495:
1.40 ! schwarze 496: strlcpy(b, m->vol, BUFSIZ);
1.1 schwarze 497:
498: if (m->arch) {
1.40 ! schwarze 499: strlcat(b, " (", BUFSIZ);
! 500: strlcat(b, m->arch, BUFSIZ);
! 501: strlcat(b, ")", BUFSIZ);
1.1 schwarze 502: }
503:
1.40 ! schwarze 504: snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.1 schwarze 505:
1.40 ! schwarze 506: PAIR_CLASS_INIT(&tag[0], "head");
! 507: PAIR_SUMMARY_INIT(&tag[1], "Document Header");
! 508: t = print_otag(h, TAG_TABLE, 2, tag);
1.3 schwarze 509:
1.1 schwarze 510: tt = print_otag(h, TAG_TR, 0, NULL);
511:
1.40 ! schwarze 512: PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1 schwarze 513: print_otag(h, TAG_TD, 1, tag);
1.40 ! schwarze 514:
1.1 schwarze 515: print_text(h, title);
516: print_stagq(h, tt);
517:
1.40 ! schwarze 518: PAIR_CLASS_INIT(&tag[0], "head-vol");
1.1 schwarze 519: print_otag(h, TAG_TD, 1, tag);
1.40 ! schwarze 520:
1.1 schwarze 521: print_text(h, b);
522: print_stagq(h, tt);
523:
1.40 ! schwarze 524: PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.1 schwarze 525: print_otag(h, TAG_TD, 1, tag);
1.40 ! schwarze 526:
1.1 schwarze 527: print_text(h, title);
528: print_tagq(h, t);
529: return(1);
530: }
531:
532:
533: /* ARGSUSED */
534: static int
535: mdoc_sh_pre(MDOC_ARGS)
536: {
1.40 ! schwarze 537: struct htmlpair tag;
! 538: char buf[BUFSIZ];
1.1 schwarze 539:
1.40 ! schwarze 540: if (MDOC_BLOCK == n->type) {
! 541: PAIR_CLASS_INIT(&tag, "section");
! 542: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 543: return(1);
1.40 ! schwarze 544: } else if (MDOC_BODY == n->type)
1.1 schwarze 545: return(1);
546:
1.3 schwarze 547: buf[0] = '\0';
1.40 ! schwarze 548: for (n = n->child; n; n = n->next) {
! 549: html_idcat(buf, n->string, BUFSIZ);
! 550: if (n->next)
1.3 schwarze 551: html_idcat(buf, " ", BUFSIZ);
1.1 schwarze 552: }
553:
1.40 ! schwarze 554: PAIR_ID_INIT(&tag, buf);
! 555: print_otag(h, TAG_H1, 1, &tag);
1.1 schwarze 556: return(1);
557: }
558:
559:
560: /* ARGSUSED */
561: static int
562: mdoc_ss_pre(MDOC_ARGS)
563: {
1.40 ! schwarze 564: struct htmlpair tag;
! 565: char buf[BUFSIZ];
1.1 schwarze 566:
1.40 ! schwarze 567: if (MDOC_BLOCK == n->type) {
! 568: PAIR_CLASS_INIT(&tag, "subsection");
! 569: print_otag(h, TAG_DIV, 1, &tag);
1.1 schwarze 570: return(1);
1.40 ! schwarze 571: } else if (MDOC_BODY == n->type)
1.1 schwarze 572: return(1);
573:
1.3 schwarze 574: buf[0] = '\0';
1.40 ! schwarze 575: for (n = n->child; n; n = n->next) {
! 576: html_idcat(buf, n->string, BUFSIZ);
! 577: if (n->next)
1.3 schwarze 578: html_idcat(buf, " ", BUFSIZ);
1.1 schwarze 579: }
580:
1.40 ! schwarze 581: PAIR_ID_INIT(&tag, buf);
! 582: print_otag(h, TAG_H2, 1, &tag);
1.1 schwarze 583: return(1);
584: }
585:
586:
587: /* ARGSUSED */
588: static int
589: mdoc_fl_pre(MDOC_ARGS)
590: {
591: struct htmlpair tag;
592:
593: PAIR_CLASS_INIT(&tag, "flag");
594: print_otag(h, TAG_SPAN, 1, &tag);
1.6 schwarze 595:
596: /* `Cm' has no leading hyphen. */
597:
598: if (MDOC_Cm == n->tok)
599: return(1);
600:
601: print_text(h, "\\-");
602:
603: if (n->child)
1.1 schwarze 604: h->flags |= HTML_NOSPACE;
1.11 schwarze 605: else if (n->next && n->next->line == n->line)
606: h->flags |= HTML_NOSPACE;
1.6 schwarze 607:
1.1 schwarze 608: return(1);
609: }
610:
611:
612: /* ARGSUSED */
613: static int
614: mdoc_nd_pre(MDOC_ARGS)
615: {
616: struct htmlpair tag;
617:
618: if (MDOC_BODY != n->type)
619: return(1);
620:
621: /* XXX: this tag in theory can contain block elements. */
622:
623: print_text(h, "\\(em");
1.40 ! schwarze 624: PAIR_CLASS_INIT(&tag, "desc");
1.1 schwarze 625: print_otag(h, TAG_SPAN, 1, &tag);
626: return(1);
627: }
628:
629:
630: static int
631: mdoc_nm_pre(MDOC_ARGS)
632: {
1.25 schwarze 633: struct htmlpair tag;
634: struct roffsu su;
1.40 ! schwarze 635: size_t len;
1.25 schwarze 636:
1.40 ! schwarze 637: switch (n->type) {
! 638: case (MDOC_ELEM):
1.25 schwarze 639: synopsis_pre(h, n);
640: PAIR_CLASS_INIT(&tag, "name");
641: print_otag(h, TAG_SPAN, 1, &tag);
1.40 ! schwarze 642: if (NULL == n->child && m->name)
1.25 schwarze 643: print_text(h, m->name);
1.40 ! schwarze 644: return(1);
! 645: case (MDOC_HEAD):
! 646: print_otag(h, TAG_TD, 0, NULL);
! 647: if (NULL == n->child && m->name)
! 648: print_text(h, m->name);
! 649: return(1);
! 650: case (MDOC_BODY):
! 651: print_otag(h, TAG_TD, 0, NULL);
! 652: return(1);
! 653: default:
! 654: break;
! 655: }
1.25 schwarze 656:
1.40 ! schwarze 657: synopsis_pre(h, n);
! 658: PAIR_CLASS_INIT(&tag, "synopsis");
! 659: print_otag(h, TAG_TABLE, 1, &tag);
1.25 schwarze 660:
1.40 ! schwarze 661: for (len = 0, n = n->child; n; n = n->next)
! 662: if (MDOC_TEXT == n->type)
! 663: len += strlen(n->string);
1.25 schwarze 664:
1.40 ! schwarze 665: if (0 == len && m->name)
! 666: len = strlen(m->name);
1.1 schwarze 667:
1.40 ! schwarze 668: SCALE_HS_INIT(&su, (double)len);
! 669: bufcat_su(h, "width", &su);
! 670: PAIR_STYLE_INIT(&tag, h);
! 671: print_otag(h, TAG_COL, 1, &tag);
! 672: print_otag(h, TAG_COL, 0, NULL);
! 673: print_otag(h, TAG_TBODY, 0, NULL);
! 674: print_otag(h, TAG_TR, 0, NULL);
1.1 schwarze 675: return(1);
676: }
677:
678:
679: /* ARGSUSED */
680: static int
681: mdoc_xr_pre(MDOC_ARGS)
682: {
683: struct htmlpair tag[2];
684: const struct mdoc_node *nn;
1.9 schwarze 685:
686: if (NULL == n->child)
687: return(0);
1.1 schwarze 688:
689: PAIR_CLASS_INIT(&tag[0], "link-man");
690:
691: if (h->base_man) {
692: buffmt_man(h, n->child->string,
693: n->child->next ?
694: n->child->next->string : NULL);
1.11 schwarze 695: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 696: print_otag(h, TAG_A, 2, tag);
697: } else
698: print_otag(h, TAG_A, 1, tag);
699:
700: nn = n->child;
701: print_text(h, nn->string);
702:
703: if (NULL == (nn = nn->next))
704: return(0);
705:
706: h->flags |= HTML_NOSPACE;
707: print_text(h, "(");
708: h->flags |= HTML_NOSPACE;
709: print_text(h, nn->string);
710: h->flags |= HTML_NOSPACE;
711: print_text(h, ")");
712: return(0);
713: }
714:
715:
716: /* ARGSUSED */
717: static int
718: mdoc_ns_pre(MDOC_ARGS)
719: {
720:
721: h->flags |= HTML_NOSPACE;
722: return(1);
723: }
724:
725:
726: /* ARGSUSED */
727: static int
728: mdoc_ar_pre(MDOC_ARGS)
729: {
730: struct htmlpair tag;
731:
732: PAIR_CLASS_INIT(&tag, "arg");
733: print_otag(h, TAG_SPAN, 1, &tag);
734: return(1);
735: }
736:
737:
738: /* ARGSUSED */
739: static int
740: mdoc_xx_pre(MDOC_ARGS)
741: {
742: const char *pp;
743: struct htmlpair tag;
744:
745: switch (n->tok) {
746: case (MDOC_Bsx):
1.37 schwarze 747: pp = "BSD/OS";
1.1 schwarze 748: break;
749: case (MDOC_Dx):
1.4 schwarze 750: pp = "DragonFly";
1.1 schwarze 751: break;
752: case (MDOC_Fx):
753: pp = "FreeBSD";
754: break;
755: case (MDOC_Nx):
756: pp = "NetBSD";
757: break;
758: case (MDOC_Ox):
759: pp = "OpenBSD";
760: break;
761: case (MDOC_Ux):
762: pp = "UNIX";
763: break;
764: default:
765: return(1);
766: }
767:
768: PAIR_CLASS_INIT(&tag, "unix");
769: print_otag(h, TAG_SPAN, 1, &tag);
770: print_text(h, pp);
771: return(1);
772: }
773:
774:
775: /* ARGSUSED */
776: static int
777: mdoc_bx_pre(MDOC_ARGS)
778: {
779: const struct mdoc_node *nn;
780: struct htmlpair tag;
781:
782: PAIR_CLASS_INIT(&tag, "unix");
783: print_otag(h, TAG_SPAN, 1, &tag);
784:
785: for (nn = n->child; nn; nn = nn->next)
786: print_mdoc_node(m, nn, h);
787:
788: if (n->child)
789: h->flags |= HTML_NOSPACE;
790:
791: print_text(h, "BSD");
792: return(0);
793: }
794:
795: static int
1.40 ! schwarze 796: mdoc_it_pre(MDOC_ARGS)
1.1 schwarze 797: {
1.40 ! schwarze 798: struct roffsu su;
! 799: enum mdoc_list type;
! 800: struct htmlpair tag[2];
! 801: const struct mdoc_node *bl;
1.1 schwarze 802:
1.40 ! schwarze 803: bl = n->parent;
! 804: while (bl && MDOC_Bl != bl->tok)
! 805: bl = bl->parent;
1.1 schwarze 806:
1.40 ! schwarze 807: assert(bl);
1.1 schwarze 808:
1.40 ! schwarze 809: type = bl->data.Bl->type;
1.1 schwarze 810:
1.40 ! schwarze 811: assert(lists[type]);
! 812: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 schwarze 813:
1.40 ! schwarze 814: if (MDOC_HEAD == n->type) {
! 815: switch (type) {
! 816: case(LIST_bullet):
! 817: /* FALLTHROUGH */
! 818: case(LIST_dash):
! 819: /* FALLTHROUGH */
! 820: case(LIST_item):
! 821: /* FALLTHROUGH */
! 822: case(LIST_hyphen):
! 823: /* FALLTHROUGH */
! 824: case(LIST_enum):
! 825: return(0);
! 826: case(LIST_diag):
! 827: /* FALLTHROUGH */
! 828: case(LIST_hang):
! 829: /* FALLTHROUGH */
! 830: case(LIST_inset):
! 831: /* FALLTHROUGH */
! 832: case(LIST_ohang):
! 833: /* FALLTHROUGH */
! 834: case(LIST_tag):
! 835: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
! 836: bufcat_su(h, "margin-top", &su);
! 837: PAIR_STYLE_INIT(&tag[1], h);
! 838: print_otag(h, TAG_DT, 2, tag);
! 839: break;
! 840: case(LIST_column):
! 841: break;
! 842: default:
! 843: break;
! 844: }
! 845: } else if (MDOC_BODY == n->type) {
! 846: switch (type) {
! 847: case(LIST_bullet):
! 848: /* FALLTHROUGH */
! 849: case(LIST_hyphen):
! 850: /* FALLTHROUGH */
! 851: case(LIST_dash):
! 852: /* FALLTHROUGH */
! 853: case(LIST_enum):
! 854: /* FALLTHROUGH */
! 855: case(LIST_item):
! 856: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
! 857: bufcat_su(h, "margin-top", &su);
! 858: PAIR_STYLE_INIT(&tag[1], h);
! 859: print_otag(h, TAG_LI, 2, tag);
! 860: break;
! 861: case(LIST_diag):
! 862: /* FALLTHROUGH */
! 863: case(LIST_hang):
! 864: /* FALLTHROUGH */
! 865: case(LIST_inset):
! 866: /* FALLTHROUGH */
! 867: case(LIST_ohang):
! 868: /* FALLTHROUGH */
! 869: case(LIST_tag):
! 870: if (NULL == bl->data.Bl->width) {
! 871: print_otag(h, TAG_DD, 1, tag);
! 872: break;
! 873: }
! 874: a2width(bl->data.Bl->width, &su);
! 875: bufcat_su(h, "margin-left", &su);
! 876: PAIR_STYLE_INIT(&tag[1], h);
! 877: print_otag(h, TAG_DD, 2, tag);
! 878: break;
! 879: case(LIST_column):
! 880: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
! 881: bufcat_su(h, "margin-top", &su);
! 882: PAIR_STYLE_INIT(&tag[1], h);
! 883: print_otag(h, TAG_TD, 2, tag);
! 884: break;
! 885: default:
! 886: break;
! 887: }
! 888: } else {
! 889: switch (type) {
! 890: case (LIST_column):
! 891: print_otag(h, TAG_TR, 1, tag);
! 892: break;
! 893: default:
1.1 schwarze 894: break;
1.40 ! schwarze 895: }
1.1 schwarze 896: }
897:
898: return(1);
899: }
900:
901: /* ARGSUSED */
902: static int
1.40 ! schwarze 903: mdoc_bl_pre(MDOC_ARGS)
1.1 schwarze 904: {
1.40 ! schwarze 905: size_t i;
! 906: struct htmlpair tag[3];
1.1 schwarze 907: struct roffsu su;
908:
1.40 ! schwarze 909: if (MDOC_BODY == n->type) {
! 910: if (LIST_column == n->data.Bl->type)
! 911: print_otag(h, TAG_TBODY, 0, NULL);
! 912: return(1);
1.1 schwarze 913: }
914:
1.40 ! schwarze 915: if (MDOC_HEAD == n->type) {
! 916: if (LIST_column != n->data.Bl->type)
! 917: return(0);
1.1 schwarze 918:
1.40 ! schwarze 919: /*
! 920: * For each column, print out the <COL> tag with our
! 921: * suggested width. The last column gets min-width, as
! 922: * in terminal mode it auto-sizes to the width of the
! 923: * screen and we want to preserve that behaviour.
! 924: */
1.1 schwarze 925:
1.40 ! schwarze 926: for (i = 0; i < n->data.Bl->ncols; i++) {
! 927: a2width(n->data.Bl->cols[i], &su);
! 928: bufinit(h);
! 929: if (i < n->data.Bl->ncols - 1)
! 930: bufcat_su(h, "width", &su);
! 931: else
! 932: bufcat_su(h, "min-width", &su);
! 933: PAIR_STYLE_INIT(&tag[0], h);
! 934: print_otag(h, TAG_COL, 1, tag);
! 935: }
1.1 schwarze 936:
1.4 schwarze 937: return(0);
1.1 schwarze 938: }
939:
1.40 ! schwarze 940: SCALE_VS_INIT(&su, 0);
! 941: bufcat_su(h, "margin-top", &su);
! 942: bufcat_su(h, "margin-bottom", &su);
! 943: PAIR_STYLE_INIT(&tag[0], h);
1.1 schwarze 944:
1.40 ! schwarze 945: assert(lists[n->data.Bl->type]);
! 946: bufinit(h);
! 947: bufcat(h, "list ");
! 948: bufcat(h, lists[n->data.Bl->type]);
! 949: PAIR_INIT(&tag[1], ATTR_CLASS, h->buf);
! 950: i = 2;
1.1 schwarze 951:
1.40 ! schwarze 952: /* Set the block's left-hand margin. */
1.1 schwarze 953:
1.40 ! schwarze 954: if (n->data.Bl->offs) {
! 955: a2offs(n->data.Bl->offs, &su);
! 956: bufcat_su(h, "margin-left", &su);
! 957: PAIR_STYLE_INIT(&tag[2], h);
! 958: i = 3;
! 959: }
1.1 schwarze 960:
1.40 ! schwarze 961: switch (n->data.Bl->type) {
! 962: case(LIST_bullet):
1.1 schwarze 963: /* FALLTHROUGH */
1.40 ! schwarze 964: case(LIST_dash):
1.1 schwarze 965: /* FALLTHROUGH */
1.40 ! schwarze 966: case(LIST_hyphen):
1.1 schwarze 967: /* FALLTHROUGH */
1.40 ! schwarze 968: case(LIST_item):
! 969: print_otag(h, TAG_UL, i, tag);
1.1 schwarze 970: break;
1.40 ! schwarze 971: case(LIST_enum):
! 972: print_otag(h, TAG_OL, i, tag);
1.1 schwarze 973: break;
1.40 ! schwarze 974: case(LIST_diag):
! 975: /* FALLTHROUGH */
! 976: case(LIST_hang):
1.4 schwarze 977: /* FALLTHROUGH */
1.40 ! schwarze 978: case(LIST_inset):
1.1 schwarze 979: /* FALLTHROUGH */
1.40 ! schwarze 980: case(LIST_ohang):
1.1 schwarze 981: /* FALLTHROUGH */
1.40 ! schwarze 982: case(LIST_tag):
! 983: print_otag(h, TAG_DL, i, tag);
! 984: break;
! 985: case(LIST_column):
! 986: print_otag(h, TAG_TABLE, i, tag);
1.1 schwarze 987: break;
988: default:
1.40 ! schwarze 989: abort();
! 990: /* NOTREACHED */
1.1 schwarze 991: }
992:
993: return(1);
994: }
995:
996: /* ARGSUSED */
997: static int
998: mdoc_ex_pre(MDOC_ARGS)
999: {
1000: const struct mdoc_node *nn;
1001: struct tag *t;
1002: struct htmlpair tag;
1003:
1.40 ! schwarze 1004: if (n->prev)
! 1005: print_otag(h, TAG_BR, 0, NULL);
! 1006:
1.1 schwarze 1007: PAIR_CLASS_INIT(&tag, "utility");
1008:
1009: print_text(h, "The");
1010: for (nn = n->child; nn; nn = nn->next) {
1011: t = print_otag(h, TAG_SPAN, 1, &tag);
1012: print_text(h, nn->string);
1013: print_tagq(h, t);
1014:
1015: h->flags |= HTML_NOSPACE;
1016:
1017: if (nn->next && NULL == nn->next->next)
1018: print_text(h, ", and");
1019: else if (nn->next)
1020: print_text(h, ",");
1021: else
1022: h->flags &= ~HTML_NOSPACE;
1023: }
1024:
1.17 schwarze 1025: if (n->child && n->child->next)
1.1 schwarze 1026: print_text(h, "utilities exit");
1027: else
1028: print_text(h, "utility exits");
1029:
1030: print_text(h, "0 on success, and >0 if an error occurs.");
1031: return(0);
1032: }
1033:
1034:
1035: /* ARGSUSED */
1036: static int
1037: mdoc_em_pre(MDOC_ARGS)
1038: {
1039: struct htmlpair tag;
1040:
1041: PAIR_CLASS_INIT(&tag, "emph");
1042: print_otag(h, TAG_SPAN, 1, &tag);
1043: return(1);
1044: }
1045:
1046:
1047: /* ARGSUSED */
1048: static int
1049: mdoc_d1_pre(MDOC_ARGS)
1050: {
1051: struct htmlpair tag[2];
1052: struct roffsu su;
1053:
1054: if (MDOC_BLOCK != n->type)
1055: return(1);
1056:
1.40 ! schwarze 1057: SCALE_VS_INIT(&su, 0);
! 1058: bufcat_su(h, "margin-top", &su);
! 1059: bufcat_su(h, "margin-bottom", &su);
! 1060: PAIR_STYLE_INIT(&tag[0], h);
! 1061: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
! 1062:
! 1063: /* BLOCKQUOTE needs a block body. */
1.1 schwarze 1064:
1.40 ! schwarze 1065: if (MDOC_Dl == n->tok)
! 1066: PAIR_CLASS_INIT(&tag[0], "lit display");
! 1067: else
! 1068: PAIR_CLASS_INIT(&tag[0], "display");
! 1069:
! 1070: print_otag(h, TAG_DIV, 1, tag);
1.1 schwarze 1071: return(1);
1072: }
1073:
1074:
1075: /* ARGSUSED */
1076: static int
1077: mdoc_sx_pre(MDOC_ARGS)
1078: {
1079: struct htmlpair tag[2];
1080: const struct mdoc_node *nn;
1081: char buf[BUFSIZ];
1082:
1.3 schwarze 1083: strlcpy(buf, "#", BUFSIZ);
1.1 schwarze 1084: for (nn = n->child; nn; nn = nn->next) {
1.3 schwarze 1085: html_idcat(buf, nn->string, BUFSIZ);
1.1 schwarze 1086: if (nn->next)
1.3 schwarze 1087: html_idcat(buf, " ", BUFSIZ);
1.1 schwarze 1088: }
1089:
1090: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.11 schwarze 1091: PAIR_HREF_INIT(&tag[1], buf);
1.1 schwarze 1092:
1093: print_otag(h, TAG_A, 2, tag);
1094: return(1);
1095: }
1096:
1097:
1098: /* ARGSUSED */
1099: static int
1100: mdoc_bd_pre(MDOC_ARGS)
1101: {
1102: struct htmlpair tag[2];
1.22 schwarze 1103: int comp;
1104: const struct mdoc_node *nn;
1.1 schwarze 1105: struct roffsu su;
1106:
1.22 schwarze 1107: if (MDOC_HEAD == n->type)
1.1 schwarze 1108: return(0);
1109:
1110: if (MDOC_BLOCK == n->type) {
1.40 ! schwarze 1111: comp = n->data.Bd->comp;
1.1 schwarze 1112: for (nn = n; nn && ! comp; nn = nn->parent) {
1113: if (MDOC_BLOCK != nn->type)
1114: continue;
1115: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1116: comp = 1;
1117: if (nn->prev)
1118: break;
1119: }
1.40 ! schwarze 1120: if ( ! comp)
! 1121: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1122: return(1);
1123: }
1124:
1.40 ! schwarze 1125: SCALE_HS_INIT(&su, 0);
! 1126: if (n->data.Bd->offs)
! 1127: a2offs(n->data.Bd->offs, &su);
! 1128:
! 1129: bufcat_su(h, "margin-left", &su);
! 1130: PAIR_STYLE_INIT(&tag[0], h);
! 1131:
1.25 schwarze 1132: if (DISP_unfilled != n->data.Bd->type &&
1.40 ! schwarze 1133: DISP_literal != n->data.Bd->type) {
! 1134: PAIR_CLASS_INIT(&tag[1], "display");
! 1135: print_otag(h, TAG_DIV, 2, tag);
1.1 schwarze 1136: return(1);
1.40 ! schwarze 1137: }
1.1 schwarze 1138:
1.40 ! schwarze 1139: PAIR_CLASS_INIT(&tag[1], "lit display");
! 1140: print_otag(h, TAG_PRE, 2, tag);
1.1 schwarze 1141:
1142: for (nn = n->child; nn; nn = nn->next) {
1143: print_mdoc_node(m, nn, h);
1.33 schwarze 1144: /*
1145: * If the printed node flushes its own line, then we
1146: * needn't do it here as well. This is hacky, but the
1147: * notion of selective eoln whitespace is pretty dumb
1148: * anyway, so don't sweat it.
1149: */
1150: switch (nn->tok) {
1.36 schwarze 1151: case (MDOC_Sm):
1152: /* FALLTHROUGH */
1.33 schwarze 1153: case (MDOC_br):
1154: /* FALLTHROUGH */
1155: case (MDOC_sp):
1156: /* FALLTHROUGH */
1157: case (MDOC_Bl):
1.39 schwarze 1158: /* FALLTHROUGH */
1159: case (MDOC_D1):
1160: /* FALLTHROUGH */
1161: case (MDOC_Dl):
1.33 schwarze 1162: /* FALLTHROUGH */
1163: case (MDOC_Lp):
1164: /* FALLTHROUGH */
1165: case (MDOC_Pp):
1166: continue;
1167: default:
1168: break;
1169: }
1.28 schwarze 1170: if (nn->next && nn->next->line == nn->line)
1171: continue;
1.40 ! schwarze 1172: else if (nn->next)
! 1173: print_text(h, "\n");
! 1174:
1.28 schwarze 1175: h->flags |= HTML_NOSPACE;
1.1 schwarze 1176: }
1177:
1178: return(0);
1179: }
1180:
1181:
1182: /* ARGSUSED */
1183: static int
1184: mdoc_pa_pre(MDOC_ARGS)
1185: {
1186: struct htmlpair tag;
1187:
1188: PAIR_CLASS_INIT(&tag, "file");
1189: print_otag(h, TAG_SPAN, 1, &tag);
1190: return(1);
1191: }
1192:
1193:
1194: /* ARGSUSED */
1195: static int
1196: mdoc_ad_pre(MDOC_ARGS)
1197: {
1198: struct htmlpair tag;
1199:
1200: PAIR_CLASS_INIT(&tag, "addr");
1201: print_otag(h, TAG_SPAN, 1, &tag);
1202: return(1);
1203: }
1204:
1205:
1206: /* ARGSUSED */
1207: static int
1208: mdoc_an_pre(MDOC_ARGS)
1209: {
1210: struct htmlpair tag;
1211:
1212: /* TODO: -split and -nosplit (see termp_an_pre()). */
1213:
1214: PAIR_CLASS_INIT(&tag, "author");
1215: print_otag(h, TAG_SPAN, 1, &tag);
1216: return(1);
1217: }
1218:
1219:
1220: /* ARGSUSED */
1221: static int
1222: mdoc_cd_pre(MDOC_ARGS)
1223: {
1224: struct htmlpair tag;
1225:
1.21 schwarze 1226: synopsis_pre(h, n);
1.1 schwarze 1227: PAIR_CLASS_INIT(&tag, "config");
1228: print_otag(h, TAG_SPAN, 1, &tag);
1229: return(1);
1230: }
1231:
1232:
1233: /* ARGSUSED */
1234: static int
1235: mdoc_dv_pre(MDOC_ARGS)
1236: {
1237: struct htmlpair tag;
1238:
1239: PAIR_CLASS_INIT(&tag, "define");
1240: print_otag(h, TAG_SPAN, 1, &tag);
1241: return(1);
1242: }
1243:
1244:
1245: /* ARGSUSED */
1246: static int
1247: mdoc_ev_pre(MDOC_ARGS)
1248: {
1249: struct htmlpair tag;
1250:
1251: PAIR_CLASS_INIT(&tag, "env");
1252: print_otag(h, TAG_SPAN, 1, &tag);
1253: return(1);
1254: }
1255:
1256:
1257: /* ARGSUSED */
1258: static int
1259: mdoc_er_pre(MDOC_ARGS)
1260: {
1261: struct htmlpair tag;
1262:
1263: PAIR_CLASS_INIT(&tag, "errno");
1264: print_otag(h, TAG_SPAN, 1, &tag);
1265: return(1);
1266: }
1267:
1268:
1269: /* ARGSUSED */
1270: static int
1271: mdoc_fa_pre(MDOC_ARGS)
1272: {
1273: const struct mdoc_node *nn;
1274: struct htmlpair tag;
1275: struct tag *t;
1276:
1277: PAIR_CLASS_INIT(&tag, "farg");
1278: if (n->parent->tok != MDOC_Fo) {
1279: print_otag(h, TAG_SPAN, 1, &tag);
1280: return(1);
1281: }
1282:
1283: for (nn = n->child; nn; nn = nn->next) {
1284: t = print_otag(h, TAG_SPAN, 1, &tag);
1285: print_text(h, nn->string);
1286: print_tagq(h, t);
1287: if (nn->next)
1288: print_text(h, ",");
1289: }
1290:
1291: if (n->child && n->next && n->next->tok == MDOC_Fa)
1292: print_text(h, ",");
1293:
1294: return(0);
1295: }
1296:
1297:
1298: /* ARGSUSED */
1299: static int
1300: mdoc_fd_pre(MDOC_ARGS)
1301: {
1302: struct htmlpair tag;
1303:
1.21 schwarze 1304: synopsis_pre(h, n);
1305:
1.1 schwarze 1306: PAIR_CLASS_INIT(&tag, "macro");
1307: print_otag(h, TAG_SPAN, 1, &tag);
1308: return(1);
1309: }
1310:
1311:
1312: /* ARGSUSED */
1313: static int
1314: mdoc_vt_pre(MDOC_ARGS)
1315: {
1316: struct htmlpair tag;
1317:
1.21 schwarze 1318: if (MDOC_BLOCK == n->type) {
1319: synopsis_pre(h, n);
1.7 schwarze 1320: return(1);
1.21 schwarze 1321: } else if (MDOC_ELEM == n->type) {
1322: synopsis_pre(h, n);
1.7 schwarze 1323: } else if (MDOC_HEAD == n->type)
1324: return(0);
1.1 schwarze 1325:
1326: PAIR_CLASS_INIT(&tag, "type");
1327: print_otag(h, TAG_SPAN, 1, &tag);
1328: return(1);
1329: }
1330:
1331:
1332: /* ARGSUSED */
1333: static int
1334: mdoc_ft_pre(MDOC_ARGS)
1335: {
1336: struct htmlpair tag;
1337:
1.21 schwarze 1338: synopsis_pre(h, n);
1.1 schwarze 1339: PAIR_CLASS_INIT(&tag, "ftype");
1340: print_otag(h, TAG_SPAN, 1, &tag);
1341: return(1);
1342: }
1343:
1344:
1345: /* ARGSUSED */
1346: static int
1347: mdoc_fn_pre(MDOC_ARGS)
1348: {
1349: struct tag *t;
1350: struct htmlpair tag[2];
1351: const struct mdoc_node *nn;
1352: char nbuf[BUFSIZ];
1353: const char *sp, *ep;
1354: int sz, i;
1355:
1.21 schwarze 1356: synopsis_pre(h, n);
1.1 schwarze 1357:
1358: /* Split apart into type and name. */
1359: assert(n->child->string);
1360: sp = n->child->string;
1361:
1362: ep = strchr(sp, ' ');
1363: if (NULL != ep) {
1364: PAIR_CLASS_INIT(&tag[0], "ftype");
1365: t = print_otag(h, TAG_SPAN, 1, tag);
1366:
1367: while (ep) {
1368: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1369: (void)memcpy(nbuf, sp, (size_t)sz);
1370: nbuf[sz] = '\0';
1371: print_text(h, nbuf);
1372: sp = ++ep;
1373: ep = strchr(sp, ' ');
1374: }
1375: print_tagq(h, t);
1376: }
1377:
1378: PAIR_CLASS_INIT(&tag[0], "fname");
1.11 schwarze 1379:
1380: /*
1381: * FIXME: only refer to IDs that we know exist.
1382: */
1383:
1384: #if 0
1.23 schwarze 1385: if (MDOC_SYNPRETTY & n->flags) {
1.11 schwarze 1386: nbuf[0] = '\0';
1387: html_idcat(nbuf, sp, BUFSIZ);
1388: PAIR_ID_INIT(&tag[1], nbuf);
1389: } else {
1390: strlcpy(nbuf, "#", BUFSIZ);
1391: html_idcat(nbuf, sp, BUFSIZ);
1392: PAIR_HREF_INIT(&tag[1], nbuf);
1393: }
1394: #endif
1395:
1.1 schwarze 1396: t = print_otag(h, TAG_SPAN, 1, tag);
1397:
1398: if (sp) {
1.11 schwarze 1399: strlcpy(nbuf, sp, BUFSIZ);
1.1 schwarze 1400: print_text(h, nbuf);
1401: }
1402:
1403: print_tagq(h, t);
1404:
1405: h->flags |= HTML_NOSPACE;
1406: print_text(h, "(");
1407:
1408: bufinit(h);
1409: PAIR_CLASS_INIT(&tag[0], "farg");
1410: bufcat_style(h, "white-space", "nowrap");
1411: PAIR_STYLE_INIT(&tag[1], h);
1412:
1413: for (nn = n->child->next; nn; nn = nn->next) {
1414: i = 1;
1.23 schwarze 1415: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1416: i = 2;
1417: t = print_otag(h, TAG_SPAN, i, tag);
1418: print_text(h, nn->string);
1419: print_tagq(h, t);
1420: if (nn->next)
1421: print_text(h, ",");
1422: }
1423:
1424: print_text(h, ")");
1.23 schwarze 1425: if (MDOC_SYNPRETTY & n->flags)
1.1 schwarze 1426: print_text(h, ";");
1427:
1428: return(0);
1429: }
1430:
1431:
1432: /* ARGSUSED */
1433: static int
1.26 schwarze 1434: mdoc_sm_pre(MDOC_ARGS)
1435: {
1436:
1437: assert(n->child && MDOC_TEXT == n->child->type);
1438: if (0 == strcmp("on", n->child->string)) {
1.36 schwarze 1439: /*
1440: * FIXME: no p->col to check. Thus, if we have
1441: * .Bd -literal
1442: * .Sm off
1443: * 1 2
1444: * .Sm on
1445: * 3
1446: * .Ed
1447: * the "3" is preceded by a space.
1448: */
1.26 schwarze 1449: h->flags &= ~HTML_NOSPACE;
1450: h->flags &= ~HTML_NONOSPACE;
1451: } else
1452: h->flags |= HTML_NONOSPACE;
1453:
1454: return(0);
1455: }
1456:
1.40 ! schwarze 1457: /* ARGSUSED */
! 1458: static int
! 1459: mdoc_pp_pre(MDOC_ARGS)
! 1460: {
! 1461:
! 1462: print_otag(h, TAG_P, 0, NULL);
! 1463: return(0);
! 1464:
! 1465: }
1.26 schwarze 1466:
1467: /* ARGSUSED */
1468: static int
1.1 schwarze 1469: mdoc_sp_pre(MDOC_ARGS)
1470: {
1.40 ! schwarze 1471: struct roffsu su;
1.1 schwarze 1472: struct htmlpair tag;
1473:
1.40 ! schwarze 1474: SCALE_VS_INIT(&su, 1);
! 1475:
! 1476: if (MDOC_sp == n->tok) {
! 1477: if (n->child)
! 1478: a2roffsu(n->child->string, &su, SCALE_VS);
! 1479: } else
! 1480: su.scale = 0;
1.1 schwarze 1481:
1482: bufcat_su(h, "height", &su);
1483: PAIR_STYLE_INIT(&tag, h);
1484: print_otag(h, TAG_DIV, 1, &tag);
1.40 ! schwarze 1485:
1.3 schwarze 1486: /* So the div isn't empty: */
1487: print_text(h, "\\~");
1488:
1489: return(0);
1.1 schwarze 1490:
1491: }
1492:
1493: /* ARGSUSED */
1494: static int
1495: mdoc_lk_pre(MDOC_ARGS)
1496: {
1497: const struct mdoc_node *nn;
1498: struct htmlpair tag[2];
1499:
1500: nn = n->child;
1501:
1502: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.11 schwarze 1503: PAIR_HREF_INIT(&tag[1], nn->string);
1.1 schwarze 1504: print_otag(h, TAG_A, 2, tag);
1505:
1.38 schwarze 1506: if (NULL == nn || NULL == nn->next)
1.2 schwarze 1507: return(1);
1508:
1.1 schwarze 1509: for (nn = nn->next; nn; nn = nn->next)
1510: print_text(h, nn->string);
1511:
1512: return(0);
1513: }
1514:
1515:
1516: /* ARGSUSED */
1517: static int
1518: mdoc_mt_pre(MDOC_ARGS)
1519: {
1520: struct htmlpair tag[2];
1521: struct tag *t;
1522: const struct mdoc_node *nn;
1523:
1524: PAIR_CLASS_INIT(&tag[0], "link-mail");
1525:
1526: for (nn = n->child; nn; nn = nn->next) {
1527: bufinit(h);
1528: bufcat(h, "mailto:");
1529: bufcat(h, nn->string);
1.10 schwarze 1530: PAIR_HREF_INIT(&tag[1], h->buf);
1.1 schwarze 1531: t = print_otag(h, TAG_A, 2, tag);
1532: print_text(h, nn->string);
1533: print_tagq(h, t);
1534: }
1535:
1536: return(0);
1537: }
1538:
1539:
1540: /* ARGSUSED */
1541: static int
1542: mdoc_fo_pre(MDOC_ARGS)
1543: {
1.20 schwarze 1544: struct htmlpair tag;
1545: struct tag *t;
1.1 schwarze 1546:
1547: if (MDOC_BODY == n->type) {
1548: h->flags |= HTML_NOSPACE;
1549: print_text(h, "(");
1550: h->flags |= HTML_NOSPACE;
1551: return(1);
1.20 schwarze 1552: } else if (MDOC_BLOCK == n->type) {
1.21 schwarze 1553: synopsis_pre(h, n);
1.1 schwarze 1554: return(1);
1.11 schwarze 1555: }
1.1 schwarze 1556:
1.20 schwarze 1557: /* XXX: we drop non-initial arguments as per groff. */
1558:
1559: assert(n->child);
1560: assert(n->child->string);
1561:
1.1 schwarze 1562: PAIR_CLASS_INIT(&tag, "fname");
1.20 schwarze 1563: t = print_otag(h, TAG_SPAN, 1, &tag);
1564: print_text(h, n->child->string);
1565: print_tagq(h, t);
1566: return(0);
1.1 schwarze 1567: }
1568:
1569:
1570: /* ARGSUSED */
1571: static void
1572: mdoc_fo_post(MDOC_ARGS)
1573: {
1.21 schwarze 1574:
1.1 schwarze 1575: if (MDOC_BODY != n->type)
1576: return;
1577: print_text(h, ")");
1578: print_text(h, ";");
1579: }
1580:
1581:
1582: /* ARGSUSED */
1583: static int
1584: mdoc_in_pre(MDOC_ARGS)
1585: {
1586: const struct mdoc_node *nn;
1587: struct tag *t;
1588: struct htmlpair tag[2];
1589: int i;
1590:
1.21 schwarze 1591: synopsis_pre(h, n);
1592:
1.1 schwarze 1593: PAIR_CLASS_INIT(&tag[0], "includes");
1594: print_otag(h, TAG_SPAN, 1, tag);
1595:
1.23 schwarze 1596: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.1 schwarze 1597: print_text(h, "#include");
1598:
1599: print_text(h, "<");
1600: h->flags |= HTML_NOSPACE;
1601:
1602: for (nn = n->child; nn; nn = nn->next) {
1603: PAIR_CLASS_INIT(&tag[0], "link-includes");
1604: i = 1;
1.3 schwarze 1605: bufinit(h);
1.1 schwarze 1606: if (h->base_includes) {
1607: buffmt_includes(h, nn->string);
1.11 schwarze 1608: PAIR_HREF_INIT(&tag[i], h->buf);
1609: i++;
1.1 schwarze 1610: }
1611: t = print_otag(h, TAG_A, i, tag);
1612: print_mdoc_node(m, nn, h);
1613: print_tagq(h, t);
1614: }
1615:
1616: h->flags |= HTML_NOSPACE;
1617: print_text(h, ">");
1.20 schwarze 1618:
1.1 schwarze 1619: return(0);
1620: }
1621:
1622:
1623: /* ARGSUSED */
1624: static int
1625: mdoc_ic_pre(MDOC_ARGS)
1626: {
1627: struct htmlpair tag;
1628:
1629: PAIR_CLASS_INIT(&tag, "cmd");
1630: print_otag(h, TAG_SPAN, 1, &tag);
1631: return(1);
1632: }
1633:
1634:
1635: /* ARGSUSED */
1636: static int
1637: mdoc_rv_pre(MDOC_ARGS)
1638: {
1639: const struct mdoc_node *nn;
1640: struct htmlpair tag;
1641: struct tag *t;
1642:
1.40 ! schwarze 1643: if (n->prev)
! 1644: print_otag(h, TAG_BR, 0, NULL);
! 1645:
1.1 schwarze 1646: print_text(h, "The");
1647:
1648: for (nn = n->child; nn; nn = nn->next) {
1649: PAIR_CLASS_INIT(&tag, "fname");
1650: t = print_otag(h, TAG_SPAN, 1, &tag);
1651: print_text(h, nn->string);
1652: print_tagq(h, t);
1653:
1654: h->flags |= HTML_NOSPACE;
1655: if (nn->next && NULL == nn->next->next)
1656: print_text(h, "(), and");
1657: else if (nn->next)
1658: print_text(h, "(),");
1659: else
1660: print_text(h, "()");
1661: }
1662:
1.17 schwarze 1663: if (n->child && n->child->next)
1.1 schwarze 1664: print_text(h, "functions return");
1665: else
1666: print_text(h, "function returns");
1667:
1668: print_text(h, "the value 0 if successful; otherwise the value "
1669: "-1 is returned and the global variable");
1670:
1671: PAIR_CLASS_INIT(&tag, "var");
1672: t = print_otag(h, TAG_SPAN, 1, &tag);
1673: print_text(h, "errno");
1674: print_tagq(h, t);
1675: print_text(h, "is set to indicate the error.");
1676: return(0);
1677: }
1678:
1679:
1680: /* ARGSUSED */
1681: static int
1682: mdoc_va_pre(MDOC_ARGS)
1683: {
1684: struct htmlpair tag;
1685:
1686: PAIR_CLASS_INIT(&tag, "var");
1687: print_otag(h, TAG_SPAN, 1, &tag);
1688: return(1);
1689: }
1690:
1691:
1692: /* ARGSUSED */
1693: static int
1694: mdoc_ap_pre(MDOC_ARGS)
1695: {
1696:
1697: h->flags |= HTML_NOSPACE;
1698: print_text(h, "\\(aq");
1699: h->flags |= HTML_NOSPACE;
1700: return(1);
1701: }
1702:
1703:
1704: /* ARGSUSED */
1705: static int
1706: mdoc_bf_pre(MDOC_ARGS)
1707: {
1708: struct htmlpair tag[2];
1709: struct roffsu su;
1710:
1711: if (MDOC_HEAD == n->type)
1712: return(0);
1.25 schwarze 1713: else if (MDOC_BODY != n->type)
1.1 schwarze 1714: return(1);
1715:
1.25 schwarze 1716: assert(n->data.Bf);
1.1 schwarze 1717:
1.25 schwarze 1718: if (FONT_Em == n->data.Bf->font)
1719: PAIR_CLASS_INIT(&tag[0], "emph");
1720: else if (FONT_Sy == n->data.Bf->font)
1721: PAIR_CLASS_INIT(&tag[0], "symb");
1722: else if (FONT_Li == n->data.Bf->font)
1723: PAIR_CLASS_INIT(&tag[0], "lit");
1724: else
1725: PAIR_CLASS_INIT(&tag[0], "none");
1.1 schwarze 1726:
1.25 schwarze 1727: /*
1728: * We want this to be inline-formatted, but needs to be div to
1729: * accept block children.
1730: */
1.1 schwarze 1731: bufcat_style(h, "display", "inline");
1732: SCALE_HS_INIT(&su, 1);
1.25 schwarze 1733: /* Needs a left-margin for spacing. */
1734: bufcat_su(h, "margin-left", &su);
1.1 schwarze 1735: PAIR_STYLE_INIT(&tag[1], h);
1736: print_otag(h, TAG_DIV, 2, tag);
1737: return(1);
1738: }
1739:
1740:
1741: /* ARGSUSED */
1742: static int
1743: mdoc_ms_pre(MDOC_ARGS)
1744: {
1745: struct htmlpair tag;
1746:
1747: PAIR_CLASS_INIT(&tag, "symb");
1748: print_otag(h, TAG_SPAN, 1, &tag);
1749: return(1);
1750: }
1751:
1752:
1753: /* ARGSUSED */
1754: static int
1.34 schwarze 1755: mdoc_igndelim_pre(MDOC_ARGS)
1.1 schwarze 1756: {
1757:
1758: h->flags |= HTML_IGNDELIM;
1759: return(1);
1760: }
1761:
1762:
1763: /* ARGSUSED */
1764: static void
1765: mdoc_pf_post(MDOC_ARGS)
1766: {
1767:
1768: h->flags |= HTML_NOSPACE;
1769: }
1770:
1771:
1772: /* ARGSUSED */
1773: static int
1774: mdoc_rs_pre(MDOC_ARGS)
1775: {
1776: struct htmlpair tag;
1777:
1778: if (MDOC_BLOCK != n->type)
1779: return(1);
1780:
1.40 ! schwarze 1781: if (n->prev && SEC_SEE_ALSO == n->sec)
! 1782: print_otag(h, TAG_P, 0, NULL);
1.1 schwarze 1783:
1784: PAIR_CLASS_INIT(&tag, "ref");
1785: print_otag(h, TAG_SPAN, 1, &tag);
1786: return(1);
1787: }
1788:
1789:
1790:
1791: /* ARGSUSED */
1792: static int
1793: mdoc_li_pre(MDOC_ARGS)
1794: {
1795: struct htmlpair tag;
1796:
1797: PAIR_CLASS_INIT(&tag, "lit");
1798: print_otag(h, TAG_SPAN, 1, &tag);
1799: return(1);
1800: }
1801:
1802:
1803: /* ARGSUSED */
1804: static int
1805: mdoc_sy_pre(MDOC_ARGS)
1806: {
1807: struct htmlpair tag;
1808:
1809: PAIR_CLASS_INIT(&tag, "symb");
1810: print_otag(h, TAG_SPAN, 1, &tag);
1811: return(1);
1812: }
1813:
1814:
1815: /* ARGSUSED */
1816: static int
1817: mdoc_bt_pre(MDOC_ARGS)
1818: {
1819:
1820: print_text(h, "is currently in beta test.");
1821: return(0);
1822: }
1823:
1824:
1825: /* ARGSUSED */
1826: static int
1827: mdoc_ud_pre(MDOC_ARGS)
1828: {
1829:
1830: print_text(h, "currently under development.");
1831: return(0);
1832: }
1833:
1834:
1835: /* ARGSUSED */
1836: static int
1837: mdoc_lb_pre(MDOC_ARGS)
1838: {
1839: struct htmlpair tag;
1840:
1.40 ! schwarze 1841: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
! 1842: print_otag(h, TAG_BR, 0, NULL);
! 1843:
1.1 schwarze 1844: PAIR_CLASS_INIT(&tag, "lib");
1845: print_otag(h, TAG_SPAN, 1, &tag);
1846: return(1);
1847: }
1848:
1849:
1850: /* ARGSUSED */
1851: static int
1852: mdoc__x_pre(MDOC_ARGS)
1853: {
1.2 schwarze 1854: struct htmlpair tag[2];
1.1 schwarze 1855:
1856: switch (n->tok) {
1857: case(MDOC__A):
1.2 schwarze 1858: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.30 schwarze 1859: if (n->prev && MDOC__A == n->prev->tok)
1860: if (NULL == n->next || MDOC__A != n->next->tok)
1861: print_text(h, "and");
1.1 schwarze 1862: break;
1863: case(MDOC__B):
1.2 schwarze 1864: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.1 schwarze 1865: break;
1866: case(MDOC__C):
1.2 schwarze 1867: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1 schwarze 1868: break;
1869: case(MDOC__D):
1.2 schwarze 1870: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1 schwarze 1871: break;
1872: case(MDOC__I):
1.2 schwarze 1873: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.1 schwarze 1874: break;
1875: case(MDOC__J):
1.2 schwarze 1876: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.1 schwarze 1877: break;
1878: case(MDOC__N):
1.2 schwarze 1879: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1 schwarze 1880: break;
1881: case(MDOC__O):
1.2 schwarze 1882: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1 schwarze 1883: break;
1884: case(MDOC__P):
1.2 schwarze 1885: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1 schwarze 1886: break;
1887: case(MDOC__Q):
1.2 schwarze 1888: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1 schwarze 1889: break;
1890: case(MDOC__R):
1.2 schwarze 1891: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1 schwarze 1892: break;
1893: case(MDOC__T):
1.2 schwarze 1894: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1 schwarze 1895: break;
1.2 schwarze 1896: case(MDOC__U):
1897: PAIR_CLASS_INIT(&tag[0], "link-ref");
1898: break;
1.1 schwarze 1899: case(MDOC__V):
1.2 schwarze 1900: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1 schwarze 1901: break;
1902: default:
1903: abort();
1904: /* NOTREACHED */
1905: }
1906:
1.2 schwarze 1907: if (MDOC__U != n->tok) {
1908: print_otag(h, TAG_SPAN, 1, tag);
1909: return(1);
1910: }
1911:
1912: PAIR_HREF_INIT(&tag[1], n->child->string);
1913: print_otag(h, TAG_A, 2, tag);
1.30 schwarze 1914:
1.1 schwarze 1915: return(1);
1916: }
1917:
1918:
1919: /* ARGSUSED */
1920: static void
1921: mdoc__x_post(MDOC_ARGS)
1922: {
1.30 schwarze 1923:
1924: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1925: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1926: if (NULL == n->prev || MDOC__A != n->prev->tok)
1927: return;
1.1 schwarze 1928:
1.12 schwarze 1929: /* TODO: %U */
1930:
1.31 schwarze 1931: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1932: return;
1933:
1.1 schwarze 1934: print_text(h, n->next ? "," : ".");
1.25 schwarze 1935: }
1936:
1937:
1938: /* ARGSUSED */
1939: static int
1940: mdoc_bk_pre(MDOC_ARGS)
1941: {
1942:
1943: switch (n->type) {
1944: case (MDOC_BLOCK):
1945: break;
1946: case (MDOC_HEAD):
1947: return(0);
1948: case (MDOC_BODY):
1949: h->flags |= HTML_PREKEEP;
1950: break;
1951: default:
1952: abort();
1953: /* NOTREACHED */
1954: }
1955:
1956: return(1);
1957: }
1958:
1959:
1960: /* ARGSUSED */
1961: static void
1962: mdoc_bk_post(MDOC_ARGS)
1963: {
1964:
1965: if (MDOC_BODY == n->type)
1966: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.1 schwarze 1967: }
1.32 schwarze 1968:
1969:
1970: /* ARGSUSED */
1971: static int
1972: mdoc_quote_pre(MDOC_ARGS)
1973: {
1974: struct htmlpair tag;
1975:
1976: if (MDOC_BODY != n->type)
1977: return(1);
1978:
1979: switch (n->tok) {
1980: case (MDOC_Ao):
1981: /* FALLTHROUGH */
1982: case (MDOC_Aq):
1983: print_text(h, "\\(la");
1984: break;
1985: case (MDOC_Bro):
1986: /* FALLTHROUGH */
1987: case (MDOC_Brq):
1988: print_text(h, "\\(lC");
1989: break;
1990: case (MDOC_Bo):
1991: /* FALLTHROUGH */
1992: case (MDOC_Bq):
1993: print_text(h, "\\(lB");
1994: break;
1995: case (MDOC_Oo):
1996: /* FALLTHROUGH */
1997: case (MDOC_Op):
1998: print_text(h, "\\(lB");
1.36 schwarze 1999: h->flags |= HTML_NOSPACE;
1.32 schwarze 2000: PAIR_CLASS_INIT(&tag, "opt");
2001: print_otag(h, TAG_SPAN, 1, &tag);
2002: break;
2003: case (MDOC_Do):
2004: /* FALLTHROUGH */
2005: case (MDOC_Dq):
2006: /* FALLTHROUGH */
2007: case (MDOC_Qo):
2008: /* FALLTHROUGH */
2009: case (MDOC_Qq):
2010: print_text(h, "\\(lq");
2011: break;
2012: case (MDOC_Po):
2013: /* FALLTHROUGH */
2014: case (MDOC_Pq):
2015: print_text(h, "(");
2016: break;
2017: case (MDOC_Ql):
2018: /* FALLTHROUGH */
2019: case (MDOC_So):
2020: /* FALLTHROUGH */
2021: case (MDOC_Sq):
2022: print_text(h, "\\(oq");
2023: break;
2024: default:
2025: abort();
2026: /* NOTREACHED */
2027: }
2028:
2029: h->flags |= HTML_NOSPACE;
2030: return(1);
2031: }
2032:
2033:
2034: /* ARGSUSED */
2035: static void
2036: mdoc_quote_post(MDOC_ARGS)
2037: {
2038:
2039: if (MDOC_BODY != n->type)
2040: return;
2041:
2042: h->flags |= HTML_NOSPACE;
2043:
2044: switch (n->tok) {
2045: case (MDOC_Ao):
2046: /* FALLTHROUGH */
2047: case (MDOC_Aq):
2048: print_text(h, "\\(ra");
2049: break;
2050: case (MDOC_Bro):
2051: /* FALLTHROUGH */
2052: case (MDOC_Brq):
2053: print_text(h, "\\(rC");
2054: break;
2055: case (MDOC_Oo):
2056: /* FALLTHROUGH */
2057: case (MDOC_Op):
2058: /* FALLTHROUGH */
2059: case (MDOC_Bo):
2060: /* FALLTHROUGH */
2061: case (MDOC_Bq):
2062: print_text(h, "\\(rB");
2063: break;
2064: case (MDOC_Qo):
2065: /* FALLTHROUGH */
2066: case (MDOC_Qq):
2067: /* FALLTHROUGH */
2068: case (MDOC_Do):
2069: /* FALLTHROUGH */
2070: case (MDOC_Dq):
2071: print_text(h, "\\(rq");
2072: break;
2073: case (MDOC_Po):
2074: /* FALLTHROUGH */
2075: case (MDOC_Pq):
2076: print_text(h, ")");
2077: break;
2078: case (MDOC_Ql):
2079: /* FALLTHROUGH */
2080: case (MDOC_So):
2081: /* FALLTHROUGH */
2082: case (MDOC_Sq):
2083: print_text(h, "\\(aq");
2084: break;
2085: default:
2086: abort();
2087: /* NOTREACHED */
2088: }
2089: }
2090:
2091: