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