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