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