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