Annotation of mandoc/mdoc_html.c, Revision 1.26
1.26 ! kristaps 1: /* $Id: mdoc_html.c,v 1.25 2009/10/07 14:50:28 kristaps Exp $ */
1.1 kristaps 2: /*
3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17: #include <sys/types.h>
1.7 kristaps 18: #include <sys/param.h>
1.1 kristaps 19: #include <sys/queue.h>
20:
21: #include <assert.h>
22: #include <ctype.h>
23: #include <err.h>
24: #include <stdio.h>
25: #include <stdlib.h>
26: #include <string.h>
27: #include <unistd.h>
28:
1.23 kristaps 29: #include "out.h"
1.1 kristaps 30: #include "html.h"
31: #include "mdoc.h"
32:
33: #define INDENT 5
34: #define HALFINDENT 3
35:
36: #define MDOC_ARGS const struct mdoc_meta *m, \
37: const struct mdoc_node *n, \
38: struct html *h
39:
40: struct htmlmdoc {
41: int (*pre)(MDOC_ARGS);
42: void (*post)(MDOC_ARGS);
43: };
44:
45: static void print_mdoc(MDOC_ARGS);
46: static void print_mdoc_head(MDOC_ARGS);
47: static void print_mdoc_node(MDOC_ARGS);
48: static void print_mdoc_nodelist(MDOC_ARGS);
49:
1.23 kristaps 50: static void a2width(const char *, struct roffsu *);
51: static void a2offs(const char *, struct roffsu *);
1.1 kristaps 52: static int a2list(const struct mdoc_node *);
53:
54: static void mdoc_root_post(MDOC_ARGS);
55: static int mdoc_root_pre(MDOC_ARGS);
1.23 kristaps 56: static int mdoc_it_block_pre(MDOC_ARGS, int,
57: struct roffsu *, int,
58: struct roffsu *);
59: static int mdoc_it_head_pre(MDOC_ARGS, int,
60: struct roffsu *);
61: static int mdoc_it_body_pre(MDOC_ARGS, int);
1.1 kristaps 62:
1.10 kristaps 63: static void mdoc__x_post(MDOC_ARGS);
64: static int mdoc__x_pre(MDOC_ARGS);
1.1 kristaps 65: static int mdoc_ad_pre(MDOC_ARGS);
66: static int mdoc_an_pre(MDOC_ARGS);
1.5 kristaps 67: static int mdoc_ap_pre(MDOC_ARGS);
1.1 kristaps 68: static void mdoc_aq_post(MDOC_ARGS);
69: static int mdoc_aq_pre(MDOC_ARGS);
70: static int mdoc_ar_pre(MDOC_ARGS);
71: static int mdoc_bd_pre(MDOC_ARGS);
1.5 kristaps 72: static int mdoc_bf_pre(MDOC_ARGS);
1.1 kristaps 73: static void mdoc_bl_post(MDOC_ARGS);
74: static int mdoc_bl_pre(MDOC_ARGS);
1.4 kristaps 75: static void mdoc_bq_post(MDOC_ARGS);
76: static int mdoc_bq_pre(MDOC_ARGS);
1.2 kristaps 77: static void mdoc_brq_post(MDOC_ARGS);
78: static int mdoc_brq_pre(MDOC_ARGS);
1.6 kristaps 79: static int mdoc_bt_pre(MDOC_ARGS);
1.4 kristaps 80: static int mdoc_bx_pre(MDOC_ARGS);
1.1 kristaps 81: static int mdoc_cd_pre(MDOC_ARGS);
82: static int mdoc_d1_pre(MDOC_ARGS);
83: static void mdoc_dq_post(MDOC_ARGS);
84: static int mdoc_dq_pre(MDOC_ARGS);
85: static int mdoc_dv_pre(MDOC_ARGS);
86: static int mdoc_fa_pre(MDOC_ARGS);
87: static int mdoc_fd_pre(MDOC_ARGS);
88: static int mdoc_fl_pre(MDOC_ARGS);
89: static int mdoc_fn_pre(MDOC_ARGS);
90: static int mdoc_ft_pre(MDOC_ARGS);
91: static int mdoc_em_pre(MDOC_ARGS);
92: static int mdoc_er_pre(MDOC_ARGS);
93: static int mdoc_ev_pre(MDOC_ARGS);
94: static int mdoc_ex_pre(MDOC_ARGS);
1.4 kristaps 95: static void mdoc_fo_post(MDOC_ARGS);
96: static int mdoc_fo_pre(MDOC_ARGS);
97: static int mdoc_ic_pre(MDOC_ARGS);
98: static int mdoc_in_pre(MDOC_ARGS);
1.1 kristaps 99: static int mdoc_it_pre(MDOC_ARGS);
1.6 kristaps 100: static int mdoc_lb_pre(MDOC_ARGS);
101: static int mdoc_li_pre(MDOC_ARGS);
1.2 kristaps 102: static int mdoc_lk_pre(MDOC_ARGS);
103: static int mdoc_mt_pre(MDOC_ARGS);
1.5 kristaps 104: static int mdoc_ms_pre(MDOC_ARGS);
1.1 kristaps 105: static int mdoc_nd_pre(MDOC_ARGS);
106: static int mdoc_nm_pre(MDOC_ARGS);
107: static int mdoc_ns_pre(MDOC_ARGS);
108: static void mdoc_op_post(MDOC_ARGS);
109: static int mdoc_op_pre(MDOC_ARGS);
110: static int mdoc_pa_pre(MDOC_ARGS);
1.5 kristaps 111: static void mdoc_pf_post(MDOC_ARGS);
112: static int mdoc_pf_pre(MDOC_ARGS);
1.1 kristaps 113: static void mdoc_pq_post(MDOC_ARGS);
114: static int mdoc_pq_pre(MDOC_ARGS);
1.5 kristaps 115: static int mdoc_rs_pre(MDOC_ARGS);
1.4 kristaps 116: static int mdoc_rv_pre(MDOC_ARGS);
1.1 kristaps 117: static int mdoc_sh_pre(MDOC_ARGS);
118: static int mdoc_sp_pre(MDOC_ARGS);
119: static void mdoc_sq_post(MDOC_ARGS);
120: static int mdoc_sq_pre(MDOC_ARGS);
121: static int mdoc_ss_pre(MDOC_ARGS);
122: static int mdoc_sx_pre(MDOC_ARGS);
1.6 kristaps 123: static int mdoc_sy_pre(MDOC_ARGS);
124: static int mdoc_ud_pre(MDOC_ARGS);
1.4 kristaps 125: static int mdoc_va_pre(MDOC_ARGS);
1.1 kristaps 126: static int mdoc_vt_pre(MDOC_ARGS);
127: static int mdoc_xr_pre(MDOC_ARGS);
128: static int mdoc_xx_pre(MDOC_ARGS);
129:
130: #ifdef __linux__
131: extern size_t strlcpy(char *, const char *, size_t);
132: extern size_t strlcat(char *, const char *, size_t);
133: #endif
134:
135: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5 kristaps 136: {mdoc_ap_pre, NULL}, /* Ap */
1.1 kristaps 137: {NULL, NULL}, /* Dd */
138: {NULL, NULL}, /* Dt */
139: {NULL, NULL}, /* Os */
140: {mdoc_sh_pre, NULL }, /* Sh */
141: {mdoc_ss_pre, NULL }, /* Ss */
142: {mdoc_sp_pre, NULL}, /* Pp */
143: {mdoc_d1_pre, NULL}, /* D1 */
144: {mdoc_d1_pre, NULL}, /* Dl */
145: {mdoc_bd_pre, NULL}, /* Bd */
146: {NULL, NULL}, /* Ed */
147: {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
148: {NULL, NULL}, /* El */
149: {mdoc_it_pre, NULL}, /* It */
150: {mdoc_ad_pre, NULL}, /* Ad */
151: {mdoc_an_pre, NULL}, /* An */
152: {mdoc_ar_pre, NULL}, /* Ar */
153: {mdoc_cd_pre, NULL}, /* Cd */
154: {mdoc_fl_pre, NULL}, /* Cm */
155: {mdoc_dv_pre, NULL}, /* Dv */
156: {mdoc_er_pre, NULL}, /* Er */
157: {mdoc_ev_pre, NULL}, /* Ev */
158: {mdoc_ex_pre, NULL}, /* Ex */
159: {mdoc_fa_pre, NULL}, /* Fa */
160: {mdoc_fd_pre, NULL}, /* Fd */
161: {mdoc_fl_pre, NULL}, /* Fl */
162: {mdoc_fn_pre, NULL}, /* Fn */
163: {mdoc_ft_pre, NULL}, /* Ft */
1.4 kristaps 164: {mdoc_ic_pre, NULL}, /* Ic */
165: {mdoc_in_pre, NULL}, /* In */
1.6 kristaps 166: {mdoc_li_pre, NULL}, /* Li */
1.1 kristaps 167: {mdoc_nd_pre, NULL}, /* Nd */
168: {mdoc_nm_pre, NULL}, /* Nm */
169: {mdoc_op_pre, mdoc_op_post}, /* Op */
170: {NULL, NULL}, /* Ot */
171: {mdoc_pa_pre, NULL}, /* Pa */
1.4 kristaps 172: {mdoc_rv_pre, NULL}, /* Rv */
1.1 kristaps 173: {NULL, NULL}, /* St */
1.4 kristaps 174: {mdoc_va_pre, NULL}, /* Va */
1.1 kristaps 175: {mdoc_vt_pre, NULL}, /* Vt */
176: {mdoc_xr_pre, NULL}, /* Xr */
1.10 kristaps 177: {mdoc__x_pre, mdoc__x_post}, /* %A */
178: {mdoc__x_pre, mdoc__x_post}, /* %B */
179: {mdoc__x_pre, mdoc__x_post}, /* %D */
180: {mdoc__x_pre, mdoc__x_post}, /* %I */
181: {mdoc__x_pre, mdoc__x_post}, /* %J */
182: {mdoc__x_pre, mdoc__x_post}, /* %N */
183: {mdoc__x_pre, mdoc__x_post}, /* %O */
184: {mdoc__x_pre, mdoc__x_post}, /* %P */
185: {mdoc__x_pre, mdoc__x_post}, /* %R */
186: {mdoc__x_pre, mdoc__x_post}, /* %T */
187: {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1 kristaps 188: {NULL, NULL}, /* Ac */
189: {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
190: {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
191: {NULL, NULL}, /* At */
192: {NULL, NULL}, /* Bc */
1.5 kristaps 193: {mdoc_bf_pre, NULL}, /* Bf */
1.4 kristaps 194: {mdoc_bq_pre, mdoc_bq_post}, /* Bo */
195: {mdoc_bq_pre, mdoc_bq_post}, /* Bq */
1.1 kristaps 196: {mdoc_xx_pre, NULL}, /* Bsx */
1.4 kristaps 197: {mdoc_bx_pre, NULL}, /* Bx */
1.1 kristaps 198: {NULL, NULL}, /* Db */
199: {NULL, NULL}, /* Dc */
1.4 kristaps 200: {mdoc_dq_pre, mdoc_dq_post}, /* Do */
1.1 kristaps 201: {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
202: {NULL, NULL}, /* Ec */
203: {NULL, NULL}, /* Ef */
204: {mdoc_em_pre, NULL}, /* Em */
205: {NULL, NULL}, /* Eo */
206: {mdoc_xx_pre, NULL}, /* Fx */
1.5 kristaps 207: {mdoc_ms_pre, NULL}, /* Ms */ /* FIXME: convert to symbol? */
1.1 kristaps 208: {NULL, NULL}, /* No */
209: {mdoc_ns_pre, NULL}, /* Ns */
210: {mdoc_xx_pre, NULL}, /* Nx */
211: {mdoc_xx_pre, NULL}, /* Ox */
212: {NULL, NULL}, /* Pc */
1.5 kristaps 213: {mdoc_pf_pre, mdoc_pf_post}, /* Pf */
1.1 kristaps 214: {mdoc_pq_pre, mdoc_pq_post}, /* Po */
215: {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
216: {NULL, NULL}, /* Qc */
1.4 kristaps 217: {mdoc_sq_pre, mdoc_sq_post}, /* Ql */
1.5 kristaps 218: {mdoc_dq_pre, mdoc_dq_post}, /* Qo */
219: {mdoc_dq_pre, mdoc_dq_post}, /* Qq */
1.1 kristaps 220: {NULL, NULL}, /* Re */
1.5 kristaps 221: {mdoc_rs_pre, NULL}, /* Rs */
1.1 kristaps 222: {NULL, NULL}, /* Sc */
223: {mdoc_sq_pre, mdoc_sq_post}, /* So */
224: {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
1.6 kristaps 225: {NULL, NULL}, /* Sm */ /* FIXME - no idea. */
1.1 kristaps 226: {mdoc_sx_pre, NULL}, /* Sx */
1.6 kristaps 227: {mdoc_sy_pre, NULL}, /* Sy */
1.1 kristaps 228: {NULL, NULL}, /* Tn */
229: {mdoc_xx_pre, NULL}, /* Ux */
230: {NULL, NULL}, /* Xc */
231: {NULL, NULL}, /* Xo */
1.4 kristaps 232: {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
1.1 kristaps 233: {NULL, NULL}, /* Fc */
1.4 kristaps 234: {mdoc_op_pre, mdoc_op_post}, /* Oo */
1.1 kristaps 235: {NULL, NULL}, /* Oc */
236: {NULL, NULL}, /* Bk */
237: {NULL, NULL}, /* Ek */
1.6 kristaps 238: {mdoc_bt_pre, NULL}, /* Bt */
1.1 kristaps 239: {NULL, NULL}, /* Hf */
240: {NULL, NULL}, /* Fr */
1.6 kristaps 241: {mdoc_ud_pre, NULL}, /* Ud */
242: {mdoc_lb_pre, NULL}, /* Lb */
1.1 kristaps 243: {mdoc_sp_pre, NULL}, /* Lp */
1.2 kristaps 244: {mdoc_lk_pre, NULL}, /* Lk */
245: {mdoc_mt_pre, NULL}, /* Mt */
246: {mdoc_brq_pre, mdoc_brq_post}, /* Brq */
247: {mdoc_brq_pre, mdoc_brq_post}, /* Bro */
1.1 kristaps 248: {NULL, NULL}, /* Brc */
1.10 kristaps 249: {mdoc__x_pre, mdoc__x_post}, /* %C */
1.2 kristaps 250: {NULL, NULL}, /* Es */ /* TODO */
251: {NULL, NULL}, /* En */ /* TODO */
1.1 kristaps 252: {mdoc_xx_pre, NULL}, /* Dx */
1.10 kristaps 253: {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1 kristaps 254: {mdoc_sp_pre, NULL}, /* br */
255: {mdoc_sp_pre, NULL}, /* sp */
256: };
257:
258:
259: void
260: html_mdoc(void *arg, const struct mdoc *m)
261: {
262: struct html *h;
263: struct tag *t;
264:
265: h = (struct html *)arg;
266:
267: print_gen_doctype(h);
268: t = print_otag(h, TAG_HTML, 0, NULL);
269: print_mdoc(mdoc_meta(m), mdoc_node(m), h);
270: print_tagq(h, t);
271:
272: printf("\n");
273: }
274:
275:
1.23 kristaps 276: /*
277: * Return the list type for `Bl', e.g., `Bl -column' returns
278: * MDOC_Column. This can ONLY be run for lists; it will abort() if no
279: * list type is found.
280: */
1.1 kristaps 281: static int
282: a2list(const struct mdoc_node *n)
283: {
284: int i;
285:
286: assert(n->args);
287: for (i = 0; i < (int)n->args->argc; i++)
288: switch (n->args->argv[i].arg) {
289: case (MDOC_Enum):
290: /* FALLTHROUGH */
291: case (MDOC_Dash):
292: /* FALLTHROUGH */
293: case (MDOC_Hyphen):
294: /* FALLTHROUGH */
295: case (MDOC_Bullet):
296: /* FALLTHROUGH */
297: case (MDOC_Tag):
298: /* FALLTHROUGH */
299: case (MDOC_Hang):
300: /* FALLTHROUGH */
301: case (MDOC_Inset):
302: /* FALLTHROUGH */
303: case (MDOC_Diag):
304: /* FALLTHROUGH */
305: case (MDOC_Item):
306: /* FALLTHROUGH */
307: case (MDOC_Column):
308: /* FALLTHROUGH */
309: case (MDOC_Ohang):
310: return(n->args->argv[i].arg);
311: default:
312: break;
313: }
314:
315: abort();
316: /* NOTREACHED */
317: }
318:
319:
1.23 kristaps 320: /*
321: * Calculate the scaling unit passed in a `-width' argument. This uses
322: * either a native scaling unit (e.g., 1i, 2m) or the string length of
323: * the value.
324: */
325: static void
326: a2width(const char *p, struct roffsu *su)
1.1 kristaps 327: {
328:
1.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.23 kristaps 858: mdoc_it_block_pre(MDOC_ARGS, int type, struct roffsu *offs,
859: int comp, 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)
1084: return(mdoc_it_block_pre(m, n, h, type,
1085: &offs, comp, &width));
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.23 kristaps 1458: PAIR_CLASS_INIT(&tag, "config");
1.1 kristaps 1459: print_otag(h, TAG_SPAN, 1, &tag);
1460: return(1);
1461: }
1462:
1463:
1464: /* ARGSUSED */
1465: static int
1466: mdoc_dv_pre(MDOC_ARGS)
1467: {
1468: struct htmlpair tag;
1469:
1.23 kristaps 1470: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1471: print_otag(h, TAG_SPAN, 1, &tag);
1472: return(1);
1473: }
1474:
1475:
1476: /* ARGSUSED */
1477: static int
1478: mdoc_ev_pre(MDOC_ARGS)
1479: {
1480: struct htmlpair tag;
1481:
1.23 kristaps 1482: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1483: print_otag(h, TAG_SPAN, 1, &tag);
1484: return(1);
1485: }
1486:
1487:
1488: /* ARGSUSED */
1489: static int
1490: mdoc_er_pre(MDOC_ARGS)
1491: {
1492: struct htmlpair tag;
1493:
1.23 kristaps 1494: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1495: print_otag(h, TAG_SPAN, 1, &tag);
1496: return(1);
1497: }
1498:
1499:
1500: /* ARGSUSED */
1501: static int
1502: mdoc_fa_pre(MDOC_ARGS)
1503: {
1504: const struct mdoc_node *nn;
1505: struct htmlpair tag;
1506: struct tag *t;
1507:
1.23 kristaps 1508: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1509: if (n->parent->tok != MDOC_Fo) {
1510: print_otag(h, TAG_SPAN, 1, &tag);
1511: return(1);
1512: }
1513:
1514: for (nn = n->child; nn; nn = nn->next) {
1515: t = print_otag(h, TAG_SPAN, 1, &tag);
1516: print_text(h, nn->string);
1517: print_tagq(h, t);
1518: if (nn->next)
1519: print_text(h, ",");
1520: }
1521:
1522: if (n->child && n->next && n->next->tok == MDOC_Fa)
1523: print_text(h, ",");
1524:
1525: return(0);
1526: }
1527:
1528:
1529: /* ARGSUSED */
1530: static int
1531: mdoc_fd_pre(MDOC_ARGS)
1532: {
1.23 kristaps 1533: struct htmlpair tag;
1534: struct roffsu su;
1.1 kristaps 1535:
1536: if (SEC_SYNOPSIS == n->sec) {
1537: if (n->next && MDOC_Fd != n->next->tok) {
1.23 kristaps 1538: SCALE_VS_INIT(&su, 1);
1539: bufcat_su(h, "margin-bottom", &su);
1540: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1541: print_otag(h, TAG_DIV, 1, &tag);
1542: } else
1543: print_otag(h, TAG_DIV, 0, NULL);
1544: }
1545:
1.23 kristaps 1546: PAIR_CLASS_INIT(&tag, "macro");
1.1 kristaps 1547: print_otag(h, TAG_SPAN, 1, &tag);
1548: return(1);
1549: }
1550:
1551:
1552: /* ARGSUSED */
1553: static int
1554: mdoc_vt_pre(MDOC_ARGS)
1555: {
1.23 kristaps 1556: struct htmlpair tag;
1557: struct roffsu su;
1.1 kristaps 1558:
1559: if (SEC_SYNOPSIS == n->sec) {
1560: if (n->next && MDOC_Vt != n->next->tok) {
1.23 kristaps 1561: SCALE_VS_INIT(&su, 1);
1562: bufcat_su(h, "margin-bottom", &su);
1563: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1564: print_otag(h, TAG_DIV, 1, &tag);
1565: } else
1566: print_otag(h, TAG_DIV, 0, NULL);
1567: }
1568:
1.23 kristaps 1569: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1570: print_otag(h, TAG_SPAN, 1, &tag);
1571: return(1);
1572: }
1573:
1.2 kristaps 1574:
1.1 kristaps 1575: /* ARGSUSED */
1576: static int
1577: mdoc_ft_pre(MDOC_ARGS)
1578: {
1.23 kristaps 1579: struct htmlpair tag;
1580: struct roffsu su;
1.1 kristaps 1581:
1582: if (SEC_SYNOPSIS == n->sec) {
1583: if (n->prev && MDOC_Fo == n->prev->tok) {
1.23 kristaps 1584: SCALE_VS_INIT(&su, 1);
1585: bufcat_su(h, "margin-top", &su);
1586: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1587: print_otag(h, TAG_DIV, 1, &tag);
1588: } else
1589: print_otag(h, TAG_DIV, 0, NULL);
1590: }
1591:
1.23 kristaps 1592: PAIR_CLASS_INIT(&tag, "ftype");
1.1 kristaps 1593: print_otag(h, TAG_SPAN, 1, &tag);
1594: return(1);
1595: }
1596:
1597:
1598: /* ARGSUSED */
1599: static int
1600: mdoc_fn_pre(MDOC_ARGS)
1601: {
1602: struct tag *t;
1.15 kristaps 1603: struct htmlpair tag[2];
1.1 kristaps 1604: const struct mdoc_node *nn;
1.7 kristaps 1605: char nbuf[BUFSIZ];
1606: const char *sp, *ep;
1.15 kristaps 1607: int sz, i;
1.23 kristaps 1608: struct roffsu su;
1.1 kristaps 1609:
1610: if (SEC_SYNOPSIS == n->sec) {
1.23 kristaps 1611: SCALE_HS_INIT(&su, INDENT);
1612: bufcat_su(h, "margin-left", &su);
1613: su.scale = -su.scale;
1614: bufcat_su(h, "text-indent", &su);
1615: if (n->next) {
1616: SCALE_VS_INIT(&su, 1);
1617: bufcat_su(h, "margin-bottom", &su);
1618: }
1619: PAIR_STYLE_INIT(&tag[0], h);
1.15 kristaps 1620: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 1621: }
1622:
1.7 kristaps 1623: /* Split apart into type and name. */
1624: assert(n->child->string);
1625: sp = n->child->string;
1.19 kristaps 1626:
1.26 ! kristaps 1627: ep = strchr(sp, ' ');
! 1628: if (NULL != ep) {
1.23 kristaps 1629: PAIR_CLASS_INIT(&tag[0], "ftype");
1.19 kristaps 1630: t = print_otag(h, TAG_SPAN, 1, tag);
1631:
1632: while (ep) {
1633: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1634: (void)memcpy(nbuf, sp, (size_t)sz);
1635: nbuf[sz] = '\0';
1636: print_text(h, nbuf);
1637: sp = ++ep;
1638: ep = strchr(sp, ' ');
1639: }
1640: print_tagq(h, t);
1.7 kristaps 1641: }
1.1 kristaps 1642:
1.23 kristaps 1643: PAIR_CLASS_INIT(&tag[0], "fname");
1.15 kristaps 1644: t = print_otag(h, TAG_SPAN, 1, tag);
1.7 kristaps 1645:
1646: if (sp) {
1647: (void)strlcpy(nbuf, sp, BUFSIZ);
1648: print_text(h, nbuf);
1649: }
1650:
1.1 kristaps 1651: print_tagq(h, t);
1652:
1653: h->flags |= HTML_NOSPACE;
1654: print_text(h, "(");
1655:
1.23 kristaps 1656: bufinit(h);
1657: PAIR_CLASS_INIT(&tag[0], "farg");
1658: bufcat_style(h, "white-space", "nowrap");
1659: PAIR_STYLE_INIT(&tag[1], h);
1660:
1.1 kristaps 1661: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1662: i = 1;
1663: if (SEC_SYNOPSIS == n->sec)
1664: i = 2;
1.15 kristaps 1665: t = print_otag(h, TAG_SPAN, i, tag);
1.1 kristaps 1666: print_text(h, nn->string);
1667: print_tagq(h, t);
1668: if (nn->next)
1669: print_text(h, ",");
1670: }
1671:
1672: print_text(h, ")");
1673: if (SEC_SYNOPSIS == n->sec)
1674: print_text(h, ";");
1675:
1676: return(0);
1677: }
1678:
1679:
1680: /* ARGSUSED */
1681: static int
1682: mdoc_sp_pre(MDOC_ARGS)
1683: {
1.23 kristaps 1684: int len;
1685: struct htmlpair tag;
1686: struct roffsu su;
1.1 kristaps 1687:
1688: switch (n->tok) {
1689: case (MDOC_sp):
1.23 kristaps 1690: /* FIXME: can this have a scaling indicator? */
1.1 kristaps 1691: len = n->child ? atoi(n->child->string) : 1;
1692: break;
1693: case (MDOC_br):
1694: len = 0;
1695: break;
1696: default:
1697: len = 1;
1698: break;
1699: }
1700:
1.23 kristaps 1701: SCALE_VS_INIT(&su, len);
1702: bufcat_su(h, "height", &su);
1703: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1704: print_otag(h, TAG_DIV, 1, &tag);
1705: return(1);
1706:
1707: }
1.2 kristaps 1708:
1709:
1710: /* ARGSUSED */
1711: static int
1712: mdoc_brq_pre(MDOC_ARGS)
1713: {
1714:
1715: if (MDOC_BODY != n->type)
1716: return(1);
1717: print_text(h, "\\(lC");
1718: h->flags |= HTML_NOSPACE;
1719: return(1);
1720: }
1721:
1722:
1723: /* ARGSUSED */
1724: static void
1725: mdoc_brq_post(MDOC_ARGS)
1726: {
1727:
1728: if (MDOC_BODY != n->type)
1729: return;
1730: h->flags |= HTML_NOSPACE;
1731: print_text(h, "\\(rC");
1732: }
1733:
1734:
1735: /* ARGSUSED */
1736: static int
1737: mdoc_lk_pre(MDOC_ARGS)
1738: {
1739: const struct mdoc_node *nn;
1740: struct htmlpair tag[2];
1741:
1742: nn = n->child;
1743:
1.23 kristaps 1744: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.2 kristaps 1745: tag[1].key = ATTR_HREF;
1746: tag[1].val = nn->string;
1747: print_otag(h, TAG_A, 2, tag);
1748:
1749: for (nn = nn->next; nn; nn = nn->next)
1750: print_text(h, nn->string);
1751:
1752: return(0);
1753: }
1754:
1755:
1756: /* ARGSUSED */
1757: static int
1758: mdoc_mt_pre(MDOC_ARGS)
1759: {
1760: struct htmlpair tag[2];
1761: struct tag *t;
1762: const struct mdoc_node *nn;
1763:
1.23 kristaps 1764: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1765:
1766: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1767: bufinit(h);
1768: bufcat(h, "mailto:");
1769: bufcat(h, nn->string);
1.23 kristaps 1770: PAIR_STYLE_INIT(&tag[1], h);
1.2 kristaps 1771: t = print_otag(h, TAG_A, 2, tag);
1772: print_text(h, nn->string);
1773: print_tagq(h, t);
1774: }
1775:
1776: return(0);
1777: }
1.4 kristaps 1778:
1779:
1780: /* ARGSUSED */
1781: static int
1782: mdoc_fo_pre(MDOC_ARGS)
1783: {
1784: struct htmlpair tag;
1785:
1786: if (MDOC_BODY == n->type) {
1787: h->flags |= HTML_NOSPACE;
1788: print_text(h, "(");
1789: h->flags |= HTML_NOSPACE;
1790: return(1);
1791: } else if (MDOC_BLOCK == n->type)
1792: return(1);
1793:
1.23 kristaps 1794: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1795: print_otag(h, TAG_SPAN, 1, &tag);
1796: return(1);
1797: }
1798:
1799:
1800: /* ARGSUSED */
1801: static void
1802: mdoc_fo_post(MDOC_ARGS)
1803: {
1804: if (MDOC_BODY != n->type)
1805: return;
1806: h->flags |= HTML_NOSPACE;
1807: print_text(h, ")");
1808: h->flags |= HTML_NOSPACE;
1809: print_text(h, ";");
1810: }
1811:
1812:
1813: /* ARGSUSED */
1814: static int
1815: mdoc_in_pre(MDOC_ARGS)
1816: {
1817: const struct mdoc_node *nn;
1.23 kristaps 1818: struct tag *t;
1.17 kristaps 1819: struct htmlpair tag[2];
1820: int i;
1.23 kristaps 1821: struct roffsu su;
1.4 kristaps 1822:
1823: if (SEC_SYNOPSIS == n->sec) {
1824: if (n->next && MDOC_In != n->next->tok) {
1.23 kristaps 1825: SCALE_VS_INIT(&su, 1);
1826: bufcat_su(h, "margin-bottom", &su);
1827: PAIR_STYLE_INIT(&tag[0], h);
1.17 kristaps 1828: print_otag(h, TAG_DIV, 1, tag);
1.4 kristaps 1829: } else
1830: print_otag(h, TAG_DIV, 0, NULL);
1831: }
1832:
1.23 kristaps 1833: PAIR_CLASS_INIT(&tag[0], "includes");
1.17 kristaps 1834: print_otag(h, TAG_SPAN, 1, tag);
1.4 kristaps 1835:
1836: if (SEC_SYNOPSIS == n->sec)
1837: print_text(h, "#include");
1838:
1839: print_text(h, "<");
1840: h->flags |= HTML_NOSPACE;
1841:
1842: /* XXX -- see warning in termp_in_post(). */
1843:
1.17 kristaps 1844: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1845: PAIR_CLASS_INIT(&tag[0], "link-includes");
1846: i = 1;
1.17 kristaps 1847: if (h->base_includes) {
1848: buffmt_includes(h, nn->string);
1849: tag[i].key = ATTR_HREF;
1850: tag[i++].val = h->buf;
1851: }
1852: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1853: print_mdoc_node(m, nn, h);
1.17 kristaps 1854: print_tagq(h, t);
1855: }
1.4 kristaps 1856:
1857: h->flags |= HTML_NOSPACE;
1858: print_text(h, ">");
1859:
1860: return(0);
1861: }
1862:
1863:
1864: /* ARGSUSED */
1865: static int
1866: mdoc_ic_pre(MDOC_ARGS)
1867: {
1868: struct htmlpair tag;
1869:
1.23 kristaps 1870: PAIR_CLASS_INIT(&tag, "cmd");
1.4 kristaps 1871: print_otag(h, TAG_SPAN, 1, &tag);
1872: return(1);
1873: }
1874:
1875:
1876: /* ARGSUSED */
1877: static int
1878: mdoc_rv_pre(MDOC_ARGS)
1879: {
1880: const struct mdoc_node *nn;
1881: struct htmlpair tag;
1882: struct tag *t;
1883:
1884: print_otag(h, TAG_DIV, 0, NULL);
1885: print_text(h, "The");
1886:
1887: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1888: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1889: t = print_otag(h, TAG_SPAN, 1, &tag);
1890: print_text(h, nn->string);
1891: print_tagq(h, t);
1892:
1893: h->flags |= HTML_NOSPACE;
1894: if (nn->next && NULL == nn->next->next)
1895: print_text(h, "(), and");
1896: else if (nn->next)
1897: print_text(h, "(),");
1898: else
1899: print_text(h, "()");
1900: }
1901:
1902: if (n->child->next)
1903: print_text(h, "functions return");
1904: else
1905: print_text(h, "function returns");
1906:
1907: print_text(h, "the value 0 if successful; otherwise the value "
1908: "-1 is returned and the global variable");
1909:
1.23 kristaps 1910: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1911: t = print_otag(h, TAG_SPAN, 1, &tag);
1912: print_text(h, "errno");
1913: print_tagq(h, t);
1914: print_text(h, "is set to indicate the error.");
1915: return(0);
1916: }
1917:
1918:
1919: /* ARGSUSED */
1920: static int
1921: mdoc_va_pre(MDOC_ARGS)
1922: {
1923: struct htmlpair tag;
1924:
1.23 kristaps 1925: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1926: print_otag(h, TAG_SPAN, 1, &tag);
1927: return(1);
1928: }
1929:
1930:
1931: /* ARGSUSED */
1932: static int
1933: mdoc_bq_pre(MDOC_ARGS)
1934: {
1935:
1936: if (MDOC_BODY != n->type)
1937: return(1);
1938: print_text(h, "\\(lB");
1939: h->flags |= HTML_NOSPACE;
1940: return(1);
1941: }
1942:
1943:
1944: /* ARGSUSED */
1945: static void
1946: mdoc_bq_post(MDOC_ARGS)
1947: {
1948:
1949: if (MDOC_BODY != n->type)
1950: return;
1951: h->flags |= HTML_NOSPACE;
1952: print_text(h, "\\(rB");
1953: }
1.5 kristaps 1954:
1955:
1956: /* ARGSUSED */
1957: static int
1958: mdoc_ap_pre(MDOC_ARGS)
1959: {
1960:
1961: h->flags |= HTML_NOSPACE;
1962: print_text(h, "\\(aq");
1963: h->flags |= HTML_NOSPACE;
1964: return(1);
1965: }
1966:
1967:
1968: /* ARGSUSED */
1969: static int
1970: mdoc_bf_pre(MDOC_ARGS)
1971: {
1.23 kristaps 1972: int i;
1973: struct htmlpair tag[2];
1974: struct roffsu su;
1.5 kristaps 1975:
1976: if (MDOC_HEAD == n->type)
1977: return(0);
1978: else if (MDOC_BLOCK != n->type)
1979: return(1);
1980:
1.23 kristaps 1981: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 1982:
1983: if (n->head->child) {
1984: if ( ! strcmp("Em", n->head->child->string))
1.23 kristaps 1985: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 1986: else if ( ! strcmp("Sy", n->head->child->string))
1.23 kristaps 1987: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 1988: else if ( ! strcmp("Li", n->head->child->string))
1.23 kristaps 1989: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 1990: } else {
1991: assert(n->args);
1992: for (i = 0; i < (int)n->args->argc; i++)
1993: switch (n->args->argv[i].arg) {
1994: case (MDOC_Symbolic):
1.23 kristaps 1995: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 1996: break;
1997: case (MDOC_Literal):
1.23 kristaps 1998: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 1999: break;
2000: case (MDOC_Emphasis):
1.23 kristaps 2001: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 2002: break;
2003: default:
2004: break;
2005: }
2006: }
2007:
2008: /* FIXME: div's have spaces stripped--we want them. */
2009:
1.23 kristaps 2010: bufcat_style(h, "display", "inline");
2011: SCALE_HS_INIT(&su, 1);
2012: bufcat_su(h, "margin-right", &su);
2013: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 2014: print_otag(h, TAG_DIV, 2, tag);
2015: return(1);
2016: }
2017:
2018:
2019: /* ARGSUSED */
2020: static int
2021: mdoc_ms_pre(MDOC_ARGS)
2022: {
2023: struct htmlpair tag;
2024:
1.23 kristaps 2025: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 2026: print_otag(h, TAG_SPAN, 1, &tag);
2027: return(1);
2028: }
2029:
2030:
2031: /* ARGSUSED */
2032: static int
2033: mdoc_pf_pre(MDOC_ARGS)
2034: {
2035:
2036: h->flags |= HTML_IGNDELIM;
2037: return(1);
2038: }
2039:
2040:
2041: /* ARGSUSED */
2042: static void
2043: mdoc_pf_post(MDOC_ARGS)
2044: {
2045:
2046: h->flags &= ~HTML_IGNDELIM;
2047: h->flags |= HTML_NOSPACE;
2048: }
2049:
2050:
2051: /* ARGSUSED */
2052: static int
2053: mdoc_rs_pre(MDOC_ARGS)
2054: {
1.23 kristaps 2055: struct htmlpair tag;
2056: struct roffsu su;
1.5 kristaps 2057:
2058: if (MDOC_BLOCK != n->type)
2059: return(1);
2060:
1.8 kristaps 2061: if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23 kristaps 2062: SCALE_VS_INIT(&su, 1);
2063: bufcat_su(h, "margin-top", &su);
2064: PAIR_STYLE_INIT(&tag, h);
1.8 kristaps 2065: print_otag(h, TAG_DIV, 1, &tag);
1.5 kristaps 2066: }
2067:
1.23 kristaps 2068: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 2069: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 2070: return(1);
2071: }
1.6 kristaps 2072:
2073:
2074:
2075: /* ARGSUSED */
2076: static int
2077: mdoc_li_pre(MDOC_ARGS)
2078: {
2079: struct htmlpair tag;
2080:
1.23 kristaps 2081: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 2082: print_otag(h, TAG_SPAN, 1, &tag);
2083: return(1);
2084: }
2085:
2086:
2087: /* ARGSUSED */
2088: static int
2089: mdoc_sy_pre(MDOC_ARGS)
2090: {
2091: struct htmlpair tag;
2092:
1.23 kristaps 2093: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 2094: print_otag(h, TAG_SPAN, 1, &tag);
2095: return(1);
2096: }
2097:
2098:
2099: /* ARGSUSED */
2100: static int
2101: mdoc_bt_pre(MDOC_ARGS)
2102: {
2103:
2104: print_text(h, "is currently in beta test.");
2105: return(0);
2106: }
2107:
2108:
2109: /* ARGSUSED */
2110: static int
2111: mdoc_ud_pre(MDOC_ARGS)
2112: {
2113:
2114: print_text(h, "currently under development.");
2115: return(0);
2116: }
2117:
2118:
2119: /* ARGSUSED */
2120: static int
2121: mdoc_lb_pre(MDOC_ARGS)
2122: {
2123: struct htmlpair tag;
2124:
2125: if (SEC_SYNOPSIS == n->sec)
2126: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 2127: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 2128: print_otag(h, TAG_SPAN, 1, &tag);
2129: return(1);
2130: }
1.10 kristaps 2131:
2132:
2133: /* ARGSUSED */
2134: static int
2135: mdoc__x_pre(MDOC_ARGS)
2136: {
2137: struct htmlpair tag;
2138:
2139: switch (n->tok) {
2140: case(MDOC__A):
1.23 kristaps 2141: PAIR_CLASS_INIT(&tag, "ref-auth");
1.10 kristaps 2142: break;
2143: case(MDOC__B):
1.23 kristaps 2144: PAIR_CLASS_INIT(&tag, "ref-book");
1.10 kristaps 2145: break;
2146: case(MDOC__C):
1.23 kristaps 2147: PAIR_CLASS_INIT(&tag, "ref-city");
1.10 kristaps 2148: break;
2149: case(MDOC__D):
1.23 kristaps 2150: PAIR_CLASS_INIT(&tag, "ref-date");
1.10 kristaps 2151: break;
2152: case(MDOC__I):
1.23 kristaps 2153: PAIR_CLASS_INIT(&tag, "ref-issue");
1.10 kristaps 2154: break;
2155: case(MDOC__J):
1.23 kristaps 2156: PAIR_CLASS_INIT(&tag, "ref-jrnl");
1.10 kristaps 2157: break;
2158: case(MDOC__N):
1.23 kristaps 2159: PAIR_CLASS_INIT(&tag, "ref-num");
1.10 kristaps 2160: break;
2161: case(MDOC__O):
1.23 kristaps 2162: PAIR_CLASS_INIT(&tag, "ref-opt");
1.10 kristaps 2163: break;
2164: case(MDOC__P):
1.23 kristaps 2165: PAIR_CLASS_INIT(&tag, "ref-page");
1.10 kristaps 2166: break;
2167: case(MDOC__Q):
1.23 kristaps 2168: PAIR_CLASS_INIT(&tag, "ref-corp");
1.10 kristaps 2169: break;
2170: case(MDOC__R):
1.23 kristaps 2171: PAIR_CLASS_INIT(&tag, "ref-rep");
1.10 kristaps 2172: break;
2173: case(MDOC__T):
1.23 kristaps 2174: PAIR_CLASS_INIT(&tag, "ref-title");
1.10 kristaps 2175: print_text(h, "\\(lq");
2176: h->flags |= HTML_NOSPACE;
2177: break;
2178: case(MDOC__V):
1.23 kristaps 2179: PAIR_CLASS_INIT(&tag, "ref-vol");
1.10 kristaps 2180: break;
2181: default:
2182: abort();
2183: /* NOTREACHED */
2184: }
2185:
2186: print_otag(h, TAG_SPAN, 1, &tag);
2187: return(1);
2188: }
2189:
2190:
2191: /* ARGSUSED */
2192: static void
2193: mdoc__x_post(MDOC_ARGS)
2194: {
2195:
2196: h->flags |= HTML_NOSPACE;
2197: switch (n->tok) {
2198: case (MDOC__T):
2199: print_text(h, "\\(rq");
2200: h->flags |= HTML_NOSPACE;
2201: break;
2202: default:
2203: break;
2204: }
2205: print_text(h, n->next ? "," : ".");
2206: }
CVSweb