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