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