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