Annotation of mandoc/mdoc_html.c, Revision 1.249
1.249 ! schwarze 1: /* $Id: mdoc_html.c,v 1.248 2017/01/17 01:47:51 schwarze Exp $ */
1.1 kristaps 2: /*
1.208 schwarze 3: * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.241 schwarze 4: * Copyright (c) 2014, 2015, 2016, 2017 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:
57: static void mdoc_root_post(MDOC_ARGS);
58: static int mdoc_root_pre(MDOC_ARGS);
59:
1.10 kristaps 60: static void mdoc__x_post(MDOC_ARGS);
61: static int mdoc__x_pre(MDOC_ARGS);
1.1 kristaps 62: static int mdoc_ad_pre(MDOC_ARGS);
63: static int mdoc_an_pre(MDOC_ARGS);
1.5 kristaps 64: static int mdoc_ap_pre(MDOC_ARGS);
1.1 kristaps 65: static int mdoc_ar_pre(MDOC_ARGS);
66: static int mdoc_bd_pre(MDOC_ARGS);
1.5 kristaps 67: static int mdoc_bf_pre(MDOC_ARGS);
1.94 kristaps 68: static void mdoc_bk_post(MDOC_ARGS);
69: static int mdoc_bk_pre(MDOC_ARGS);
1.1 kristaps 70: static int mdoc_bl_pre(MDOC_ARGS);
71: static int mdoc_cd_pre(MDOC_ARGS);
72: static int mdoc_d1_pre(MDOC_ARGS);
73: static int mdoc_dv_pre(MDOC_ARGS);
74: static int mdoc_fa_pre(MDOC_ARGS);
75: static int mdoc_fd_pre(MDOC_ARGS);
76: static int mdoc_fl_pre(MDOC_ARGS);
77: static int mdoc_fn_pre(MDOC_ARGS);
78: static int mdoc_ft_pre(MDOC_ARGS);
79: static int mdoc_em_pre(MDOC_ARGS);
1.221 schwarze 80: static void mdoc_eo_post(MDOC_ARGS);
81: static int mdoc_eo_pre(MDOC_ARGS);
1.1 kristaps 82: static int mdoc_er_pre(MDOC_ARGS);
83: static int mdoc_ev_pre(MDOC_ARGS);
84: static int mdoc_ex_pre(MDOC_ARGS);
1.4 kristaps 85: static void mdoc_fo_post(MDOC_ARGS);
86: static int mdoc_fo_pre(MDOC_ARGS);
87: static int mdoc_ic_pre(MDOC_ARGS);
1.110 schwarze 88: static int mdoc_igndelim_pre(MDOC_ARGS);
1.4 kristaps 89: static int mdoc_in_pre(MDOC_ARGS);
1.1 kristaps 90: static int mdoc_it_pre(MDOC_ARGS);
1.6 kristaps 91: static int mdoc_lb_pre(MDOC_ARGS);
92: static int mdoc_li_pre(MDOC_ARGS);
1.2 kristaps 93: static int mdoc_lk_pre(MDOC_ARGS);
94: static int mdoc_mt_pre(MDOC_ARGS);
1.5 kristaps 95: static int mdoc_ms_pre(MDOC_ARGS);
1.1 kristaps 96: static int mdoc_nd_pre(MDOC_ARGS);
97: static int mdoc_nm_pre(MDOC_ARGS);
1.210 schwarze 98: static int mdoc_no_pre(MDOC_ARGS);
1.1 kristaps 99: static int mdoc_ns_pre(MDOC_ARGS);
100: static int mdoc_pa_pre(MDOC_ARGS);
1.5 kristaps 101: static void mdoc_pf_post(MDOC_ARGS);
1.120 kristaps 102: static int mdoc_pp_pre(MDOC_ARGS);
1.107 kristaps 103: static void mdoc_quote_post(MDOC_ARGS);
104: static int mdoc_quote_pre(MDOC_ARGS);
1.5 kristaps 105: static int mdoc_rs_pre(MDOC_ARGS);
1.1 kristaps 106: static int mdoc_sh_pre(MDOC_ARGS);
1.191 schwarze 107: static int mdoc_skip_pre(MDOC_ARGS);
1.99 kristaps 108: static int mdoc_sm_pre(MDOC_ARGS);
1.1 kristaps 109: static int mdoc_sp_pre(MDOC_ARGS);
110: static int mdoc_ss_pre(MDOC_ARGS);
111: static int mdoc_sx_pre(MDOC_ARGS);
1.6 kristaps 112: static int mdoc_sy_pre(MDOC_ARGS);
1.4 kristaps 113: static int mdoc_va_pre(MDOC_ARGS);
1.1 kristaps 114: static int mdoc_vt_pre(MDOC_ARGS);
115: static int mdoc_xr_pre(MDOC_ARGS);
116: static int mdoc_xx_pre(MDOC_ARGS);
117:
118: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5 kristaps 119: {mdoc_ap_pre, NULL}, /* Ap */
1.1 kristaps 120: {NULL, NULL}, /* Dd */
121: {NULL, NULL}, /* Dt */
122: {NULL, NULL}, /* Os */
123: {mdoc_sh_pre, NULL }, /* Sh */
1.188 schwarze 124: {mdoc_ss_pre, NULL }, /* Ss */
125: {mdoc_pp_pre, NULL}, /* Pp */
1.1 kristaps 126: {mdoc_d1_pre, NULL}, /* D1 */
127: {mdoc_d1_pre, NULL}, /* Dl */
128: {mdoc_bd_pre, NULL}, /* Bd */
129: {NULL, NULL}, /* Ed */
1.115 kristaps 130: {mdoc_bl_pre, NULL}, /* Bl */
1.1 kristaps 131: {NULL, NULL}, /* El */
132: {mdoc_it_pre, NULL}, /* It */
1.188 schwarze 133: {mdoc_ad_pre, NULL}, /* Ad */
1.1 kristaps 134: {mdoc_an_pre, NULL}, /* An */
135: {mdoc_ar_pre, NULL}, /* Ar */
136: {mdoc_cd_pre, NULL}, /* Cd */
137: {mdoc_fl_pre, NULL}, /* Cm */
1.188 schwarze 138: {mdoc_dv_pre, NULL}, /* Dv */
139: {mdoc_er_pre, NULL}, /* Er */
140: {mdoc_ev_pre, NULL}, /* Ev */
1.1 kristaps 141: {mdoc_ex_pre, NULL}, /* Ex */
1.188 schwarze 142: {mdoc_fa_pre, NULL}, /* Fa */
143: {mdoc_fd_pre, NULL}, /* Fd */
1.1 kristaps 144: {mdoc_fl_pre, NULL}, /* Fl */
1.188 schwarze 145: {mdoc_fn_pre, NULL}, /* Fn */
146: {mdoc_ft_pre, NULL}, /* Ft */
147: {mdoc_ic_pre, NULL}, /* Ic */
148: {mdoc_in_pre, NULL}, /* In */
1.6 kristaps 149: {mdoc_li_pre, NULL}, /* Li */
1.188 schwarze 150: {mdoc_nd_pre, NULL}, /* Nd */
151: {mdoc_nm_pre, NULL}, /* Nm */
1.107 kristaps 152: {mdoc_quote_pre, mdoc_quote_post}, /* Op */
1.191 schwarze 153: {mdoc_ft_pre, NULL}, /* Ot */
1.1 kristaps 154: {mdoc_pa_pre, NULL}, /* Pa */
1.247 schwarze 155: {mdoc_ex_pre, NULL}, /* Rv */
1.188 schwarze 156: {NULL, NULL}, /* St */
1.4 kristaps 157: {mdoc_va_pre, NULL}, /* Va */
1.188 schwarze 158: {mdoc_vt_pre, NULL}, /* Vt */
1.1 kristaps 159: {mdoc_xr_pre, NULL}, /* Xr */
1.10 kristaps 160: {mdoc__x_pre, mdoc__x_post}, /* %A */
161: {mdoc__x_pre, mdoc__x_post}, /* %B */
162: {mdoc__x_pre, mdoc__x_post}, /* %D */
163: {mdoc__x_pre, mdoc__x_post}, /* %I */
164: {mdoc__x_pre, mdoc__x_post}, /* %J */
165: {mdoc__x_pre, mdoc__x_post}, /* %N */
166: {mdoc__x_pre, mdoc__x_post}, /* %O */
167: {mdoc__x_pre, mdoc__x_post}, /* %P */
168: {mdoc__x_pre, mdoc__x_post}, /* %R */
169: {mdoc__x_pre, mdoc__x_post}, /* %T */
170: {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1 kristaps 171: {NULL, NULL}, /* Ac */
1.107 kristaps 172: {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
173: {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
1.1 kristaps 174: {NULL, NULL}, /* At */
175: {NULL, NULL}, /* Bc */
1.188 schwarze 176: {mdoc_bf_pre, NULL}, /* Bf */
1.107 kristaps 177: {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
178: {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
1.1 kristaps 179: {mdoc_xx_pre, NULL}, /* Bsx */
1.246 schwarze 180: {mdoc_xx_pre, NULL}, /* Bx */
1.212 schwarze 181: {mdoc_skip_pre, NULL}, /* Db */
1.1 kristaps 182: {NULL, NULL}, /* Dc */
1.107 kristaps 183: {mdoc_quote_pre, mdoc_quote_post}, /* Do */
184: {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
1.55 kristaps 185: {NULL, NULL}, /* Ec */ /* FIXME: no space */
1.1 kristaps 186: {NULL, NULL}, /* Ef */
1.188 schwarze 187: {mdoc_em_pre, NULL}, /* Em */
1.221 schwarze 188: {mdoc_eo_pre, mdoc_eo_post}, /* Eo */
1.1 kristaps 189: {mdoc_xx_pre, NULL}, /* Fx */
1.98 kristaps 190: {mdoc_ms_pre, NULL}, /* Ms */
1.210 schwarze 191: {mdoc_no_pre, NULL}, /* No */
1.1 kristaps 192: {mdoc_ns_pre, NULL}, /* Ns */
193: {mdoc_xx_pre, NULL}, /* Nx */
194: {mdoc_xx_pre, NULL}, /* Ox */
195: {NULL, NULL}, /* Pc */
1.110 schwarze 196: {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
1.107 kristaps 197: {mdoc_quote_pre, mdoc_quote_post}, /* Po */
198: {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
1.1 kristaps 199: {NULL, NULL}, /* Qc */
1.107 kristaps 200: {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
201: {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
202: {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
1.1 kristaps 203: {NULL, NULL}, /* Re */
1.5 kristaps 204: {mdoc_rs_pre, NULL}, /* Rs */
1.1 kristaps 205: {NULL, NULL}, /* Sc */
1.107 kristaps 206: {mdoc_quote_pre, mdoc_quote_post}, /* So */
207: {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
1.188 schwarze 208: {mdoc_sm_pre, NULL}, /* Sm */
1.1 kristaps 209: {mdoc_sx_pre, NULL}, /* Sx */
1.6 kristaps 210: {mdoc_sy_pre, NULL}, /* Sy */
1.1 kristaps 211: {NULL, NULL}, /* Tn */
212: {mdoc_xx_pre, NULL}, /* Ux */
213: {NULL, NULL}, /* Xc */
214: {NULL, NULL}, /* Xo */
1.188 schwarze 215: {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
216: {NULL, NULL}, /* Fc */
1.107 kristaps 217: {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
1.1 kristaps 218: {NULL, NULL}, /* Oc */
1.94 kristaps 219: {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
1.1 kristaps 220: {NULL, NULL}, /* Ek */
1.247 schwarze 221: {NULL, NULL}, /* Bt */
1.1 kristaps 222: {NULL, NULL}, /* Hf */
1.191 schwarze 223: {mdoc_em_pre, NULL}, /* Fr */
1.247 schwarze 224: {NULL, NULL}, /* Ud */
1.6 kristaps 225: {mdoc_lb_pre, NULL}, /* Lb */
1.188 schwarze 226: {mdoc_pp_pre, NULL}, /* Lp */
227: {mdoc_lk_pre, NULL}, /* Lk */
228: {mdoc_mt_pre, NULL}, /* Mt */
229: {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
230: {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
231: {NULL, NULL}, /* Brc */
232: {mdoc__x_pre, mdoc__x_post}, /* %C */
1.191 schwarze 233: {mdoc_skip_pre, NULL}, /* Es */
234: {mdoc_quote_pre, mdoc_quote_post}, /* En */
1.188 schwarze 235: {mdoc_xx_pre, NULL}, /* Dx */
236: {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1 kristaps 237: {mdoc_sp_pre, NULL}, /* br */
1.188 schwarze 238: {mdoc_sp_pre, NULL}, /* sp */
239: {mdoc__x_pre, mdoc__x_post}, /* %U */
240: {NULL, NULL}, /* Ta */
1.191 schwarze 241: {mdoc_skip_pre, NULL}, /* ll */
1.1 kristaps 242: };
243:
1.115 kristaps 244: static const char * const lists[LIST_MAX] = {
245: NULL,
1.116 kristaps 246: "list-bul",
247: "list-col",
1.115 kristaps 248: "list-dash",
249: "list-diag",
250: "list-enum",
251: "list-hang",
1.116 kristaps 252: "list-hyph",
1.115 kristaps 253: "list-inset",
254: "list-item",
255: "list-ohang",
256: "list-tag"
257: };
1.1 kristaps 258:
1.188 schwarze 259:
1.23 kristaps 260: /*
1.78 kristaps 261: * See the same function in mdoc_term.c for documentation.
262: */
263: static void
1.228 schwarze 264: synopsis_pre(struct html *h, const struct roff_node *n)
1.78 kristaps 265: {
266:
1.244 schwarze 267: if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
1.78 kristaps 268: return;
269:
1.188 schwarze 270: if (n->prev->tok == n->tok &&
271: MDOC_Fo != n->tok &&
272: MDOC_Ft != n->tok &&
273: MDOC_Fn != n->tok) {
1.248 schwarze 274: print_otag(h, TAG_BR, "");
1.78 kristaps 275: return;
276: }
277:
278: switch (n->prev->tok) {
1.188 schwarze 279: case MDOC_Fd:
280: case MDOC_Fn:
281: case MDOC_Fo:
282: case MDOC_In:
283: case MDOC_Vt:
1.206 kristaps 284: print_paragraph(h);
1.78 kristaps 285: break;
1.188 schwarze 286: case MDOC_Ft:
1.78 kristaps 287: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1.206 kristaps 288: print_paragraph(h);
1.78 kristaps 289: break;
290: }
291: /* FALLTHROUGH */
292: default:
1.248 schwarze 293: print_otag(h, TAG_BR, "");
1.78 kristaps 294: break;
295: }
296: }
297:
1.232 schwarze 298: void
299: html_mdoc(void *arg, const struct roff_man *mdoc)
1.1 kristaps 300: {
1.232 schwarze 301: struct html *h;
1.179 kristaps 302: struct tag *t, *tt;
303:
1.232 schwarze 304: h = (struct html *)arg;
1.1 kristaps 305:
1.179 kristaps 306: if ( ! (HTML_FRAGMENT & h->oflags)) {
307: print_gen_decls(h);
1.248 schwarze 308: t = print_otag(h, TAG_HTML, "");
309: tt = print_otag(h, TAG_HEAD, "");
1.232 schwarze 310: print_mdoc_head(&mdoc->meta, mdoc->first->child, h);
1.179 kristaps 311: print_tagq(h, tt);
1.248 schwarze 312: print_otag(h, TAG_BODY, "");
313: print_otag(h, TAG_DIV, "c", "mandoc");
1.188 schwarze 314: } else
1.248 schwarze 315: t = print_otag(h, TAG_DIV, "c", "mandoc");
1.1 kristaps 316:
1.232 schwarze 317: mdoc_root_pre(&mdoc->meta, mdoc->first->child, h);
318: print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h);
319: mdoc_root_post(&mdoc->meta, mdoc->first->child, h);
1.1 kristaps 320: print_tagq(h, t);
1.232 schwarze 321: putchar('\n');
1.1 kristaps 322: }
323:
324: static void
325: print_mdoc_head(MDOC_ARGS)
326: {
1.249 ! schwarze 327: char *cp;
1.1 kristaps 328:
329: print_gen_head(h);
1.249 ! schwarze 330:
! 331: if (meta->arch != NULL && meta->msec != NULL)
! 332: mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title,
! 333: meta->msec, meta->arch);
! 334: else if (meta->msec != NULL)
! 335: mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec);
! 336: else if (meta->arch != NULL)
! 337: mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch);
! 338: else
! 339: cp = mandoc_strdup(meta->title);
1.1 kristaps 340:
1.248 schwarze 341: print_otag(h, TAG_TITLE, "");
1.249 ! schwarze 342: print_text(h, cp);
! 343: free(cp);
1.1 kristaps 344: }
345:
346: static void
347: print_mdoc_nodelist(MDOC_ARGS)
348: {
349:
1.220 schwarze 350: while (n != NULL) {
351: print_mdoc_node(meta, n, h);
352: n = n->next;
353: }
1.1 kristaps 354: }
355:
356: static void
357: print_mdoc_node(MDOC_ARGS)
358: {
359: int child;
360: struct tag *t;
1.243 schwarze 361:
362: if (n->flags & NODE_NOPRT)
363: return;
1.1 kristaps 364:
365: child = 1;
1.39 kristaps 366: t = h->tags.head;
1.244 schwarze 367: n->flags &= ~NODE_ENDED;
1.1 kristaps 368:
369: switch (n->type) {
1.227 schwarze 370: case ROFFT_TEXT:
1.144 kristaps 371: /* No tables in this mode... */
372: assert(NULL == h->tblt);
1.149 kristaps 373:
374: /*
375: * Make sure that if we're in a literal mode already
376: * (i.e., within a <PRE>) don't print the newline.
377: */
1.244 schwarze 378: if (' ' == *n->string && NODE_LINE & n->flags)
1.149 kristaps 379: if ( ! (HTML_LITERAL & h->flags))
1.248 schwarze 380: print_otag(h, TAG_BR, "");
1.244 schwarze 381: if (NODE_DELIMC & n->flags)
1.155 kristaps 382: h->flags |= HTML_NOSPACE;
1.1 kristaps 383: print_text(h, n->string);
1.244 schwarze 384: if (NODE_DELIMO & n->flags)
1.155 kristaps 385: h->flags |= HTML_NOSPACE;
1.151 kristaps 386: return;
1.227 schwarze 387: case ROFFT_EQN:
1.244 schwarze 388: if (n->flags & NODE_LINE)
1.226 schwarze 389: putchar('\n');
1.174 kristaps 390: print_eqn(h, n->eqn);
1.153 kristaps 391: break;
1.227 schwarze 392: case ROFFT_TBL:
1.144 kristaps 393: /*
394: * This will take care of initialising all of the table
395: * state data for the first table, then tearing it down
396: * for the last one.
397: */
1.141 kristaps 398: print_tbl(h, n->span);
1.144 kristaps 399: return;
1.1 kristaps 400: default:
1.144 kristaps 401: /*
402: * Close out the current table, if it's open, and unset
403: * the "meta" table state. This will be reopened on the
404: * next table element.
405: */
1.213 schwarze 406: if (h->tblt != NULL) {
1.144 kristaps 407: print_tblclose(h);
408: t = h->tags.head;
409: }
1.213 schwarze 410: assert(h->tblt == NULL);
411: if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
1.184 schwarze 412: child = (*mdocs[n->tok].pre)(meta, n, h);
1.1 kristaps 413: break;
414: }
415:
1.244 schwarze 416: if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
1.222 schwarze 417: h->flags &= ~HTML_KEEP;
418: h->flags |= HTML_PREKEEP;
1.94 kristaps 419: }
420:
1.1 kristaps 421: if (child && n->child)
1.184 schwarze 422: print_mdoc_nodelist(meta, n->child, h);
1.1 kristaps 423:
424: print_stagq(h, t);
425:
426: switch (n->type) {
1.227 schwarze 427: case ROFFT_EQN:
1.1 kristaps 428: break;
429: default:
1.244 schwarze 430: if ( ! mdocs[n->tok].post || n->flags & NODE_ENDED)
1.213 schwarze 431: break;
432: (*mdocs[n->tok].post)(meta, n, h);
433: if (n->end != ENDBODY_NOT)
1.244 schwarze 434: n->body->flags |= NODE_ENDED;
1.213 schwarze 435: if (n->end == ENDBODY_NOSPACE)
436: h->flags |= HTML_NOSPACE;
1.1 kristaps 437: break;
438: }
439: }
440:
441: static void
442: mdoc_root_post(MDOC_ARGS)
443: {
444: struct tag *t, *tt;
445:
1.248 schwarze 446: t = print_otag(h, TAG_TABLE, "c", "foot");
447: print_otag(h, TAG_TBODY, "");
448: tt = print_otag(h, TAG_TR, "");
1.40 kristaps 449:
1.248 schwarze 450: print_otag(h, TAG_TD, "c", "foot-date");
1.184 schwarze 451: print_text(h, meta->date);
1.1 kristaps 452: print_stagq(h, tt);
453:
1.248 schwarze 454: print_otag(h, TAG_TD, "c", "foot-os");
1.184 schwarze 455: print_text(h, meta->os);
1.1 kristaps 456: print_tagq(h, t);
457: }
458:
459: static int
460: mdoc_root_pre(MDOC_ARGS)
461: {
462: struct tag *t, *tt;
1.190 schwarze 463: char *volume, *title;
1.1 kristaps 464:
1.190 schwarze 465: if (NULL == meta->arch)
466: volume = mandoc_strdup(meta->vol);
467: else
468: mandoc_asprintf(&volume, "%s (%s)",
469: meta->vol, meta->arch);
1.1 kristaps 470:
1.195 schwarze 471: if (NULL == meta->msec)
472: title = mandoc_strdup(meta->title);
473: else
474: mandoc_asprintf(&title, "%s(%s)",
475: meta->title, meta->msec);
1.23 kristaps 476:
1.248 schwarze 477: t = print_otag(h, TAG_TABLE, "c", "head");
478: print_otag(h, TAG_TBODY, "");
479: tt = print_otag(h, TAG_TR, "");
1.1 kristaps 480:
1.248 schwarze 481: print_otag(h, TAG_TD, "c", "head-ltitle");
1.2 kristaps 482: print_text(h, title);
1.1 kristaps 483: print_stagq(h, tt);
484:
1.248 schwarze 485: print_otag(h, TAG_TD, "c", "head-vol");
1.190 schwarze 486: print_text(h, volume);
1.1 kristaps 487: print_stagq(h, tt);
488:
1.248 schwarze 489: print_otag(h, TAG_TD, "c", "head-rtitle");
1.2 kristaps 490: print_text(h, title);
1.1 kristaps 491: print_tagq(h, t);
1.189 schwarze 492:
493: free(title);
1.190 schwarze 494: free(volume);
1.237 schwarze 495: return 1;
1.1 kristaps 496: }
497:
1.249 ! schwarze 498: char *
! 499: make_id(const struct roff_node *n)
! 500: {
! 501: const struct roff_node *nch;
! 502: char *buf, *cp;
! 503:
! 504: for (nch = n->child; nch != NULL; nch = nch->next)
! 505: if (nch->type != ROFFT_TEXT)
! 506: return NULL;
! 507:
! 508: buf = NULL;
! 509: deroff(&buf, n);
! 510:
! 511: /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
! 512:
! 513: for (cp = buf; *cp != '\0'; cp++)
! 514: if (*cp == ' ')
! 515: *cp = '_';
! 516:
! 517: return buf;
! 518: }
! 519:
1.1 kristaps 520: static int
521: mdoc_sh_pre(MDOC_ARGS)
522: {
1.249 ! schwarze 523: char *id;
! 524:
1.200 schwarze 525: switch (n->type) {
1.227 schwarze 526: case ROFFT_BLOCK:
1.248 schwarze 527: print_otag(h, TAG_DIV, "c", "section");
1.237 schwarze 528: return 1;
1.227 schwarze 529: case ROFFT_BODY:
1.200 schwarze 530: if (n->sec == SEC_AUTHORS)
531: h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
1.237 schwarze 532: return 1;
1.200 schwarze 533: default:
534: break;
535: }
1.1 kristaps 536:
1.249 ! schwarze 537: if ((id = make_id(n)) != NULL) {
! 538: print_otag(h, TAG_H1, "i", id);
! 539: free(id);
! 540: } else
1.248 schwarze 541: print_otag(h, TAG_H1, "");
1.175 kristaps 542:
1.237 schwarze 543: return 1;
1.1 kristaps 544: }
545:
546: static int
547: mdoc_ss_pre(MDOC_ARGS)
548: {
1.249 ! schwarze 549: char *id;
! 550:
1.227 schwarze 551: if (n->type == ROFFT_BLOCK) {
1.248 schwarze 552: print_otag(h, TAG_DIV, "c", "subsection");
1.237 schwarze 553: return 1;
1.227 schwarze 554: } else if (n->type == ROFFT_BODY)
1.237 schwarze 555: return 1;
1.23 kristaps 556:
1.249 ! schwarze 557: if ((id = make_id(n)) != NULL) {
! 558: print_otag(h, TAG_H2, "i", id);
! 559: free(id);
! 560: } else
1.248 schwarze 561: print_otag(h, TAG_H2, "");
1.175 kristaps 562:
1.237 schwarze 563: return 1;
1.1 kristaps 564: }
565:
566: static int
567: mdoc_fl_pre(MDOC_ARGS)
568: {
1.248 schwarze 569: print_otag(h, TAG_B, "c", "flag");
1.51 kristaps 570:
1.50 kristaps 571: /* `Cm' has no leading hyphen. */
572:
1.51 kristaps 573: if (MDOC_Cm == n->tok)
1.237 schwarze 574: return 1;
1.50 kristaps 575:
576: print_text(h, "\\-");
577:
1.240 schwarze 578: if (!(n->child == NULL &&
1.199 schwarze 579: (n->next == NULL ||
1.227 schwarze 580: n->next->type == ROFFT_TEXT ||
1.244 schwarze 581: n->next->flags & NODE_LINE)))
1.1 kristaps 582: h->flags |= HTML_NOSPACE;
1.50 kristaps 583:
1.237 schwarze 584: return 1;
1.1 kristaps 585: }
586:
587: static int
588: mdoc_nd_pre(MDOC_ARGS)
589: {
1.227 schwarze 590: if (n->type != ROFFT_BODY)
1.237 schwarze 591: return 1;
1.1 kristaps 592:
1.24 kristaps 593: /* XXX: this tag in theory can contain block elements. */
594:
1.1 kristaps 595: print_text(h, "\\(em");
1.248 schwarze 596: print_otag(h, TAG_SPAN, "c", "desc");
1.237 schwarze 597: return 1;
1.1 kristaps 598: }
599:
600: static int
601: mdoc_nm_pre(MDOC_ARGS)
602: {
1.166 kristaps 603: int len;
1.91 kristaps 604:
1.124 kristaps 605: switch (n->type) {
1.227 schwarze 606: case ROFFT_HEAD:
1.248 schwarze 607: print_otag(h, TAG_TD, "");
1.235 schwarze 608: /* FALLTHROUGH */
609: case ROFFT_ELEM:
1.248 schwarze 610: print_otag(h, TAG_B, "c", "name");
1.235 schwarze 611: if (n->child == NULL && meta->name != NULL)
1.184 schwarze 612: print_text(h, meta->name);
1.237 schwarze 613: return 1;
1.227 schwarze 614: case ROFFT_BODY:
1.248 schwarze 615: print_otag(h, TAG_TD, "");
1.237 schwarze 616: return 1;
1.124 kristaps 617: default:
618: break;
619: }
1.91 kristaps 620:
1.124 kristaps 621: synopsis_pre(h, n);
1.248 schwarze 622: print_otag(h, TAG_TABLE, "c", "synopsis");
1.124 kristaps 623:
1.234 schwarze 624: for (len = 0, n = n->head->child; n; n = n->next)
1.227 schwarze 625: if (n->type == ROFFT_TEXT)
1.166 kristaps 626: len += html_strlen(n->string);
1.91 kristaps 627:
1.235 schwarze 628: if (len == 0 && meta->name != NULL)
1.184 schwarze 629: len = html_strlen(meta->name);
1.1 kristaps 630:
1.248 schwarze 631: print_otag(h, TAG_COL, "shw", len);
632: print_otag(h, TAG_COL, "");
633: print_otag(h, TAG_TBODY, "");
634: print_otag(h, TAG_TR, "");
1.237 schwarze 635: return 1;
1.1 kristaps 636: }
637:
638: static int
639: mdoc_xr_pre(MDOC_ARGS)
640: {
1.56 kristaps 641: if (NULL == n->child)
1.237 schwarze 642: return 0;
1.17 kristaps 643:
1.249 ! schwarze 644: if (h->base_man)
! 645: print_otag(h, TAG_A, "chM", "link-man",
! 646: n->child->string, n->child->next == NULL ?
! 647: NULL : n->child->next->string);
! 648: else
1.248 schwarze 649: print_otag(h, TAG_A, "c", "link-man");
1.1 kristaps 650:
1.157 kristaps 651: n = n->child;
652: print_text(h, n->string);
1.16 kristaps 653:
1.157 kristaps 654: if (NULL == (n = n->next))
1.237 schwarze 655: return 0;
1.1 kristaps 656:
657: h->flags |= HTML_NOSPACE;
658: print_text(h, "(");
659: h->flags |= HTML_NOSPACE;
1.157 kristaps 660: print_text(h, n->string);
1.1 kristaps 661: h->flags |= HTML_NOSPACE;
662: print_text(h, ")");
1.237 schwarze 663: return 0;
1.1 kristaps 664: }
665:
666: static int
667: mdoc_ns_pre(MDOC_ARGS)
668: {
669:
1.244 schwarze 670: if ( ! (NODE_LINE & n->flags))
1.150 kristaps 671: h->flags |= HTML_NOSPACE;
1.237 schwarze 672: return 1;
1.1 kristaps 673: }
674:
675: static int
676: mdoc_ar_pre(MDOC_ARGS)
677: {
1.248 schwarze 678: print_otag(h, TAG_I, "c", "arg");
1.237 schwarze 679: return 1;
1.1 kristaps 680: }
681:
682: static int
683: mdoc_xx_pre(MDOC_ARGS)
684: {
1.248 schwarze 685: print_otag(h, TAG_SPAN, "c", "unix");
1.245 schwarze 686: return 1;
1.4 kristaps 687: }
688:
689: static int
1.115 kristaps 690: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 691: {
1.115 kristaps 692: enum mdoc_list type;
1.228 schwarze 693: const struct roff_node *bl;
1.115 kristaps 694:
695: bl = n->parent;
696: while (bl && MDOC_Bl != bl->tok)
697: bl = bl->parent;
1.137 kristaps 698: type = bl->norm->Bl.type;
1.24 kristaps 699:
1.227 schwarze 700: if (n->type == ROFFT_HEAD) {
1.115 kristaps 701: switch (type) {
1.188 schwarze 702: case LIST_bullet:
703: case LIST_dash:
704: case LIST_item:
705: case LIST_hyphen:
706: case LIST_enum:
1.237 schwarze 707: return 0;
1.188 schwarze 708: case LIST_diag:
709: case LIST_hang:
710: case LIST_inset:
711: case LIST_ohang:
712: case LIST_tag:
1.248 schwarze 713: print_otag(h, TAG_DT, "csvt", lists[type],
714: !bl->norm->Bl.comp);
1.134 kristaps 715: if (LIST_diag != type)
716: break;
1.248 schwarze 717: print_otag(h, TAG_B, "c", "diag");
1.115 kristaps 718: break;
1.188 schwarze 719: case LIST_column:
1.115 kristaps 720: break;
721: default:
722: break;
723: }
1.227 schwarze 724: } else if (n->type == ROFFT_BODY) {
1.115 kristaps 725: switch (type) {
1.188 schwarze 726: case LIST_bullet:
727: case LIST_hyphen:
728: case LIST_dash:
729: case LIST_enum:
730: case LIST_item:
1.248 schwarze 731: print_otag(h, TAG_LI, "csvt", lists[type],
732: !bl->norm->Bl.comp);
1.115 kristaps 733: break;
1.188 schwarze 734: case LIST_diag:
735: case LIST_hang:
736: case LIST_inset:
737: case LIST_ohang:
738: case LIST_tag:
1.137 kristaps 739: if (NULL == bl->norm->Bl.width) {
1.248 schwarze 740: print_otag(h, TAG_DD, "c", lists[type]);
1.122 kristaps 741: break;
742: }
1.248 schwarze 743: print_otag(h, TAG_DD, "cswl", lists[type],
744: bl->norm->Bl.width);
1.115 kristaps 745: break;
1.188 schwarze 746: case LIST_column:
1.248 schwarze 747: print_otag(h, TAG_TD, "csvt", lists[type],
748: !bl->norm->Bl.comp);
1.115 kristaps 749: break;
750: default:
751: break;
752: }
753: } else {
754: switch (type) {
1.188 schwarze 755: case LIST_column:
1.248 schwarze 756: print_otag(h, TAG_TR, "c", lists[type]);
1.115 kristaps 757: break;
758: default:
1.23 kristaps 759: break;
1.115 kristaps 760: }
1.1 kristaps 761: }
762:
1.237 schwarze 763: return 1;
1.1 kristaps 764: }
765:
766: static int
1.115 kristaps 767: mdoc_bl_pre(MDOC_ARGS)
1.1 kristaps 768: {
1.142 kristaps 769: int i;
1.134 kristaps 770: char buf[BUFSIZ];
1.248 schwarze 771: enum htmltag elemtype;
1.23 kristaps 772:
1.227 schwarze 773: if (n->type == ROFFT_BODY) {
1.137 kristaps 774: if (LIST_column == n->norm->Bl.type)
1.248 schwarze 775: print_otag(h, TAG_TBODY, "");
1.237 schwarze 776: return 1;
1.23 kristaps 777: }
1.1 kristaps 778:
1.227 schwarze 779: if (n->type == ROFFT_HEAD) {
1.137 kristaps 780: if (LIST_column != n->norm->Bl.type)
1.237 schwarze 781: return 0;
1.115 kristaps 782:
783: /*
784: * For each column, print out the <COL> tag with our
785: * suggested width. The last column gets min-width, as
786: * in terminal mode it auto-sizes to the width of the
787: * screen and we want to preserve that behaviour.
788: */
1.1 kristaps 789:
1.248 schwarze 790: for (i = 0; i < (int)n->norm->Bl.ncols - 1; i++)
791: print_otag(h, TAG_COL, "sww", n->norm->Bl.cols[i]);
792: print_otag(h, TAG_COL, "swW", n->norm->Bl.cols[i]);
1.1 kristaps 793:
1.237 schwarze 794: return 0;
1.1 kristaps 795: }
796:
1.137 kristaps 797: assert(lists[n->norm->Bl.type]);
1.190 schwarze 798: (void)strlcpy(buf, "list ", BUFSIZ);
799: (void)strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.1 kristaps 800:
1.137 kristaps 801: switch (n->norm->Bl.type) {
1.188 schwarze 802: case LIST_bullet:
803: case LIST_dash:
804: case LIST_hyphen:
805: case LIST_item:
1.248 schwarze 806: elemtype = TAG_UL;
1.1 kristaps 807: break;
1.188 schwarze 808: case LIST_enum:
1.248 schwarze 809: elemtype = TAG_OL;
1.23 kristaps 810: break;
1.188 schwarze 811: case LIST_diag:
812: case LIST_hang:
813: case LIST_inset:
814: case LIST_ohang:
815: case LIST_tag:
1.248 schwarze 816: elemtype = TAG_DL;
1.115 kristaps 817: break;
1.188 schwarze 818: case LIST_column:
1.248 schwarze 819: elemtype = TAG_TABLE;
1.1 kristaps 820: break;
821: default:
1.115 kristaps 822: abort();
1.1 kristaps 823: }
824:
1.248 schwarze 825: if (n->norm->Bl.offs)
826: print_otag(h, elemtype, "csvtvbwl", buf, 0, 0,
827: n->norm->Bl.offs);
828: else
829: print_otag(h, elemtype, "csvtvb", buf, 0, 0);
830:
1.237 schwarze 831: return 1;
1.1 kristaps 832: }
833:
834: static int
835: mdoc_ex_pre(MDOC_ARGS)
836: {
1.127 kristaps 837: if (n->prev)
1.248 schwarze 838: print_otag(h, TAG_BR, "");
1.247 schwarze 839: return 1;
1.1 kristaps 840: }
841:
842: static int
843: mdoc_em_pre(MDOC_ARGS)
844: {
1.248 schwarze 845: print_otag(h, TAG_SPAN, "c", "emph");
1.237 schwarze 846: return 1;
1.1 kristaps 847: }
848:
849: static int
850: mdoc_d1_pre(MDOC_ARGS)
851: {
1.227 schwarze 852: if (n->type != ROFFT_BLOCK)
1.237 schwarze 853: return 1;
1.1 kristaps 854:
1.248 schwarze 855: print_otag(h, TAG_BLOCKQUOTE, "svtvb", 0, 0);
1.120 kristaps 856:
857: /* BLOCKQUOTE needs a block body. */
1.118 kristaps 858:
1.248 schwarze 859: print_otag(h, TAG_DIV, "c", "display");
1.136 kristaps 860:
1.248 schwarze 861: if (MDOC_Dl == n->tok)
862: print_otag(h, TAG_CODE, "c", "lit");
1.35 kristaps 863:
1.237 schwarze 864: return 1;
1.1 kristaps 865: }
866:
867: static int
868: mdoc_sx_pre(MDOC_ARGS)
869: {
1.249 ! schwarze 870: char *id;
1.175 kristaps 871:
1.249 ! schwarze 872: print_otag(h, TAG_I, "c", "link-sec");
! 873: if ((id = make_id(n)) != NULL) {
! 874: print_otag(h, TAG_A, "chR", "link-sec", id);
! 875: free(id);
! 876: } else
! 877: print_otag(h, TAG_A, "c", "link-sec");
1.1 kristaps 878:
1.237 schwarze 879: return 1;
1.1 kristaps 880: }
881:
882: static int
883: mdoc_bd_pre(MDOC_ARGS)
884: {
1.248 schwarze 885: int comp, offs, sv;
1.228 schwarze 886: struct roff_node *nn;
1.1 kristaps 887:
1.227 schwarze 888: if (n->type == ROFFT_HEAD)
1.237 schwarze 889: return 0;
1.1 kristaps 890:
1.227 schwarze 891: if (n->type == ROFFT_BLOCK) {
1.137 kristaps 892: comp = n->norm->Bd.comp;
1.23 kristaps 893: for (nn = n; nn && ! comp; nn = nn->parent) {
1.227 schwarze 894: if (nn->type != ROFFT_BLOCK)
1.23 kristaps 895: continue;
896: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
897: comp = 1;
898: if (nn->prev)
899: break;
900: }
1.126 kristaps 901: if ( ! comp)
1.206 kristaps 902: print_paragraph(h);
1.237 schwarze 903: return 1;
1.1 kristaps 904: }
905:
1.209 schwarze 906: /* Handle the -offset argument. */
907:
908: if (n->norm->Bd.offs == NULL ||
909: ! strcmp(n->norm->Bd.offs, "left"))
1.248 schwarze 910: offs = 0;
1.209 schwarze 911: else if ( ! strcmp(n->norm->Bd.offs, "indent"))
1.248 schwarze 912: offs = INDENT;
1.209 schwarze 913: else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
1.248 schwarze 914: offs = INDENT * 2;
1.209 schwarze 915: else
1.248 schwarze 916: offs = -1;
1.188 schwarze 917:
1.248 schwarze 918: if (offs == -1)
919: print_otag(h, TAG_DIV, "cswl", "display", n->norm->Bd.offs);
920: else
921: print_otag(h, TAG_DIV, "cshl", "display", offs);
1.241 schwarze 922:
923: if (n->norm->Bd.type != DISP_unfilled &&
924: n->norm->Bd.type != DISP_literal)
1.237 schwarze 925: return 1;
1.1 kristaps 926:
1.248 schwarze 927: print_otag(h, TAG_PRE, "c", "lit");
1.1 kristaps 928:
1.149 kristaps 929: /* This can be recursive: save & set our literal state. */
930:
931: sv = h->flags & HTML_LITERAL;
932: h->flags |= HTML_LITERAL;
933:
1.14 kristaps 934: for (nn = n->child; nn; nn = nn->next) {
1.184 schwarze 935: print_mdoc_node(meta, nn, h);
1.108 kristaps 936: /*
937: * If the printed node flushes its own line, then we
938: * needn't do it here as well. This is hacky, but the
939: * notion of selective eoln whitespace is pretty dumb
940: * anyway, so don't sweat it.
941: */
942: switch (nn->tok) {
1.188 schwarze 943: case MDOC_Sm:
944: case MDOC_br:
945: case MDOC_sp:
946: case MDOC_Bl:
947: case MDOC_D1:
948: case MDOC_Dl:
949: case MDOC_Lp:
950: case MDOC_Pp:
1.108 kristaps 951: continue;
952: default:
953: break;
954: }
1.216 schwarze 955: if (h->flags & HTML_NONEWLINE ||
1.244 schwarze 956: (nn->next && ! (nn->next->flags & NODE_LINE)))
1.101 schwarze 957: continue;
1.126 kristaps 958: else if (nn->next)
959: print_text(h, "\n");
1.125 kristaps 960:
1.101 schwarze 961: h->flags |= HTML_NOSPACE;
1.1 kristaps 962: }
1.149 kristaps 963:
964: if (0 == sv)
965: h->flags &= ~HTML_LITERAL;
1.1 kristaps 966:
1.237 schwarze 967: return 0;
1.1 kristaps 968: }
969:
970: static int
971: mdoc_pa_pre(MDOC_ARGS)
972: {
1.248 schwarze 973: print_otag(h, TAG_I, "c", "file");
1.237 schwarze 974: return 1;
1.1 kristaps 975: }
976:
977: static int
978: mdoc_ad_pre(MDOC_ARGS)
979: {
1.248 schwarze 980: print_otag(h, TAG_I, "c", "addr");
1.237 schwarze 981: return 1;
1.1 kristaps 982: }
983:
984: static int
985: mdoc_an_pre(MDOC_ARGS)
986: {
1.200 schwarze 987: if (n->norm->An.auth == AUTH_split) {
988: h->flags &= ~HTML_NOSPLIT;
989: h->flags |= HTML_SPLIT;
1.237 schwarze 990: return 0;
1.200 schwarze 991: }
992: if (n->norm->An.auth == AUTH_nosplit) {
993: h->flags &= ~HTML_SPLIT;
994: h->flags |= HTML_NOSPLIT;
1.237 schwarze 995: return 0;
1.200 schwarze 996: }
997:
998: if (h->flags & HTML_SPLIT)
1.248 schwarze 999: print_otag(h, TAG_BR, "");
1.200 schwarze 1000:
1001: if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
1002: h->flags |= HTML_SPLIT;
1.19 kristaps 1003:
1.248 schwarze 1004: print_otag(h, TAG_SPAN, "c", "author");
1.237 schwarze 1005: return 1;
1.1 kristaps 1006: }
1007:
1008: static int
1009: mdoc_cd_pre(MDOC_ARGS)
1010: {
1.78 kristaps 1011: synopsis_pre(h, n);
1.248 schwarze 1012: print_otag(h, TAG_B, "c", "config");
1.237 schwarze 1013: return 1;
1.1 kristaps 1014: }
1015:
1016: static int
1017: mdoc_dv_pre(MDOC_ARGS)
1018: {
1.248 schwarze 1019: print_otag(h, TAG_SPAN, "c", "define");
1.237 schwarze 1020: return 1;
1.1 kristaps 1021: }
1022:
1023: static int
1024: mdoc_ev_pre(MDOC_ARGS)
1025: {
1.248 schwarze 1026: print_otag(h, TAG_SPAN, "c", "env");
1.237 schwarze 1027: return 1;
1.1 kristaps 1028: }
1029:
1030: static int
1031: mdoc_er_pre(MDOC_ARGS)
1032: {
1.248 schwarze 1033: print_otag(h, TAG_SPAN, "c", "errno");
1.237 schwarze 1034: return 1;
1.1 kristaps 1035: }
1036:
1037: static int
1038: mdoc_fa_pre(MDOC_ARGS)
1039: {
1.228 schwarze 1040: const struct roff_node *nn;
1.1 kristaps 1041: struct tag *t;
1042:
1043: if (n->parent->tok != MDOC_Fo) {
1.248 schwarze 1044: print_otag(h, TAG_I, "c", "farg");
1.237 schwarze 1045: return 1;
1.1 kristaps 1046: }
1047:
1048: for (nn = n->child; nn; nn = nn->next) {
1.248 schwarze 1049: t = print_otag(h, TAG_I, "c", "farg");
1.1 kristaps 1050: print_text(h, nn->string);
1051: print_tagq(h, t);
1.155 kristaps 1052: if (nn->next) {
1053: h->flags |= HTML_NOSPACE;
1.1 kristaps 1054: print_text(h, ",");
1.155 kristaps 1055: }
1.1 kristaps 1056: }
1057:
1.155 kristaps 1058: if (n->child && n->next && n->next->tok == MDOC_Fa) {
1059: h->flags |= HTML_NOSPACE;
1.1 kristaps 1060: print_text(h, ",");
1.155 kristaps 1061: }
1.1 kristaps 1062:
1.237 schwarze 1063: return 0;
1.1 kristaps 1064: }
1065:
1066: static int
1067: mdoc_fd_pre(MDOC_ARGS)
1068: {
1.162 kristaps 1069: struct tag *t;
1.249 ! schwarze 1070: char *buf, *cp;
1.1 kristaps 1071:
1.78 kristaps 1072: synopsis_pre(h, n);
1073:
1.162 kristaps 1074: if (NULL == (n = n->child))
1.237 schwarze 1075: return 0;
1.162 kristaps 1076:
1.227 schwarze 1077: assert(n->type == ROFFT_TEXT);
1.162 kristaps 1078:
1079: if (strcmp(n->string, "#include")) {
1.248 schwarze 1080: print_otag(h, TAG_B, "c", "macro");
1.237 schwarze 1081: return 1;
1.162 kristaps 1082: }
1083:
1.248 schwarze 1084: print_otag(h, TAG_B, "c", "includes");
1.162 kristaps 1085: print_text(h, n->string);
1086:
1087: if (NULL != (n = n->next)) {
1.227 schwarze 1088: assert(n->type == ROFFT_TEXT);
1.190 schwarze 1089:
1.162 kristaps 1090: if (h->base_includes) {
1.249 ! schwarze 1091: cp = n->string;
! 1092: if (*cp == '<' || *cp == '"')
! 1093: cp++;
! 1094: buf = mandoc_strdup(cp);
! 1095: cp = strchr(buf, '\0') - 1;
! 1096: if (cp >= buf && (*cp == '>' || *cp == '"'))
! 1097: *cp = '\0';
! 1098: t = print_otag(h, TAG_A, "chI", "link-includes", buf);
! 1099: free(buf);
1.248 schwarze 1100: } else
1101: t = print_otag(h, TAG_A, "c", "link-includes");
1.162 kristaps 1102:
1103: print_text(h, n->string);
1104: print_tagq(h, t);
1105:
1106: n = n->next;
1107: }
1108:
1109: for ( ; n; n = n->next) {
1.227 schwarze 1110: assert(n->type == ROFFT_TEXT);
1.162 kristaps 1111: print_text(h, n->string);
1112: }
1113:
1.237 schwarze 1114: return 0;
1.1 kristaps 1115: }
1116:
1117: static int
1118: mdoc_vt_pre(MDOC_ARGS)
1119: {
1.227 schwarze 1120: if (n->type == ROFFT_BLOCK) {
1.78 kristaps 1121: synopsis_pre(h, n);
1.237 schwarze 1122: return 1;
1.227 schwarze 1123: } else if (n->type == ROFFT_ELEM) {
1.78 kristaps 1124: synopsis_pre(h, n);
1.227 schwarze 1125: } else if (n->type == ROFFT_HEAD)
1.237 schwarze 1126: return 0;
1.1 kristaps 1127:
1.248 schwarze 1128: print_otag(h, TAG_SPAN, "c", "type");
1.237 schwarze 1129: return 1;
1.1 kristaps 1130: }
1131:
1132: static int
1133: mdoc_ft_pre(MDOC_ARGS)
1134: {
1.78 kristaps 1135: synopsis_pre(h, n);
1.248 schwarze 1136: print_otag(h, TAG_I, "c", "ftype");
1.237 schwarze 1137: return 1;
1.1 kristaps 1138: }
1139:
1140: static int
1141: mdoc_fn_pre(MDOC_ARGS)
1142: {
1.157 kristaps 1143: struct tag *t;
1144: char nbuf[BUFSIZ];
1145: const char *sp, *ep;
1.248 schwarze 1146: int sz, pretty;
1.1 kristaps 1147:
1.244 schwarze 1148: pretty = NODE_SYNPRETTY & n->flags;
1.78 kristaps 1149: synopsis_pre(h, n);
1.1 kristaps 1150:
1.7 kristaps 1151: /* Split apart into type and name. */
1152: assert(n->child->string);
1153: sp = n->child->string;
1.19 kristaps 1154:
1.26 kristaps 1155: ep = strchr(sp, ' ');
1156: if (NULL != ep) {
1.248 schwarze 1157: t = print_otag(h, TAG_I, "c", "ftype");
1.188 schwarze 1158:
1.19 kristaps 1159: while (ep) {
1160: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1161: (void)memcpy(nbuf, sp, (size_t)sz);
1162: nbuf[sz] = '\0';
1163: print_text(h, nbuf);
1164: sp = ++ep;
1165: ep = strchr(sp, ' ');
1166: }
1167: print_tagq(h, t);
1.7 kristaps 1168: }
1.1 kristaps 1169:
1.248 schwarze 1170: t = print_otag(h, TAG_B, "c", "fname");
1.7 kristaps 1171:
1.190 schwarze 1172: if (sp)
1173: print_text(h, sp);
1.7 kristaps 1174:
1.1 kristaps 1175: print_tagq(h, t);
1176:
1177: h->flags |= HTML_NOSPACE;
1178: print_text(h, "(");
1.163 kristaps 1179: h->flags |= HTML_NOSPACE;
1.1 kristaps 1180:
1.157 kristaps 1181: for (n = n->child->next; n; n = n->next) {
1.244 schwarze 1182: if (NODE_SYNPRETTY & n->flags)
1.248 schwarze 1183: t = print_otag(h, TAG_I, "css?", "farg",
1184: "white-space", "nowrap");
1185: else
1186: t = print_otag(h, TAG_I, "c", "farg");
1.157 kristaps 1187: print_text(h, n->string);
1.1 kristaps 1188: print_tagq(h, t);
1.157 kristaps 1189: if (n->next) {
1.155 kristaps 1190: h->flags |= HTML_NOSPACE;
1.1 kristaps 1191: print_text(h, ",");
1.155 kristaps 1192: }
1.1 kristaps 1193: }
1194:
1.155 kristaps 1195: h->flags |= HTML_NOSPACE;
1.1 kristaps 1196: print_text(h, ")");
1.155 kristaps 1197:
1.157 kristaps 1198: if (pretty) {
1.155 kristaps 1199: h->flags |= HTML_NOSPACE;
1.1 kristaps 1200: print_text(h, ";");
1.155 kristaps 1201: }
1.99 kristaps 1202:
1.237 schwarze 1203: return 0;
1.99 kristaps 1204: }
1205:
1206: static int
1207: mdoc_sm_pre(MDOC_ARGS)
1208: {
1209:
1.192 schwarze 1210: if (NULL == n->child)
1211: h->flags ^= HTML_NONOSPACE;
1212: else if (0 == strcmp("on", n->child->string))
1.99 kristaps 1213: h->flags &= ~HTML_NONOSPACE;
1.192 schwarze 1214: else
1.99 kristaps 1215: h->flags |= HTML_NONOSPACE;
1.192 schwarze 1216:
1217: if ( ! (HTML_NONOSPACE & h->flags))
1218: h->flags &= ~HTML_NOSPACE;
1.1 kristaps 1219:
1.237 schwarze 1220: return 0;
1.1 kristaps 1221: }
1222:
1.120 kristaps 1223: static int
1.191 schwarze 1224: mdoc_skip_pre(MDOC_ARGS)
1.187 schwarze 1225: {
1226:
1.237 schwarze 1227: return 0;
1.187 schwarze 1228: }
1229:
1230: static int
1.120 kristaps 1231: mdoc_pp_pre(MDOC_ARGS)
1232: {
1233:
1.206 kristaps 1234: print_paragraph(h);
1.237 schwarze 1235: return 0;
1.120 kristaps 1236: }
1.1 kristaps 1237:
1238: static int
1239: mdoc_sp_pre(MDOC_ARGS)
1240: {
1.120 kristaps 1241: struct roffsu su;
1.1 kristaps 1242:
1.120 kristaps 1243: SCALE_VS_INIT(&su, 1);
1244:
1245: if (MDOC_sp == n->tok) {
1.218 schwarze 1246: if (NULL != (n = n->child)) {
1.171 kristaps 1247: if ( ! a2roffsu(n->string, &su, SCALE_VS))
1.217 schwarze 1248: su.scale = 1.0;
1.218 schwarze 1249: else if (su.scale < 0.0)
1250: su.scale = 0.0;
1251: }
1.120 kristaps 1252: } else
1.194 schwarze 1253: su.scale = 0.0;
1.1 kristaps 1254:
1.248 schwarze 1255: print_otag(h, TAG_DIV, "suh", &su);
1.120 kristaps 1256:
1.42 kristaps 1257: /* So the div isn't empty: */
1258: print_text(h, "\\~");
1259:
1.237 schwarze 1260: return 0;
1.1 kristaps 1261:
1262: }
1.2 kristaps 1263:
1264: static int
1265: mdoc_lk_pre(MDOC_ARGS)
1266: {
1.158 kristaps 1267: if (NULL == (n = n->child))
1.237 schwarze 1268: return 0;
1.2 kristaps 1269:
1.227 schwarze 1270: assert(n->type == ROFFT_TEXT);
1.2 kristaps 1271:
1.248 schwarze 1272: print_otag(h, TAG_A, "ch", "link-ext", n->string);
1.2 kristaps 1273:
1.170 kristaps 1274: if (NULL == n->next)
1275: print_text(h, n->string);
1276:
1277: for (n = n->next; n; n = n->next)
1.158 kristaps 1278: print_text(h, n->string);
1.2 kristaps 1279:
1.237 schwarze 1280: return 0;
1.2 kristaps 1281: }
1282:
1283: static int
1284: mdoc_mt_pre(MDOC_ARGS)
1285: {
1.159 kristaps 1286: struct tag *t;
1.249 ! schwarze 1287: char *cp;
1.2 kristaps 1288:
1.159 kristaps 1289: for (n = n->child; n; n = n->next) {
1.227 schwarze 1290: assert(n->type == ROFFT_TEXT);
1.159 kristaps 1291:
1.249 ! schwarze 1292: mandoc_asprintf(&cp, "mailto:%s", n->string);
! 1293: t = print_otag(h, TAG_A, "ch", "link-mail", cp);
1.159 kristaps 1294: print_text(h, n->string);
1.2 kristaps 1295: print_tagq(h, t);
1.249 ! schwarze 1296: free(cp);
1.2 kristaps 1297: }
1.188 schwarze 1298:
1.237 schwarze 1299: return 0;
1.2 kristaps 1300: }
1.4 kristaps 1301:
1302: static int
1303: mdoc_fo_pre(MDOC_ARGS)
1304: {
1.77 kristaps 1305: struct tag *t;
1.4 kristaps 1306:
1.227 schwarze 1307: if (n->type == ROFFT_BODY) {
1.4 kristaps 1308: h->flags |= HTML_NOSPACE;
1309: print_text(h, "(");
1310: h->flags |= HTML_NOSPACE;
1.237 schwarze 1311: return 1;
1.227 schwarze 1312: } else if (n->type == ROFFT_BLOCK) {
1.78 kristaps 1313: synopsis_pre(h, n);
1.237 schwarze 1314: return 1;
1.57 kristaps 1315: }
1.4 kristaps 1316:
1.233 schwarze 1317: if (n->child == NULL)
1.237 schwarze 1318: return 0;
1.77 kristaps 1319:
1320: assert(n->child->string);
1.248 schwarze 1321: t = print_otag(h, TAG_B, "c", "fname");
1.77 kristaps 1322: print_text(h, n->child->string);
1323: print_tagq(h, t);
1.237 schwarze 1324: return 0;
1.4 kristaps 1325: }
1326:
1327: static void
1328: mdoc_fo_post(MDOC_ARGS)
1329: {
1.78 kristaps 1330:
1.227 schwarze 1331: if (n->type != ROFFT_BODY)
1.4 kristaps 1332: return;
1.155 kristaps 1333: h->flags |= HTML_NOSPACE;
1.4 kristaps 1334: print_text(h, ")");
1.155 kristaps 1335: h->flags |= HTML_NOSPACE;
1.4 kristaps 1336: print_text(h, ";");
1337: }
1338:
1339: static int
1340: mdoc_in_pre(MDOC_ARGS)
1341: {
1.156 kristaps 1342: struct tag *t;
1.34 kristaps 1343:
1.78 kristaps 1344: synopsis_pre(h, n);
1.248 schwarze 1345: print_otag(h, TAG_B, "c", "includes");
1.4 kristaps 1346:
1.156 kristaps 1347: /*
1348: * The first argument of the `In' gets special treatment as
1349: * being a linked value. Subsequent values are printed
1350: * afterward. groff does similarly. This also handles the case
1351: * of no children.
1352: */
1353:
1.244 schwarze 1354: if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
1.4 kristaps 1355: print_text(h, "#include");
1356:
1357: print_text(h, "<");
1358: h->flags |= HTML_NOSPACE;
1359:
1.156 kristaps 1360: if (NULL != (n = n->child)) {
1.227 schwarze 1361: assert(n->type == ROFFT_TEXT);
1.156 kristaps 1362:
1.249 ! schwarze 1363: if (h->base_includes)
! 1364: t = print_otag(h, TAG_A, "chI", "link-includes",
! 1365: n->string);
! 1366: else
1.248 schwarze 1367: t = print_otag(h, TAG_A, "c", "link-includes");
1.156 kristaps 1368: print_text(h, n->string);
1.17 kristaps 1369: print_tagq(h, t);
1.156 kristaps 1370:
1371: n = n->next;
1.17 kristaps 1372: }
1.4 kristaps 1373:
1374: h->flags |= HTML_NOSPACE;
1375: print_text(h, ">");
1.156 kristaps 1376:
1377: for ( ; n; n = n->next) {
1.227 schwarze 1378: assert(n->type == ROFFT_TEXT);
1.156 kristaps 1379: print_text(h, n->string);
1380: }
1.4 kristaps 1381:
1.237 schwarze 1382: return 0;
1.4 kristaps 1383: }
1384:
1385: static int
1386: mdoc_ic_pre(MDOC_ARGS)
1387: {
1.248 schwarze 1388: print_otag(h, TAG_B, "c", "cmd");
1.237 schwarze 1389: return 1;
1.4 kristaps 1390: }
1391:
1392: static int
1393: mdoc_va_pre(MDOC_ARGS)
1394: {
1.248 schwarze 1395: print_otag(h, TAG_B, "c", "var");
1.237 schwarze 1396: return 1;
1.4 kristaps 1397: }
1398:
1399: static int
1.5 kristaps 1400: mdoc_ap_pre(MDOC_ARGS)
1401: {
1.188 schwarze 1402:
1.5 kristaps 1403: h->flags |= HTML_NOSPACE;
1404: print_text(h, "\\(aq");
1405: h->flags |= HTML_NOSPACE;
1.237 schwarze 1406: return 1;
1.5 kristaps 1407: }
1408:
1409: static int
1410: mdoc_bf_pre(MDOC_ARGS)
1411: {
1.248 schwarze 1412: const char *cattr;
1.5 kristaps 1413:
1.227 schwarze 1414: if (n->type == ROFFT_HEAD)
1.237 schwarze 1415: return 0;
1.227 schwarze 1416: else if (n->type != ROFFT_BODY)
1.237 schwarze 1417: return 1;
1.5 kristaps 1418:
1.198 schwarze 1419: if (FONT_Em == n->norm->Bf.font)
1.248 schwarze 1420: cattr = "emph";
1.198 schwarze 1421: else if (FONT_Sy == n->norm->Bf.font)
1.248 schwarze 1422: cattr = "symb";
1.188 schwarze 1423: else if (FONT_Li == n->norm->Bf.font)
1.248 schwarze 1424: cattr = "lit";
1.92 kristaps 1425: else
1.248 schwarze 1426: cattr = "none";
1.5 kristaps 1427:
1.188 schwarze 1428: /*
1.92 kristaps 1429: * We want this to be inline-formatted, but needs to be div to
1.188 schwarze 1430: * accept block children.
1.92 kristaps 1431: */
1.248 schwarze 1432:
1433: print_otag(h, TAG_DIV, "css?hl", cattr, "display", "inline", 1);
1.237 schwarze 1434: return 1;
1.5 kristaps 1435: }
1436:
1437: static int
1438: mdoc_ms_pre(MDOC_ARGS)
1439: {
1.248 schwarze 1440: print_otag(h, TAG_SPAN, "c", "symb");
1.237 schwarze 1441: return 1;
1.5 kristaps 1442: }
1443:
1444: static int
1.110 schwarze 1445: mdoc_igndelim_pre(MDOC_ARGS)
1.5 kristaps 1446: {
1447:
1448: h->flags |= HTML_IGNDELIM;
1.237 schwarze 1449: return 1;
1.5 kristaps 1450: }
1451:
1452: static void
1453: mdoc_pf_post(MDOC_ARGS)
1454: {
1455:
1.244 schwarze 1456: if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1.214 schwarze 1457: h->flags |= HTML_NOSPACE;
1.5 kristaps 1458: }
1459:
1460: static int
1461: mdoc_rs_pre(MDOC_ARGS)
1462: {
1.227 schwarze 1463: if (n->type != ROFFT_BLOCK)
1.237 schwarze 1464: return 1;
1.5 kristaps 1465:
1.120 kristaps 1466: if (n->prev && SEC_SEE_ALSO == n->sec)
1.206 kristaps 1467: print_paragraph(h);
1.5 kristaps 1468:
1.248 schwarze 1469: print_otag(h, TAG_SPAN, "c", "ref");
1.237 schwarze 1470: return 1;
1.210 schwarze 1471: }
1472:
1473: static int
1474: mdoc_no_pre(MDOC_ARGS)
1475: {
1.248 schwarze 1476: print_otag(h, TAG_SPAN, "c", "none");
1.237 schwarze 1477: return 1;
1.5 kristaps 1478: }
1.6 kristaps 1479:
1480: static int
1481: mdoc_li_pre(MDOC_ARGS)
1482: {
1.248 schwarze 1483: print_otag(h, TAG_CODE, "c", "lit");
1.237 schwarze 1484: return 1;
1.6 kristaps 1485: }
1486:
1487: static int
1488: mdoc_sy_pre(MDOC_ARGS)
1489: {
1.248 schwarze 1490: print_otag(h, TAG_SPAN, "c", "symb");
1.237 schwarze 1491: return 1;
1.6 kristaps 1492: }
1493:
1494: static int
1495: mdoc_lb_pre(MDOC_ARGS)
1496: {
1.244 schwarze 1497: if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
1.248 schwarze 1498: print_otag(h, TAG_BR, "");
1.127 kristaps 1499:
1.248 schwarze 1500: print_otag(h, TAG_SPAN, "c", "lib");
1.237 schwarze 1501: return 1;
1.6 kristaps 1502: }
1.10 kristaps 1503:
1504: static int
1505: mdoc__x_pre(MDOC_ARGS)
1506: {
1.248 schwarze 1507: const char *cattr;
1508: enum htmltag t;
1.133 kristaps 1509:
1510: t = TAG_SPAN;
1.37 kristaps 1511:
1.10 kristaps 1512: switch (n->tok) {
1.188 schwarze 1513: case MDOC__A:
1.248 schwarze 1514: cattr = "ref-auth";
1.103 kristaps 1515: if (n->prev && MDOC__A == n->prev->tok)
1516: if (NULL == n->next || MDOC__A != n->next->tok)
1517: print_text(h, "and");
1.10 kristaps 1518: break;
1.188 schwarze 1519: case MDOC__B:
1.248 schwarze 1520: cattr = "ref-book";
1.133 kristaps 1521: t = TAG_I;
1.10 kristaps 1522: break;
1.188 schwarze 1523: case MDOC__C:
1.248 schwarze 1524: cattr = "ref-city";
1.10 kristaps 1525: break;
1.188 schwarze 1526: case MDOC__D:
1.248 schwarze 1527: cattr = "ref-date";
1.10 kristaps 1528: break;
1.188 schwarze 1529: case MDOC__I:
1.248 schwarze 1530: cattr = "ref-issue";
1.133 kristaps 1531: t = TAG_I;
1.10 kristaps 1532: break;
1.188 schwarze 1533: case MDOC__J:
1.248 schwarze 1534: cattr = "ref-jrnl";
1.133 kristaps 1535: t = TAG_I;
1.10 kristaps 1536: break;
1.188 schwarze 1537: case MDOC__N:
1.248 schwarze 1538: cattr = "ref-num";
1.10 kristaps 1539: break;
1.188 schwarze 1540: case MDOC__O:
1.248 schwarze 1541: cattr = "ref-opt";
1.10 kristaps 1542: break;
1.188 schwarze 1543: case MDOC__P:
1.248 schwarze 1544: cattr = "ref-page";
1.10 kristaps 1545: break;
1.188 schwarze 1546: case MDOC__Q:
1.248 schwarze 1547: cattr = "ref-corp";
1.10 kristaps 1548: break;
1.188 schwarze 1549: case MDOC__R:
1.248 schwarze 1550: cattr = "ref-rep";
1.10 kristaps 1551: break;
1.188 schwarze 1552: case MDOC__T:
1.248 schwarze 1553: cattr = "ref-title";
1.10 kristaps 1554: break;
1.188 schwarze 1555: case MDOC__U:
1.248 schwarze 1556: cattr = "link-ref";
1.38 kristaps 1557: break;
1.188 schwarze 1558: case MDOC__V:
1.248 schwarze 1559: cattr = "ref-vol";
1.10 kristaps 1560: break;
1561: default:
1562: abort();
1563: }
1564:
1.38 kristaps 1565: if (MDOC__U != n->tok) {
1.248 schwarze 1566: print_otag(h, t, "c", cattr);
1.237 schwarze 1567: return 1;
1.38 kristaps 1568: }
1569:
1.248 schwarze 1570: print_otag(h, TAG_A, "ch", cattr, n->child->string);
1.103 kristaps 1571:
1.237 schwarze 1572: return 1;
1.10 kristaps 1573: }
1574:
1575: static void
1576: mdoc__x_post(MDOC_ARGS)
1577: {
1.103 kristaps 1578:
1579: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1580: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1581: if (NULL == n->prev || MDOC__A != n->prev->tok)
1582: return;
1.10 kristaps 1583:
1.61 kristaps 1584: /* TODO: %U */
1585:
1.106 kristaps 1586: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1587: return;
1588:
1.155 kristaps 1589: h->flags |= HTML_NOSPACE;
1.10 kristaps 1590: print_text(h, n->next ? "," : ".");
1.94 kristaps 1591: }
1592:
1593: static int
1594: mdoc_bk_pre(MDOC_ARGS)
1595: {
1596:
1597: switch (n->type) {
1.227 schwarze 1598: case ROFFT_BLOCK:
1.94 kristaps 1599: break;
1.227 schwarze 1600: case ROFFT_HEAD:
1.237 schwarze 1601: return 0;
1.227 schwarze 1602: case ROFFT_BODY:
1.240 schwarze 1603: if (n->parent->args != NULL || n->prev->child == NULL)
1.131 kristaps 1604: h->flags |= HTML_PREKEEP;
1.94 kristaps 1605: break;
1606: default:
1607: abort();
1608: }
1609:
1.237 schwarze 1610: return 1;
1.94 kristaps 1611: }
1612:
1613: static void
1614: mdoc_bk_post(MDOC_ARGS)
1615: {
1616:
1.227 schwarze 1617: if (n->type == ROFFT_BODY)
1.94 kristaps 1618: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.10 kristaps 1619: }
1.107 kristaps 1620:
1621: static int
1622: mdoc_quote_pre(MDOC_ARGS)
1623: {
1.227 schwarze 1624: if (n->type != ROFFT_BODY)
1.237 schwarze 1625: return 1;
1.107 kristaps 1626:
1627: switch (n->tok) {
1.188 schwarze 1628: case MDOC_Ao:
1629: case MDOC_Aq:
1.240 schwarze 1630: print_text(h, n->child != NULL && n->child->next == NULL &&
1.219 schwarze 1631: n->child->tok == MDOC_Mt ? "<" : "\\(la");
1.107 kristaps 1632: break;
1.188 schwarze 1633: case MDOC_Bro:
1634: case MDOC_Brq:
1.107 kristaps 1635: print_text(h, "\\(lC");
1636: break;
1.188 schwarze 1637: case MDOC_Bo:
1638: case MDOC_Bq:
1.107 kristaps 1639: print_text(h, "\\(lB");
1640: break;
1.188 schwarze 1641: case MDOC_Oo:
1642: case MDOC_Op:
1.107 kristaps 1643: print_text(h, "\\(lB");
1.109 kristaps 1644: h->flags |= HTML_NOSPACE;
1.248 schwarze 1645: print_otag(h, TAG_SPAN, "c", "opt");
1.107 kristaps 1646: break;
1.191 schwarze 1647: case MDOC_En:
1648: if (NULL == n->norm->Es ||
1649: NULL == n->norm->Es->child)
1.237 schwarze 1650: return 1;
1.191 schwarze 1651: print_text(h, n->norm->Es->child->string);
1652: break;
1.188 schwarze 1653: case MDOC_Do:
1654: case MDOC_Dq:
1655: case MDOC_Qo:
1656: case MDOC_Qq:
1.107 kristaps 1657: print_text(h, "\\(lq");
1658: break;
1.188 schwarze 1659: case MDOC_Po:
1660: case MDOC_Pq:
1.107 kristaps 1661: print_text(h, "(");
1662: break;
1.188 schwarze 1663: case MDOC_Ql:
1.178 kristaps 1664: print_text(h, "\\(oq");
1665: h->flags |= HTML_NOSPACE;
1.248 schwarze 1666: print_otag(h, TAG_CODE, "c", "lit");
1.178 kristaps 1667: break;
1.188 schwarze 1668: case MDOC_So:
1669: case MDOC_Sq:
1.107 kristaps 1670: print_text(h, "\\(oq");
1671: break;
1672: default:
1673: abort();
1674: }
1675:
1676: h->flags |= HTML_NOSPACE;
1.237 schwarze 1677: return 1;
1.107 kristaps 1678: }
1679:
1680: static void
1681: mdoc_quote_post(MDOC_ARGS)
1682: {
1683:
1.227 schwarze 1684: if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.107 kristaps 1685: return;
1686:
1.221 schwarze 1687: h->flags |= HTML_NOSPACE;
1.107 kristaps 1688:
1689: switch (n->tok) {
1.188 schwarze 1690: case MDOC_Ao:
1691: case MDOC_Aq:
1.240 schwarze 1692: print_text(h, n->child != NULL && n->child->next == NULL &&
1.219 schwarze 1693: n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1.107 kristaps 1694: break;
1.188 schwarze 1695: case MDOC_Bro:
1696: case MDOC_Brq:
1.107 kristaps 1697: print_text(h, "\\(rC");
1698: break;
1.188 schwarze 1699: case MDOC_Oo:
1700: case MDOC_Op:
1701: case MDOC_Bo:
1702: case MDOC_Bq:
1.107 kristaps 1703: print_text(h, "\\(rB");
1.191 schwarze 1704: break;
1705: case MDOC_En:
1.221 schwarze 1706: if (n->norm->Es == NULL ||
1707: n->norm->Es->child == NULL ||
1708: n->norm->Es->child->next == NULL)
1709: h->flags &= ~HTML_NOSPACE;
1710: else
1.191 schwarze 1711: print_text(h, n->norm->Es->child->next->string);
1.107 kristaps 1712: break;
1.188 schwarze 1713: case MDOC_Qo:
1714: case MDOC_Qq:
1715: case MDOC_Do:
1716: case MDOC_Dq:
1.107 kristaps 1717: print_text(h, "\\(rq");
1718: break;
1.188 schwarze 1719: case MDOC_Po:
1720: case MDOC_Pq:
1.107 kristaps 1721: print_text(h, ")");
1722: break;
1.188 schwarze 1723: case MDOC_Ql:
1724: case MDOC_So:
1725: case MDOC_Sq:
1.183 schwarze 1726: print_text(h, "\\(cq");
1.107 kristaps 1727: break;
1728: default:
1729: abort();
1730: }
1.221 schwarze 1731: }
1732:
1733: static int
1734: mdoc_eo_pre(MDOC_ARGS)
1735: {
1736:
1.227 schwarze 1737: if (n->type != ROFFT_BODY)
1.237 schwarze 1738: return 1;
1.221 schwarze 1739:
1740: if (n->end == ENDBODY_NOT &&
1741: n->parent->head->child == NULL &&
1742: n->child != NULL &&
1743: n->child->end != ENDBODY_NOT)
1744: print_text(h, "\\&");
1745: else if (n->end != ENDBODY_NOT ? n->child != NULL :
1.224 schwarze 1746: n->parent->head->child != NULL && (n->child != NULL ||
1747: (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1.221 schwarze 1748: h->flags |= HTML_NOSPACE;
1.237 schwarze 1749: return 1;
1.221 schwarze 1750: }
1751:
1752: static void
1753: mdoc_eo_post(MDOC_ARGS)
1754: {
1755: int body, tail;
1756:
1.227 schwarze 1757: if (n->type != ROFFT_BODY)
1.221 schwarze 1758: return;
1759:
1760: if (n->end != ENDBODY_NOT) {
1761: h->flags &= ~HTML_NOSPACE;
1762: return;
1763: }
1764:
1765: body = n->child != NULL || n->parent->head->child != NULL;
1766: tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1767:
1768: if (body && tail)
1769: h->flags |= HTML_NOSPACE;
1770: else if ( ! tail)
1771: h->flags &= ~HTML_NOSPACE;
1.107 kristaps 1772: }
CVSweb