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