Annotation of mandoc/mdoc_html.c, Revision 1.124
1.124 ! kristaps 1: /* $Id: mdoc_html.c,v 1.123 2010/12/17 00:18:29 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: {
1.123 kristaps 560: struct htmlpair tag;
561: char buf[BUFSIZ];
562:
563: if (MDOC_BLOCK == n->type) {
564: PAIR_CLASS_INIT(&tag, "section");
565: print_otag(h, TAG_DIV, 1, &tag);
1.1 kristaps 566: return(1);
1.123 kristaps 567: } else if (MDOC_BODY == n->type)
1.1 kristaps 568: return(1);
569:
1.42 kristaps 570: buf[0] = '\0';
1.123 kristaps 571: for (n = n->child; n; n = n->next) {
572: html_idcat(buf, n->string, BUFSIZ);
573: if (n->next)
1.42 kristaps 574: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 575: }
576:
1.123 kristaps 577: PAIR_ID_INIT(&tag, buf);
578: print_otag(h, TAG_H1, 1, &tag);
1.1 kristaps 579: return(1);
580: }
581:
582:
583: /* ARGSUSED */
584: static int
585: mdoc_ss_pre(MDOC_ARGS)
586: {
1.123 kristaps 587: struct htmlpair tag;
588: char buf[BUFSIZ];
1.1 kristaps 589:
1.123 kristaps 590: if (MDOC_BLOCK == n->type) {
591: PAIR_CLASS_INIT(&tag, "subsection");
592: print_otag(h, TAG_DIV, 1, &tag);
1.1 kristaps 593: return(1);
1.123 kristaps 594: } else if (MDOC_BODY == n->type)
1.1 kristaps 595: return(1);
1.23 kristaps 596:
1.42 kristaps 597: buf[0] = '\0';
1.123 kristaps 598: for (n = n->child; n; n = n->next) {
599: html_idcat(buf, n->string, BUFSIZ);
600: if (n->next)
1.42 kristaps 601: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 602: }
603:
1.123 kristaps 604: PAIR_ID_INIT(&tag, buf);
605: print_otag(h, TAG_H2, 1, &tag);
1.1 kristaps 606: return(1);
607: }
608:
609:
610: /* ARGSUSED */
611: static int
612: mdoc_fl_pre(MDOC_ARGS)
613: {
614: struct htmlpair tag;
615:
1.51 kristaps 616: PAIR_CLASS_INIT(&tag, "flag");
617: print_otag(h, TAG_SPAN, 1, &tag);
618:
1.50 kristaps 619: /* `Cm' has no leading hyphen. */
620:
1.51 kristaps 621: if (MDOC_Cm == n->tok)
1.50 kristaps 622: return(1);
623:
624: print_text(h, "\\-");
625:
626: if (n->child)
1.58 kristaps 627: h->flags |= HTML_NOSPACE;
628: else if (n->next && n->next->line == n->line)
1.1 kristaps 629: h->flags |= HTML_NOSPACE;
1.50 kristaps 630:
1.1 kristaps 631: return(1);
632: }
633:
634:
635: /* ARGSUSED */
636: static int
637: mdoc_nd_pre(MDOC_ARGS)
638: {
639: struct htmlpair tag;
640:
641: if (MDOC_BODY != n->type)
642: return(1);
643:
1.24 kristaps 644: /* XXX: this tag in theory can contain block elements. */
645:
1.1 kristaps 646: print_text(h, "\\(em");
1.124 ! kristaps 647: PAIR_CLASS_INIT(&tag, "desc");
1.1 kristaps 648: print_otag(h, TAG_SPAN, 1, &tag);
649: return(1);
650: }
651:
652:
653: static int
654: mdoc_nm_pre(MDOC_ARGS)
655: {
1.91 kristaps 656: struct htmlpair tag;
657: struct roffsu su;
1.124 ! kristaps 658: size_t len;
1.91 kristaps 659:
1.124 ! kristaps 660: switch (n->type) {
! 661: case (MDOC_ELEM):
1.91 kristaps 662: synopsis_pre(h, n);
663: PAIR_CLASS_INIT(&tag, "name");
664: print_otag(h, TAG_SPAN, 1, &tag);
1.124 ! kristaps 665: if (NULL == n->child && m->name)
! 666: print_text(h, m->name);
! 667: return(1);
! 668: case (MDOC_HEAD):
! 669: print_otag(h, TAG_TD, 0, NULL);
! 670: if (NULL == n->child && m->name)
1.91 kristaps 671: print_text(h, m->name);
1.124 ! kristaps 672: return(1);
! 673: case (MDOC_BODY):
! 674: print_otag(h, TAG_TD, 0, NULL);
! 675: return(1);
! 676: default:
! 677: break;
! 678: }
1.91 kristaps 679:
1.124 ! kristaps 680: synopsis_pre(h, n);
! 681: PAIR_CLASS_INIT(&tag, "synopsis");
! 682: print_otag(h, TAG_TABLE, 1, &tag);
! 683:
! 684: for (len = 0, n = n->child; n; n = n->next)
! 685: if (MDOC_TEXT == n->type)
! 686: len += strlen(n->string);
1.91 kristaps 687:
1.124 ! kristaps 688: if (0 == len && m->name)
! 689: len = strlen(m->name);
1.1 kristaps 690:
1.124 ! kristaps 691: SCALE_HS_INIT(&su, (double)len);
! 692: bufcat_su(h, "width", &su);
! 693: PAIR_STYLE_INIT(&tag, h);
! 694: print_otag(h, TAG_COL, 1, &tag);
! 695: print_otag(h, TAG_COL, 0, NULL);
! 696: print_otag(h, TAG_TBODY, 0, NULL);
! 697: print_otag(h, TAG_TR, 0, NULL);
1.1 kristaps 698: return(1);
699: }
700:
701:
702: /* ARGSUSED */
703: static int
704: mdoc_xr_pre(MDOC_ARGS)
705: {
706: struct htmlpair tag[2];
707: const struct mdoc_node *nn;
1.56 kristaps 708:
709: if (NULL == n->child)
710: return(0);
1.17 kristaps 711:
1.23 kristaps 712: PAIR_CLASS_INIT(&tag[0], "link-man");
1.1 kristaps 713:
1.17 kristaps 714: if (h->base_man) {
1.23 kristaps 715: buffmt_man(h, n->child->string,
716: n->child->next ?
1.17 kristaps 717: n->child->next->string : NULL);
1.57 kristaps 718: PAIR_HREF_INIT(&tag[1], h->buf);
1.23 kristaps 719: print_otag(h, TAG_A, 2, tag);
720: } else
721: print_otag(h, TAG_A, 1, tag);
1.1 kristaps 722:
723: nn = n->child;
724: print_text(h, nn->string);
1.16 kristaps 725:
1.1 kristaps 726: if (NULL == (nn = nn->next))
727: return(0);
728:
729: h->flags |= HTML_NOSPACE;
730: print_text(h, "(");
731: h->flags |= HTML_NOSPACE;
732: print_text(h, nn->string);
733: h->flags |= HTML_NOSPACE;
734: print_text(h, ")");
735: return(0);
736: }
737:
738:
739: /* ARGSUSED */
740: static int
741: mdoc_ns_pre(MDOC_ARGS)
742: {
743:
744: h->flags |= HTML_NOSPACE;
745: return(1);
746: }
747:
748:
749: /* ARGSUSED */
750: static int
751: mdoc_ar_pre(MDOC_ARGS)
752: {
753: struct htmlpair tag;
754:
1.23 kristaps 755: PAIR_CLASS_INIT(&tag, "arg");
1.1 kristaps 756: print_otag(h, TAG_SPAN, 1, &tag);
757: return(1);
758: }
759:
760:
761: /* ARGSUSED */
762: static int
763: mdoc_xx_pre(MDOC_ARGS)
764: {
765: const char *pp;
766: struct htmlpair tag;
767:
768: switch (n->tok) {
769: case (MDOC_Bsx):
1.112 schwarze 770: pp = "BSD/OS";
1.1 kristaps 771: break;
772: case (MDOC_Dx):
1.45 kristaps 773: pp = "DragonFly";
1.1 kristaps 774: break;
775: case (MDOC_Fx):
776: pp = "FreeBSD";
777: break;
778: case (MDOC_Nx):
779: pp = "NetBSD";
780: break;
781: case (MDOC_Ox):
782: pp = "OpenBSD";
783: break;
784: case (MDOC_Ux):
785: pp = "UNIX";
786: break;
787: default:
788: return(1);
789: }
790:
1.23 kristaps 791: PAIR_CLASS_INIT(&tag, "unix");
1.1 kristaps 792: print_otag(h, TAG_SPAN, 1, &tag);
793: print_text(h, pp);
794: return(1);
795: }
796:
797:
798: /* ARGSUSED */
799: static int
1.4 kristaps 800: mdoc_bx_pre(MDOC_ARGS)
801: {
802: const struct mdoc_node *nn;
803: struct htmlpair tag;
804:
1.23 kristaps 805: PAIR_CLASS_INIT(&tag, "unix");
1.4 kristaps 806: print_otag(h, TAG_SPAN, 1, &tag);
807:
808: for (nn = n->child; nn; nn = nn->next)
809: print_mdoc_node(m, nn, h);
810:
811: if (n->child)
812: h->flags |= HTML_NOSPACE;
813:
814: print_text(h, "BSD");
815: return(0);
816: }
817:
818: static int
1.115 kristaps 819: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 820: {
1.115 kristaps 821: struct roffsu su;
822: enum mdoc_list type;
1.116 kristaps 823: struct htmlpair tag[2];
1.115 kristaps 824: const struct mdoc_node *bl;
825:
826: bl = n->parent;
827: while (bl && MDOC_Bl != bl->tok)
828: bl = bl->parent;
1.23 kristaps 829:
1.115 kristaps 830: assert(bl);
1.23 kristaps 831:
1.115 kristaps 832: type = bl->data.Bl->type;
1.24 kristaps 833:
1.116 kristaps 834: assert(lists[type]);
835: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 kristaps 836:
1.115 kristaps 837: if (MDOC_HEAD == n->type) {
838: switch (type) {
839: case(LIST_bullet):
840: /* FALLTHROUGH */
841: case(LIST_dash):
842: /* FALLTHROUGH */
843: case(LIST_item):
844: /* FALLTHROUGH */
845: case(LIST_hyphen):
846: /* FALLTHROUGH */
847: case(LIST_enum):
848: return(0);
849: case(LIST_diag):
850: /* FALLTHROUGH */
851: case(LIST_hang):
852: /* FALLTHROUGH */
853: case(LIST_inset):
854: /* FALLTHROUGH */
855: case(LIST_ohang):
856: /* FALLTHROUGH */
857: case(LIST_tag):
1.122 kristaps 858: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
859: bufcat_su(h, "margin-top", &su);
860: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 861: print_otag(h, TAG_DT, 2, tag);
1.115 kristaps 862: break;
863: case(LIST_column):
864: break;
865: default:
866: break;
867: }
868: } else if (MDOC_BODY == n->type) {
869: switch (type) {
870: case(LIST_bullet):
871: /* FALLTHROUGH */
872: case(LIST_hyphen):
873: /* FALLTHROUGH */
874: case(LIST_dash):
875: /* FALLTHROUGH */
876: case(LIST_enum):
877: /* FALLTHROUGH */
878: case(LIST_item):
1.122 kristaps 879: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
880: bufcat_su(h, "margin-top", &su);
881: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 882: print_otag(h, TAG_LI, 2, tag);
1.115 kristaps 883: break;
884: case(LIST_diag):
885: /* FALLTHROUGH */
886: case(LIST_hang):
887: /* FALLTHROUGH */
888: case(LIST_inset):
889: /* FALLTHROUGH */
890: case(LIST_ohang):
891: /* FALLTHROUGH */
892: case(LIST_tag):
1.122 kristaps 893: if (NULL == bl->data.Bl->width) {
894: print_otag(h, TAG_DD, 1, tag);
895: break;
896: }
897: a2width(bl->data.Bl->width, &su);
898: bufcat_su(h, "margin-left", &su);
899: PAIR_STYLE_INIT(&tag[1], h);
900: print_otag(h, TAG_DD, 2, tag);
1.115 kristaps 901: break;
902: case(LIST_column):
1.122 kristaps 903: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
904: bufcat_su(h, "margin-top", &su);
905: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 906: print_otag(h, TAG_TD, 2, tag);
1.115 kristaps 907: break;
908: default:
909: break;
910: }
911: } else {
912: switch (type) {
913: case (LIST_column):
1.116 kristaps 914: print_otag(h, TAG_TR, 1, tag);
1.115 kristaps 915: break;
916: default:
1.23 kristaps 917: break;
1.115 kristaps 918: }
1.1 kristaps 919: }
920:
921: return(1);
922: }
923:
1.25 kristaps 924: /* ARGSUSED */
1.1 kristaps 925: static int
1.115 kristaps 926: mdoc_bl_pre(MDOC_ARGS)
1.1 kristaps 927: {
1.115 kristaps 928: size_t i;
1.119 kristaps 929: struct htmlpair tag[3];
1.23 kristaps 930: struct roffsu su;
931:
1.115 kristaps 932: if (MDOC_BODY == n->type) {
933: if (LIST_column == n->data.Bl->type)
934: print_otag(h, TAG_TBODY, 0, NULL);
935: return(1);
1.23 kristaps 936: }
1.1 kristaps 937:
1.115 kristaps 938: if (MDOC_HEAD == n->type) {
939: if (LIST_column != n->data.Bl->type)
940: return(0);
941:
942: /*
943: * For each column, print out the <COL> tag with our
944: * suggested width. The last column gets min-width, as
945: * in terminal mode it auto-sizes to the width of the
946: * screen and we want to preserve that behaviour.
947: */
1.1 kristaps 948:
1.115 kristaps 949: for (i = 0; i < n->data.Bl->ncols; i++) {
950: a2width(n->data.Bl->cols[i], &su);
951: bufinit(h);
952: if (i < n->data.Bl->ncols - 1)
953: bufcat_su(h, "width", &su);
954: else
955: bufcat_su(h, "min-width", &su);
956: PAIR_STYLE_INIT(&tag[0], h);
957: print_otag(h, TAG_COL, 1, tag);
958: }
1.1 kristaps 959:
960: return(0);
961: }
962:
1.119 kristaps 963: SCALE_VS_INIT(&su, 0);
964: bufcat_su(h, "margin-top", &su);
965: bufcat_su(h, "margin-bottom", &su);
966: PAIR_STYLE_INIT(&tag[0], h);
967:
1.115 kristaps 968: assert(lists[n->data.Bl->type]);
1.119 kristaps 969: PAIR_CLASS_INIT(&tag[1], lists[n->data.Bl->type]);
970: i = 2;
1.1 kristaps 971:
1.115 kristaps 972: /* Set the block's left-hand margin. */
1.1 kristaps 973:
1.115 kristaps 974: if (n->data.Bl->offs) {
975: a2offs(n->data.Bl->offs, &su);
976: bufcat_su(h, "margin-left", &su);
1.119 kristaps 977: PAIR_STYLE_INIT(&tag[2], h);
978: i = 3;
1.115 kristaps 979: }
1.1 kristaps 980:
1.115 kristaps 981: switch (n->data.Bl->type) {
982: case(LIST_bullet):
1.1 kristaps 983: /* FALLTHROUGH */
1.115 kristaps 984: case(LIST_dash):
1.1 kristaps 985: /* FALLTHROUGH */
1.115 kristaps 986: case(LIST_hyphen):
1.1 kristaps 987: /* FALLTHROUGH */
1.115 kristaps 988: case(LIST_item):
989: print_otag(h, TAG_UL, i, tag);
1.1 kristaps 990: break;
1.115 kristaps 991: case(LIST_enum):
992: print_otag(h, TAG_OL, i, tag);
1.23 kristaps 993: break;
1.115 kristaps 994: case(LIST_diag):
995: /* FALLTHROUGH */
996: case(LIST_hang):
1.46 kristaps 997: /* FALLTHROUGH */
1.115 kristaps 998: case(LIST_inset):
1.33 kristaps 999: /* FALLTHROUGH */
1.115 kristaps 1000: case(LIST_ohang):
1.1 kristaps 1001: /* FALLTHROUGH */
1.115 kristaps 1002: case(LIST_tag):
1003: print_otag(h, TAG_DL, i, tag);
1004: break;
1005: case(LIST_column):
1006: print_otag(h, TAG_TABLE, i, tag);
1.1 kristaps 1007: break;
1008: default:
1.115 kristaps 1009: abort();
1010: /* NOTREACHED */
1.1 kristaps 1011: }
1012:
1013: return(1);
1014: }
1015:
1016: /* ARGSUSED */
1017: static int
1018: mdoc_ex_pre(MDOC_ARGS)
1019: {
1020: const struct mdoc_node *nn;
1021: struct tag *t;
1022: struct htmlpair tag;
1023:
1.23 kristaps 1024: PAIR_CLASS_INIT(&tag, "utility");
1025:
1.1 kristaps 1026: print_text(h, "The");
1027: for (nn = n->child; nn; nn = nn->next) {
1028: t = print_otag(h, TAG_SPAN, 1, &tag);
1029: print_text(h, nn->string);
1030: print_tagq(h, t);
1031:
1032: h->flags |= HTML_NOSPACE;
1033:
1034: if (nn->next && NULL == nn->next->next)
1035: print_text(h, ", and");
1036: else if (nn->next)
1037: print_text(h, ",");
1038: else
1039: h->flags &= ~HTML_NOSPACE;
1040: }
1041:
1.65 kristaps 1042: if (n->child && n->child->next)
1.1 kristaps 1043: print_text(h, "utilities exit");
1044: else
1045: print_text(h, "utility exits");
1046:
1047: print_text(h, "0 on success, and >0 if an error occurs.");
1048: return(0);
1049: }
1050:
1051:
1052: /* ARGSUSED */
1053: static int
1054: mdoc_em_pre(MDOC_ARGS)
1055: {
1056: struct htmlpair tag;
1057:
1.23 kristaps 1058: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1059: print_otag(h, TAG_SPAN, 1, &tag);
1060: return(1);
1061: }
1062:
1063:
1064: /* ARGSUSED */
1065: static int
1066: mdoc_d1_pre(MDOC_ARGS)
1067: {
1.23 kristaps 1068: struct htmlpair tag[2];
1069: struct roffsu su;
1.1 kristaps 1070:
1071: if (MDOC_BLOCK != n->type)
1072: return(1);
1073:
1.118 kristaps 1074: SCALE_VS_INIT(&su, 0);
1075: bufcat_su(h, "margin-top", &su);
1076: bufcat_su(h, "margin-bottom", &su);
1077: PAIR_STYLE_INIT(&tag[0], h);
1.120 kristaps 1078: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1079:
1080: /* BLOCKQUOTE needs a block body. */
1.118 kristaps 1081:
1082: if (MDOC_Dl == n->tok) {
1083: PAIR_CLASS_INIT(&tag[1], "lit");
1.120 kristaps 1084: print_otag(h, TAG_DIV, 1, tag);
1.118 kristaps 1085: } else
1.120 kristaps 1086: print_otag(h, TAG_DIV, 0, tag);
1.35 kristaps 1087:
1.1 kristaps 1088: return(1);
1089: }
1090:
1091:
1092: /* ARGSUSED */
1093: static int
1094: mdoc_sx_pre(MDOC_ARGS)
1095: {
1.18 kristaps 1096: struct htmlpair tag[2];
1.1 kristaps 1097: const struct mdoc_node *nn;
1.35 kristaps 1098: char buf[BUFSIZ];
1.1 kristaps 1099:
1.41 kristaps 1100: strlcpy(buf, "#", BUFSIZ);
1.1 kristaps 1101: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 1102: html_idcat(buf, nn->string, BUFSIZ);
1.1 kristaps 1103: if (nn->next)
1.42 kristaps 1104: html_idcat(buf, " ", BUFSIZ);
1.1 kristaps 1105: }
1106:
1.23 kristaps 1107: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 kristaps 1108: PAIR_HREF_INIT(&tag[1], buf);
1.1 kristaps 1109:
1.18 kristaps 1110: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1111: return(1);
1112: }
1113:
1114:
1115: /* ARGSUSED */
1116: static int
1117: mdoc_bd_pre(MDOC_ARGS)
1118: {
1119: struct htmlpair tag[2];
1.80 kristaps 1120: int comp;
1121: const struct mdoc_node *nn;
1.23 kristaps 1122: struct roffsu su;
1.1 kristaps 1123:
1.80 kristaps 1124: if (MDOC_HEAD == n->type)
1.1 kristaps 1125: return(0);
1126:
1.24 kristaps 1127: SCALE_VS_INIT(&su, 0);
1128:
1.90 kristaps 1129: assert(n->data.Bd);
1130: if (n->data.Bd->offs)
1131: a2offs(n->data.Bd->offs, &su);
1.80 kristaps 1132:
1.90 kristaps 1133: comp = n->data.Bd->comp;
1.1 kristaps 1134:
1.31 kristaps 1135: /* FIXME: -centered, etc. formatting. */
1.60 kristaps 1136: /* FIXME: does not respect -offset ??? */
1.31 kristaps 1137:
1.1 kristaps 1138: if (MDOC_BLOCK == n->type) {
1.24 kristaps 1139: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1140: for (nn = n; nn && ! comp; nn = nn->parent) {
1141: if (MDOC_BLOCK != nn->type)
1142: continue;
1143: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1144: comp = 1;
1145: if (nn->prev)
1146: break;
1147: }
1148: if (comp) {
1.64 kristaps 1149: PAIR_STYLE_INIT(&tag[0], h);
1150: print_otag(h, TAG_DIV, 1, tag);
1.23 kristaps 1151: return(1);
1.14 kristaps 1152: }
1.23 kristaps 1153: SCALE_VS_INIT(&su, 1);
1154: bufcat_su(h, "margin-top", &su);
1155: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 1156: print_otag(h, TAG_DIV, 1, tag);
1157: return(1);
1158: }
1159:
1.90 kristaps 1160: if (DISP_unfilled != n->data.Bd->type &&
1161: DISP_literal != n->data.Bd->type)
1.1 kristaps 1162: return(1);
1163:
1.23 kristaps 1164: PAIR_CLASS_INIT(&tag[0], "lit");
1165: bufcat_style(h, "white-space", "pre");
1166: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1167: print_otag(h, TAG_DIV, 2, tag);
1168:
1.14 kristaps 1169: for (nn = n->child; nn; nn = nn->next) {
1170: print_mdoc_node(m, nn, h);
1.108 kristaps 1171: /*
1172: * If the printed node flushes its own line, then we
1173: * needn't do it here as well. This is hacky, but the
1174: * notion of selective eoln whitespace is pretty dumb
1175: * anyway, so don't sweat it.
1176: */
1177: switch (nn->tok) {
1.111 kristaps 1178: case (MDOC_Sm):
1179: /* FALLTHROUGH */
1.108 kristaps 1180: case (MDOC_br):
1181: /* FALLTHROUGH */
1182: case (MDOC_sp):
1183: /* FALLTHROUGH */
1184: case (MDOC_Bl):
1.114 kristaps 1185: /* FALLTHROUGH */
1186: case (MDOC_D1):
1187: /* FALLTHROUGH */
1188: case (MDOC_Dl):
1.108 kristaps 1189: /* FALLTHROUGH */
1190: case (MDOC_Lp):
1191: /* FALLTHROUGH */
1192: case (MDOC_Pp):
1193: continue;
1194: default:
1195: break;
1196: }
1.101 schwarze 1197: if (nn->next && nn->next->line == nn->line)
1198: continue;
1199: print_text(h, "\n");
1200: h->flags |= HTML_NOSPACE;
1.1 kristaps 1201: }
1202:
1203: return(0);
1204: }
1205:
1206:
1207: /* ARGSUSED */
1208: static int
1209: mdoc_pa_pre(MDOC_ARGS)
1210: {
1211: struct htmlpair tag;
1212:
1.23 kristaps 1213: PAIR_CLASS_INIT(&tag, "file");
1.1 kristaps 1214: print_otag(h, TAG_SPAN, 1, &tag);
1215: return(1);
1216: }
1217:
1218:
1219: /* ARGSUSED */
1220: static int
1221: mdoc_ad_pre(MDOC_ARGS)
1222: {
1223: struct htmlpair tag;
1224:
1.23 kristaps 1225: PAIR_CLASS_INIT(&tag, "addr");
1.1 kristaps 1226: print_otag(h, TAG_SPAN, 1, &tag);
1227: return(1);
1228: }
1229:
1230:
1231: /* ARGSUSED */
1232: static int
1233: mdoc_an_pre(MDOC_ARGS)
1234: {
1235: struct htmlpair tag;
1236:
1.19 kristaps 1237: /* TODO: -split and -nosplit (see termp_an_pre()). */
1238:
1.23 kristaps 1239: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1240: print_otag(h, TAG_SPAN, 1, &tag);
1241: return(1);
1242: }
1243:
1244:
1245: /* ARGSUSED */
1246: static int
1247: mdoc_cd_pre(MDOC_ARGS)
1248: {
1249: struct htmlpair tag;
1250:
1.78 kristaps 1251: synopsis_pre(h, n);
1.23 kristaps 1252: PAIR_CLASS_INIT(&tag, "config");
1.1 kristaps 1253: print_otag(h, TAG_SPAN, 1, &tag);
1254: return(1);
1255: }
1256:
1257:
1258: /* ARGSUSED */
1259: static int
1260: mdoc_dv_pre(MDOC_ARGS)
1261: {
1262: struct htmlpair tag;
1263:
1.23 kristaps 1264: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1265: print_otag(h, TAG_SPAN, 1, &tag);
1266: return(1);
1267: }
1268:
1269:
1270: /* ARGSUSED */
1271: static int
1272: mdoc_ev_pre(MDOC_ARGS)
1273: {
1274: struct htmlpair tag;
1275:
1.23 kristaps 1276: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1277: print_otag(h, TAG_SPAN, 1, &tag);
1278: return(1);
1279: }
1280:
1281:
1282: /* ARGSUSED */
1283: static int
1284: mdoc_er_pre(MDOC_ARGS)
1285: {
1286: struct htmlpair tag;
1287:
1.23 kristaps 1288: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1289: print_otag(h, TAG_SPAN, 1, &tag);
1290: return(1);
1291: }
1292:
1293:
1294: /* ARGSUSED */
1295: static int
1296: mdoc_fa_pre(MDOC_ARGS)
1297: {
1298: const struct mdoc_node *nn;
1299: struct htmlpair tag;
1300: struct tag *t;
1301:
1.23 kristaps 1302: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1303: if (n->parent->tok != MDOC_Fo) {
1304: print_otag(h, TAG_SPAN, 1, &tag);
1305: return(1);
1306: }
1307:
1308: for (nn = n->child; nn; nn = nn->next) {
1309: t = print_otag(h, TAG_SPAN, 1, &tag);
1310: print_text(h, nn->string);
1311: print_tagq(h, t);
1312: if (nn->next)
1313: print_text(h, ",");
1314: }
1315:
1316: if (n->child && n->next && n->next->tok == MDOC_Fa)
1317: print_text(h, ",");
1318:
1319: return(0);
1320: }
1321:
1322:
1323: /* ARGSUSED */
1324: static int
1325: mdoc_fd_pre(MDOC_ARGS)
1326: {
1.23 kristaps 1327: struct htmlpair tag;
1.1 kristaps 1328:
1.78 kristaps 1329: synopsis_pre(h, n);
1330:
1.23 kristaps 1331: PAIR_CLASS_INIT(&tag, "macro");
1.1 kristaps 1332: print_otag(h, TAG_SPAN, 1, &tag);
1333: return(1);
1334: }
1335:
1336:
1337: /* ARGSUSED */
1338: static int
1339: mdoc_vt_pre(MDOC_ARGS)
1340: {
1.23 kristaps 1341: struct htmlpair tag;
1.1 kristaps 1342:
1.78 kristaps 1343: if (MDOC_BLOCK == n->type) {
1344: synopsis_pre(h, n);
1.54 kristaps 1345: return(1);
1.78 kristaps 1346: } else if (MDOC_ELEM == n->type) {
1347: synopsis_pre(h, n);
1.54 kristaps 1348: } else if (MDOC_HEAD == n->type)
1349: return(0);
1.1 kristaps 1350:
1.23 kristaps 1351: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1352: print_otag(h, TAG_SPAN, 1, &tag);
1353: return(1);
1354: }
1355:
1.2 kristaps 1356:
1.1 kristaps 1357: /* ARGSUSED */
1358: static int
1359: mdoc_ft_pre(MDOC_ARGS)
1360: {
1.23 kristaps 1361: struct htmlpair tag;
1.1 kristaps 1362:
1.78 kristaps 1363: synopsis_pre(h, n);
1.23 kristaps 1364: PAIR_CLASS_INIT(&tag, "ftype");
1.1 kristaps 1365: print_otag(h, TAG_SPAN, 1, &tag);
1366: return(1);
1367: }
1368:
1369:
1370: /* ARGSUSED */
1371: static int
1372: mdoc_fn_pre(MDOC_ARGS)
1373: {
1374: struct tag *t;
1.15 kristaps 1375: struct htmlpair tag[2];
1.1 kristaps 1376: const struct mdoc_node *nn;
1.7 kristaps 1377: char nbuf[BUFSIZ];
1378: const char *sp, *ep;
1.15 kristaps 1379: int sz, i;
1.1 kristaps 1380:
1.78 kristaps 1381: synopsis_pre(h, n);
1.1 kristaps 1382:
1.7 kristaps 1383: /* Split apart into type and name. */
1384: assert(n->child->string);
1385: sp = n->child->string;
1.19 kristaps 1386:
1.26 kristaps 1387: ep = strchr(sp, ' ');
1388: if (NULL != ep) {
1.23 kristaps 1389: PAIR_CLASS_INIT(&tag[0], "ftype");
1.19 kristaps 1390: t = print_otag(h, TAG_SPAN, 1, tag);
1391:
1392: while (ep) {
1393: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1394: (void)memcpy(nbuf, sp, (size_t)sz);
1395: nbuf[sz] = '\0';
1396: print_text(h, nbuf);
1397: sp = ++ep;
1398: ep = strchr(sp, ' ');
1399: }
1400: print_tagq(h, t);
1.7 kristaps 1401: }
1.1 kristaps 1402:
1.23 kristaps 1403: PAIR_CLASS_INIT(&tag[0], "fname");
1.57 kristaps 1404:
1405: /*
1406: * FIXME: only refer to IDs that we know exist.
1407: */
1408:
1409: #if 0
1.87 kristaps 1410: if (MDOC_SYNPRETTY & n->flags) {
1.57 kristaps 1411: nbuf[0] = '\0';
1412: html_idcat(nbuf, sp, BUFSIZ);
1413: PAIR_ID_INIT(&tag[1], nbuf);
1414: } else {
1415: strlcpy(nbuf, "#", BUFSIZ);
1416: html_idcat(nbuf, sp, BUFSIZ);
1417: PAIR_HREF_INIT(&tag[1], nbuf);
1418: }
1419: #endif
1420:
1.15 kristaps 1421: t = print_otag(h, TAG_SPAN, 1, tag);
1.7 kristaps 1422:
1423: if (sp) {
1.57 kristaps 1424: strlcpy(nbuf, sp, BUFSIZ);
1.7 kristaps 1425: print_text(h, nbuf);
1426: }
1427:
1.1 kristaps 1428: print_tagq(h, t);
1429:
1430: h->flags |= HTML_NOSPACE;
1431: print_text(h, "(");
1432:
1.23 kristaps 1433: bufinit(h);
1434: PAIR_CLASS_INIT(&tag[0], "farg");
1435: bufcat_style(h, "white-space", "nowrap");
1436: PAIR_STYLE_INIT(&tag[1], h);
1437:
1.1 kristaps 1438: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1439: i = 1;
1.87 kristaps 1440: if (MDOC_SYNPRETTY & n->flags)
1.23 kristaps 1441: i = 2;
1.15 kristaps 1442: t = print_otag(h, TAG_SPAN, i, tag);
1.1 kristaps 1443: print_text(h, nn->string);
1444: print_tagq(h, t);
1445: if (nn->next)
1446: print_text(h, ",");
1447: }
1448:
1449: print_text(h, ")");
1.87 kristaps 1450: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1451: print_text(h, ";");
1.99 kristaps 1452:
1453: return(0);
1454: }
1455:
1456:
1457: /* ARGSUSED */
1458: static int
1459: mdoc_sm_pre(MDOC_ARGS)
1460: {
1461:
1462: assert(n->child && MDOC_TEXT == n->child->type);
1463: if (0 == strcmp("on", n->child->string)) {
1.111 kristaps 1464: /*
1465: * FIXME: no p->col to check. Thus, if we have
1466: * .Bd -literal
1467: * .Sm off
1468: * 1 2
1469: * .Sm on
1470: * 3
1471: * .Ed
1472: * the "3" is preceded by a space.
1473: */
1.99 kristaps 1474: h->flags &= ~HTML_NOSPACE;
1475: h->flags &= ~HTML_NONOSPACE;
1476: } else
1477: h->flags |= HTML_NONOSPACE;
1.1 kristaps 1478:
1479: return(0);
1480: }
1481:
1.120 kristaps 1482: /* ARGSUSED */
1483: static int
1484: mdoc_pp_pre(MDOC_ARGS)
1485: {
1486:
1487: print_otag(h, TAG_P, 0, NULL);
1488: return(0);
1489:
1490: }
1.1 kristaps 1491:
1492: /* ARGSUSED */
1493: static int
1494: mdoc_sp_pre(MDOC_ARGS)
1495: {
1.120 kristaps 1496: struct roffsu su;
1.23 kristaps 1497: struct htmlpair tag;
1.1 kristaps 1498:
1.120 kristaps 1499: SCALE_VS_INIT(&su, 1);
1500:
1501: if (MDOC_sp == n->tok) {
1502: if (n->child)
1503: a2roffsu(n->child->string, &su, SCALE_VS);
1504: } else
1505: su.scale = 0;
1.1 kristaps 1506:
1.23 kristaps 1507: bufcat_su(h, "height", &su);
1508: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1509: print_otag(h, TAG_DIV, 1, &tag);
1.120 kristaps 1510:
1.42 kristaps 1511: /* So the div isn't empty: */
1512: print_text(h, "\\~");
1513:
1514: return(0);
1.1 kristaps 1515:
1516: }
1.2 kristaps 1517:
1518: /* ARGSUSED */
1519: static int
1520: mdoc_lk_pre(MDOC_ARGS)
1521: {
1522: const struct mdoc_node *nn;
1523: struct htmlpair tag[2];
1524:
1525: nn = n->child;
1526:
1.23 kristaps 1527: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57 kristaps 1528: PAIR_HREF_INIT(&tag[1], nn->string);
1.2 kristaps 1529: print_otag(h, TAG_A, 2, tag);
1530:
1.113 kristaps 1531: if (NULL == nn || NULL == nn->next)
1.38 kristaps 1532: return(1);
1533:
1.2 kristaps 1534: for (nn = nn->next; nn; nn = nn->next)
1535: print_text(h, nn->string);
1536:
1537: return(0);
1538: }
1539:
1540:
1541: /* ARGSUSED */
1542: static int
1543: mdoc_mt_pre(MDOC_ARGS)
1544: {
1545: struct htmlpair tag[2];
1546: struct tag *t;
1547: const struct mdoc_node *nn;
1548:
1.23 kristaps 1549: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1550:
1551: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1552: bufinit(h);
1553: bufcat(h, "mailto:");
1554: bufcat(h, nn->string);
1.57 kristaps 1555: PAIR_HREF_INIT(&tag[1], h->buf);
1.2 kristaps 1556: t = print_otag(h, TAG_A, 2, tag);
1557: print_text(h, nn->string);
1558: print_tagq(h, t);
1559: }
1560:
1561: return(0);
1562: }
1.4 kristaps 1563:
1564:
1565: /* ARGSUSED */
1566: static int
1567: mdoc_fo_pre(MDOC_ARGS)
1568: {
1.77 kristaps 1569: struct htmlpair tag;
1570: struct tag *t;
1.4 kristaps 1571:
1572: if (MDOC_BODY == n->type) {
1573: h->flags |= HTML_NOSPACE;
1574: print_text(h, "(");
1575: h->flags |= HTML_NOSPACE;
1576: return(1);
1.77 kristaps 1577: } else if (MDOC_BLOCK == n->type) {
1.78 kristaps 1578: synopsis_pre(h, n);
1.4 kristaps 1579: return(1);
1.57 kristaps 1580: }
1.4 kristaps 1581:
1.77 kristaps 1582: /* XXX: we drop non-initial arguments as per groff. */
1583:
1584: assert(n->child);
1585: assert(n->child->string);
1586:
1.23 kristaps 1587: PAIR_CLASS_INIT(&tag, "fname");
1.77 kristaps 1588: t = print_otag(h, TAG_SPAN, 1, &tag);
1589: print_text(h, n->child->string);
1590: print_tagq(h, t);
1591: return(0);
1.4 kristaps 1592: }
1593:
1594:
1595: /* ARGSUSED */
1596: static void
1597: mdoc_fo_post(MDOC_ARGS)
1598: {
1.78 kristaps 1599:
1.4 kristaps 1600: if (MDOC_BODY != n->type)
1601: return;
1602: print_text(h, ")");
1603: print_text(h, ";");
1604: }
1605:
1606:
1607: /* ARGSUSED */
1608: static int
1609: mdoc_in_pre(MDOC_ARGS)
1610: {
1611: const struct mdoc_node *nn;
1.23 kristaps 1612: struct tag *t;
1.17 kristaps 1613: struct htmlpair tag[2];
1614: int i;
1.34 kristaps 1615:
1.78 kristaps 1616: synopsis_pre(h, n);
1617:
1.23 kristaps 1618: PAIR_CLASS_INIT(&tag[0], "includes");
1.17 kristaps 1619: print_otag(h, TAG_SPAN, 1, tag);
1.4 kristaps 1620:
1.87 kristaps 1621: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.4 kristaps 1622: print_text(h, "#include");
1623:
1624: print_text(h, "<");
1625: h->flags |= HTML_NOSPACE;
1626:
1.17 kristaps 1627: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1628: PAIR_CLASS_INIT(&tag[0], "link-includes");
1629: i = 1;
1.41 kristaps 1630: bufinit(h);
1.17 kristaps 1631: if (h->base_includes) {
1632: buffmt_includes(h, nn->string);
1.57 kristaps 1633: PAIR_HREF_INIT(&tag[i], h->buf);
1634: i++;
1.17 kristaps 1635: }
1636: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1637: print_mdoc_node(m, nn, h);
1.17 kristaps 1638: print_tagq(h, t);
1639: }
1.4 kristaps 1640:
1641: h->flags |= HTML_NOSPACE;
1642: print_text(h, ">");
1643:
1644: return(0);
1645: }
1646:
1647:
1648: /* ARGSUSED */
1649: static int
1650: mdoc_ic_pre(MDOC_ARGS)
1651: {
1652: struct htmlpair tag;
1653:
1.23 kristaps 1654: PAIR_CLASS_INIT(&tag, "cmd");
1.4 kristaps 1655: print_otag(h, TAG_SPAN, 1, &tag);
1656: return(1);
1657: }
1658:
1659:
1660: /* ARGSUSED */
1661: static int
1662: mdoc_rv_pre(MDOC_ARGS)
1663: {
1664: const struct mdoc_node *nn;
1665: struct htmlpair tag;
1666: struct tag *t;
1667:
1668: print_otag(h, TAG_DIV, 0, NULL);
1669: print_text(h, "The");
1670:
1671: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1672: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1673: t = print_otag(h, TAG_SPAN, 1, &tag);
1674: print_text(h, nn->string);
1675: print_tagq(h, t);
1676:
1677: h->flags |= HTML_NOSPACE;
1678: if (nn->next && NULL == nn->next->next)
1679: print_text(h, "(), and");
1680: else if (nn->next)
1681: print_text(h, "(),");
1682: else
1683: print_text(h, "()");
1684: }
1685:
1.65 kristaps 1686: if (n->child && n->child->next)
1.4 kristaps 1687: print_text(h, "functions return");
1688: else
1689: print_text(h, "function returns");
1690:
1691: print_text(h, "the value 0 if successful; otherwise the value "
1692: "-1 is returned and the global variable");
1693:
1.23 kristaps 1694: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1695: t = print_otag(h, TAG_SPAN, 1, &tag);
1696: print_text(h, "errno");
1697: print_tagq(h, t);
1698: print_text(h, "is set to indicate the error.");
1699: return(0);
1700: }
1701:
1702:
1703: /* ARGSUSED */
1704: static int
1705: mdoc_va_pre(MDOC_ARGS)
1706: {
1707: struct htmlpair tag;
1708:
1.23 kristaps 1709: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1710: print_otag(h, TAG_SPAN, 1, &tag);
1711: return(1);
1712: }
1713:
1714:
1715: /* ARGSUSED */
1716: static int
1.5 kristaps 1717: mdoc_ap_pre(MDOC_ARGS)
1718: {
1719:
1720: h->flags |= HTML_NOSPACE;
1721: print_text(h, "\\(aq");
1722: h->flags |= HTML_NOSPACE;
1723: return(1);
1724: }
1725:
1726:
1727: /* ARGSUSED */
1728: static int
1729: mdoc_bf_pre(MDOC_ARGS)
1730: {
1.23 kristaps 1731: struct htmlpair tag[2];
1732: struct roffsu su;
1.5 kristaps 1733:
1734: if (MDOC_HEAD == n->type)
1735: return(0);
1.92 kristaps 1736: else if (MDOC_BODY != n->type)
1.5 kristaps 1737: return(1);
1738:
1.92 kristaps 1739: assert(n->data.Bf);
1.5 kristaps 1740:
1.92 kristaps 1741: if (FONT_Em == n->data.Bf->font)
1742: PAIR_CLASS_INIT(&tag[0], "emph");
1743: else if (FONT_Sy == n->data.Bf->font)
1744: PAIR_CLASS_INIT(&tag[0], "symb");
1745: else if (FONT_Li == n->data.Bf->font)
1746: PAIR_CLASS_INIT(&tag[0], "lit");
1747: else
1748: PAIR_CLASS_INIT(&tag[0], "none");
1.5 kristaps 1749:
1.92 kristaps 1750: /*
1751: * We want this to be inline-formatted, but needs to be div to
1752: * accept block children.
1753: */
1.23 kristaps 1754: bufcat_style(h, "display", "inline");
1755: SCALE_HS_INIT(&su, 1);
1.92 kristaps 1756: /* Needs a left-margin for spacing. */
1757: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1758: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 1759: print_otag(h, TAG_DIV, 2, tag);
1760: return(1);
1761: }
1762:
1763:
1764: /* ARGSUSED */
1765: static int
1766: mdoc_ms_pre(MDOC_ARGS)
1767: {
1768: struct htmlpair tag;
1769:
1.23 kristaps 1770: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 1771: print_otag(h, TAG_SPAN, 1, &tag);
1772: return(1);
1773: }
1774:
1775:
1776: /* ARGSUSED */
1777: static int
1.110 schwarze 1778: mdoc_igndelim_pre(MDOC_ARGS)
1.5 kristaps 1779: {
1780:
1781: h->flags |= HTML_IGNDELIM;
1782: return(1);
1783: }
1784:
1785:
1786: /* ARGSUSED */
1787: static void
1788: mdoc_pf_post(MDOC_ARGS)
1789: {
1790:
1791: h->flags |= HTML_NOSPACE;
1792: }
1793:
1794:
1795: /* ARGSUSED */
1796: static int
1797: mdoc_rs_pre(MDOC_ARGS)
1798: {
1.23 kristaps 1799: struct htmlpair tag;
1.5 kristaps 1800:
1801: if (MDOC_BLOCK != n->type)
1802: return(1);
1803:
1.120 kristaps 1804: if (n->prev && SEC_SEE_ALSO == n->sec)
1805: print_otag(h, TAG_P, 0, NULL);
1.5 kristaps 1806:
1.23 kristaps 1807: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 1808: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 1809: return(1);
1810: }
1.6 kristaps 1811:
1812:
1813:
1814: /* ARGSUSED */
1815: static int
1816: mdoc_li_pre(MDOC_ARGS)
1817: {
1818: struct htmlpair tag;
1819:
1.23 kristaps 1820: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 1821: print_otag(h, TAG_SPAN, 1, &tag);
1822: return(1);
1823: }
1824:
1825:
1826: /* ARGSUSED */
1827: static int
1828: mdoc_sy_pre(MDOC_ARGS)
1829: {
1830: struct htmlpair tag;
1831:
1.23 kristaps 1832: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 1833: print_otag(h, TAG_SPAN, 1, &tag);
1834: return(1);
1835: }
1836:
1837:
1838: /* ARGSUSED */
1839: static int
1840: mdoc_bt_pre(MDOC_ARGS)
1841: {
1842:
1843: print_text(h, "is currently in beta test.");
1844: return(0);
1845: }
1846:
1847:
1848: /* ARGSUSED */
1849: static int
1850: mdoc_ud_pre(MDOC_ARGS)
1851: {
1852:
1853: print_text(h, "currently under development.");
1854: return(0);
1855: }
1856:
1857:
1858: /* ARGSUSED */
1859: static int
1860: mdoc_lb_pre(MDOC_ARGS)
1861: {
1862: struct htmlpair tag;
1863:
1.62 kristaps 1864: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.6 kristaps 1865: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 1866: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 1867: print_otag(h, TAG_SPAN, 1, &tag);
1868: return(1);
1869: }
1.10 kristaps 1870:
1871:
1872: /* ARGSUSED */
1873: static int
1874: mdoc__x_pre(MDOC_ARGS)
1875: {
1.38 kristaps 1876: struct htmlpair tag[2];
1.37 kristaps 1877:
1.10 kristaps 1878: switch (n->tok) {
1879: case(MDOC__A):
1.38 kristaps 1880: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.103 kristaps 1881: if (n->prev && MDOC__A == n->prev->tok)
1882: if (NULL == n->next || MDOC__A != n->next->tok)
1883: print_text(h, "and");
1.10 kristaps 1884: break;
1885: case(MDOC__B):
1.38 kristaps 1886: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10 kristaps 1887: break;
1888: case(MDOC__C):
1.38 kristaps 1889: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10 kristaps 1890: break;
1891: case(MDOC__D):
1.38 kristaps 1892: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10 kristaps 1893: break;
1894: case(MDOC__I):
1.38 kristaps 1895: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10 kristaps 1896: break;
1897: case(MDOC__J):
1.38 kristaps 1898: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10 kristaps 1899: break;
1900: case(MDOC__N):
1.38 kristaps 1901: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10 kristaps 1902: break;
1903: case(MDOC__O):
1.38 kristaps 1904: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10 kristaps 1905: break;
1906: case(MDOC__P):
1.38 kristaps 1907: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10 kristaps 1908: break;
1909: case(MDOC__Q):
1.38 kristaps 1910: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10 kristaps 1911: break;
1912: case(MDOC__R):
1.38 kristaps 1913: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10 kristaps 1914: break;
1915: case(MDOC__T):
1.38 kristaps 1916: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10 kristaps 1917: break;
1.38 kristaps 1918: case(MDOC__U):
1919: PAIR_CLASS_INIT(&tag[0], "link-ref");
1920: break;
1.10 kristaps 1921: case(MDOC__V):
1.38 kristaps 1922: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10 kristaps 1923: break;
1924: default:
1925: abort();
1926: /* NOTREACHED */
1927: }
1928:
1.38 kristaps 1929: if (MDOC__U != n->tok) {
1930: print_otag(h, TAG_SPAN, 1, tag);
1931: return(1);
1932: }
1933:
1934: PAIR_HREF_INIT(&tag[1], n->child->string);
1935: print_otag(h, TAG_A, 2, tag);
1.103 kristaps 1936:
1.10 kristaps 1937: return(1);
1938: }
1939:
1940:
1941: /* ARGSUSED */
1942: static void
1943: mdoc__x_post(MDOC_ARGS)
1944: {
1.103 kristaps 1945:
1946: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1947: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1948: if (NULL == n->prev || MDOC__A != n->prev->tok)
1949: return;
1.10 kristaps 1950:
1.61 kristaps 1951: /* TODO: %U */
1952:
1.106 kristaps 1953: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1954: return;
1955:
1.10 kristaps 1956: print_text(h, n->next ? "," : ".");
1.94 kristaps 1957: }
1958:
1959:
1960: /* ARGSUSED */
1961: static int
1962: mdoc_bk_pre(MDOC_ARGS)
1963: {
1964:
1965: switch (n->type) {
1966: case (MDOC_BLOCK):
1967: break;
1968: case (MDOC_HEAD):
1969: return(0);
1970: case (MDOC_BODY):
1971: h->flags |= HTML_PREKEEP;
1972: break;
1973: default:
1974: abort();
1975: /* NOTREACHED */
1976: }
1977:
1978: return(1);
1979: }
1980:
1981:
1982: /* ARGSUSED */
1983: static void
1984: mdoc_bk_post(MDOC_ARGS)
1985: {
1986:
1987: if (MDOC_BODY == n->type)
1988: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.10 kristaps 1989: }
1.107 kristaps 1990:
1991:
1992: /* ARGSUSED */
1993: static int
1994: mdoc_quote_pre(MDOC_ARGS)
1995: {
1996: struct htmlpair tag;
1997:
1998: if (MDOC_BODY != n->type)
1999: return(1);
2000:
2001: switch (n->tok) {
2002: case (MDOC_Ao):
2003: /* FALLTHROUGH */
2004: case (MDOC_Aq):
2005: print_text(h, "\\(la");
2006: break;
2007: case (MDOC_Bro):
2008: /* FALLTHROUGH */
2009: case (MDOC_Brq):
2010: print_text(h, "\\(lC");
2011: break;
2012: case (MDOC_Bo):
2013: /* FALLTHROUGH */
2014: case (MDOC_Bq):
2015: print_text(h, "\\(lB");
2016: break;
2017: case (MDOC_Oo):
2018: /* FALLTHROUGH */
2019: case (MDOC_Op):
2020: print_text(h, "\\(lB");
1.109 kristaps 2021: h->flags |= HTML_NOSPACE;
1.107 kristaps 2022: PAIR_CLASS_INIT(&tag, "opt");
2023: print_otag(h, TAG_SPAN, 1, &tag);
2024: break;
2025: case (MDOC_Do):
2026: /* FALLTHROUGH */
2027: case (MDOC_Dq):
2028: /* FALLTHROUGH */
2029: case (MDOC_Qo):
2030: /* FALLTHROUGH */
2031: case (MDOC_Qq):
2032: print_text(h, "\\(lq");
2033: break;
2034: case (MDOC_Po):
2035: /* FALLTHROUGH */
2036: case (MDOC_Pq):
2037: print_text(h, "(");
2038: break;
2039: case (MDOC_Ql):
2040: /* FALLTHROUGH */
2041: case (MDOC_So):
2042: /* FALLTHROUGH */
2043: case (MDOC_Sq):
2044: print_text(h, "\\(oq");
2045: break;
2046: default:
2047: abort();
2048: /* NOTREACHED */
2049: }
2050:
2051: h->flags |= HTML_NOSPACE;
2052: return(1);
2053: }
2054:
2055:
2056: /* ARGSUSED */
2057: static void
2058: mdoc_quote_post(MDOC_ARGS)
2059: {
2060:
2061: if (MDOC_BODY != n->type)
2062: return;
2063:
2064: h->flags |= HTML_NOSPACE;
2065:
2066: switch (n->tok) {
2067: case (MDOC_Ao):
2068: /* FALLTHROUGH */
2069: case (MDOC_Aq):
2070: print_text(h, "\\(ra");
2071: break;
2072: case (MDOC_Bro):
2073: /* FALLTHROUGH */
2074: case (MDOC_Brq):
2075: print_text(h, "\\(rC");
2076: break;
2077: case (MDOC_Oo):
2078: /* FALLTHROUGH */
2079: case (MDOC_Op):
2080: /* FALLTHROUGH */
2081: case (MDOC_Bo):
2082: /* FALLTHROUGH */
2083: case (MDOC_Bq):
2084: print_text(h, "\\(rB");
2085: break;
2086: case (MDOC_Qo):
2087: /* FALLTHROUGH */
2088: case (MDOC_Qq):
2089: /* FALLTHROUGH */
2090: case (MDOC_Do):
2091: /* FALLTHROUGH */
2092: case (MDOC_Dq):
2093: print_text(h, "\\(rq");
2094: break;
2095: case (MDOC_Po):
2096: /* FALLTHROUGH */
2097: case (MDOC_Pq):
2098: print_text(h, ")");
2099: break;
2100: case (MDOC_Ql):
2101: /* FALLTHROUGH */
2102: case (MDOC_So):
2103: /* FALLTHROUGH */
2104: case (MDOC_Sq):
2105: print_text(h, "\\(aq");
2106: break;
2107: default:
2108: abort();
2109: /* NOTREACHED */
2110: }
2111: }
2112:
2113:
CVSweb