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