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