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