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