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