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