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