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