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