Annotation of mandoc/mdoc_html.c, Revision 1.121
1.121 ! kristaps 1: /* $Id: mdoc_html.c,v 1.120 2010/12/15 17:19:41 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: SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
907: bufcat_su(h, "margin-top", &su);
1.116 kristaps 908: PAIR_STYLE_INIT(&tag[1], h);
1.23 kristaps 909:
1.115 kristaps 910: if (MDOC_HEAD == n->type) {
911: switch (type) {
912: case(LIST_bullet):
913: /* FALLTHROUGH */
914: case(LIST_dash):
915: /* FALLTHROUGH */
916: case(LIST_item):
917: /* FALLTHROUGH */
918: case(LIST_hyphen):
919: /* FALLTHROUGH */
920: case(LIST_enum):
921: return(0);
922: case(LIST_diag):
923: /* FALLTHROUGH */
924: case(LIST_hang):
925: /* FALLTHROUGH */
926: case(LIST_inset):
927: /* FALLTHROUGH */
928: case(LIST_ohang):
929: /* FALLTHROUGH */
930: case(LIST_tag):
1.116 kristaps 931: print_otag(h, TAG_DT, 2, tag);
1.115 kristaps 932: break;
933: case(LIST_column):
934: break;
935: default:
936: break;
937: }
938: } else if (MDOC_BODY == n->type) {
939: switch (type) {
940: case(LIST_bullet):
941: /* FALLTHROUGH */
942: case(LIST_hyphen):
943: /* FALLTHROUGH */
944: case(LIST_dash):
945: /* FALLTHROUGH */
946: case(LIST_enum):
947: /* FALLTHROUGH */
948: case(LIST_item):
949: /* FALLTHROUGH */
1.116 kristaps 950: print_otag(h, TAG_LI, 2, tag);
1.115 kristaps 951: break;
952: case(LIST_diag):
953: /* FALLTHROUGH */
954: case(LIST_hang):
955: /* FALLTHROUGH */
956: case(LIST_inset):
957: /* FALLTHROUGH */
958: case(LIST_ohang):
959: /* FALLTHROUGH */
960: case(LIST_tag):
1.116 kristaps 961: print_otag(h, TAG_DD, 1, tag);
1.115 kristaps 962: break;
963: case(LIST_column):
1.116 kristaps 964: print_otag(h, TAG_TD, 2, tag);
1.115 kristaps 965: break;
966: default:
967: break;
968: }
969: } else {
970: switch (type) {
971: case (LIST_column):
1.116 kristaps 972: print_otag(h, TAG_TR, 1, tag);
1.115 kristaps 973: break;
974: default:
1.23 kristaps 975: break;
1.115 kristaps 976: }
1.1 kristaps 977: }
978:
979: return(1);
980: }
981:
1.25 kristaps 982: /* ARGSUSED */
1.1 kristaps 983: static int
1.115 kristaps 984: mdoc_bl_pre(MDOC_ARGS)
1.1 kristaps 985: {
1.115 kristaps 986: size_t i;
1.119 kristaps 987: struct htmlpair tag[3];
1.23 kristaps 988: struct roffsu su;
989:
1.115 kristaps 990: if (MDOC_BODY == n->type) {
991: if (LIST_column == n->data.Bl->type)
992: print_otag(h, TAG_TBODY, 0, NULL);
993: return(1);
1.23 kristaps 994: }
1.1 kristaps 995:
1.115 kristaps 996: if (MDOC_HEAD == n->type) {
997: if (LIST_column != n->data.Bl->type)
998: return(0);
999:
1000: /*
1001: * For each column, print out the <COL> tag with our
1002: * suggested width. The last column gets min-width, as
1003: * in terminal mode it auto-sizes to the width of the
1004: * screen and we want to preserve that behaviour.
1005: */
1.1 kristaps 1006:
1.115 kristaps 1007: for (i = 0; i < n->data.Bl->ncols; i++) {
1008: a2width(n->data.Bl->cols[i], &su);
1009: bufinit(h);
1010: if (i < n->data.Bl->ncols - 1)
1011: bufcat_su(h, "width", &su);
1012: else
1013: bufcat_su(h, "min-width", &su);
1014: PAIR_STYLE_INIT(&tag[0], h);
1015: print_otag(h, TAG_COL, 1, tag);
1016: }
1.1 kristaps 1017:
1018: return(0);
1019: }
1020:
1.119 kristaps 1021: SCALE_VS_INIT(&su, 0);
1022: bufcat_su(h, "margin-top", &su);
1023: bufcat_su(h, "margin-bottom", &su);
1024: PAIR_STYLE_INIT(&tag[0], h);
1025:
1.115 kristaps 1026: assert(lists[n->data.Bl->type]);
1.119 kristaps 1027: PAIR_CLASS_INIT(&tag[1], lists[n->data.Bl->type]);
1028: i = 2;
1.1 kristaps 1029:
1.115 kristaps 1030: /* Set the block's left-hand margin. */
1.1 kristaps 1031:
1.115 kristaps 1032: if (n->data.Bl->offs) {
1033: a2offs(n->data.Bl->offs, &su);
1034: bufcat_su(h, "margin-left", &su);
1.119 kristaps 1035: PAIR_STYLE_INIT(&tag[2], h);
1036: i = 3;
1.115 kristaps 1037: }
1.1 kristaps 1038:
1.115 kristaps 1039: switch (n->data.Bl->type) {
1040: case(LIST_bullet):
1.1 kristaps 1041: /* FALLTHROUGH */
1.115 kristaps 1042: case(LIST_dash):
1.1 kristaps 1043: /* FALLTHROUGH */
1.115 kristaps 1044: case(LIST_hyphen):
1.1 kristaps 1045: /* FALLTHROUGH */
1.115 kristaps 1046: case(LIST_item):
1047: print_otag(h, TAG_UL, i, tag);
1.1 kristaps 1048: break;
1.115 kristaps 1049: case(LIST_enum):
1050: print_otag(h, TAG_OL, i, tag);
1.23 kristaps 1051: break;
1.115 kristaps 1052: case(LIST_diag):
1053: /* FALLTHROUGH */
1054: case(LIST_hang):
1.46 kristaps 1055: /* FALLTHROUGH */
1.115 kristaps 1056: case(LIST_inset):
1.33 kristaps 1057: /* FALLTHROUGH */
1.115 kristaps 1058: case(LIST_ohang):
1.1 kristaps 1059: /* FALLTHROUGH */
1.115 kristaps 1060: case(LIST_tag):
1061: print_otag(h, TAG_DL, i, tag);
1062: break;
1063: case(LIST_column):
1064: print_otag(h, TAG_TABLE, i, tag);
1.1 kristaps 1065: break;
1066: default:
1.115 kristaps 1067: abort();
1068: /* NOTREACHED */
1.1 kristaps 1069: }
1070:
1071: return(1);
1072: }
1073:
1074: /* ARGSUSED */
1075: static int
1076: mdoc_ex_pre(MDOC_ARGS)
1077: {
1078: const struct mdoc_node *nn;
1079: struct tag *t;
1080: struct htmlpair tag;
1081:
1.23 kristaps 1082: PAIR_CLASS_INIT(&tag, "utility");
1083:
1.1 kristaps 1084: print_text(h, "The");
1085: for (nn = n->child; nn; nn = nn->next) {
1086: t = print_otag(h, TAG_SPAN, 1, &tag);
1087: print_text(h, nn->string);
1088: print_tagq(h, t);
1089:
1090: h->flags |= HTML_NOSPACE;
1091:
1092: if (nn->next && NULL == nn->next->next)
1093: print_text(h, ", and");
1094: else if (nn->next)
1095: print_text(h, ",");
1096: else
1097: h->flags &= ~HTML_NOSPACE;
1098: }
1099:
1.65 kristaps 1100: if (n->child && n->child->next)
1.1 kristaps 1101: print_text(h, "utilities exit");
1102: else
1103: print_text(h, "utility exits");
1104:
1105: print_text(h, "0 on success, and >0 if an error occurs.");
1106: return(0);
1107: }
1108:
1109:
1110: /* ARGSUSED */
1111: static int
1112: mdoc_em_pre(MDOC_ARGS)
1113: {
1114: struct htmlpair tag;
1115:
1.23 kristaps 1116: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1117: print_otag(h, TAG_SPAN, 1, &tag);
1118: return(1);
1119: }
1120:
1121:
1122: /* ARGSUSED */
1123: static int
1124: mdoc_d1_pre(MDOC_ARGS)
1125: {
1.23 kristaps 1126: struct htmlpair tag[2];
1127: struct roffsu su;
1.1 kristaps 1128:
1129: if (MDOC_BLOCK != n->type)
1130: return(1);
1131:
1.118 kristaps 1132: SCALE_VS_INIT(&su, 0);
1133: bufcat_su(h, "margin-top", &su);
1134: bufcat_su(h, "margin-bottom", &su);
1135: PAIR_STYLE_INIT(&tag[0], h);
1.120 kristaps 1136: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1137:
1138: /* BLOCKQUOTE needs a block body. */
1.118 kristaps 1139:
1140: if (MDOC_Dl == n->tok) {
1141: PAIR_CLASS_INIT(&tag[1], "lit");
1.120 kristaps 1142: print_otag(h, TAG_DIV, 1, tag);
1.118 kristaps 1143: } else
1.120 kristaps 1144: print_otag(h, TAG_DIV, 0, tag);
1.35 kristaps 1145:
1.1 kristaps 1146: return(1);
1147: }
1148:
1149:
1150: /* ARGSUSED */
1151: static int
1152: mdoc_sx_pre(MDOC_ARGS)
1153: {
1.18 kristaps 1154: struct htmlpair tag[2];
1.1 kristaps 1155: const struct mdoc_node *nn;
1.35 kristaps 1156: char buf[BUFSIZ];
1.1 kristaps 1157:
1.41 kristaps 1158: strlcpy(buf, "#", BUFSIZ);
1.1 kristaps 1159: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 1160: html_idcat(buf, nn->string, BUFSIZ);
1.1 kristaps 1161: if (nn->next)
1.42 kristaps 1162: html_idcat(buf, " ", BUFSIZ);
1.1 kristaps 1163: }
1164:
1.23 kristaps 1165: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 kristaps 1166: PAIR_HREF_INIT(&tag[1], buf);
1.1 kristaps 1167:
1.18 kristaps 1168: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1169: return(1);
1170: }
1171:
1172:
1173: /* ARGSUSED */
1174: static int
1175: mdoc_bd_pre(MDOC_ARGS)
1176: {
1177: struct htmlpair tag[2];
1.80 kristaps 1178: int comp;
1179: const struct mdoc_node *nn;
1.23 kristaps 1180: struct roffsu su;
1.1 kristaps 1181:
1.80 kristaps 1182: if (MDOC_HEAD == n->type)
1.1 kristaps 1183: return(0);
1184:
1.24 kristaps 1185: SCALE_VS_INIT(&su, 0);
1186:
1.90 kristaps 1187: assert(n->data.Bd);
1188: if (n->data.Bd->offs)
1189: a2offs(n->data.Bd->offs, &su);
1.80 kristaps 1190:
1.90 kristaps 1191: comp = n->data.Bd->comp;
1.1 kristaps 1192:
1.31 kristaps 1193: /* FIXME: -centered, etc. formatting. */
1.60 kristaps 1194: /* FIXME: does not respect -offset ??? */
1.31 kristaps 1195:
1.1 kristaps 1196: if (MDOC_BLOCK == n->type) {
1.24 kristaps 1197: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1198: for (nn = n; nn && ! comp; nn = nn->parent) {
1199: if (MDOC_BLOCK != nn->type)
1200: continue;
1201: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1202: comp = 1;
1203: if (nn->prev)
1204: break;
1205: }
1206: if (comp) {
1.64 kristaps 1207: PAIR_STYLE_INIT(&tag[0], h);
1208: print_otag(h, TAG_DIV, 1, tag);
1.23 kristaps 1209: return(1);
1.14 kristaps 1210: }
1.23 kristaps 1211: SCALE_VS_INIT(&su, 1);
1212: bufcat_su(h, "margin-top", &su);
1213: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 1214: print_otag(h, TAG_DIV, 1, tag);
1215: return(1);
1216: }
1217:
1.90 kristaps 1218: if (DISP_unfilled != n->data.Bd->type &&
1219: DISP_literal != n->data.Bd->type)
1.1 kristaps 1220: return(1);
1221:
1.23 kristaps 1222: PAIR_CLASS_INIT(&tag[0], "lit");
1223: bufcat_style(h, "white-space", "pre");
1224: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1225: print_otag(h, TAG_DIV, 2, tag);
1226:
1.14 kristaps 1227: for (nn = n->child; nn; nn = nn->next) {
1228: print_mdoc_node(m, nn, h);
1.108 kristaps 1229: /*
1230: * If the printed node flushes its own line, then we
1231: * needn't do it here as well. This is hacky, but the
1232: * notion of selective eoln whitespace is pretty dumb
1233: * anyway, so don't sweat it.
1234: */
1235: switch (nn->tok) {
1.111 kristaps 1236: case (MDOC_Sm):
1237: /* FALLTHROUGH */
1.108 kristaps 1238: case (MDOC_br):
1239: /* FALLTHROUGH */
1240: case (MDOC_sp):
1241: /* FALLTHROUGH */
1242: case (MDOC_Bl):
1.114 kristaps 1243: /* FALLTHROUGH */
1244: case (MDOC_D1):
1245: /* FALLTHROUGH */
1246: case (MDOC_Dl):
1.108 kristaps 1247: /* FALLTHROUGH */
1248: case (MDOC_Lp):
1249: /* FALLTHROUGH */
1250: case (MDOC_Pp):
1251: continue;
1252: default:
1253: break;
1254: }
1.101 schwarze 1255: if (nn->next && nn->next->line == nn->line)
1256: continue;
1257: print_text(h, "\n");
1258: h->flags |= HTML_NOSPACE;
1.1 kristaps 1259: }
1260:
1261: return(0);
1262: }
1263:
1264:
1265: /* ARGSUSED */
1266: static int
1267: mdoc_pa_pre(MDOC_ARGS)
1268: {
1269: struct htmlpair tag;
1270:
1.23 kristaps 1271: PAIR_CLASS_INIT(&tag, "file");
1.1 kristaps 1272: print_otag(h, TAG_SPAN, 1, &tag);
1273: return(1);
1274: }
1275:
1276:
1277: /* ARGSUSED */
1278: static int
1279: mdoc_ad_pre(MDOC_ARGS)
1280: {
1281: struct htmlpair tag;
1282:
1.23 kristaps 1283: PAIR_CLASS_INIT(&tag, "addr");
1.1 kristaps 1284: print_otag(h, TAG_SPAN, 1, &tag);
1285: return(1);
1286: }
1287:
1288:
1289: /* ARGSUSED */
1290: static int
1291: mdoc_an_pre(MDOC_ARGS)
1292: {
1293: struct htmlpair tag;
1294:
1.19 kristaps 1295: /* TODO: -split and -nosplit (see termp_an_pre()). */
1296:
1.23 kristaps 1297: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1298: print_otag(h, TAG_SPAN, 1, &tag);
1299: return(1);
1300: }
1301:
1302:
1303: /* ARGSUSED */
1304: static int
1305: mdoc_cd_pre(MDOC_ARGS)
1306: {
1307: struct htmlpair tag;
1308:
1.78 kristaps 1309: synopsis_pre(h, n);
1.23 kristaps 1310: PAIR_CLASS_INIT(&tag, "config");
1.1 kristaps 1311: print_otag(h, TAG_SPAN, 1, &tag);
1312: return(1);
1313: }
1314:
1315:
1316: /* ARGSUSED */
1317: static int
1318: mdoc_dv_pre(MDOC_ARGS)
1319: {
1320: struct htmlpair tag;
1321:
1.23 kristaps 1322: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1323: print_otag(h, TAG_SPAN, 1, &tag);
1324: return(1);
1325: }
1326:
1327:
1328: /* ARGSUSED */
1329: static int
1330: mdoc_ev_pre(MDOC_ARGS)
1331: {
1332: struct htmlpair tag;
1333:
1.23 kristaps 1334: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1335: print_otag(h, TAG_SPAN, 1, &tag);
1336: return(1);
1337: }
1338:
1339:
1340: /* ARGSUSED */
1341: static int
1342: mdoc_er_pre(MDOC_ARGS)
1343: {
1344: struct htmlpair tag;
1345:
1.23 kristaps 1346: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1347: print_otag(h, TAG_SPAN, 1, &tag);
1348: return(1);
1349: }
1350:
1351:
1352: /* ARGSUSED */
1353: static int
1354: mdoc_fa_pre(MDOC_ARGS)
1355: {
1356: const struct mdoc_node *nn;
1357: struct htmlpair tag;
1358: struct tag *t;
1359:
1.23 kristaps 1360: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1361: if (n->parent->tok != MDOC_Fo) {
1362: print_otag(h, TAG_SPAN, 1, &tag);
1363: return(1);
1364: }
1365:
1366: for (nn = n->child; nn; nn = nn->next) {
1367: t = print_otag(h, TAG_SPAN, 1, &tag);
1368: print_text(h, nn->string);
1369: print_tagq(h, t);
1370: if (nn->next)
1371: print_text(h, ",");
1372: }
1373:
1374: if (n->child && n->next && n->next->tok == MDOC_Fa)
1375: print_text(h, ",");
1376:
1377: return(0);
1378: }
1379:
1380:
1381: /* ARGSUSED */
1382: static int
1383: mdoc_fd_pre(MDOC_ARGS)
1384: {
1.23 kristaps 1385: struct htmlpair tag;
1.1 kristaps 1386:
1.78 kristaps 1387: synopsis_pre(h, n);
1388:
1.23 kristaps 1389: PAIR_CLASS_INIT(&tag, "macro");
1.1 kristaps 1390: print_otag(h, TAG_SPAN, 1, &tag);
1391: return(1);
1392: }
1393:
1394:
1395: /* ARGSUSED */
1396: static int
1397: mdoc_vt_pre(MDOC_ARGS)
1398: {
1.23 kristaps 1399: struct htmlpair tag;
1.1 kristaps 1400:
1.78 kristaps 1401: if (MDOC_BLOCK == n->type) {
1402: synopsis_pre(h, n);
1.54 kristaps 1403: return(1);
1.78 kristaps 1404: } else if (MDOC_ELEM == n->type) {
1405: synopsis_pre(h, n);
1.54 kristaps 1406: } else if (MDOC_HEAD == n->type)
1407: return(0);
1.1 kristaps 1408:
1.23 kristaps 1409: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1410: print_otag(h, TAG_SPAN, 1, &tag);
1411: return(1);
1412: }
1413:
1.2 kristaps 1414:
1.1 kristaps 1415: /* ARGSUSED */
1416: static int
1417: mdoc_ft_pre(MDOC_ARGS)
1418: {
1.23 kristaps 1419: struct htmlpair tag;
1.1 kristaps 1420:
1.78 kristaps 1421: synopsis_pre(h, n);
1.23 kristaps 1422: PAIR_CLASS_INIT(&tag, "ftype");
1.1 kristaps 1423: print_otag(h, TAG_SPAN, 1, &tag);
1424: return(1);
1425: }
1426:
1427:
1428: /* ARGSUSED */
1429: static int
1430: mdoc_fn_pre(MDOC_ARGS)
1431: {
1432: struct tag *t;
1.15 kristaps 1433: struct htmlpair tag[2];
1.1 kristaps 1434: const struct mdoc_node *nn;
1.7 kristaps 1435: char nbuf[BUFSIZ];
1436: const char *sp, *ep;
1.15 kristaps 1437: int sz, i;
1.1 kristaps 1438:
1.78 kristaps 1439: synopsis_pre(h, n);
1.1 kristaps 1440:
1.7 kristaps 1441: /* Split apart into type and name. */
1442: assert(n->child->string);
1443: sp = n->child->string;
1.19 kristaps 1444:
1.26 kristaps 1445: ep = strchr(sp, ' ');
1446: if (NULL != ep) {
1.23 kristaps 1447: PAIR_CLASS_INIT(&tag[0], "ftype");
1.19 kristaps 1448: t = print_otag(h, TAG_SPAN, 1, tag);
1449:
1450: while (ep) {
1451: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1452: (void)memcpy(nbuf, sp, (size_t)sz);
1453: nbuf[sz] = '\0';
1454: print_text(h, nbuf);
1455: sp = ++ep;
1456: ep = strchr(sp, ' ');
1457: }
1458: print_tagq(h, t);
1.7 kristaps 1459: }
1.1 kristaps 1460:
1.23 kristaps 1461: PAIR_CLASS_INIT(&tag[0], "fname");
1.57 kristaps 1462:
1463: /*
1464: * FIXME: only refer to IDs that we know exist.
1465: */
1466:
1467: #if 0
1.87 kristaps 1468: if (MDOC_SYNPRETTY & n->flags) {
1.57 kristaps 1469: nbuf[0] = '\0';
1470: html_idcat(nbuf, sp, BUFSIZ);
1471: PAIR_ID_INIT(&tag[1], nbuf);
1472: } else {
1473: strlcpy(nbuf, "#", BUFSIZ);
1474: html_idcat(nbuf, sp, BUFSIZ);
1475: PAIR_HREF_INIT(&tag[1], nbuf);
1476: }
1477: #endif
1478:
1.15 kristaps 1479: t = print_otag(h, TAG_SPAN, 1, tag);
1.7 kristaps 1480:
1481: if (sp) {
1.57 kristaps 1482: strlcpy(nbuf, sp, BUFSIZ);
1.7 kristaps 1483: print_text(h, nbuf);
1484: }
1485:
1.1 kristaps 1486: print_tagq(h, t);
1487:
1488: h->flags |= HTML_NOSPACE;
1489: print_text(h, "(");
1490:
1.23 kristaps 1491: bufinit(h);
1492: PAIR_CLASS_INIT(&tag[0], "farg");
1493: bufcat_style(h, "white-space", "nowrap");
1494: PAIR_STYLE_INIT(&tag[1], h);
1495:
1.1 kristaps 1496: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1497: i = 1;
1.87 kristaps 1498: if (MDOC_SYNPRETTY & n->flags)
1.23 kristaps 1499: i = 2;
1.15 kristaps 1500: t = print_otag(h, TAG_SPAN, i, tag);
1.1 kristaps 1501: print_text(h, nn->string);
1502: print_tagq(h, t);
1503: if (nn->next)
1504: print_text(h, ",");
1505: }
1506:
1507: print_text(h, ")");
1.87 kristaps 1508: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1509: print_text(h, ";");
1.99 kristaps 1510:
1511: return(0);
1512: }
1513:
1514:
1515: /* ARGSUSED */
1516: static int
1517: mdoc_sm_pre(MDOC_ARGS)
1518: {
1519:
1520: assert(n->child && MDOC_TEXT == n->child->type);
1521: if (0 == strcmp("on", n->child->string)) {
1.111 kristaps 1522: /*
1523: * FIXME: no p->col to check. Thus, if we have
1524: * .Bd -literal
1525: * .Sm off
1526: * 1 2
1527: * .Sm on
1528: * 3
1529: * .Ed
1530: * the "3" is preceded by a space.
1531: */
1.99 kristaps 1532: h->flags &= ~HTML_NOSPACE;
1533: h->flags &= ~HTML_NONOSPACE;
1534: } else
1535: h->flags |= HTML_NONOSPACE;
1.1 kristaps 1536:
1537: return(0);
1538: }
1539:
1.120 kristaps 1540: /* ARGSUSED */
1541: static int
1542: mdoc_pp_pre(MDOC_ARGS)
1543: {
1544:
1545: print_otag(h, TAG_P, 0, NULL);
1546: return(0);
1547:
1548: }
1.1 kristaps 1549:
1550: /* ARGSUSED */
1551: static int
1552: mdoc_sp_pre(MDOC_ARGS)
1553: {
1.120 kristaps 1554: struct roffsu su;
1.23 kristaps 1555: struct htmlpair tag;
1.1 kristaps 1556:
1.120 kristaps 1557: SCALE_VS_INIT(&su, 1);
1558:
1559: if (MDOC_sp == n->tok) {
1560: if (n->child)
1561: a2roffsu(n->child->string, &su, SCALE_VS);
1562: } else
1563: su.scale = 0;
1.1 kristaps 1564:
1.23 kristaps 1565: bufcat_su(h, "height", &su);
1566: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1567: print_otag(h, TAG_DIV, 1, &tag);
1.120 kristaps 1568:
1.42 kristaps 1569: /* So the div isn't empty: */
1570: print_text(h, "\\~");
1571:
1572: return(0);
1.1 kristaps 1573:
1574: }
1.2 kristaps 1575:
1576: /* ARGSUSED */
1577: static int
1578: mdoc_lk_pre(MDOC_ARGS)
1579: {
1580: const struct mdoc_node *nn;
1581: struct htmlpair tag[2];
1582:
1583: nn = n->child;
1584:
1.23 kristaps 1585: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57 kristaps 1586: PAIR_HREF_INIT(&tag[1], nn->string);
1.2 kristaps 1587: print_otag(h, TAG_A, 2, tag);
1588:
1.113 kristaps 1589: if (NULL == nn || NULL == nn->next)
1.38 kristaps 1590: return(1);
1591:
1.2 kristaps 1592: for (nn = nn->next; nn; nn = nn->next)
1593: print_text(h, nn->string);
1594:
1595: return(0);
1596: }
1597:
1598:
1599: /* ARGSUSED */
1600: static int
1601: mdoc_mt_pre(MDOC_ARGS)
1602: {
1603: struct htmlpair tag[2];
1604: struct tag *t;
1605: const struct mdoc_node *nn;
1606:
1.23 kristaps 1607: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1608:
1609: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1610: bufinit(h);
1611: bufcat(h, "mailto:");
1612: bufcat(h, nn->string);
1.57 kristaps 1613: PAIR_HREF_INIT(&tag[1], h->buf);
1.2 kristaps 1614: t = print_otag(h, TAG_A, 2, tag);
1615: print_text(h, nn->string);
1616: print_tagq(h, t);
1617: }
1618:
1619: return(0);
1620: }
1.4 kristaps 1621:
1622:
1623: /* ARGSUSED */
1624: static int
1625: mdoc_fo_pre(MDOC_ARGS)
1626: {
1.77 kristaps 1627: struct htmlpair tag;
1628: struct tag *t;
1.4 kristaps 1629:
1630: if (MDOC_BODY == n->type) {
1631: h->flags |= HTML_NOSPACE;
1632: print_text(h, "(");
1633: h->flags |= HTML_NOSPACE;
1634: return(1);
1.77 kristaps 1635: } else if (MDOC_BLOCK == n->type) {
1.78 kristaps 1636: synopsis_pre(h, n);
1.4 kristaps 1637: return(1);
1.57 kristaps 1638: }
1.4 kristaps 1639:
1.77 kristaps 1640: /* XXX: we drop non-initial arguments as per groff. */
1641:
1642: assert(n->child);
1643: assert(n->child->string);
1644:
1.23 kristaps 1645: PAIR_CLASS_INIT(&tag, "fname");
1.77 kristaps 1646: t = print_otag(h, TAG_SPAN, 1, &tag);
1647: print_text(h, n->child->string);
1648: print_tagq(h, t);
1649: return(0);
1.4 kristaps 1650: }
1651:
1652:
1653: /* ARGSUSED */
1654: static void
1655: mdoc_fo_post(MDOC_ARGS)
1656: {
1.78 kristaps 1657:
1.4 kristaps 1658: if (MDOC_BODY != n->type)
1659: return;
1660: print_text(h, ")");
1661: print_text(h, ";");
1662: }
1663:
1664:
1665: /* ARGSUSED */
1666: static int
1667: mdoc_in_pre(MDOC_ARGS)
1668: {
1669: const struct mdoc_node *nn;
1.23 kristaps 1670: struct tag *t;
1.17 kristaps 1671: struct htmlpair tag[2];
1672: int i;
1.34 kristaps 1673:
1.78 kristaps 1674: synopsis_pre(h, n);
1675:
1.23 kristaps 1676: PAIR_CLASS_INIT(&tag[0], "includes");
1.17 kristaps 1677: print_otag(h, TAG_SPAN, 1, tag);
1.4 kristaps 1678:
1.87 kristaps 1679: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.4 kristaps 1680: print_text(h, "#include");
1681:
1682: print_text(h, "<");
1683: h->flags |= HTML_NOSPACE;
1684:
1.17 kristaps 1685: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1686: PAIR_CLASS_INIT(&tag[0], "link-includes");
1687: i = 1;
1.41 kristaps 1688: bufinit(h);
1.17 kristaps 1689: if (h->base_includes) {
1690: buffmt_includes(h, nn->string);
1.57 kristaps 1691: PAIR_HREF_INIT(&tag[i], h->buf);
1692: i++;
1.17 kristaps 1693: }
1694: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1695: print_mdoc_node(m, nn, h);
1.17 kristaps 1696: print_tagq(h, t);
1697: }
1.4 kristaps 1698:
1699: h->flags |= HTML_NOSPACE;
1700: print_text(h, ">");
1701:
1702: return(0);
1703: }
1704:
1705:
1706: /* ARGSUSED */
1707: static int
1708: mdoc_ic_pre(MDOC_ARGS)
1709: {
1710: struct htmlpair tag;
1711:
1.23 kristaps 1712: PAIR_CLASS_INIT(&tag, "cmd");
1.4 kristaps 1713: print_otag(h, TAG_SPAN, 1, &tag);
1714: return(1);
1715: }
1716:
1717:
1718: /* ARGSUSED */
1719: static int
1720: mdoc_rv_pre(MDOC_ARGS)
1721: {
1722: const struct mdoc_node *nn;
1723: struct htmlpair tag;
1724: struct tag *t;
1725:
1726: print_otag(h, TAG_DIV, 0, NULL);
1727: print_text(h, "The");
1728:
1729: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1730: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1731: t = print_otag(h, TAG_SPAN, 1, &tag);
1732: print_text(h, nn->string);
1733: print_tagq(h, t);
1734:
1735: h->flags |= HTML_NOSPACE;
1736: if (nn->next && NULL == nn->next->next)
1737: print_text(h, "(), and");
1738: else if (nn->next)
1739: print_text(h, "(),");
1740: else
1741: print_text(h, "()");
1742: }
1743:
1.65 kristaps 1744: if (n->child && n->child->next)
1.4 kristaps 1745: print_text(h, "functions return");
1746: else
1747: print_text(h, "function returns");
1748:
1749: print_text(h, "the value 0 if successful; otherwise the value "
1750: "-1 is returned and the global variable");
1751:
1.23 kristaps 1752: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1753: t = print_otag(h, TAG_SPAN, 1, &tag);
1754: print_text(h, "errno");
1755: print_tagq(h, t);
1756: print_text(h, "is set to indicate the error.");
1757: return(0);
1758: }
1759:
1760:
1761: /* ARGSUSED */
1762: static int
1763: mdoc_va_pre(MDOC_ARGS)
1764: {
1765: struct htmlpair tag;
1766:
1.23 kristaps 1767: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1768: print_otag(h, TAG_SPAN, 1, &tag);
1769: return(1);
1770: }
1771:
1772:
1773: /* ARGSUSED */
1774: static int
1.5 kristaps 1775: mdoc_ap_pre(MDOC_ARGS)
1776: {
1777:
1778: h->flags |= HTML_NOSPACE;
1779: print_text(h, "\\(aq");
1780: h->flags |= HTML_NOSPACE;
1781: return(1);
1782: }
1783:
1784:
1785: /* ARGSUSED */
1786: static int
1787: mdoc_bf_pre(MDOC_ARGS)
1788: {
1.23 kristaps 1789: struct htmlpair tag[2];
1790: struct roffsu su;
1.5 kristaps 1791:
1792: if (MDOC_HEAD == n->type)
1793: return(0);
1.92 kristaps 1794: else if (MDOC_BODY != n->type)
1.5 kristaps 1795: return(1);
1796:
1.92 kristaps 1797: assert(n->data.Bf);
1.5 kristaps 1798:
1.92 kristaps 1799: if (FONT_Em == n->data.Bf->font)
1800: PAIR_CLASS_INIT(&tag[0], "emph");
1801: else if (FONT_Sy == n->data.Bf->font)
1802: PAIR_CLASS_INIT(&tag[0], "symb");
1803: else if (FONT_Li == n->data.Bf->font)
1804: PAIR_CLASS_INIT(&tag[0], "lit");
1805: else
1806: PAIR_CLASS_INIT(&tag[0], "none");
1.5 kristaps 1807:
1.92 kristaps 1808: /*
1809: * We want this to be inline-formatted, but needs to be div to
1810: * accept block children.
1811: */
1.23 kristaps 1812: bufcat_style(h, "display", "inline");
1813: SCALE_HS_INIT(&su, 1);
1.92 kristaps 1814: /* Needs a left-margin for spacing. */
1815: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1816: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 1817: print_otag(h, TAG_DIV, 2, tag);
1818: return(1);
1819: }
1820:
1821:
1822: /* ARGSUSED */
1823: static int
1824: mdoc_ms_pre(MDOC_ARGS)
1825: {
1826: struct htmlpair tag;
1827:
1.23 kristaps 1828: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 1829: print_otag(h, TAG_SPAN, 1, &tag);
1830: return(1);
1831: }
1832:
1833:
1834: /* ARGSUSED */
1835: static int
1.110 schwarze 1836: mdoc_igndelim_pre(MDOC_ARGS)
1.5 kristaps 1837: {
1838:
1839: h->flags |= HTML_IGNDELIM;
1840: return(1);
1841: }
1842:
1843:
1844: /* ARGSUSED */
1845: static void
1846: mdoc_pf_post(MDOC_ARGS)
1847: {
1848:
1849: h->flags |= HTML_NOSPACE;
1850: }
1851:
1852:
1853: /* ARGSUSED */
1854: static int
1855: mdoc_rs_pre(MDOC_ARGS)
1856: {
1.23 kristaps 1857: struct htmlpair tag;
1.5 kristaps 1858:
1859: if (MDOC_BLOCK != n->type)
1860: return(1);
1861:
1.120 kristaps 1862: if (n->prev && SEC_SEE_ALSO == n->sec)
1863: print_otag(h, TAG_P, 0, NULL);
1.5 kristaps 1864:
1.23 kristaps 1865: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 1866: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 1867: return(1);
1868: }
1.6 kristaps 1869:
1870:
1871:
1872: /* ARGSUSED */
1873: static int
1874: mdoc_li_pre(MDOC_ARGS)
1875: {
1876: struct htmlpair tag;
1877:
1.23 kristaps 1878: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 1879: print_otag(h, TAG_SPAN, 1, &tag);
1880: return(1);
1881: }
1882:
1883:
1884: /* ARGSUSED */
1885: static int
1886: mdoc_sy_pre(MDOC_ARGS)
1887: {
1888: struct htmlpair tag;
1889:
1.23 kristaps 1890: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 1891: print_otag(h, TAG_SPAN, 1, &tag);
1892: return(1);
1893: }
1894:
1895:
1896: /* ARGSUSED */
1897: static int
1898: mdoc_bt_pre(MDOC_ARGS)
1899: {
1900:
1901: print_text(h, "is currently in beta test.");
1902: return(0);
1903: }
1904:
1905:
1906: /* ARGSUSED */
1907: static int
1908: mdoc_ud_pre(MDOC_ARGS)
1909: {
1910:
1911: print_text(h, "currently under development.");
1912: return(0);
1913: }
1914:
1915:
1916: /* ARGSUSED */
1917: static int
1918: mdoc_lb_pre(MDOC_ARGS)
1919: {
1920: struct htmlpair tag;
1921:
1.62 kristaps 1922: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.6 kristaps 1923: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 1924: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 1925: print_otag(h, TAG_SPAN, 1, &tag);
1926: return(1);
1927: }
1.10 kristaps 1928:
1929:
1930: /* ARGSUSED */
1931: static int
1932: mdoc__x_pre(MDOC_ARGS)
1933: {
1.38 kristaps 1934: struct htmlpair tag[2];
1.37 kristaps 1935:
1.10 kristaps 1936: switch (n->tok) {
1937: case(MDOC__A):
1.38 kristaps 1938: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.103 kristaps 1939: if (n->prev && MDOC__A == n->prev->tok)
1940: if (NULL == n->next || MDOC__A != n->next->tok)
1941: print_text(h, "and");
1.10 kristaps 1942: break;
1943: case(MDOC__B):
1.38 kristaps 1944: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10 kristaps 1945: break;
1946: case(MDOC__C):
1.38 kristaps 1947: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10 kristaps 1948: break;
1949: case(MDOC__D):
1.38 kristaps 1950: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10 kristaps 1951: break;
1952: case(MDOC__I):
1.38 kristaps 1953: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10 kristaps 1954: break;
1955: case(MDOC__J):
1.38 kristaps 1956: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10 kristaps 1957: break;
1958: case(MDOC__N):
1.38 kristaps 1959: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10 kristaps 1960: break;
1961: case(MDOC__O):
1.38 kristaps 1962: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10 kristaps 1963: break;
1964: case(MDOC__P):
1.38 kristaps 1965: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10 kristaps 1966: break;
1967: case(MDOC__Q):
1.38 kristaps 1968: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10 kristaps 1969: break;
1970: case(MDOC__R):
1.38 kristaps 1971: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10 kristaps 1972: break;
1973: case(MDOC__T):
1.38 kristaps 1974: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10 kristaps 1975: break;
1.38 kristaps 1976: case(MDOC__U):
1977: PAIR_CLASS_INIT(&tag[0], "link-ref");
1978: break;
1.10 kristaps 1979: case(MDOC__V):
1.38 kristaps 1980: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10 kristaps 1981: break;
1982: default:
1983: abort();
1984: /* NOTREACHED */
1985: }
1986:
1.38 kristaps 1987: if (MDOC__U != n->tok) {
1988: print_otag(h, TAG_SPAN, 1, tag);
1989: return(1);
1990: }
1991:
1992: PAIR_HREF_INIT(&tag[1], n->child->string);
1993: print_otag(h, TAG_A, 2, tag);
1.103 kristaps 1994:
1.10 kristaps 1995: return(1);
1996: }
1997:
1998:
1999: /* ARGSUSED */
2000: static void
2001: mdoc__x_post(MDOC_ARGS)
2002: {
1.103 kristaps 2003:
2004: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2005: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2006: if (NULL == n->prev || MDOC__A != n->prev->tok)
2007: return;
1.10 kristaps 2008:
1.61 kristaps 2009: /* TODO: %U */
2010:
1.106 kristaps 2011: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2012: return;
2013:
1.10 kristaps 2014: print_text(h, n->next ? "," : ".");
1.94 kristaps 2015: }
2016:
2017:
2018: /* ARGSUSED */
2019: static int
2020: mdoc_bk_pre(MDOC_ARGS)
2021: {
2022:
2023: switch (n->type) {
2024: case (MDOC_BLOCK):
2025: break;
2026: case (MDOC_HEAD):
2027: return(0);
2028: case (MDOC_BODY):
2029: h->flags |= HTML_PREKEEP;
2030: break;
2031: default:
2032: abort();
2033: /* NOTREACHED */
2034: }
2035:
2036: return(1);
2037: }
2038:
2039:
2040: /* ARGSUSED */
2041: static void
2042: mdoc_bk_post(MDOC_ARGS)
2043: {
2044:
2045: if (MDOC_BODY == n->type)
2046: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.10 kristaps 2047: }
1.107 kristaps 2048:
2049:
2050: /* ARGSUSED */
2051: static int
2052: mdoc_quote_pre(MDOC_ARGS)
2053: {
2054: struct htmlpair tag;
2055:
2056: if (MDOC_BODY != n->type)
2057: return(1);
2058:
2059: switch (n->tok) {
2060: case (MDOC_Ao):
2061: /* FALLTHROUGH */
2062: case (MDOC_Aq):
2063: print_text(h, "\\(la");
2064: break;
2065: case (MDOC_Bro):
2066: /* FALLTHROUGH */
2067: case (MDOC_Brq):
2068: print_text(h, "\\(lC");
2069: break;
2070: case (MDOC_Bo):
2071: /* FALLTHROUGH */
2072: case (MDOC_Bq):
2073: print_text(h, "\\(lB");
2074: break;
2075: case (MDOC_Oo):
2076: /* FALLTHROUGH */
2077: case (MDOC_Op):
2078: print_text(h, "\\(lB");
1.109 kristaps 2079: h->flags |= HTML_NOSPACE;
1.107 kristaps 2080: PAIR_CLASS_INIT(&tag, "opt");
2081: print_otag(h, TAG_SPAN, 1, &tag);
2082: break;
2083: case (MDOC_Do):
2084: /* FALLTHROUGH */
2085: case (MDOC_Dq):
2086: /* FALLTHROUGH */
2087: case (MDOC_Qo):
2088: /* FALLTHROUGH */
2089: case (MDOC_Qq):
2090: print_text(h, "\\(lq");
2091: break;
2092: case (MDOC_Po):
2093: /* FALLTHROUGH */
2094: case (MDOC_Pq):
2095: print_text(h, "(");
2096: break;
2097: case (MDOC_Ql):
2098: /* FALLTHROUGH */
2099: case (MDOC_So):
2100: /* FALLTHROUGH */
2101: case (MDOC_Sq):
2102: print_text(h, "\\(oq");
2103: break;
2104: default:
2105: abort();
2106: /* NOTREACHED */
2107: }
2108:
2109: h->flags |= HTML_NOSPACE;
2110: return(1);
2111: }
2112:
2113:
2114: /* ARGSUSED */
2115: static void
2116: mdoc_quote_post(MDOC_ARGS)
2117: {
2118:
2119: if (MDOC_BODY != n->type)
2120: return;
2121:
2122: h->flags |= HTML_NOSPACE;
2123:
2124: switch (n->tok) {
2125: case (MDOC_Ao):
2126: /* FALLTHROUGH */
2127: case (MDOC_Aq):
2128: print_text(h, "\\(ra");
2129: break;
2130: case (MDOC_Bro):
2131: /* FALLTHROUGH */
2132: case (MDOC_Brq):
2133: print_text(h, "\\(rC");
2134: break;
2135: case (MDOC_Oo):
2136: /* FALLTHROUGH */
2137: case (MDOC_Op):
2138: /* FALLTHROUGH */
2139: case (MDOC_Bo):
2140: /* FALLTHROUGH */
2141: case (MDOC_Bq):
2142: print_text(h, "\\(rB");
2143: break;
2144: case (MDOC_Qo):
2145: /* FALLTHROUGH */
2146: case (MDOC_Qq):
2147: /* FALLTHROUGH */
2148: case (MDOC_Do):
2149: /* FALLTHROUGH */
2150: case (MDOC_Dq):
2151: print_text(h, "\\(rq");
2152: break;
2153: case (MDOC_Po):
2154: /* FALLTHROUGH */
2155: case (MDOC_Pq):
2156: print_text(h, ")");
2157: break;
2158: case (MDOC_Ql):
2159: /* FALLTHROUGH */
2160: case (MDOC_So):
2161: /* FALLTHROUGH */
2162: case (MDOC_Sq):
2163: print_text(h, "\\(aq");
2164: break;
2165: default:
2166: abort();
2167: /* NOTREACHED */
2168: }
2169: }
2170:
2171:
CVSweb