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