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