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