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