Annotation of mandoc/mdoc_html.c, Revision 1.30
1.30 ! kristaps 1: /* $Id: mdoc_html.c,v 1.29 2009/10/13 10:57:25 kristaps Exp $ */
1.1 kristaps 2: /*
3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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: */
17: #include <sys/types.h>
1.7 kristaps 18: #include <sys/param.h>
1.1 kristaps 19: #include <sys/queue.h>
20:
21: #include <assert.h>
22: #include <ctype.h>
23: #include <err.h>
24: #include <stdio.h>
25: #include <stdlib.h>
26: #include <string.h>
27: #include <unistd.h>
28:
1.23 kristaps 29: #include "out.h"
1.1 kristaps 30: #include "html.h"
31: #include "mdoc.h"
1.29 kristaps 32: #include "main.h"
1.1 kristaps 33:
34: #define INDENT 5
35: #define HALFINDENT 3
36:
37: #define MDOC_ARGS const struct mdoc_meta *m, \
38: const struct mdoc_node *n, \
39: struct html *h
40:
41: struct htmlmdoc {
42: int (*pre)(MDOC_ARGS);
43: void (*post)(MDOC_ARGS);
44: };
45:
46: static void print_mdoc(MDOC_ARGS);
47: static void print_mdoc_head(MDOC_ARGS);
48: static void print_mdoc_node(MDOC_ARGS);
49: static void print_mdoc_nodelist(MDOC_ARGS);
50:
1.23 kristaps 51: static void a2width(const char *, struct roffsu *);
52: static void a2offs(const char *, struct roffsu *);
1.27 kristaps 53:
1.1 kristaps 54: static int a2list(const struct mdoc_node *);
55:
56: static void mdoc_root_post(MDOC_ARGS);
57: static int mdoc_root_pre(MDOC_ARGS);
58:
1.10 kristaps 59: static void mdoc__x_post(MDOC_ARGS);
60: static int mdoc__x_pre(MDOC_ARGS);
1.1 kristaps 61: static int mdoc_ad_pre(MDOC_ARGS);
62: static int mdoc_an_pre(MDOC_ARGS);
1.5 kristaps 63: static int mdoc_ap_pre(MDOC_ARGS);
1.1 kristaps 64: static void mdoc_aq_post(MDOC_ARGS);
65: static int mdoc_aq_pre(MDOC_ARGS);
66: static int mdoc_ar_pre(MDOC_ARGS);
67: static int mdoc_bd_pre(MDOC_ARGS);
1.5 kristaps 68: static int mdoc_bf_pre(MDOC_ARGS);
1.1 kristaps 69: static void mdoc_bl_post(MDOC_ARGS);
70: static int mdoc_bl_pre(MDOC_ARGS);
1.4 kristaps 71: static void mdoc_bq_post(MDOC_ARGS);
72: static int mdoc_bq_pre(MDOC_ARGS);
1.2 kristaps 73: static void mdoc_brq_post(MDOC_ARGS);
74: static int mdoc_brq_pre(MDOC_ARGS);
1.6 kristaps 75: static int mdoc_bt_pre(MDOC_ARGS);
1.4 kristaps 76: static int mdoc_bx_pre(MDOC_ARGS);
1.1 kristaps 77: static int mdoc_cd_pre(MDOC_ARGS);
78: static int mdoc_d1_pre(MDOC_ARGS);
79: static void mdoc_dq_post(MDOC_ARGS);
80: static int mdoc_dq_pre(MDOC_ARGS);
81: static int mdoc_dv_pre(MDOC_ARGS);
82: static int mdoc_fa_pre(MDOC_ARGS);
83: static int mdoc_fd_pre(MDOC_ARGS);
84: static int mdoc_fl_pre(MDOC_ARGS);
85: static int mdoc_fn_pre(MDOC_ARGS);
86: static int mdoc_ft_pre(MDOC_ARGS);
87: static int mdoc_em_pre(MDOC_ARGS);
88: static int mdoc_er_pre(MDOC_ARGS);
89: static int mdoc_ev_pre(MDOC_ARGS);
90: static int mdoc_ex_pre(MDOC_ARGS);
1.4 kristaps 91: static void mdoc_fo_post(MDOC_ARGS);
92: static int mdoc_fo_pre(MDOC_ARGS);
93: static int mdoc_ic_pre(MDOC_ARGS);
94: static int mdoc_in_pre(MDOC_ARGS);
1.27 kristaps 95: static int mdoc_it_block_pre(MDOC_ARGS, int, int,
96: struct roffsu *, struct roffsu *);
97: static int mdoc_it_head_pre(MDOC_ARGS, int,
98: struct roffsu *);
99: static int mdoc_it_body_pre(MDOC_ARGS, int);
1.1 kristaps 100: static int mdoc_it_pre(MDOC_ARGS);
1.6 kristaps 101: static int mdoc_lb_pre(MDOC_ARGS);
102: static int mdoc_li_pre(MDOC_ARGS);
1.2 kristaps 103: static int mdoc_lk_pre(MDOC_ARGS);
104: static int mdoc_mt_pre(MDOC_ARGS);
1.5 kristaps 105: static int mdoc_ms_pre(MDOC_ARGS);
1.1 kristaps 106: static int mdoc_nd_pre(MDOC_ARGS);
107: static int mdoc_nm_pre(MDOC_ARGS);
108: static int mdoc_ns_pre(MDOC_ARGS);
109: static void mdoc_op_post(MDOC_ARGS);
110: static int mdoc_op_pre(MDOC_ARGS);
111: static int mdoc_pa_pre(MDOC_ARGS);
1.5 kristaps 112: static void mdoc_pf_post(MDOC_ARGS);
113: static int mdoc_pf_pre(MDOC_ARGS);
1.1 kristaps 114: static void mdoc_pq_post(MDOC_ARGS);
115: static int mdoc_pq_pre(MDOC_ARGS);
1.5 kristaps 116: static int mdoc_rs_pre(MDOC_ARGS);
1.4 kristaps 117: static int mdoc_rv_pre(MDOC_ARGS);
1.1 kristaps 118: static int mdoc_sh_pre(MDOC_ARGS);
119: static int mdoc_sp_pre(MDOC_ARGS);
120: static void mdoc_sq_post(MDOC_ARGS);
121: static int mdoc_sq_pre(MDOC_ARGS);
122: static int mdoc_ss_pre(MDOC_ARGS);
123: static int mdoc_sx_pre(MDOC_ARGS);
1.6 kristaps 124: static int mdoc_sy_pre(MDOC_ARGS);
125: static int mdoc_ud_pre(MDOC_ARGS);
1.4 kristaps 126: static int mdoc_va_pre(MDOC_ARGS);
1.1 kristaps 127: static int mdoc_vt_pre(MDOC_ARGS);
128: static int mdoc_xr_pre(MDOC_ARGS);
129: static int mdoc_xx_pre(MDOC_ARGS);
130:
131: #ifdef __linux__
132: extern size_t strlcpy(char *, const char *, size_t);
133: extern size_t strlcat(char *, const char *, size_t);
134: #endif
135:
136: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5 kristaps 137: {mdoc_ap_pre, NULL}, /* Ap */
1.1 kristaps 138: {NULL, NULL}, /* Dd */
139: {NULL, NULL}, /* Dt */
140: {NULL, NULL}, /* Os */
141: {mdoc_sh_pre, NULL }, /* Sh */
142: {mdoc_ss_pre, NULL }, /* Ss */
143: {mdoc_sp_pre, NULL}, /* Pp */
144: {mdoc_d1_pre, NULL}, /* D1 */
145: {mdoc_d1_pre, NULL}, /* Dl */
146: {mdoc_bd_pre, NULL}, /* Bd */
147: {NULL, NULL}, /* Ed */
148: {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
149: {NULL, NULL}, /* El */
150: {mdoc_it_pre, NULL}, /* It */
151: {mdoc_ad_pre, NULL}, /* Ad */
152: {mdoc_an_pre, NULL}, /* An */
153: {mdoc_ar_pre, NULL}, /* Ar */
154: {mdoc_cd_pre, NULL}, /* Cd */
155: {mdoc_fl_pre, NULL}, /* Cm */
156: {mdoc_dv_pre, NULL}, /* Dv */
157: {mdoc_er_pre, NULL}, /* Er */
158: {mdoc_ev_pre, NULL}, /* Ev */
159: {mdoc_ex_pre, NULL}, /* Ex */
160: {mdoc_fa_pre, NULL}, /* Fa */
161: {mdoc_fd_pre, NULL}, /* Fd */
162: {mdoc_fl_pre, NULL}, /* Fl */
163: {mdoc_fn_pre, NULL}, /* Fn */
164: {mdoc_ft_pre, NULL}, /* Ft */
1.4 kristaps 165: {mdoc_ic_pre, NULL}, /* Ic */
166: {mdoc_in_pre, NULL}, /* In */
1.6 kristaps 167: {mdoc_li_pre, NULL}, /* Li */
1.1 kristaps 168: {mdoc_nd_pre, NULL}, /* Nd */
169: {mdoc_nm_pre, NULL}, /* Nm */
170: {mdoc_op_pre, mdoc_op_post}, /* Op */
171: {NULL, NULL}, /* Ot */
172: {mdoc_pa_pre, NULL}, /* Pa */
1.4 kristaps 173: {mdoc_rv_pre, NULL}, /* Rv */
1.1 kristaps 174: {NULL, NULL}, /* St */
1.4 kristaps 175: {mdoc_va_pre, NULL}, /* Va */
1.1 kristaps 176: {mdoc_vt_pre, NULL}, /* Vt */
177: {mdoc_xr_pre, NULL}, /* Xr */
1.10 kristaps 178: {mdoc__x_pre, mdoc__x_post}, /* %A */
179: {mdoc__x_pre, mdoc__x_post}, /* %B */
180: {mdoc__x_pre, mdoc__x_post}, /* %D */
181: {mdoc__x_pre, mdoc__x_post}, /* %I */
182: {mdoc__x_pre, mdoc__x_post}, /* %J */
183: {mdoc__x_pre, mdoc__x_post}, /* %N */
184: {mdoc__x_pre, mdoc__x_post}, /* %O */
185: {mdoc__x_pre, mdoc__x_post}, /* %P */
186: {mdoc__x_pre, mdoc__x_post}, /* %R */
187: {mdoc__x_pre, mdoc__x_post}, /* %T */
188: {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1 kristaps 189: {NULL, NULL}, /* Ac */
190: {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
191: {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
192: {NULL, NULL}, /* At */
193: {NULL, NULL}, /* Bc */
1.5 kristaps 194: {mdoc_bf_pre, NULL}, /* Bf */
1.4 kristaps 195: {mdoc_bq_pre, mdoc_bq_post}, /* Bo */
196: {mdoc_bq_pre, mdoc_bq_post}, /* Bq */
1.1 kristaps 197: {mdoc_xx_pre, NULL}, /* Bsx */
1.4 kristaps 198: {mdoc_bx_pre, NULL}, /* Bx */
1.1 kristaps 199: {NULL, NULL}, /* Db */
200: {NULL, NULL}, /* Dc */
1.4 kristaps 201: {mdoc_dq_pre, mdoc_dq_post}, /* Do */
1.1 kristaps 202: {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
203: {NULL, NULL}, /* Ec */
204: {NULL, NULL}, /* Ef */
205: {mdoc_em_pre, NULL}, /* Em */
206: {NULL, NULL}, /* Eo */
207: {mdoc_xx_pre, NULL}, /* Fx */
1.5 kristaps 208: {mdoc_ms_pre, NULL}, /* Ms */ /* FIXME: convert to symbol? */
1.1 kristaps 209: {NULL, NULL}, /* No */
210: {mdoc_ns_pre, NULL}, /* Ns */
211: {mdoc_xx_pre, NULL}, /* Nx */
212: {mdoc_xx_pre, NULL}, /* Ox */
213: {NULL, NULL}, /* Pc */
1.5 kristaps 214: {mdoc_pf_pre, mdoc_pf_post}, /* Pf */
1.1 kristaps 215: {mdoc_pq_pre, mdoc_pq_post}, /* Po */
216: {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
217: {NULL, NULL}, /* Qc */
1.4 kristaps 218: {mdoc_sq_pre, mdoc_sq_post}, /* Ql */
1.5 kristaps 219: {mdoc_dq_pre, mdoc_dq_post}, /* Qo */
220: {mdoc_dq_pre, mdoc_dq_post}, /* Qq */
1.1 kristaps 221: {NULL, NULL}, /* Re */
1.5 kristaps 222: {mdoc_rs_pre, NULL}, /* Rs */
1.1 kristaps 223: {NULL, NULL}, /* Sc */
224: {mdoc_sq_pre, mdoc_sq_post}, /* So */
225: {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
1.6 kristaps 226: {NULL, NULL}, /* Sm */ /* FIXME - no idea. */
1.1 kristaps 227: {mdoc_sx_pre, NULL}, /* Sx */
1.6 kristaps 228: {mdoc_sy_pre, NULL}, /* Sy */
1.1 kristaps 229: {NULL, NULL}, /* Tn */
230: {mdoc_xx_pre, NULL}, /* Ux */
231: {NULL, NULL}, /* Xc */
232: {NULL, NULL}, /* Xo */
1.4 kristaps 233: {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
1.1 kristaps 234: {NULL, NULL}, /* Fc */
1.4 kristaps 235: {mdoc_op_pre, mdoc_op_post}, /* Oo */
1.1 kristaps 236: {NULL, NULL}, /* Oc */
237: {NULL, NULL}, /* Bk */
238: {NULL, NULL}, /* Ek */
1.6 kristaps 239: {mdoc_bt_pre, NULL}, /* Bt */
1.1 kristaps 240: {NULL, NULL}, /* Hf */
241: {NULL, NULL}, /* Fr */
1.6 kristaps 242: {mdoc_ud_pre, NULL}, /* Ud */
243: {mdoc_lb_pre, NULL}, /* Lb */
1.1 kristaps 244: {mdoc_sp_pre, NULL}, /* Lp */
1.2 kristaps 245: {mdoc_lk_pre, NULL}, /* Lk */
246: {mdoc_mt_pre, NULL}, /* Mt */
247: {mdoc_brq_pre, mdoc_brq_post}, /* Brq */
248: {mdoc_brq_pre, mdoc_brq_post}, /* Bro */
1.1 kristaps 249: {NULL, NULL}, /* Brc */
1.10 kristaps 250: {mdoc__x_pre, mdoc__x_post}, /* %C */
1.2 kristaps 251: {NULL, NULL}, /* Es */ /* TODO */
252: {NULL, NULL}, /* En */ /* TODO */
1.1 kristaps 253: {mdoc_xx_pre, NULL}, /* Dx */
1.10 kristaps 254: {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1 kristaps 255: {mdoc_sp_pre, NULL}, /* br */
256: {mdoc_sp_pre, NULL}, /* sp */
257: };
258:
259:
260: void
261: html_mdoc(void *arg, const struct mdoc *m)
262: {
263: struct html *h;
264: struct tag *t;
265:
266: h = (struct html *)arg;
267:
268: print_gen_doctype(h);
269: t = print_otag(h, TAG_HTML, 0, NULL);
270: print_mdoc(mdoc_meta(m), mdoc_node(m), h);
271: print_tagq(h, t);
272:
273: printf("\n");
274: }
275:
276:
1.23 kristaps 277: /*
278: * Return the list type for `Bl', e.g., `Bl -column' returns
279: * MDOC_Column. This can ONLY be run for lists; it will abort() if no
280: * list type is found.
281: */
1.1 kristaps 282: static int
283: a2list(const struct mdoc_node *n)
284: {
285: int i;
286:
287: assert(n->args);
288: for (i = 0; i < (int)n->args->argc; i++)
289: switch (n->args->argv[i].arg) {
290: case (MDOC_Enum):
291: /* FALLTHROUGH */
292: case (MDOC_Dash):
293: /* FALLTHROUGH */
294: case (MDOC_Hyphen):
295: /* FALLTHROUGH */
296: case (MDOC_Bullet):
297: /* FALLTHROUGH */
298: case (MDOC_Tag):
299: /* FALLTHROUGH */
300: case (MDOC_Hang):
301: /* FALLTHROUGH */
302: case (MDOC_Inset):
303: /* FALLTHROUGH */
304: case (MDOC_Diag):
305: /* FALLTHROUGH */
306: case (MDOC_Item):
307: /* FALLTHROUGH */
308: case (MDOC_Column):
309: /* FALLTHROUGH */
310: case (MDOC_Ohang):
311: return(n->args->argv[i].arg);
312: default:
313: break;
314: }
315:
316: abort();
317: /* NOTREACHED */
318: }
319:
320:
1.23 kristaps 321: /*
322: * Calculate the scaling unit passed in a `-width' argument. This uses
323: * either a native scaling unit (e.g., 1i, 2m) or the string length of
324: * the value.
325: */
326: static void
327: a2width(const char *p, struct roffsu *su)
1.1 kristaps 328: {
329:
1.24 kristaps 330: if (a2roffsu(p, su))
331: return;
332: su->unit = SCALE_EM;
333: su->scale = (int)strlen(p);
1.1 kristaps 334: }
335:
336:
1.23 kristaps 337: /*
338: * Calculate the scaling unit passed in an `-offset' argument. This
339: * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
340: * predefined strings (indent, etc.), or the string length of the value.
341: */
342: static void
343: a2offs(const char *p, struct roffsu *su)
1.1 kristaps 344: {
345:
346: if (0 == strcmp(p, "left"))
1.23 kristaps 347: SCALE_HS_INIT(su, 0);
348: else if (0 == strcmp(p, "indent"))
349: SCALE_HS_INIT(su, INDENT);
350: else if (0 == strcmp(p, "indent-two"))
351: SCALE_HS_INIT(su, INDENT * 2);
1.24 kristaps 352: else if ( ! a2roffsu(p, su)) {
353: su->unit = SCALE_EM;
354: su->scale = (int)strlen(p);
355: }
1.1 kristaps 356: }
357:
358:
359: static void
360: print_mdoc(MDOC_ARGS)
361: {
362: struct tag *t;
363: struct htmlpair tag;
364:
365: t = print_otag(h, TAG_HEAD, 0, NULL);
366: print_mdoc_head(m, n, h);
367: print_tagq(h, t);
368:
369: t = print_otag(h, TAG_BODY, 0, NULL);
370:
371: tag.key = ATTR_CLASS;
372: tag.val = "body";
373: print_otag(h, TAG_DIV, 1, &tag);
374:
375: print_mdoc_nodelist(m, n, h);
376: print_tagq(h, t);
377: }
378:
379:
380: /* ARGSUSED */
381: static void
382: print_mdoc_head(MDOC_ARGS)
383: {
384:
385: print_gen_head(h);
1.20 kristaps 386: bufinit(h);
387: buffmt(h, "%s(%d)", m->title, m->msec);
1.1 kristaps 388:
389: if (m->arch) {
1.20 kristaps 390: bufcat(h, " (");
391: bufcat(h, m->arch);
392: bufcat(h, ")");
1.1 kristaps 393: }
394:
395: print_otag(h, TAG_TITLE, 0, NULL);
1.20 kristaps 396: print_text(h, h->buf);
1.1 kristaps 397: }
398:
399:
400: static void
401: print_mdoc_nodelist(MDOC_ARGS)
402: {
403:
404: print_mdoc_node(m, n, h);
405: if (n->next)
406: print_mdoc_nodelist(m, n->next, h);
407: }
408:
409:
410: static void
411: print_mdoc_node(MDOC_ARGS)
412: {
413: int child;
414: struct tag *t;
415:
416: child = 1;
417: t = SLIST_FIRST(&h->tags);
418:
1.16 kristaps 419: bufinit(h);
1.1 kristaps 420: switch (n->type) {
421: case (MDOC_ROOT):
422: child = mdoc_root_pre(m, n, h);
423: break;
424: case (MDOC_TEXT):
425: print_text(h, n->string);
426: break;
427: default:
428: if (mdocs[n->tok].pre)
429: child = (*mdocs[n->tok].pre)(m, n, h);
430: break;
431: }
432:
433: if (child && n->child)
434: print_mdoc_nodelist(m, n->child, h);
435:
436: print_stagq(h, t);
437:
1.16 kristaps 438: bufinit(h);
1.1 kristaps 439: switch (n->type) {
440: case (MDOC_ROOT):
441: mdoc_root_post(m, n, h);
442: break;
443: case (MDOC_TEXT):
444: break;
445: default:
446: if (mdocs[n->tok].post)
447: (*mdocs[n->tok].post)(m, n, h);
448: break;
449: }
450: }
451:
452:
453: /* ARGSUSED */
454: static void
455: mdoc_root_post(MDOC_ARGS)
456: {
457: struct tm tm;
458: struct htmlpair tag[2];
459: struct tag *t, *tt;
460: char b[BUFSIZ];
461:
1.23 kristaps 462: /*
463: * XXX: this should use divs, but in Firefox, divs with nested
464: * divs for some reason puke when trying to put a border line
465: * below. So I use tables, instead.
466: */
467:
1.1 kristaps 468: (void)localtime_r(&m->date, &tm);
469:
470: if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm))
471: err(EXIT_FAILURE, "strftime");
472:
1.23 kristaps 473: PAIR_CLASS_INIT(&tag[0], "footer");
474: bufcat_style(h, "width", "100%");
475: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 476: t = print_otag(h, TAG_TABLE, 2, tag);
477: tt = print_otag(h, TAG_TR, 0, NULL);
478:
1.23 kristaps 479: bufinit(h);
480: bufcat_style(h, "width", "50%");
481: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 482: print_otag(h, TAG_TD, 1, tag);
483: print_text(h, b);
484: print_stagq(h, tt);
485:
1.23 kristaps 486: bufinit(h);
487: bufcat_style(h, "width", "50%");
488: bufcat_style(h, "text-align", "right");
489: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 490: print_otag(h, TAG_TD, 1, tag);
491: print_text(h, m->os);
492: print_tagq(h, t);
493: }
494:
495:
496: /* ARGSUSED */
497: static int
498: mdoc_root_pre(MDOC_ARGS)
499: {
500: struct htmlpair tag[2];
501: struct tag *t, *tt;
502: char b[BUFSIZ], title[BUFSIZ];
503:
504: (void)strlcpy(b, m->vol, BUFSIZ);
505:
506: if (m->arch) {
507: (void)strlcat(b, " (", BUFSIZ);
508: (void)strlcat(b, m->arch, BUFSIZ);
509: (void)strlcat(b, ")", BUFSIZ);
510: }
511:
512: (void)snprintf(title, BUFSIZ - 1,
513: "%s(%d)", m->title, m->msec);
514:
1.23 kristaps 515: /* XXX: see note in mdoc_root_post() about divs. */
516:
517: PAIR_CLASS_INIT(&tag[0], "header");
518: bufcat_style(h, "width", "100%");
519: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 520: t = print_otag(h, TAG_TABLE, 2, tag);
521: tt = print_otag(h, TAG_TR, 0, NULL);
522:
1.23 kristaps 523: bufinit(h);
524: bufcat_style(h, "width", "10%");
525: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 526: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 527: print_text(h, title);
1.1 kristaps 528: print_stagq(h, tt);
529:
1.23 kristaps 530: bufinit(h);
531: bufcat_style(h, "text-align", "center");
532: bufcat_style(h, "white-space", "nowrap");
533: bufcat_style(h, "width", "80%");
534: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 535: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 536: print_text(h, b);
1.1 kristaps 537: print_stagq(h, tt);
538:
1.23 kristaps 539: bufinit(h);
540: bufcat_style(h, "text-align", "right");
541: bufcat_style(h, "width", "10%");
542: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 543: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 544: print_text(h, title);
1.1 kristaps 545: print_tagq(h, t);
546: return(1);
547: }
548:
549:
550: /* ARGSUSED */
551: static int
552: mdoc_sh_pre(MDOC_ARGS)
553: {
554: struct htmlpair tag[2];
555: const struct mdoc_node *nn;
1.25 kristaps 556: char lbuf[BUFSIZ];
1.23 kristaps 557: struct roffsu su;
1.21 kristaps 558:
559: if (MDOC_BODY == n->type) {
1.23 kristaps 560: SCALE_HS_INIT(&su, INDENT);
561: bufcat_su(h, "margin-left", &su);
562: PAIR_CLASS_INIT(&tag[0], "sec-body");
563: PAIR_STYLE_INIT(&tag[1], h);
1.21 kristaps 564: print_otag(h, TAG_DIV, 2, tag);
1.1 kristaps 565: return(1);
566: } else if (MDOC_BLOCK == n->type) {
1.23 kristaps 567: PAIR_CLASS_INIT(&tag[0], "sec-block");
1.1 kristaps 568: if (n->prev && NULL == n->prev->body->child) {
569: print_otag(h, TAG_DIV, 1, tag);
570: return(1);
571: }
1.23 kristaps 572:
573: SCALE_VS_INIT(&su, 1);
574: bufcat_su(h, "margin-top", &su);
1.1 kristaps 575: if (NULL == n->next)
1.23 kristaps 576: bufcat_su(h, "margin-bottom", &su);
1.1 kristaps 577:
1.23 kristaps 578: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 579: print_otag(h, TAG_DIV, 2, tag);
580: return(1);
581: }
582:
1.25 kristaps 583: lbuf[0] = 0;
1.21 kristaps 584: for (nn = n->child; nn; nn = nn->next) {
1.25 kristaps 585: (void)strlcat(lbuf, nn->string, BUFSIZ);
1.21 kristaps 586: if (nn->next)
1.25 kristaps 587: (void)strlcat(lbuf, "_", BUFSIZ);
1.21 kristaps 588: }
589:
1.23 kristaps 590: /*
591: * TODO: make sure there are no duplicates, as HTML does not
592: * allow for multiple `id' tags of the same name.
593: */
1.22 kristaps 594:
1.23 kristaps 595: PAIR_CLASS_INIT(&tag[0], "sec-head");
1.21 kristaps 596: tag[1].key = ATTR_ID;
1.25 kristaps 597: tag[1].val = lbuf;
1.1 kristaps 598: print_otag(h, TAG_DIV, 2, tag);
599: return(1);
600: }
601:
602:
603: /* ARGSUSED */
604: static int
605: mdoc_ss_pre(MDOC_ARGS)
606: {
1.21 kristaps 607: struct htmlpair tag[3];
1.1 kristaps 608: const struct mdoc_node *nn;
1.25 kristaps 609: char lbuf[BUFSIZ];
1.23 kristaps 610: struct roffsu su;
1.1 kristaps 611:
1.23 kristaps 612: SCALE_VS_INIT(&su, 1);
1.1 kristaps 613:
614: if (MDOC_BODY == n->type) {
1.23 kristaps 615: PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.1 kristaps 616: if (n->parent->next && n->child) {
1.23 kristaps 617: bufcat_su(h, "margin-bottom", &su);
618: PAIR_STYLE_INIT(&tag[1], h);
619: print_otag(h, TAG_DIV, 2, tag);
620: } else
621: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 622: return(1);
623: } else if (MDOC_BLOCK == n->type) {
1.23 kristaps 624: PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.1 kristaps 625: if (n->prev) {
1.23 kristaps 626: bufcat_su(h, "margin-top", &su);
627: PAIR_STYLE_INIT(&tag[1], h);
628: print_otag(h, TAG_DIV, 2, tag);
629: } else
630: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 631: return(1);
632: }
633:
1.23 kristaps 634: /* TODO: see note in mdoc_sh_pre() about duplicates. */
635:
1.25 kristaps 636: lbuf[0] = 0;
1.21 kristaps 637: for (nn = n->child; nn; nn = nn->next) {
1.25 kristaps 638: (void)strlcat(lbuf, nn->string, BUFSIZ);
1.21 kristaps 639: if (nn->next)
1.25 kristaps 640: (void)strlcat(lbuf, "_", BUFSIZ);
1.21 kristaps 641: }
642:
1.23 kristaps 643: SCALE_HS_INIT(&su, INDENT - HALFINDENT);
644: su.scale = -su.scale;
645: bufcat_su(h, "margin-left", &su);
1.22 kristaps 646:
1.23 kristaps 647: PAIR_CLASS_INIT(&tag[0], "ssec-head");
648: PAIR_STYLE_INIT(&tag[1], h);
1.21 kristaps 649: tag[2].key = ATTR_ID;
1.25 kristaps 650: tag[2].val = lbuf;
1.21 kristaps 651: print_otag(h, TAG_DIV, 3, tag);
1.1 kristaps 652: return(1);
653: }
654:
655:
656: /* ARGSUSED */
657: static int
658: mdoc_fl_pre(MDOC_ARGS)
659: {
660: struct htmlpair tag;
661:
1.23 kristaps 662: PAIR_CLASS_INIT(&tag, "flag");
1.1 kristaps 663: print_otag(h, TAG_SPAN, 1, &tag);
664: if (MDOC_Fl == n->tok) {
665: print_text(h, "\\-");
666: h->flags |= HTML_NOSPACE;
667: }
668: return(1);
669: }
670:
671:
672: /* ARGSUSED */
673: static int
674: mdoc_nd_pre(MDOC_ARGS)
675: {
676: struct htmlpair tag;
677:
678: if (MDOC_BODY != n->type)
679: return(1);
680:
1.24 kristaps 681: /* XXX: this tag in theory can contain block elements. */
682:
1.1 kristaps 683: print_text(h, "\\(em");
1.23 kristaps 684: PAIR_CLASS_INIT(&tag, "desc-body");
1.1 kristaps 685: print_otag(h, TAG_SPAN, 1, &tag);
686: return(1);
687: }
688:
689:
690: /* ARGSUSED */
691: static int
692: mdoc_op_pre(MDOC_ARGS)
693: {
694: struct htmlpair tag;
695:
696: if (MDOC_BODY != n->type)
697: return(1);
698:
1.24 kristaps 699: /* XXX: this tag in theory can contain block elements. */
700:
1.1 kristaps 701: print_text(h, "\\(lB");
702: h->flags |= HTML_NOSPACE;
1.23 kristaps 703: PAIR_CLASS_INIT(&tag, "opt");
1.1 kristaps 704: print_otag(h, TAG_SPAN, 1, &tag);
705: return(1);
706: }
707:
708:
709: /* ARGSUSED */
710: static void
711: mdoc_op_post(MDOC_ARGS)
712: {
713:
714: if (MDOC_BODY != n->type)
715: return;
716: h->flags |= HTML_NOSPACE;
717: print_text(h, "\\(rB");
718: }
719:
720:
721: static int
722: mdoc_nm_pre(MDOC_ARGS)
723: {
724: struct htmlpair tag;
725:
726: if ( ! (HTML_NEWLINE & h->flags))
727: if (SEC_SYNOPSIS == n->sec) {
1.23 kristaps 728: bufcat_style(h, "clear", "both");
729: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 730: print_otag(h, TAG_BR, 1, &tag);
731: }
732:
1.23 kristaps 733: PAIR_CLASS_INIT(&tag, "name");
1.1 kristaps 734: print_otag(h, TAG_SPAN, 1, &tag);
735: if (NULL == n->child)
736: print_text(h, m->name);
737:
738: return(1);
739: }
740:
741:
742: /* ARGSUSED */
743: static int
744: mdoc_xr_pre(MDOC_ARGS)
745: {
746: struct htmlpair tag[2];
747: const struct mdoc_node *nn;
1.17 kristaps 748:
1.23 kristaps 749: PAIR_CLASS_INIT(&tag[0], "link-man");
1.1 kristaps 750:
1.17 kristaps 751: if (h->base_man) {
1.23 kristaps 752: buffmt_man(h, n->child->string,
753: n->child->next ?
1.17 kristaps 754: n->child->next->string : NULL);
1.23 kristaps 755: tag[1].key = ATTR_HREF;
756: tag[1].val = h->buf;
757: print_otag(h, TAG_A, 2, tag);
758: } else
759: print_otag(h, TAG_A, 1, tag);
1.1 kristaps 760:
761: nn = n->child;
762: print_text(h, nn->string);
1.16 kristaps 763:
1.1 kristaps 764: if (NULL == (nn = nn->next))
765: return(0);
766:
767: h->flags |= HTML_NOSPACE;
768: print_text(h, "(");
769: h->flags |= HTML_NOSPACE;
770: print_text(h, nn->string);
771: h->flags |= HTML_NOSPACE;
772: print_text(h, ")");
773: return(0);
774: }
775:
776:
777: /* ARGSUSED */
778: static int
779: mdoc_ns_pre(MDOC_ARGS)
780: {
781:
782: h->flags |= HTML_NOSPACE;
783: return(1);
784: }
785:
786:
787: /* ARGSUSED */
788: static int
789: mdoc_ar_pre(MDOC_ARGS)
790: {
791: struct htmlpair tag;
792:
1.23 kristaps 793: PAIR_CLASS_INIT(&tag, "arg");
1.1 kristaps 794: print_otag(h, TAG_SPAN, 1, &tag);
795: return(1);
796: }
797:
798:
799: /* ARGSUSED */
800: static int
801: mdoc_xx_pre(MDOC_ARGS)
802: {
803: const char *pp;
804: struct htmlpair tag;
805:
806: switch (n->tok) {
807: case (MDOC_Bsx):
808: pp = "BSDI BSD/OS";
809: break;
810: case (MDOC_Dx):
811: pp = "DragonFlyBSD";
812: break;
813: case (MDOC_Fx):
814: pp = "FreeBSD";
815: break;
816: case (MDOC_Nx):
817: pp = "NetBSD";
818: break;
819: case (MDOC_Ox):
820: pp = "OpenBSD";
821: break;
822: case (MDOC_Ux):
823: pp = "UNIX";
824: break;
825: default:
826: return(1);
827: }
828:
1.23 kristaps 829: PAIR_CLASS_INIT(&tag, "unix");
1.1 kristaps 830: print_otag(h, TAG_SPAN, 1, &tag);
831: print_text(h, pp);
832: return(1);
833: }
834:
835:
836: /* ARGSUSED */
837: static int
1.4 kristaps 838: mdoc_bx_pre(MDOC_ARGS)
839: {
840: const struct mdoc_node *nn;
841: struct htmlpair tag;
842:
1.23 kristaps 843: PAIR_CLASS_INIT(&tag, "unix");
1.4 kristaps 844: print_otag(h, TAG_SPAN, 1, &tag);
845:
846: for (nn = n->child; nn; nn = nn->next)
847: print_mdoc_node(m, nn, h);
848:
849: if (n->child)
850: h->flags |= HTML_NOSPACE;
851:
852: print_text(h, "BSD");
853: return(0);
854: }
855:
856:
857: /* ARGSUSED */
858: static int
1.27 kristaps 859: mdoc_it_block_pre(MDOC_ARGS, int type, int comp,
860: struct roffsu *offs, struct roffsu *width)
1.1 kristaps 861: {
1.14 kristaps 862: struct htmlpair tag;
863: const struct mdoc_node *nn;
1.23 kristaps 864: struct roffsu su;
865:
866: nn = n->parent->parent;
867: assert(nn->args);
868:
1.24 kristaps 869: /* XXX: see notes in mdoc_it_pre(). */
870:
871: if (MDOC_Column == type) {
872: /* Don't width-pad on the left. */
873: SCALE_HS_INIT(width, 0);
874: /* Also disallow non-compact. */
875: comp = 1;
876: }
1.23 kristaps 877: if (MDOC_Diag == type)
1.24 kristaps 878: /* Mandate non-compact with empty prior. */
1.23 kristaps 879: if (n->prev && NULL == n->prev->body->child)
880: comp = 1;
881:
1.24 kristaps 882: bufcat_style(h, "clear", "both");
1.23 kristaps 883: if (offs->scale > 0)
884: bufcat_su(h, "margin-left", offs);
885: if (width->scale > 0)
886: bufcat_su(h, "padding-left", width);
1.1 kristaps 887:
1.23 kristaps 888: PAIR_STYLE_INIT(&tag, h);
889:
1.24 kristaps 890: /* Mandate compact following `Ss' and `Sh' starts. */
891:
1.23 kristaps 892: for (nn = n; nn && ! comp; nn = nn->parent) {
893: if (MDOC_BLOCK != nn->type)
894: continue;
895: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
896: comp = 1;
897: if (nn->prev)
898: break;
1.1 kristaps 899: }
900:
1.23 kristaps 901: if ( ! comp) {
902: SCALE_VS_INIT(&su, 1);
903: bufcat_su(h, "padding-top", &su);
1.1 kristaps 904: }
905:
1.23 kristaps 906: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 907: print_otag(h, TAG_DIV, 1, &tag);
908: return(1);
909: }
910:
911:
1.25 kristaps 912: /* ARGSUSED */
1.1 kristaps 913: static int
1.23 kristaps 914: mdoc_it_body_pre(MDOC_ARGS, int type)
1.1 kristaps 915: {
1.23 kristaps 916: struct htmlpair tag;
917: struct roffsu su;
918:
919: switch (type) {
920: case (MDOC_Item):
921: /* FALLTHROUGH */
922: case (MDOC_Ohang):
923: /* FALLTHROUGH */
924: case (MDOC_Column):
925: break;
926: default:
1.24 kristaps 927: /*
928: * XXX: this tricks CSS into aligning the bodies with
929: * the right-padding in the head.
930: */
1.23 kristaps 931: SCALE_HS_INIT(&su, 2);
932: bufcat_su(h, "margin-left", &su);
933: PAIR_STYLE_INIT(&tag, h);
934: print_otag(h, TAG_DIV, 1, &tag);
935: break;
936: }
1.1 kristaps 937:
938: return(1);
939: }
940:
941:
1.25 kristaps 942: /* ARGSUSED */
1.1 kristaps 943: static int
1.23 kristaps 944: mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *width)
1.1 kristaps 945: {
946: struct htmlpair tag;
947: struct ord *ord;
948: char nbuf[BUFSIZ];
949:
1.23 kristaps 950: switch (type) {
1.1 kristaps 951: case (MDOC_Item):
952: /* FALLTHROUGH */
953: case (MDOC_Ohang):
954: print_otag(h, TAG_DIV, 0, NULL);
955: break;
956: case (MDOC_Column):
1.23 kristaps 957: bufcat_su(h, "min-width", width);
958: bufcat_style(h, "clear", "none");
1.1 kristaps 959: if (n->next && MDOC_HEAD == n->next->type)
1.23 kristaps 960: bufcat_style(h, "float", "left");
961: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 962: print_otag(h, TAG_DIV, 1, &tag);
963: break;
964: default:
1.23 kristaps 965: bufcat_su(h, "min-width", width);
966: SCALE_INVERT(width);
967: bufcat_su(h, "margin-left", width);
1.2 kristaps 968: if (n->next && n->next->child)
1.23 kristaps 969: bufcat_style(h, "float", "left");
1.24 kristaps 970:
971: /* XXX: buffer if we run into body. */
1.23 kristaps 972: SCALE_HS_INIT(width, 1);
973: bufcat_su(h, "margin-right", width);
974: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 975: print_otag(h, TAG_DIV, 1, &tag);
976: break;
977: }
978:
1.23 kristaps 979: switch (type) {
1.1 kristaps 980: case (MDOC_Diag):
1.23 kristaps 981: PAIR_CLASS_INIT(&tag, "diag");
1.1 kristaps 982: print_otag(h, TAG_SPAN, 1, &tag);
983: break;
984: case (MDOC_Enum):
985: ord = SLIST_FIRST(&h->ords);
986: assert(ord);
987: nbuf[BUFSIZ - 1] = 0;
988: (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
989: print_text(h, nbuf);
990: return(0);
991: case (MDOC_Dash):
992: print_text(h, "\\(en");
993: return(0);
994: case (MDOC_Hyphen):
1.4 kristaps 995: print_text(h, "\\(hy");
1.1 kristaps 996: return(0);
997: case (MDOC_Bullet):
998: print_text(h, "\\(bu");
999: return(0);
1000: default:
1001: break;
1002: }
1003:
1004: return(1);
1005: }
1006:
1007:
1008: static int
1.23 kristaps 1009: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 1010: {
1.23 kristaps 1011: int i, type, wp, comp;
1.1 kristaps 1012: const struct mdoc_node *bl, *nn;
1.23 kristaps 1013: struct roffsu width, offs;
1014:
1.24 kristaps 1015: /*
1016: * XXX: be very careful in changing anything, here. Lists in
1017: * mandoc have many peculiarities; furthermore, they don't
1018: * translate well into HTML and require a bit of mangling.
1019: */
1.1 kristaps 1020:
1021: bl = n->parent->parent;
1.23 kristaps 1022: if (MDOC_BLOCK != n->type)
1.1 kristaps 1023: bl = bl->parent;
1024:
1.23 kristaps 1025: type = a2list(bl);
1.1 kristaps 1026:
1.23 kristaps 1027: /* Set default width and offset. */
1.1 kristaps 1028:
1.24 kristaps 1029: SCALE_HS_INIT(&offs, 0);
1030:
1.1 kristaps 1031: switch (type) {
1032: case (MDOC_Enum):
1033: /* FALLTHROUGH */
1034: case (MDOC_Dash):
1035: /* FALLTHROUGH */
1036: case (MDOC_Hyphen):
1037: /* FALLTHROUGH */
1038: case (MDOC_Bullet):
1.23 kristaps 1039: SCALE_HS_INIT(&width, 2);
1.1 kristaps 1040: break;
1.23 kristaps 1041: default:
1042: SCALE_HS_INIT(&width, INDENT);
1043: break;
1044: }
1045:
1046: /* Get width, offset, and compact arguments. */
1047:
1048: for (wp = -1, comp = i = 0; i < (int)bl->args->argc; i++)
1049: switch (bl->args->argv[i].arg) {
1.24 kristaps 1050: case (MDOC_Column):
1051: wp = i; /* Save for later. */
1052: break;
1.23 kristaps 1053: case (MDOC_Width):
1054: a2width(bl->args->argv[i].value[0], &width);
1055: break;
1056: case (MDOC_Offset):
1057: a2offs(bl->args->argv[i].value[0], &offs);
1058: break;
1059: case (MDOC_Compact):
1060: comp = 1;
1061: break;
1062: default:
1063: break;
1064: }
1065:
1066: /* Override width in some cases. */
1067:
1068: switch (type) {
1.1 kristaps 1069: case (MDOC_Inset):
1070: /* FALLTHROUGH */
1071: case (MDOC_Diag):
1.23 kristaps 1072: SCALE_HS_INIT(&width, 0);
1.1 kristaps 1073: break;
1074: default:
1.23 kristaps 1075: if (0 == width.scale)
1076: SCALE_HS_INIT(&width, INDENT);
1.1 kristaps 1077: break;
1078: }
1079:
1.23 kristaps 1080: /* Flip to body/block processing. */
1081:
1082: if (MDOC_BODY == n->type)
1083: return(mdoc_it_body_pre(m, n, h, type));
1084: if (MDOC_BLOCK == n->type)
1.27 kristaps 1085: return(mdoc_it_block_pre(m, n, h, type, comp,
1086: &offs, &width));
1.23 kristaps 1087:
1088: /* Override column widths. */
1089:
1090: if (MDOC_Column == type) {
1091: nn = n->parent->child;
1092: for (i = 0; nn && nn != n; nn = nn->next, i++)
1093: /* Counter... */ ;
1.24 kristaps 1094: if (i < (int)bl->args->argv[wp].sz)
1.23 kristaps 1095: a2width(bl->args->argv[wp].value[i], &width);
1.1 kristaps 1096: }
1097:
1.23 kristaps 1098: return(mdoc_it_head_pre(m, n, h, type, &width));
1.1 kristaps 1099: }
1100:
1101:
1102: /* ARGSUSED */
1103: static int
1104: mdoc_bl_pre(MDOC_ARGS)
1105: {
1106: struct ord *ord;
1107:
1108: if (MDOC_BLOCK != n->type)
1109: return(1);
1110: if (MDOC_Enum != a2list(n))
1111: return(1);
1112:
1113: ord = malloc(sizeof(struct ord));
1114: if (NULL == ord)
1115: err(EXIT_FAILURE, "malloc");
1116: ord->cookie = n;
1117: ord->pos = 1;
1118: SLIST_INSERT_HEAD(&h->ords, ord, entry);
1119: return(1);
1120: }
1121:
1122:
1123: /* ARGSUSED */
1124: static void
1125: mdoc_bl_post(MDOC_ARGS)
1126: {
1127: struct ord *ord;
1128:
1129: if (MDOC_BLOCK != n->type)
1130: return;
1131: if (MDOC_Enum != a2list(n))
1132: return;
1133:
1134: ord = SLIST_FIRST(&h->ords);
1135: assert(ord);
1136: SLIST_REMOVE_HEAD(&h->ords, entry);
1137: free(ord);
1138: }
1139:
1140:
1141: /* ARGSUSED */
1142: static int
1143: mdoc_ex_pre(MDOC_ARGS)
1144: {
1145: const struct mdoc_node *nn;
1146: struct tag *t;
1147: struct htmlpair tag;
1148:
1.23 kristaps 1149: PAIR_CLASS_INIT(&tag, "utility");
1150:
1.1 kristaps 1151: print_text(h, "The");
1152: for (nn = n->child; nn; nn = nn->next) {
1153: t = print_otag(h, TAG_SPAN, 1, &tag);
1154: print_text(h, nn->string);
1155: print_tagq(h, t);
1156:
1157: h->flags |= HTML_NOSPACE;
1158:
1159: if (nn->next && NULL == nn->next->next)
1160: print_text(h, ", and");
1161: else if (nn->next)
1162: print_text(h, ",");
1163: else
1164: h->flags &= ~HTML_NOSPACE;
1165: }
1166:
1167: if (n->child->next)
1168: print_text(h, "utilities exit");
1169: else
1170: print_text(h, "utility exits");
1171:
1172: print_text(h, "0 on success, and >0 if an error occurs.");
1173: return(0);
1174: }
1175:
1176:
1177: /* ARGSUSED */
1178: static int
1179: mdoc_dq_pre(MDOC_ARGS)
1180: {
1181:
1182: if (MDOC_BODY != n->type)
1183: return(1);
1184: print_text(h, "\\(lq");
1185: h->flags |= HTML_NOSPACE;
1186: return(1);
1187: }
1188:
1189:
1190: /* ARGSUSED */
1191: static void
1192: mdoc_dq_post(MDOC_ARGS)
1193: {
1194:
1195: if (MDOC_BODY != n->type)
1196: return;
1197: h->flags |= HTML_NOSPACE;
1198: print_text(h, "\\(rq");
1199: }
1200:
1201:
1202: /* ARGSUSED */
1203: static int
1204: mdoc_pq_pre(MDOC_ARGS)
1205: {
1206:
1207: if (MDOC_BODY != n->type)
1208: return(1);
1209: print_text(h, "\\&(");
1210: h->flags |= HTML_NOSPACE;
1211: return(1);
1212: }
1213:
1214:
1215: /* ARGSUSED */
1216: static void
1217: mdoc_pq_post(MDOC_ARGS)
1218: {
1219:
1220: if (MDOC_BODY != n->type)
1221: return;
1222: print_text(h, ")");
1223: }
1224:
1225:
1226: /* ARGSUSED */
1227: static int
1228: mdoc_sq_pre(MDOC_ARGS)
1229: {
1230:
1231: if (MDOC_BODY != n->type)
1232: return(1);
1233: print_text(h, "\\(oq");
1234: h->flags |= HTML_NOSPACE;
1235: return(1);
1236: }
1237:
1238:
1239: /* ARGSUSED */
1240: static void
1241: mdoc_sq_post(MDOC_ARGS)
1242: {
1243:
1244: if (MDOC_BODY != n->type)
1245: return;
1246: h->flags |= HTML_NOSPACE;
1247: print_text(h, "\\(aq");
1248: }
1249:
1250:
1251: /* ARGSUSED */
1252: static int
1253: mdoc_em_pre(MDOC_ARGS)
1254: {
1255: struct htmlpair tag;
1256:
1.23 kristaps 1257: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1258: print_otag(h, TAG_SPAN, 1, &tag);
1259: return(1);
1260: }
1261:
1262:
1263: /* ARGSUSED */
1264: static int
1265: mdoc_d1_pre(MDOC_ARGS)
1266: {
1.23 kristaps 1267: struct htmlpair tag[2];
1268: struct roffsu su;
1.1 kristaps 1269:
1270: if (MDOC_BLOCK != n->type)
1271: return(1);
1272:
1.23 kristaps 1273: SCALE_VS_INIT(&su, INDENT - 2);
1274: bufcat_su(h, "margin-left", &su);
1275: PAIR_CLASS_INIT(&tag[0], "lit");
1276: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1277: print_otag(h, TAG_DIV, 2, tag);
1278: return(1);
1279: }
1280:
1281:
1282: /* ARGSUSED */
1283: static int
1284: mdoc_sx_pre(MDOC_ARGS)
1285: {
1.18 kristaps 1286: struct htmlpair tag[2];
1.1 kristaps 1287: const struct mdoc_node *nn;
1.25 kristaps 1288: char lbuf[BUFSIZ];
1.1 kristaps 1289:
1.23 kristaps 1290: /* FIXME: duplicates? */
1291:
1.25 kristaps 1292: (void)strlcpy(lbuf, "#", BUFSIZ);
1.1 kristaps 1293: for (nn = n->child; nn; nn = nn->next) {
1.25 kristaps 1294: (void)strlcat(lbuf, nn->string, BUFSIZ);
1.1 kristaps 1295: if (nn->next)
1.25 kristaps 1296: (void)strlcat(lbuf, "_", BUFSIZ);
1.1 kristaps 1297: }
1298:
1.23 kristaps 1299: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.21 kristaps 1300: tag[1].key = ATTR_HREF;
1.25 kristaps 1301: tag[1].val = lbuf;
1.1 kristaps 1302:
1.18 kristaps 1303: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1304: return(1);
1305: }
1306:
1307:
1308: /* ARGSUSED */
1309: static int
1310: mdoc_aq_pre(MDOC_ARGS)
1311: {
1312:
1313: if (MDOC_BODY != n->type)
1314: return(1);
1315: print_text(h, "\\(la");
1316: h->flags |= HTML_NOSPACE;
1317: return(1);
1318: }
1319:
1320:
1321: /* ARGSUSED */
1322: static void
1323: mdoc_aq_post(MDOC_ARGS)
1324: {
1325:
1326: if (MDOC_BODY != n->type)
1327: return;
1328: h->flags |= HTML_NOSPACE;
1329: print_text(h, "\\(ra");
1330: }
1331:
1332:
1333: /* ARGSUSED */
1334: static int
1335: mdoc_bd_pre(MDOC_ARGS)
1336: {
1337: struct htmlpair tag[2];
1.23 kristaps 1338: int type, comp, i;
1.14 kristaps 1339: const struct mdoc_node *bl, *nn;
1.23 kristaps 1340: struct roffsu su;
1.1 kristaps 1341:
1342: if (MDOC_BLOCK == n->type)
1343: bl = n;
1344: else if (MDOC_HEAD == n->type)
1345: return(0);
1346: else
1347: bl = n->parent;
1348:
1.24 kristaps 1349: SCALE_VS_INIT(&su, 0);
1350:
1.23 kristaps 1351: type = comp = 0;
1.1 kristaps 1352: for (i = 0; i < (int)bl->args->argc; i++)
1353: switch (bl->args->argv[i].arg) {
1354: case (MDOC_Offset):
1.23 kristaps 1355: a2offs(bl->args->argv[i].value[0], &su);
1.1 kristaps 1356: break;
1357: case (MDOC_Compact):
1.23 kristaps 1358: comp = 1;
1.1 kristaps 1359: break;
1.30 ! kristaps 1360: case (MDOC_Centred):
! 1361: /* FALLTHROUGH */
1.1 kristaps 1362: case (MDOC_Ragged):
1363: /* FALLTHROUGH */
1364: case (MDOC_Filled):
1365: /* FALLTHROUGH */
1366: case (MDOC_Unfilled):
1367: /* FALLTHROUGH */
1368: case (MDOC_Literal):
1.23 kristaps 1369: type = bl->args->argv[i].arg;
1.1 kristaps 1370: break;
1.30 ! kristaps 1371: default:
! 1372: break;
1.1 kristaps 1373: }
1374:
1375: if (MDOC_BLOCK == n->type) {
1.24 kristaps 1376: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1377: for (nn = n; nn && ! comp; nn = nn->parent) {
1378: if (MDOC_BLOCK != nn->type)
1379: continue;
1380: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1381: comp = 1;
1382: if (nn->prev)
1383: break;
1384: }
1385: if (comp) {
1386: print_otag(h, TAG_DIV, 0, tag);
1387: return(1);
1.14 kristaps 1388: }
1.23 kristaps 1389: SCALE_VS_INIT(&su, 1);
1390: bufcat_su(h, "margin-top", &su);
1391: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 1392: print_otag(h, TAG_DIV, 1, tag);
1393: return(1);
1394: }
1395:
1.23 kristaps 1396: if (MDOC_Unfilled != type && MDOC_Literal != type)
1.1 kristaps 1397: return(1);
1398:
1.23 kristaps 1399: PAIR_CLASS_INIT(&tag[0], "lit");
1400: bufcat_style(h, "white-space", "pre");
1401: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1402: print_otag(h, TAG_DIV, 2, tag);
1403:
1.14 kristaps 1404: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1405: h->flags |= HTML_NOSPACE;
1.14 kristaps 1406: print_mdoc_node(m, nn, h);
1407: if (NULL == nn->next)
1408: continue;
1409: if (nn->prev && nn->prev->line < nn->line)
1.1 kristaps 1410: print_text(h, "\n");
1.23 kristaps 1411: else if (NULL == nn->prev)
1412: print_text(h, "\n");
1.1 kristaps 1413: }
1414:
1415: return(0);
1416: }
1417:
1418:
1419: /* ARGSUSED */
1420: static int
1421: mdoc_pa_pre(MDOC_ARGS)
1422: {
1423: struct htmlpair tag;
1424:
1.23 kristaps 1425: PAIR_CLASS_INIT(&tag, "file");
1.1 kristaps 1426: print_otag(h, TAG_SPAN, 1, &tag);
1427: return(1);
1428: }
1429:
1430:
1431: /* ARGSUSED */
1432: static int
1433: mdoc_ad_pre(MDOC_ARGS)
1434: {
1435: struct htmlpair tag;
1436:
1.23 kristaps 1437: PAIR_CLASS_INIT(&tag, "addr");
1.1 kristaps 1438: print_otag(h, TAG_SPAN, 1, &tag);
1439: return(1);
1440: }
1441:
1442:
1443: /* ARGSUSED */
1444: static int
1445: mdoc_an_pre(MDOC_ARGS)
1446: {
1447: struct htmlpair tag;
1448:
1.19 kristaps 1449: /* TODO: -split and -nosplit (see termp_an_pre()). */
1450:
1.23 kristaps 1451: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1452: print_otag(h, TAG_SPAN, 1, &tag);
1453: return(1);
1454: }
1455:
1456:
1457: /* ARGSUSED */
1458: static int
1459: mdoc_cd_pre(MDOC_ARGS)
1460: {
1461: struct htmlpair tag;
1462:
1.28 kristaps 1463: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 1464: PAIR_CLASS_INIT(&tag, "config");
1.1 kristaps 1465: print_otag(h, TAG_SPAN, 1, &tag);
1466: return(1);
1467: }
1468:
1469:
1470: /* ARGSUSED */
1471: static int
1472: mdoc_dv_pre(MDOC_ARGS)
1473: {
1474: struct htmlpair tag;
1475:
1.23 kristaps 1476: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1477: print_otag(h, TAG_SPAN, 1, &tag);
1478: return(1);
1479: }
1480:
1481:
1482: /* ARGSUSED */
1483: static int
1484: mdoc_ev_pre(MDOC_ARGS)
1485: {
1486: struct htmlpair tag;
1487:
1.23 kristaps 1488: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1489: print_otag(h, TAG_SPAN, 1, &tag);
1490: return(1);
1491: }
1492:
1493:
1494: /* ARGSUSED */
1495: static int
1496: mdoc_er_pre(MDOC_ARGS)
1497: {
1498: struct htmlpair tag;
1499:
1.23 kristaps 1500: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1501: print_otag(h, TAG_SPAN, 1, &tag);
1502: return(1);
1503: }
1504:
1505:
1506: /* ARGSUSED */
1507: static int
1508: mdoc_fa_pre(MDOC_ARGS)
1509: {
1510: const struct mdoc_node *nn;
1511: struct htmlpair tag;
1512: struct tag *t;
1513:
1.23 kristaps 1514: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1515: if (n->parent->tok != MDOC_Fo) {
1516: print_otag(h, TAG_SPAN, 1, &tag);
1517: return(1);
1518: }
1519:
1520: for (nn = n->child; nn; nn = nn->next) {
1521: t = print_otag(h, TAG_SPAN, 1, &tag);
1522: print_text(h, nn->string);
1523: print_tagq(h, t);
1524: if (nn->next)
1525: print_text(h, ",");
1526: }
1527:
1528: if (n->child && n->next && n->next->tok == MDOC_Fa)
1529: print_text(h, ",");
1530:
1531: return(0);
1532: }
1533:
1534:
1535: /* ARGSUSED */
1536: static int
1537: mdoc_fd_pre(MDOC_ARGS)
1538: {
1.23 kristaps 1539: struct htmlpair tag;
1540: struct roffsu su;
1.1 kristaps 1541:
1542: if (SEC_SYNOPSIS == n->sec) {
1543: if (n->next && MDOC_Fd != n->next->tok) {
1.23 kristaps 1544: SCALE_VS_INIT(&su, 1);
1545: bufcat_su(h, "margin-bottom", &su);
1546: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1547: print_otag(h, TAG_DIV, 1, &tag);
1548: } else
1549: print_otag(h, TAG_DIV, 0, NULL);
1550: }
1551:
1.23 kristaps 1552: PAIR_CLASS_INIT(&tag, "macro");
1.1 kristaps 1553: print_otag(h, TAG_SPAN, 1, &tag);
1554: return(1);
1555: }
1556:
1557:
1558: /* ARGSUSED */
1559: static int
1560: mdoc_vt_pre(MDOC_ARGS)
1561: {
1.23 kristaps 1562: struct htmlpair tag;
1563: struct roffsu su;
1.1 kristaps 1564:
1565: if (SEC_SYNOPSIS == n->sec) {
1566: if (n->next && MDOC_Vt != n->next->tok) {
1.23 kristaps 1567: SCALE_VS_INIT(&su, 1);
1568: bufcat_su(h, "margin-bottom", &su);
1569: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1570: print_otag(h, TAG_DIV, 1, &tag);
1571: } else
1572: print_otag(h, TAG_DIV, 0, NULL);
1573: }
1574:
1.23 kristaps 1575: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1576: print_otag(h, TAG_SPAN, 1, &tag);
1577: return(1);
1578: }
1579:
1.2 kristaps 1580:
1.1 kristaps 1581: /* ARGSUSED */
1582: static int
1583: mdoc_ft_pre(MDOC_ARGS)
1584: {
1.23 kristaps 1585: struct htmlpair tag;
1586: struct roffsu su;
1.1 kristaps 1587:
1588: if (SEC_SYNOPSIS == n->sec) {
1589: if (n->prev && MDOC_Fo == n->prev->tok) {
1.23 kristaps 1590: SCALE_VS_INIT(&su, 1);
1591: bufcat_su(h, "margin-top", &su);
1592: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1593: print_otag(h, TAG_DIV, 1, &tag);
1594: } else
1595: print_otag(h, TAG_DIV, 0, NULL);
1596: }
1597:
1.23 kristaps 1598: PAIR_CLASS_INIT(&tag, "ftype");
1.1 kristaps 1599: print_otag(h, TAG_SPAN, 1, &tag);
1600: return(1);
1601: }
1602:
1603:
1604: /* ARGSUSED */
1605: static int
1606: mdoc_fn_pre(MDOC_ARGS)
1607: {
1608: struct tag *t;
1.15 kristaps 1609: struct htmlpair tag[2];
1.1 kristaps 1610: const struct mdoc_node *nn;
1.7 kristaps 1611: char nbuf[BUFSIZ];
1612: const char *sp, *ep;
1.15 kristaps 1613: int sz, i;
1.23 kristaps 1614: struct roffsu su;
1.1 kristaps 1615:
1616: if (SEC_SYNOPSIS == n->sec) {
1.23 kristaps 1617: SCALE_HS_INIT(&su, INDENT);
1618: bufcat_su(h, "margin-left", &su);
1619: su.scale = -su.scale;
1620: bufcat_su(h, "text-indent", &su);
1621: if (n->next) {
1622: SCALE_VS_INIT(&su, 1);
1623: bufcat_su(h, "margin-bottom", &su);
1624: }
1625: PAIR_STYLE_INIT(&tag[0], h);
1.15 kristaps 1626: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 1627: }
1628:
1.7 kristaps 1629: /* Split apart into type and name. */
1630: assert(n->child->string);
1631: sp = n->child->string;
1.19 kristaps 1632:
1.26 kristaps 1633: ep = strchr(sp, ' ');
1634: if (NULL != ep) {
1.23 kristaps 1635: PAIR_CLASS_INIT(&tag[0], "ftype");
1.19 kristaps 1636: t = print_otag(h, TAG_SPAN, 1, tag);
1637:
1638: while (ep) {
1639: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1640: (void)memcpy(nbuf, sp, (size_t)sz);
1641: nbuf[sz] = '\0';
1642: print_text(h, nbuf);
1643: sp = ++ep;
1644: ep = strchr(sp, ' ');
1645: }
1646: print_tagq(h, t);
1.7 kristaps 1647: }
1.1 kristaps 1648:
1.23 kristaps 1649: PAIR_CLASS_INIT(&tag[0], "fname");
1.15 kristaps 1650: t = print_otag(h, TAG_SPAN, 1, tag);
1.7 kristaps 1651:
1652: if (sp) {
1653: (void)strlcpy(nbuf, sp, BUFSIZ);
1654: print_text(h, nbuf);
1655: }
1656:
1.1 kristaps 1657: print_tagq(h, t);
1658:
1659: h->flags |= HTML_NOSPACE;
1660: print_text(h, "(");
1661:
1.23 kristaps 1662: bufinit(h);
1663: PAIR_CLASS_INIT(&tag[0], "farg");
1664: bufcat_style(h, "white-space", "nowrap");
1665: PAIR_STYLE_INIT(&tag[1], h);
1666:
1.1 kristaps 1667: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1668: i = 1;
1669: if (SEC_SYNOPSIS == n->sec)
1670: i = 2;
1.15 kristaps 1671: t = print_otag(h, TAG_SPAN, i, tag);
1.1 kristaps 1672: print_text(h, nn->string);
1673: print_tagq(h, t);
1674: if (nn->next)
1675: print_text(h, ",");
1676: }
1677:
1678: print_text(h, ")");
1679: if (SEC_SYNOPSIS == n->sec)
1680: print_text(h, ";");
1681:
1682: return(0);
1683: }
1684:
1685:
1686: /* ARGSUSED */
1687: static int
1688: mdoc_sp_pre(MDOC_ARGS)
1689: {
1.23 kristaps 1690: int len;
1691: struct htmlpair tag;
1692: struct roffsu su;
1.1 kristaps 1693:
1694: switch (n->tok) {
1695: case (MDOC_sp):
1.23 kristaps 1696: /* FIXME: can this have a scaling indicator? */
1.1 kristaps 1697: len = n->child ? atoi(n->child->string) : 1;
1698: break;
1699: case (MDOC_br):
1700: len = 0;
1701: break;
1702: default:
1703: len = 1;
1704: break;
1705: }
1706:
1.23 kristaps 1707: SCALE_VS_INIT(&su, len);
1708: bufcat_su(h, "height", &su);
1709: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1710: print_otag(h, TAG_DIV, 1, &tag);
1711: return(1);
1712:
1713: }
1.2 kristaps 1714:
1715:
1716: /* ARGSUSED */
1717: static int
1718: mdoc_brq_pre(MDOC_ARGS)
1719: {
1720:
1721: if (MDOC_BODY != n->type)
1722: return(1);
1723: print_text(h, "\\(lC");
1724: h->flags |= HTML_NOSPACE;
1725: return(1);
1726: }
1727:
1728:
1729: /* ARGSUSED */
1730: static void
1731: mdoc_brq_post(MDOC_ARGS)
1732: {
1733:
1734: if (MDOC_BODY != n->type)
1735: return;
1736: h->flags |= HTML_NOSPACE;
1737: print_text(h, "\\(rC");
1738: }
1739:
1740:
1741: /* ARGSUSED */
1742: static int
1743: mdoc_lk_pre(MDOC_ARGS)
1744: {
1745: const struct mdoc_node *nn;
1746: struct htmlpair tag[2];
1747:
1748: nn = n->child;
1749:
1.23 kristaps 1750: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.2 kristaps 1751: tag[1].key = ATTR_HREF;
1752: tag[1].val = nn->string;
1753: print_otag(h, TAG_A, 2, tag);
1754:
1755: for (nn = nn->next; nn; nn = nn->next)
1756: print_text(h, nn->string);
1757:
1758: return(0);
1759: }
1760:
1761:
1762: /* ARGSUSED */
1763: static int
1764: mdoc_mt_pre(MDOC_ARGS)
1765: {
1766: struct htmlpair tag[2];
1767: struct tag *t;
1768: const struct mdoc_node *nn;
1769:
1.23 kristaps 1770: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1771:
1772: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1773: bufinit(h);
1774: bufcat(h, "mailto:");
1775: bufcat(h, nn->string);
1.23 kristaps 1776: PAIR_STYLE_INIT(&tag[1], h);
1.2 kristaps 1777: t = print_otag(h, TAG_A, 2, tag);
1778: print_text(h, nn->string);
1779: print_tagq(h, t);
1780: }
1781:
1782: return(0);
1783: }
1.4 kristaps 1784:
1785:
1786: /* ARGSUSED */
1787: static int
1788: mdoc_fo_pre(MDOC_ARGS)
1789: {
1790: struct htmlpair tag;
1791:
1792: if (MDOC_BODY == n->type) {
1793: h->flags |= HTML_NOSPACE;
1794: print_text(h, "(");
1795: h->flags |= HTML_NOSPACE;
1796: return(1);
1797: } else if (MDOC_BLOCK == n->type)
1798: return(1);
1799:
1.23 kristaps 1800: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1801: print_otag(h, TAG_SPAN, 1, &tag);
1802: return(1);
1803: }
1804:
1805:
1806: /* ARGSUSED */
1807: static void
1808: mdoc_fo_post(MDOC_ARGS)
1809: {
1810: if (MDOC_BODY != n->type)
1811: return;
1812: h->flags |= HTML_NOSPACE;
1813: print_text(h, ")");
1814: h->flags |= HTML_NOSPACE;
1815: print_text(h, ";");
1816: }
1817:
1818:
1819: /* ARGSUSED */
1820: static int
1821: mdoc_in_pre(MDOC_ARGS)
1822: {
1823: const struct mdoc_node *nn;
1.23 kristaps 1824: struct tag *t;
1.17 kristaps 1825: struct htmlpair tag[2];
1826: int i;
1.23 kristaps 1827: struct roffsu su;
1.4 kristaps 1828:
1829: if (SEC_SYNOPSIS == n->sec) {
1830: if (n->next && MDOC_In != n->next->tok) {
1.23 kristaps 1831: SCALE_VS_INIT(&su, 1);
1832: bufcat_su(h, "margin-bottom", &su);
1833: PAIR_STYLE_INIT(&tag[0], h);
1.17 kristaps 1834: print_otag(h, TAG_DIV, 1, tag);
1.4 kristaps 1835: } else
1836: print_otag(h, TAG_DIV, 0, NULL);
1837: }
1838:
1.23 kristaps 1839: PAIR_CLASS_INIT(&tag[0], "includes");
1.17 kristaps 1840: print_otag(h, TAG_SPAN, 1, tag);
1.4 kristaps 1841:
1842: if (SEC_SYNOPSIS == n->sec)
1843: print_text(h, "#include");
1844:
1845: print_text(h, "<");
1846: h->flags |= HTML_NOSPACE;
1847:
1848: /* XXX -- see warning in termp_in_post(). */
1849:
1.17 kristaps 1850: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1851: PAIR_CLASS_INIT(&tag[0], "link-includes");
1852: i = 1;
1.17 kristaps 1853: if (h->base_includes) {
1854: buffmt_includes(h, nn->string);
1855: tag[i].key = ATTR_HREF;
1856: tag[i++].val = h->buf;
1857: }
1858: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1859: print_mdoc_node(m, nn, h);
1.17 kristaps 1860: print_tagq(h, t);
1861: }
1.4 kristaps 1862:
1863: h->flags |= HTML_NOSPACE;
1864: print_text(h, ">");
1865:
1866: return(0);
1867: }
1868:
1869:
1870: /* ARGSUSED */
1871: static int
1872: mdoc_ic_pre(MDOC_ARGS)
1873: {
1874: struct htmlpair tag;
1875:
1.23 kristaps 1876: PAIR_CLASS_INIT(&tag, "cmd");
1.4 kristaps 1877: print_otag(h, TAG_SPAN, 1, &tag);
1878: return(1);
1879: }
1880:
1881:
1882: /* ARGSUSED */
1883: static int
1884: mdoc_rv_pre(MDOC_ARGS)
1885: {
1886: const struct mdoc_node *nn;
1887: struct htmlpair tag;
1888: struct tag *t;
1889:
1890: print_otag(h, TAG_DIV, 0, NULL);
1891: print_text(h, "The");
1892:
1893: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1894: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1895: t = print_otag(h, TAG_SPAN, 1, &tag);
1896: print_text(h, nn->string);
1897: print_tagq(h, t);
1898:
1899: h->flags |= HTML_NOSPACE;
1900: if (nn->next && NULL == nn->next->next)
1901: print_text(h, "(), and");
1902: else if (nn->next)
1903: print_text(h, "(),");
1904: else
1905: print_text(h, "()");
1906: }
1907:
1908: if (n->child->next)
1909: print_text(h, "functions return");
1910: else
1911: print_text(h, "function returns");
1912:
1913: print_text(h, "the value 0 if successful; otherwise the value "
1914: "-1 is returned and the global variable");
1915:
1.23 kristaps 1916: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1917: t = print_otag(h, TAG_SPAN, 1, &tag);
1918: print_text(h, "errno");
1919: print_tagq(h, t);
1920: print_text(h, "is set to indicate the error.");
1921: return(0);
1922: }
1923:
1924:
1925: /* ARGSUSED */
1926: static int
1927: mdoc_va_pre(MDOC_ARGS)
1928: {
1929: struct htmlpair tag;
1930:
1.23 kristaps 1931: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1932: print_otag(h, TAG_SPAN, 1, &tag);
1933: return(1);
1934: }
1935:
1936:
1937: /* ARGSUSED */
1938: static int
1939: mdoc_bq_pre(MDOC_ARGS)
1940: {
1941:
1942: if (MDOC_BODY != n->type)
1943: return(1);
1944: print_text(h, "\\(lB");
1945: h->flags |= HTML_NOSPACE;
1946: return(1);
1947: }
1948:
1949:
1950: /* ARGSUSED */
1951: static void
1952: mdoc_bq_post(MDOC_ARGS)
1953: {
1954:
1955: if (MDOC_BODY != n->type)
1956: return;
1957: h->flags |= HTML_NOSPACE;
1958: print_text(h, "\\(rB");
1959: }
1.5 kristaps 1960:
1961:
1962: /* ARGSUSED */
1963: static int
1964: mdoc_ap_pre(MDOC_ARGS)
1965: {
1966:
1967: h->flags |= HTML_NOSPACE;
1968: print_text(h, "\\(aq");
1969: h->flags |= HTML_NOSPACE;
1970: return(1);
1971: }
1972:
1973:
1974: /* ARGSUSED */
1975: static int
1976: mdoc_bf_pre(MDOC_ARGS)
1977: {
1.23 kristaps 1978: int i;
1979: struct htmlpair tag[2];
1980: struct roffsu su;
1.5 kristaps 1981:
1982: if (MDOC_HEAD == n->type)
1983: return(0);
1984: else if (MDOC_BLOCK != n->type)
1985: return(1);
1986:
1.23 kristaps 1987: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 1988:
1989: if (n->head->child) {
1990: if ( ! strcmp("Em", n->head->child->string))
1.23 kristaps 1991: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 1992: else if ( ! strcmp("Sy", n->head->child->string))
1.23 kristaps 1993: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 1994: else if ( ! strcmp("Li", n->head->child->string))
1.23 kristaps 1995: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 1996: } else {
1997: assert(n->args);
1998: for (i = 0; i < (int)n->args->argc; i++)
1999: switch (n->args->argv[i].arg) {
2000: case (MDOC_Symbolic):
1.23 kristaps 2001: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 2002: break;
2003: case (MDOC_Literal):
1.23 kristaps 2004: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 2005: break;
2006: case (MDOC_Emphasis):
1.23 kristaps 2007: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 2008: break;
2009: default:
2010: break;
2011: }
2012: }
2013:
2014: /* FIXME: div's have spaces stripped--we want them. */
2015:
1.23 kristaps 2016: bufcat_style(h, "display", "inline");
2017: SCALE_HS_INIT(&su, 1);
2018: bufcat_su(h, "margin-right", &su);
2019: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 2020: print_otag(h, TAG_DIV, 2, tag);
2021: return(1);
2022: }
2023:
2024:
2025: /* ARGSUSED */
2026: static int
2027: mdoc_ms_pre(MDOC_ARGS)
2028: {
2029: struct htmlpair tag;
2030:
1.23 kristaps 2031: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 2032: print_otag(h, TAG_SPAN, 1, &tag);
2033: return(1);
2034: }
2035:
2036:
2037: /* ARGSUSED */
2038: static int
2039: mdoc_pf_pre(MDOC_ARGS)
2040: {
2041:
2042: h->flags |= HTML_IGNDELIM;
2043: return(1);
2044: }
2045:
2046:
2047: /* ARGSUSED */
2048: static void
2049: mdoc_pf_post(MDOC_ARGS)
2050: {
2051:
2052: h->flags &= ~HTML_IGNDELIM;
2053: h->flags |= HTML_NOSPACE;
2054: }
2055:
2056:
2057: /* ARGSUSED */
2058: static int
2059: mdoc_rs_pre(MDOC_ARGS)
2060: {
1.23 kristaps 2061: struct htmlpair tag;
2062: struct roffsu su;
1.5 kristaps 2063:
2064: if (MDOC_BLOCK != n->type)
2065: return(1);
2066:
1.8 kristaps 2067: if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23 kristaps 2068: SCALE_VS_INIT(&su, 1);
2069: bufcat_su(h, "margin-top", &su);
2070: PAIR_STYLE_INIT(&tag, h);
1.8 kristaps 2071: print_otag(h, TAG_DIV, 1, &tag);
1.5 kristaps 2072: }
2073:
1.23 kristaps 2074: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 2075: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 2076: return(1);
2077: }
1.6 kristaps 2078:
2079:
2080:
2081: /* ARGSUSED */
2082: static int
2083: mdoc_li_pre(MDOC_ARGS)
2084: {
2085: struct htmlpair tag;
2086:
1.23 kristaps 2087: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 2088: print_otag(h, TAG_SPAN, 1, &tag);
2089: return(1);
2090: }
2091:
2092:
2093: /* ARGSUSED */
2094: static int
2095: mdoc_sy_pre(MDOC_ARGS)
2096: {
2097: struct htmlpair tag;
2098:
1.23 kristaps 2099: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 2100: print_otag(h, TAG_SPAN, 1, &tag);
2101: return(1);
2102: }
2103:
2104:
2105: /* ARGSUSED */
2106: static int
2107: mdoc_bt_pre(MDOC_ARGS)
2108: {
2109:
2110: print_text(h, "is currently in beta test.");
2111: return(0);
2112: }
2113:
2114:
2115: /* ARGSUSED */
2116: static int
2117: mdoc_ud_pre(MDOC_ARGS)
2118: {
2119:
2120: print_text(h, "currently under development.");
2121: return(0);
2122: }
2123:
2124:
2125: /* ARGSUSED */
2126: static int
2127: mdoc_lb_pre(MDOC_ARGS)
2128: {
2129: struct htmlpair tag;
2130:
2131: if (SEC_SYNOPSIS == n->sec)
2132: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 2133: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 2134: print_otag(h, TAG_SPAN, 1, &tag);
2135: return(1);
2136: }
1.10 kristaps 2137:
2138:
2139: /* ARGSUSED */
2140: static int
2141: mdoc__x_pre(MDOC_ARGS)
2142: {
2143: struct htmlpair tag;
2144:
2145: switch (n->tok) {
2146: case(MDOC__A):
1.23 kristaps 2147: PAIR_CLASS_INIT(&tag, "ref-auth");
1.10 kristaps 2148: break;
2149: case(MDOC__B):
1.23 kristaps 2150: PAIR_CLASS_INIT(&tag, "ref-book");
1.10 kristaps 2151: break;
2152: case(MDOC__C):
1.23 kristaps 2153: PAIR_CLASS_INIT(&tag, "ref-city");
1.10 kristaps 2154: break;
2155: case(MDOC__D):
1.23 kristaps 2156: PAIR_CLASS_INIT(&tag, "ref-date");
1.10 kristaps 2157: break;
2158: case(MDOC__I):
1.23 kristaps 2159: PAIR_CLASS_INIT(&tag, "ref-issue");
1.10 kristaps 2160: break;
2161: case(MDOC__J):
1.23 kristaps 2162: PAIR_CLASS_INIT(&tag, "ref-jrnl");
1.10 kristaps 2163: break;
2164: case(MDOC__N):
1.23 kristaps 2165: PAIR_CLASS_INIT(&tag, "ref-num");
1.10 kristaps 2166: break;
2167: case(MDOC__O):
1.23 kristaps 2168: PAIR_CLASS_INIT(&tag, "ref-opt");
1.10 kristaps 2169: break;
2170: case(MDOC__P):
1.23 kristaps 2171: PAIR_CLASS_INIT(&tag, "ref-page");
1.10 kristaps 2172: break;
2173: case(MDOC__Q):
1.23 kristaps 2174: PAIR_CLASS_INIT(&tag, "ref-corp");
1.10 kristaps 2175: break;
2176: case(MDOC__R):
1.23 kristaps 2177: PAIR_CLASS_INIT(&tag, "ref-rep");
1.10 kristaps 2178: break;
2179: case(MDOC__T):
1.23 kristaps 2180: PAIR_CLASS_INIT(&tag, "ref-title");
1.10 kristaps 2181: print_text(h, "\\(lq");
2182: h->flags |= HTML_NOSPACE;
2183: break;
2184: case(MDOC__V):
1.23 kristaps 2185: PAIR_CLASS_INIT(&tag, "ref-vol");
1.10 kristaps 2186: break;
2187: default:
2188: abort();
2189: /* NOTREACHED */
2190: }
2191:
2192: print_otag(h, TAG_SPAN, 1, &tag);
2193: return(1);
2194: }
2195:
2196:
2197: /* ARGSUSED */
2198: static void
2199: mdoc__x_post(MDOC_ARGS)
2200: {
2201:
2202: h->flags |= HTML_NOSPACE;
2203: switch (n->tok) {
2204: case (MDOC__T):
2205: print_text(h, "\\(rq");
2206: h->flags |= HTML_NOSPACE;
2207: break;
2208: default:
2209: break;
2210: }
2211: print_text(h, n->next ? "," : ".");
2212: }
CVSweb