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