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