]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
In the SYNOPSIS, .Nm at the beginning of an input line starts
[mandoc.git] / mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.98 2010/07/19 11:11:54 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 #include "mandoc.h"
31 #include "out.h"
32 #include "html.h"
33 #include "mdoc.h"
34 #include "main.h"
35
36 #define INDENT 5
37 #define HALFINDENT 3
38
39 #define MDOC_ARGS const struct mdoc_meta *m, \
40 const struct mdoc_node *n, \
41 struct html *h
42
43 #ifndef MIN
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
45 #endif
46
47 struct htmlmdoc {
48 int (*pre)(MDOC_ARGS);
49 void (*post)(MDOC_ARGS);
50 };
51
52 static void print_mdoc(MDOC_ARGS);
53 static void print_mdoc_head(MDOC_ARGS);
54 static void print_mdoc_node(MDOC_ARGS);
55 static void print_mdoc_nodelist(MDOC_ARGS);
56 static void synopsis_pre(struct html *,
57 const struct mdoc_node *);
58
59 static void a2width(const char *, struct roffsu *);
60 static void a2offs(const char *, struct roffsu *);
61
62 static void mdoc_root_post(MDOC_ARGS);
63 static int mdoc_root_pre(MDOC_ARGS);
64
65 static void mdoc__x_post(MDOC_ARGS);
66 static int mdoc__x_pre(MDOC_ARGS);
67 static int mdoc_ad_pre(MDOC_ARGS);
68 static int mdoc_an_pre(MDOC_ARGS);
69 static int mdoc_ap_pre(MDOC_ARGS);
70 static void mdoc_aq_post(MDOC_ARGS);
71 static int mdoc_aq_pre(MDOC_ARGS);
72 static int mdoc_ar_pre(MDOC_ARGS);
73 static int mdoc_bd_pre(MDOC_ARGS);
74 static int mdoc_bf_pre(MDOC_ARGS);
75 static void mdoc_bk_post(MDOC_ARGS);
76 static int mdoc_bk_pre(MDOC_ARGS);
77 static void mdoc_bl_post(MDOC_ARGS);
78 static int mdoc_bl_pre(MDOC_ARGS);
79 static void mdoc_bq_post(MDOC_ARGS);
80 static int mdoc_bq_pre(MDOC_ARGS);
81 static void mdoc_brq_post(MDOC_ARGS);
82 static int mdoc_brq_pre(MDOC_ARGS);
83 static int mdoc_bt_pre(MDOC_ARGS);
84 static int mdoc_bx_pre(MDOC_ARGS);
85 static int mdoc_cd_pre(MDOC_ARGS);
86 static int mdoc_d1_pre(MDOC_ARGS);
87 static void mdoc_dq_post(MDOC_ARGS);
88 static int mdoc_dq_pre(MDOC_ARGS);
89 static int mdoc_dv_pre(MDOC_ARGS);
90 static int mdoc_fa_pre(MDOC_ARGS);
91 static int mdoc_fd_pre(MDOC_ARGS);
92 static int mdoc_fl_pre(MDOC_ARGS);
93 static int mdoc_fn_pre(MDOC_ARGS);
94 static int mdoc_ft_pre(MDOC_ARGS);
95 static int mdoc_em_pre(MDOC_ARGS);
96 static int mdoc_er_pre(MDOC_ARGS);
97 static int mdoc_ev_pre(MDOC_ARGS);
98 static int mdoc_ex_pre(MDOC_ARGS);
99 static void mdoc_fo_post(MDOC_ARGS);
100 static int mdoc_fo_pre(MDOC_ARGS);
101 static int mdoc_ic_pre(MDOC_ARGS);
102 static int mdoc_in_pre(MDOC_ARGS);
103 static int mdoc_it_block_pre(MDOC_ARGS, enum mdoc_list,
104 int, struct roffsu *, struct roffsu *);
105 static int mdoc_it_head_pre(MDOC_ARGS, enum mdoc_list,
106 struct roffsu *);
107 static int mdoc_it_body_pre(MDOC_ARGS, enum mdoc_list,
108 struct roffsu *);
109 static int mdoc_it_pre(MDOC_ARGS);
110 static int mdoc_lb_pre(MDOC_ARGS);
111 static int mdoc_li_pre(MDOC_ARGS);
112 static int mdoc_lk_pre(MDOC_ARGS);
113 static int mdoc_mt_pre(MDOC_ARGS);
114 static int mdoc_ms_pre(MDOC_ARGS);
115 static int mdoc_nd_pre(MDOC_ARGS);
116 static int mdoc_nm_pre(MDOC_ARGS);
117 static int mdoc_ns_pre(MDOC_ARGS);
118 static void mdoc_op_post(MDOC_ARGS);
119 static int mdoc_op_pre(MDOC_ARGS);
120 static int mdoc_pa_pre(MDOC_ARGS);
121 static void mdoc_pf_post(MDOC_ARGS);
122 static int mdoc_pf_pre(MDOC_ARGS);
123 static void mdoc_pq_post(MDOC_ARGS);
124 static int mdoc_pq_pre(MDOC_ARGS);
125 static int mdoc_rs_pre(MDOC_ARGS);
126 static int mdoc_rv_pre(MDOC_ARGS);
127 static int mdoc_sh_pre(MDOC_ARGS);
128 static int mdoc_sp_pre(MDOC_ARGS);
129 static void mdoc_sq_post(MDOC_ARGS);
130 static int mdoc_sq_pre(MDOC_ARGS);
131 static int mdoc_ss_pre(MDOC_ARGS);
132 static int mdoc_sx_pre(MDOC_ARGS);
133 static int mdoc_sy_pre(MDOC_ARGS);
134 static int mdoc_ud_pre(MDOC_ARGS);
135 static int mdoc_va_pre(MDOC_ARGS);
136 static int mdoc_vt_pre(MDOC_ARGS);
137 static int mdoc_xr_pre(MDOC_ARGS);
138 static int mdoc_xx_pre(MDOC_ARGS);
139
140 static const struct htmlmdoc mdocs[MDOC_MAX] = {
141 {mdoc_ap_pre, NULL}, /* Ap */
142 {NULL, NULL}, /* Dd */
143 {NULL, NULL}, /* Dt */
144 {NULL, NULL}, /* Os */
145 {mdoc_sh_pre, NULL }, /* Sh */
146 {mdoc_ss_pre, NULL }, /* Ss */
147 {mdoc_sp_pre, NULL}, /* Pp */
148 {mdoc_d1_pre, NULL}, /* D1 */
149 {mdoc_d1_pre, NULL}, /* Dl */
150 {mdoc_bd_pre, NULL}, /* Bd */
151 {NULL, NULL}, /* Ed */
152 {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
153 {NULL, NULL}, /* El */
154 {mdoc_it_pre, NULL}, /* It */
155 {mdoc_ad_pre, NULL}, /* Ad */
156 {mdoc_an_pre, NULL}, /* An */
157 {mdoc_ar_pre, NULL}, /* Ar */
158 {mdoc_cd_pre, NULL}, /* Cd */
159 {mdoc_fl_pre, NULL}, /* Cm */
160 {mdoc_dv_pre, NULL}, /* Dv */
161 {mdoc_er_pre, NULL}, /* Er */
162 {mdoc_ev_pre, NULL}, /* Ev */
163 {mdoc_ex_pre, NULL}, /* Ex */
164 {mdoc_fa_pre, NULL}, /* Fa */
165 {mdoc_fd_pre, NULL}, /* Fd */
166 {mdoc_fl_pre, NULL}, /* Fl */
167 {mdoc_fn_pre, NULL}, /* Fn */
168 {mdoc_ft_pre, NULL}, /* Ft */
169 {mdoc_ic_pre, NULL}, /* Ic */
170 {mdoc_in_pre, NULL}, /* In */
171 {mdoc_li_pre, NULL}, /* Li */
172 {mdoc_nd_pre, NULL}, /* Nd */
173 {mdoc_nm_pre, NULL}, /* Nm */
174 {mdoc_op_pre, mdoc_op_post}, /* Op */
175 {NULL, NULL}, /* Ot */
176 {mdoc_pa_pre, NULL}, /* Pa */
177 {mdoc_rv_pre, NULL}, /* Rv */
178 {NULL, NULL}, /* St */
179 {mdoc_va_pre, NULL}, /* Va */
180 {mdoc_vt_pre, NULL}, /* Vt */
181 {mdoc_xr_pre, NULL}, /* Xr */
182 {mdoc__x_pre, mdoc__x_post}, /* %A */
183 {mdoc__x_pre, mdoc__x_post}, /* %B */
184 {mdoc__x_pre, mdoc__x_post}, /* %D */
185 {mdoc__x_pre, mdoc__x_post}, /* %I */
186 {mdoc__x_pre, mdoc__x_post}, /* %J */
187 {mdoc__x_pre, mdoc__x_post}, /* %N */
188 {mdoc__x_pre, mdoc__x_post}, /* %O */
189 {mdoc__x_pre, mdoc__x_post}, /* %P */
190 {mdoc__x_pre, mdoc__x_post}, /* %R */
191 {mdoc__x_pre, mdoc__x_post}, /* %T */
192 {mdoc__x_pre, mdoc__x_post}, /* %V */
193 {NULL, NULL}, /* Ac */
194 {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
195 {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
196 {NULL, NULL}, /* At */
197 {NULL, NULL}, /* Bc */
198 {mdoc_bf_pre, NULL}, /* Bf */
199 {mdoc_bq_pre, mdoc_bq_post}, /* Bo */
200 {mdoc_bq_pre, mdoc_bq_post}, /* Bq */
201 {mdoc_xx_pre, NULL}, /* Bsx */
202 {mdoc_bx_pre, NULL}, /* Bx */
203 {NULL, NULL}, /* Db */
204 {NULL, NULL}, /* Dc */
205 {mdoc_dq_pre, mdoc_dq_post}, /* Do */
206 {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
207 {NULL, NULL}, /* Ec */ /* FIXME: no space */
208 {NULL, NULL}, /* Ef */
209 {mdoc_em_pre, NULL}, /* Em */
210 {NULL, NULL}, /* Eo */
211 {mdoc_xx_pre, NULL}, /* Fx */
212 {mdoc_ms_pre, NULL}, /* Ms */
213 {NULL, NULL}, /* No */
214 {mdoc_ns_pre, NULL}, /* Ns */
215 {mdoc_xx_pre, NULL}, /* Nx */
216 {mdoc_xx_pre, NULL}, /* Ox */
217 {NULL, NULL}, /* Pc */
218 {mdoc_pf_pre, mdoc_pf_post}, /* Pf */
219 {mdoc_pq_pre, mdoc_pq_post}, /* Po */
220 {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
221 {NULL, NULL}, /* Qc */
222 {mdoc_sq_pre, mdoc_sq_post}, /* Ql */
223 {mdoc_dq_pre, mdoc_dq_post}, /* Qo */
224 {mdoc_dq_pre, mdoc_dq_post}, /* Qq */
225 {NULL, NULL}, /* Re */
226 {mdoc_rs_pre, NULL}, /* Rs */
227 {NULL, NULL}, /* Sc */
228 {mdoc_sq_pre, mdoc_sq_post}, /* So */
229 {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
230 {NULL, NULL}, /* Sm */ /* FIXME - no idea. */
231 {mdoc_sx_pre, NULL}, /* Sx */
232 {mdoc_sy_pre, NULL}, /* Sy */
233 {NULL, NULL}, /* Tn */
234 {mdoc_xx_pre, NULL}, /* Ux */
235 {NULL, NULL}, /* Xc */
236 {NULL, NULL}, /* Xo */
237 {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
238 {NULL, NULL}, /* Fc */
239 {mdoc_op_pre, mdoc_op_post}, /* Oo */
240 {NULL, NULL}, /* Oc */
241 {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
242 {NULL, NULL}, /* Ek */
243 {mdoc_bt_pre, NULL}, /* Bt */
244 {NULL, NULL}, /* Hf */
245 {NULL, NULL}, /* Fr */
246 {mdoc_ud_pre, NULL}, /* Ud */
247 {mdoc_lb_pre, NULL}, /* Lb */
248 {mdoc_sp_pre, NULL}, /* Lp */
249 {mdoc_lk_pre, NULL}, /* Lk */
250 {mdoc_mt_pre, NULL}, /* Mt */
251 {mdoc_brq_pre, mdoc_brq_post}, /* Brq */
252 {mdoc_brq_pre, mdoc_brq_post}, /* Bro */
253 {NULL, NULL}, /* Brc */
254 {mdoc__x_pre, mdoc__x_post}, /* %C */
255 {NULL, NULL}, /* Es */ /* TODO */
256 {NULL, NULL}, /* En */ /* TODO */
257 {mdoc_xx_pre, NULL}, /* Dx */
258 {mdoc__x_pre, mdoc__x_post}, /* %Q */
259 {mdoc_sp_pre, NULL}, /* br */
260 {mdoc_sp_pre, NULL}, /* sp */
261 {mdoc__x_pre, mdoc__x_post}, /* %U */
262 {NULL, NULL}, /* Ta */
263 };
264
265
266 void
267 html_mdoc(void *arg, const struct mdoc *m)
268 {
269 struct html *h;
270 struct tag *t;
271
272 h = (struct html *)arg;
273
274 print_gen_decls(h);
275 t = print_otag(h, TAG_HTML, 0, NULL);
276 print_mdoc(mdoc_meta(m), mdoc_node(m), h);
277 print_tagq(h, t);
278
279 printf("\n");
280 }
281
282
283 /*
284 * Calculate the scaling unit passed in a `-width' argument. This uses
285 * either a native scaling unit (e.g., 1i, 2m) or the string length of
286 * the value.
287 */
288 static void
289 a2width(const char *p, struct roffsu *su)
290 {
291
292 if ( ! a2roffsu(p, su, SCALE_MAX)) {
293 su->unit = SCALE_EM;
294 su->scale = (int)strlen(p);
295 }
296 }
297
298
299 /*
300 * See the same function in mdoc_term.c for documentation.
301 */
302 static void
303 synopsis_pre(struct html *h, const struct mdoc_node *n)
304 {
305 struct roffsu su;
306 struct htmlpair tag;
307
308 if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
309 return;
310
311 SCALE_VS_INIT(&su, 1);
312 bufcat_su(h, "margin-top", &su);
313 PAIR_STYLE_INIT(&tag, h);
314
315 if (n->prev->tok == n->tok &&
316 MDOC_Fo != n->tok &&
317 MDOC_Ft != n->tok &&
318 MDOC_Fn != n->tok) {
319 print_otag(h, TAG_DIV, 0, NULL);
320 return;
321 }
322
323 switch (n->prev->tok) {
324 case (MDOC_Fd):
325 /* FALLTHROUGH */
326 case (MDOC_Fn):
327 /* FALLTHROUGH */
328 case (MDOC_Fo):
329 /* FALLTHROUGH */
330 case (MDOC_In):
331 /* FALLTHROUGH */
332 case (MDOC_Vt):
333 print_otag(h, TAG_DIV, 1, &tag);
334 break;
335 case (MDOC_Ft):
336 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
337 print_otag(h, TAG_DIV, 1, &tag);
338 break;
339 }
340 /* FALLTHROUGH */
341 default:
342 print_otag(h, TAG_DIV, 0, NULL);
343 break;
344 }
345 }
346
347
348 /*
349 * Calculate the scaling unit passed in an `-offset' argument. This
350 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
351 * predefined strings (indent, etc.), or the string length of the value.
352 */
353 static void
354 a2offs(const char *p, struct roffsu *su)
355 {
356
357 /* FIXME: "right"? */
358
359 if (0 == strcmp(p, "left"))
360 SCALE_HS_INIT(su, 0);
361 else if (0 == strcmp(p, "indent"))
362 SCALE_HS_INIT(su, INDENT);
363 else if (0 == strcmp(p, "indent-two"))
364 SCALE_HS_INIT(su, INDENT * 2);
365 else if ( ! a2roffsu(p, su, SCALE_MAX)) {
366 su->unit = SCALE_EM;
367 su->scale = (int)strlen(p);
368 }
369 }
370
371
372 static void
373 print_mdoc(MDOC_ARGS)
374 {
375 struct tag *t;
376 struct htmlpair tag;
377
378 t = print_otag(h, TAG_HEAD, 0, NULL);
379 print_mdoc_head(m, n, h);
380 print_tagq(h, t);
381
382 t = print_otag(h, TAG_BODY, 0, NULL);
383
384 tag.key = ATTR_CLASS;
385 tag.val = "body";
386 print_otag(h, TAG_DIV, 1, &tag);
387
388 print_mdoc_nodelist(m, n, h);
389 print_tagq(h, t);
390 }
391
392
393 /* ARGSUSED */
394 static void
395 print_mdoc_head(MDOC_ARGS)
396 {
397
398 print_gen_head(h);
399 bufinit(h);
400 buffmt(h, "%s(%s)", m->title, m->msec);
401
402 if (m->arch) {
403 bufcat(h, " (");
404 bufcat(h, m->arch);
405 bufcat(h, ")");
406 }
407
408 print_otag(h, TAG_TITLE, 0, NULL);
409 print_text(h, h->buf);
410 }
411
412
413 static void
414 print_mdoc_nodelist(MDOC_ARGS)
415 {
416
417 print_mdoc_node(m, n, h);
418 if (n->next)
419 print_mdoc_nodelist(m, n->next, h);
420 }
421
422
423 static void
424 print_mdoc_node(MDOC_ARGS)
425 {
426 int child;
427 struct tag *t;
428
429 child = 1;
430 t = h->tags.head;
431
432 bufinit(h);
433 switch (n->type) {
434 case (MDOC_ROOT):
435 child = mdoc_root_pre(m, n, h);
436 break;
437 case (MDOC_TEXT):
438 print_text(h, n->string);
439 return;
440 default:
441 if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
442 child = (*mdocs[n->tok].pre)(m, n, h);
443 break;
444 }
445
446 if (HTML_KEEP & h->flags) {
447 if (n->prev && n->prev->line != n->line) {
448 h->flags &= ~HTML_KEEP;
449 h->flags |= HTML_PREKEEP;
450 } else if (NULL == n->prev) {
451 if (n->parent && n->parent->line != n->line) {
452 h->flags &= ~HTML_KEEP;
453 h->flags |= HTML_PREKEEP;
454 }
455 }
456 }
457
458 if (child && n->child)
459 print_mdoc_nodelist(m, n->child, h);
460
461 print_stagq(h, t);
462
463 bufinit(h);
464 switch (n->type) {
465 case (MDOC_ROOT):
466 mdoc_root_post(m, n, h);
467 break;
468 default:
469 if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
470 (*mdocs[n->tok].post)(m, n, h);
471 break;
472 }
473 }
474
475
476 /* ARGSUSED */
477 static void
478 mdoc_root_post(MDOC_ARGS)
479 {
480 struct htmlpair tag[3];
481 struct tag *t, *tt;
482 char b[DATESIZ];
483
484 time2a(m->date, b, DATESIZ);
485
486 /*
487 * XXX: this should use divs, but in Firefox, divs with nested
488 * divs for some reason puke when trying to put a border line
489 * below. So I use tables, instead.
490 */
491
492 PAIR_CLASS_INIT(&tag[0], "footer");
493 bufcat_style(h, "width", "100%");
494 PAIR_STYLE_INIT(&tag[1], h);
495 PAIR_SUMMARY_INIT(&tag[2], "footer");
496
497 t = print_otag(h, TAG_TABLE, 3, tag);
498 tt = print_otag(h, TAG_TR, 0, NULL);
499
500 bufinit(h);
501 bufcat_style(h, "width", "50%");
502 PAIR_STYLE_INIT(&tag[0], h);
503 print_otag(h, TAG_TD, 1, tag);
504 print_text(h, b);
505 print_stagq(h, tt);
506
507 bufinit(h);
508 bufcat_style(h, "width", "50%");
509 bufcat_style(h, "text-align", "right");
510 PAIR_STYLE_INIT(&tag[0], h);
511 print_otag(h, TAG_TD, 1, tag);
512 print_text(h, m->os);
513 print_tagq(h, t);
514 }
515
516
517 /* ARGSUSED */
518 static int
519 mdoc_root_pre(MDOC_ARGS)
520 {
521 struct htmlpair tag[3];
522 struct tag *t, *tt;
523 char b[BUFSIZ], title[BUFSIZ];
524
525 (void)strlcpy(b, m->vol, BUFSIZ);
526
527 if (m->arch) {
528 (void)strlcat(b, " (", BUFSIZ);
529 (void)strlcat(b, m->arch, BUFSIZ);
530 (void)strlcat(b, ")", BUFSIZ);
531 }
532
533 (void)snprintf(title, BUFSIZ - 1,
534 "%s(%s)", m->title, m->msec);
535
536 /* XXX: see note in mdoc_root_post() about divs. */
537
538 PAIR_CLASS_INIT(&tag[0], "header");
539 bufcat_style(h, "width", "100%");
540 PAIR_STYLE_INIT(&tag[1], h);
541 PAIR_SUMMARY_INIT(&tag[2], "header");
542
543 t = print_otag(h, TAG_TABLE, 3, tag);
544
545 tt = print_otag(h, TAG_TR, 0, NULL);
546
547 bufinit(h);
548 bufcat_style(h, "width", "10%");
549 PAIR_STYLE_INIT(&tag[0], h);
550 print_otag(h, TAG_TD, 1, tag);
551 print_text(h, title);
552 print_stagq(h, tt);
553
554 bufinit(h);
555 bufcat_style(h, "text-align", "center");
556 bufcat_style(h, "white-space", "nowrap");
557 bufcat_style(h, "width", "80%");
558 PAIR_STYLE_INIT(&tag[0], h);
559 print_otag(h, TAG_TD, 1, tag);
560 print_text(h, b);
561 print_stagq(h, tt);
562
563 bufinit(h);
564 bufcat_style(h, "text-align", "right");
565 bufcat_style(h, "width", "10%");
566 PAIR_STYLE_INIT(&tag[0], h);
567 print_otag(h, TAG_TD, 1, tag);
568 print_text(h, title);
569 print_tagq(h, t);
570 return(1);
571 }
572
573
574 /* ARGSUSED */
575 static int
576 mdoc_sh_pre(MDOC_ARGS)
577 {
578 struct htmlpair tag[2];
579 const struct mdoc_node *nn;
580 char buf[BUFSIZ];
581 struct roffsu su;
582
583 if (MDOC_BODY == n->type) {
584 SCALE_HS_INIT(&su, INDENT);
585 bufcat_su(h, "margin-left", &su);
586 PAIR_CLASS_INIT(&tag[0], "sec-body");
587 PAIR_STYLE_INIT(&tag[1], h);
588 print_otag(h, TAG_DIV, 2, tag);
589 return(1);
590 } else if (MDOC_BLOCK == n->type) {
591 PAIR_CLASS_INIT(&tag[0], "sec-block");
592 if (n->prev && NULL == n->prev->body->child) {
593 print_otag(h, TAG_DIV, 1, tag);
594 return(1);
595 }
596
597 SCALE_VS_INIT(&su, 1);
598 bufcat_su(h, "margin-top", &su);
599 if (NULL == n->next)
600 bufcat_su(h, "margin-bottom", &su);
601
602 PAIR_STYLE_INIT(&tag[1], h);
603 print_otag(h, TAG_DIV, 2, tag);
604 return(1);
605 }
606
607 buf[0] = '\0';
608 for (nn = n->child; nn; nn = nn->next) {
609 html_idcat(buf, nn->string, BUFSIZ);
610 if (nn->next)
611 html_idcat(buf, " ", BUFSIZ);
612 }
613
614 PAIR_CLASS_INIT(&tag[0], "sec-head");
615 PAIR_ID_INIT(&tag[1], buf);
616
617 print_otag(h, TAG_DIV, 2, tag);
618 return(1);
619 }
620
621
622 /* ARGSUSED */
623 static int
624 mdoc_ss_pre(MDOC_ARGS)
625 {
626 struct htmlpair tag[3];
627 const struct mdoc_node *nn;
628 char buf[BUFSIZ];
629 struct roffsu su;
630
631 SCALE_VS_INIT(&su, 1);
632
633 if (MDOC_BODY == n->type) {
634 PAIR_CLASS_INIT(&tag[0], "ssec-body");
635 if (n->parent->next && n->child) {
636 bufcat_su(h, "margin-bottom", &su);
637 PAIR_STYLE_INIT(&tag[1], h);
638 print_otag(h, TAG_DIV, 2, tag);
639 } else
640 print_otag(h, TAG_DIV, 1, tag);
641 return(1);
642 } else if (MDOC_BLOCK == n->type) {
643 PAIR_CLASS_INIT(&tag[0], "ssec-block");
644 if (n->prev) {
645 bufcat_su(h, "margin-top", &su);
646 PAIR_STYLE_INIT(&tag[1], h);
647 print_otag(h, TAG_DIV, 2, tag);
648 } else
649 print_otag(h, TAG_DIV, 1, tag);
650 return(1);
651 }
652
653 /* TODO: see note in mdoc_sh_pre() about duplicates. */
654
655 buf[0] = '\0';
656 for (nn = n->child; nn; nn = nn->next) {
657 html_idcat(buf, nn->string, BUFSIZ);
658 if (nn->next)
659 html_idcat(buf, " ", BUFSIZ);
660 }
661
662 SCALE_HS_INIT(&su, INDENT - HALFINDENT);
663 su.scale = -su.scale;
664 bufcat_su(h, "margin-left", &su);
665
666 PAIR_CLASS_INIT(&tag[0], "ssec-head");
667 PAIR_STYLE_INIT(&tag[1], h);
668 PAIR_ID_INIT(&tag[2], buf);
669
670 print_otag(h, TAG_DIV, 3, tag);
671 return(1);
672 }
673
674
675 /* ARGSUSED */
676 static int
677 mdoc_fl_pre(MDOC_ARGS)
678 {
679 struct htmlpair tag;
680
681 PAIR_CLASS_INIT(&tag, "flag");
682 print_otag(h, TAG_SPAN, 1, &tag);
683
684 /* `Cm' has no leading hyphen. */
685
686 if (MDOC_Cm == n->tok)
687 return(1);
688
689 print_text(h, "\\-");
690
691 if (n->child)
692 h->flags |= HTML_NOSPACE;
693 else if (n->next && n->next->line == n->line)
694 h->flags |= HTML_NOSPACE;
695
696 return(1);
697 }
698
699
700 /* ARGSUSED */
701 static int
702 mdoc_nd_pre(MDOC_ARGS)
703 {
704 struct htmlpair tag;
705
706 if (MDOC_BODY != n->type)
707 return(1);
708
709 /* XXX: this tag in theory can contain block elements. */
710
711 print_text(h, "\\(em");
712 PAIR_CLASS_INIT(&tag, "desc-body");
713 print_otag(h, TAG_SPAN, 1, &tag);
714 return(1);
715 }
716
717
718 /* ARGSUSED */
719 static int
720 mdoc_op_pre(MDOC_ARGS)
721 {
722 struct htmlpair tag;
723
724 if (MDOC_BODY != n->type)
725 return(1);
726
727 /* XXX: this tag in theory can contain block elements. */
728
729 print_text(h, "\\(lB");
730 h->flags |= HTML_NOSPACE;
731 PAIR_CLASS_INIT(&tag, "opt");
732 print_otag(h, TAG_SPAN, 1, &tag);
733 return(1);
734 }
735
736
737 /* ARGSUSED */
738 static void
739 mdoc_op_post(MDOC_ARGS)
740 {
741
742 if (MDOC_BODY != n->type)
743 return;
744 h->flags |= HTML_NOSPACE;
745 print_text(h, "\\(rB");
746 }
747
748
749 static int
750 mdoc_nm_pre(MDOC_ARGS)
751 {
752 struct htmlpair tag;
753 struct roffsu su;
754 const char *cp;
755
756 /*
757 * Accomodate for `Nm' being both an element (which may have
758 * NULL children AND no m->name) and a block.
759 */
760
761 cp = NULL;
762
763 if (MDOC_ELEM == n->type) {
764 if (NULL == n->child && NULL == m->name)
765 return(1);
766 synopsis_pre(h, n);
767 PAIR_CLASS_INIT(&tag, "name");
768 print_otag(h, TAG_SPAN, 1, &tag);
769 if (NULL == n->child)
770 print_text(h, m->name);
771 } else if (MDOC_BLOCK == n->type) {
772 synopsis_pre(h, n);
773
774 bufcat_style(h, "clear", "both");
775 if (n->head->child || m->name) {
776 if (n->head->child && MDOC_TEXT ==
777 n->head->child->type)
778 cp = n->head->child->string;
779 if (NULL == cp || '\0' == *cp)
780 cp = m->name;
781
782 SCALE_HS_INIT(&su, (double)strlen(cp));
783 bufcat_su(h, "padding-left", &su);
784 }
785
786 PAIR_STYLE_INIT(&tag, h);
787 print_otag(h, TAG_DIV, 1, &tag);
788 } else if (MDOC_HEAD == n->type) {
789 if (NULL == n->child && NULL == m->name)
790 return(1);
791
792 if (n->child && MDOC_TEXT == n->child->type)
793 cp = n->child->string;
794 if (NULL == cp || '\0' == *cp)
795 cp = m->name;
796
797 SCALE_HS_INIT(&su, (double)strlen(cp));
798
799 bufcat_style(h, "float", "left");
800 bufcat_su(h, "min-width", &su);
801 SCALE_INVERT(&su);
802 bufcat_su(h, "margin-left", &su);
803
804 PAIR_STYLE_INIT(&tag, h);
805 print_otag(h, TAG_DIV, 1, &tag);
806
807 if (NULL == n->child)
808 print_text(h, m->name);
809 } else if (MDOC_BODY == n->type) {
810 SCALE_HS_INIT(&su, 2);
811 bufcat_su(h, "margin-left", &su);
812 PAIR_STYLE_INIT(&tag, h);
813 print_otag(h, TAG_DIV, 1, &tag);
814 }
815
816 return(1);
817 }
818
819
820 /* ARGSUSED */
821 static int
822 mdoc_xr_pre(MDOC_ARGS)
823 {
824 struct htmlpair tag[2];
825 const struct mdoc_node *nn;
826
827 if (NULL == n->child)
828 return(0);
829
830 PAIR_CLASS_INIT(&tag[0], "link-man");
831
832 if (h->base_man) {
833 buffmt_man(h, n->child->string,
834 n->child->next ?
835 n->child->next->string : NULL);
836 PAIR_HREF_INIT(&tag[1], h->buf);
837 print_otag(h, TAG_A, 2, tag);
838 } else
839 print_otag(h, TAG_A, 1, tag);
840
841 nn = n->child;
842 print_text(h, nn->string);
843
844 if (NULL == (nn = nn->next))
845 return(0);
846
847 h->flags |= HTML_NOSPACE;
848 print_text(h, "(");
849 h->flags |= HTML_NOSPACE;
850 print_text(h, nn->string);
851 h->flags |= HTML_NOSPACE;
852 print_text(h, ")");
853 return(0);
854 }
855
856
857 /* ARGSUSED */
858 static int
859 mdoc_ns_pre(MDOC_ARGS)
860 {
861
862 h->flags |= HTML_NOSPACE;
863 return(1);
864 }
865
866
867 /* ARGSUSED */
868 static int
869 mdoc_ar_pre(MDOC_ARGS)
870 {
871 struct htmlpair tag;
872
873 PAIR_CLASS_INIT(&tag, "arg");
874 print_otag(h, TAG_SPAN, 1, &tag);
875 return(1);
876 }
877
878
879 /* ARGSUSED */
880 static int
881 mdoc_xx_pre(MDOC_ARGS)
882 {
883 const char *pp;
884 struct htmlpair tag;
885
886 switch (n->tok) {
887 case (MDOC_Bsx):
888 pp = "BSDI BSD/OS";
889 break;
890 case (MDOC_Dx):
891 pp = "DragonFly";
892 break;
893 case (MDOC_Fx):
894 pp = "FreeBSD";
895 break;
896 case (MDOC_Nx):
897 pp = "NetBSD";
898 break;
899 case (MDOC_Ox):
900 pp = "OpenBSD";
901 break;
902 case (MDOC_Ux):
903 pp = "UNIX";
904 break;
905 default:
906 return(1);
907 }
908
909 PAIR_CLASS_INIT(&tag, "unix");
910 print_otag(h, TAG_SPAN, 1, &tag);
911 print_text(h, pp);
912 return(1);
913 }
914
915
916 /* ARGSUSED */
917 static int
918 mdoc_bx_pre(MDOC_ARGS)
919 {
920 const struct mdoc_node *nn;
921 struct htmlpair tag;
922
923 PAIR_CLASS_INIT(&tag, "unix");
924 print_otag(h, TAG_SPAN, 1, &tag);
925
926 for (nn = n->child; nn; nn = nn->next)
927 print_mdoc_node(m, nn, h);
928
929 if (n->child)
930 h->flags |= HTML_NOSPACE;
931
932 print_text(h, "BSD");
933 return(0);
934 }
935
936
937 /* ARGSUSED */
938 static int
939 mdoc_it_block_pre(MDOC_ARGS, enum mdoc_list type, int comp,
940 struct roffsu *offs, struct roffsu *width)
941 {
942 struct htmlpair tag;
943 const struct mdoc_node *nn;
944 struct roffsu su;
945
946 nn = n->parent->parent;
947
948 /* XXX: see notes in mdoc_it_pre(). */
949
950 if (LIST_column == type) {
951 /* Don't width-pad on the left. */
952 SCALE_HS_INIT(width, 0);
953 /* Also disallow non-compact. */
954 comp = 1;
955 }
956 if (LIST_diag == type)
957 /* Mandate non-compact with empty prior. */
958 if (n->prev && NULL == n->prev->body->child)
959 comp = 1;
960
961 bufcat_style(h, "clear", "both");
962 if (offs->scale > 0)
963 bufcat_su(h, "margin-left", offs);
964 if (width->scale > 0)
965 bufcat_su(h, "padding-left", width);
966
967 PAIR_STYLE_INIT(&tag, h);
968
969 /* Mandate compact following `Ss' and `Sh' starts. */
970
971 for (nn = n; nn && ! comp; nn = nn->parent) {
972 if (MDOC_BLOCK != nn->type)
973 continue;
974 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
975 comp = 1;
976 if (nn->prev)
977 break;
978 }
979
980 if ( ! comp) {
981 SCALE_VS_INIT(&su, 1);
982 bufcat_su(h, "padding-top", &su);
983 }
984
985 PAIR_STYLE_INIT(&tag, h);
986 print_otag(h, TAG_DIV, 1, &tag);
987 return(1);
988 }
989
990
991 /* ARGSUSED */
992 static int
993 mdoc_it_body_pre(MDOC_ARGS, enum mdoc_list type, struct roffsu *width)
994 {
995 struct htmlpair tag;
996 struct roffsu su;
997
998 switch (type) {
999 case (LIST_item):
1000 /* FALLTHROUGH */
1001 case (LIST_ohang):
1002 /* FALLTHROUGH */
1003 case (LIST_column):
1004 bufcat_su(h, "min-width", width);
1005 bufcat_style(h, "clear", "none");
1006 if (n->next)
1007 bufcat_style(h, "float", "left");
1008 PAIR_STYLE_INIT(&tag, h);
1009 print_otag(h, TAG_DIV, 1, &tag);
1010 break;
1011 default:
1012 /*
1013 * XXX: this tricks CSS into aligning the bodies with
1014 * the right-padding in the head.
1015 */
1016 SCALE_HS_INIT(&su, 2);
1017 bufcat_su(h, "margin-left", &su);
1018 PAIR_STYLE_INIT(&tag, h);
1019 print_otag(h, TAG_DIV, 1, &tag);
1020 break;
1021 }
1022
1023 return(1);
1024 }
1025
1026
1027 /* ARGSUSED */
1028 static int
1029 mdoc_it_head_pre(MDOC_ARGS, enum mdoc_list type, struct roffsu *width)
1030 {
1031 struct htmlpair tag;
1032 struct ord *ord;
1033 char nbuf[BUFSIZ];
1034
1035 switch (type) {
1036 case (LIST_item):
1037 return(0);
1038 case (LIST_ohang):
1039 print_otag(h, TAG_DIV, 0, &tag);
1040 return(1);
1041 case (LIST_column):
1042 break;
1043 default:
1044 bufcat_su(h, "min-width", width);
1045 SCALE_INVERT(width);
1046 bufcat_su(h, "margin-left", width);
1047 if (n->next && n->next->child)
1048 bufcat_style(h, "float", "left");
1049
1050 /* XXX: buffer if we run into body. */
1051 SCALE_HS_INIT(width, 1);
1052 bufcat_su(h, "margin-right", width);
1053 PAIR_STYLE_INIT(&tag, h);
1054 print_otag(h, TAG_DIV, 1, &tag);
1055 break;
1056 }
1057
1058 switch (type) {
1059 case (LIST_diag):
1060 PAIR_CLASS_INIT(&tag, "diag");
1061 print_otag(h, TAG_SPAN, 1, &tag);
1062 break;
1063 case (LIST_enum):
1064 ord = h->ords.head;
1065 assert(ord);
1066 nbuf[BUFSIZ - 1] = 0;
1067 (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
1068 print_text(h, nbuf);
1069 return(0);
1070 case (LIST_dash):
1071 print_text(h, "\\(en");
1072 return(0);
1073 case (LIST_hyphen):
1074 print_text(h, "\\(hy");
1075 return(0);
1076 case (LIST_bullet):
1077 print_text(h, "\\(bu");
1078 return(0);
1079 default:
1080 break;
1081 }
1082
1083 return(1);
1084 }
1085
1086
1087 static int
1088 mdoc_it_pre(MDOC_ARGS)
1089 {
1090 int i, comp;
1091 const struct mdoc_node *bl, *nn;
1092 struct roffsu width, offs;
1093 enum mdoc_list type;
1094
1095 /*
1096 * XXX: be very careful in changing anything, here. Lists in
1097 * mandoc have many peculiarities; furthermore, they don't
1098 * translate well into HTML and require a bit of mangling.
1099 */
1100
1101 bl = n->parent->parent;
1102 if (MDOC_BLOCK != n->type)
1103 bl = bl->parent;
1104
1105 SCALE_HS_INIT(&offs, 0);
1106
1107 assert(bl->data.Bl);
1108 type = bl->data.Bl->type;
1109 comp = bl->data.Bl->comp;
1110
1111 if (bl->data.Bl->offs)
1112 a2offs(bl->data.Bl->offs, &offs);
1113
1114 switch (type) {
1115 case (LIST_enum):
1116 /* FALLTHROUGH */
1117 case (LIST_dash):
1118 /* FALLTHROUGH */
1119 case (LIST_hyphen):
1120 /* FALLTHROUGH */
1121 case (LIST_bullet):
1122 SCALE_HS_INIT(&width, 2);
1123 break;
1124 default:
1125 SCALE_HS_INIT(&width, INDENT);
1126 break;
1127 }
1128
1129 if (bl->data.Bl->width)
1130 a2width(bl->data.Bl->width, &width);
1131
1132 /* Override width in some cases. */
1133
1134 switch (type) {
1135 case (LIST_ohang):
1136 /* FALLTHROUGH */
1137 case (LIST_item):
1138 /* FALLTHROUGH */
1139 case (LIST_inset):
1140 /* FALLTHROUGH */
1141 case (LIST_diag):
1142 SCALE_HS_INIT(&width, 0);
1143 break;
1144 default:
1145 if (0 == width.scale)
1146 SCALE_HS_INIT(&width, INDENT);
1147 break;
1148 }
1149
1150 if (LIST_column == type && MDOC_BODY == n->type) {
1151 nn = n->parent->child;
1152 for (i = 0; nn && nn != n; nn = nn->next)
1153 if (MDOC_BODY == nn->type)
1154 i++;
1155 if (i < (int)bl->data.Bl->ncols)
1156 a2width(bl->data.Bl->cols[i], &width);
1157 }
1158
1159 if (MDOC_HEAD == n->type)
1160 return(mdoc_it_head_pre(m, n, h, type, &width));
1161 else if (MDOC_BODY == n->type)
1162 return(mdoc_it_body_pre(m, n, h, type, &width));
1163
1164 return(mdoc_it_block_pre(m, n, h, type, comp, &offs, &width));
1165 }
1166
1167
1168 /* ARGSUSED */
1169 static int
1170 mdoc_bl_pre(MDOC_ARGS)
1171 {
1172 struct ord *ord;
1173
1174 if (MDOC_HEAD == n->type)
1175 return(0);
1176 if (MDOC_BLOCK != n->type)
1177 return(1);
1178 assert(n->data.Bl);
1179 if (LIST_enum != n->data.Bl->type)
1180 return(1);
1181
1182 ord = malloc(sizeof(struct ord));
1183 if (NULL == ord) {
1184 perror(NULL);
1185 exit(EXIT_FAILURE);
1186 }
1187 ord->cookie = n;
1188 ord->pos = 1;
1189 ord->next = h->ords.head;
1190 h->ords.head = ord;
1191 return(1);
1192 }
1193
1194
1195 /* ARGSUSED */
1196 static void
1197 mdoc_bl_post(MDOC_ARGS)
1198 {
1199 struct ord *ord;
1200
1201 if (MDOC_BLOCK != n->type)
1202 return;
1203 if (LIST_enum != n->data.Bl->type)
1204 return;
1205
1206 ord = h->ords.head;
1207 assert(ord);
1208 h->ords.head = ord->next;
1209 free(ord);
1210 }
1211
1212
1213 /* ARGSUSED */
1214 static int
1215 mdoc_ex_pre(MDOC_ARGS)
1216 {
1217 const struct mdoc_node *nn;
1218 struct tag *t;
1219 struct htmlpair tag;
1220
1221 PAIR_CLASS_INIT(&tag, "utility");
1222
1223 print_text(h, "The");
1224 for (nn = n->child; nn; nn = nn->next) {
1225 t = print_otag(h, TAG_SPAN, 1, &tag);
1226 print_text(h, nn->string);
1227 print_tagq(h, t);
1228
1229 h->flags |= HTML_NOSPACE;
1230
1231 if (nn->next && NULL == nn->next->next)
1232 print_text(h, ", and");
1233 else if (nn->next)
1234 print_text(h, ",");
1235 else
1236 h->flags &= ~HTML_NOSPACE;
1237 }
1238
1239 if (n->child && n->child->next)
1240 print_text(h, "utilities exit");
1241 else
1242 print_text(h, "utility exits");
1243
1244 print_text(h, "0 on success, and >0 if an error occurs.");
1245 return(0);
1246 }
1247
1248
1249 /* ARGSUSED */
1250 static int
1251 mdoc_dq_pre(MDOC_ARGS)
1252 {
1253
1254 if (MDOC_BODY != n->type)
1255 return(1);
1256 print_text(h, "\\(lq");
1257 h->flags |= HTML_NOSPACE;
1258 return(1);
1259 }
1260
1261
1262 /* ARGSUSED */
1263 static void
1264 mdoc_dq_post(MDOC_ARGS)
1265 {
1266
1267 if (MDOC_BODY != n->type)
1268 return;
1269 h->flags |= HTML_NOSPACE;
1270 print_text(h, "\\(rq");
1271 }
1272
1273
1274 /* ARGSUSED */
1275 static int
1276 mdoc_pq_pre(MDOC_ARGS)
1277 {
1278
1279 if (MDOC_BODY != n->type)
1280 return(1);
1281 print_text(h, "\\&(");
1282 h->flags |= HTML_NOSPACE;
1283 return(1);
1284 }
1285
1286
1287 /* ARGSUSED */
1288 static void
1289 mdoc_pq_post(MDOC_ARGS)
1290 {
1291
1292 if (MDOC_BODY != n->type)
1293 return;
1294 print_text(h, ")");
1295 }
1296
1297
1298 /* ARGSUSED */
1299 static int
1300 mdoc_sq_pre(MDOC_ARGS)
1301 {
1302
1303 if (MDOC_BODY != n->type)
1304 return(1);
1305 print_text(h, "\\(oq");
1306 h->flags |= HTML_NOSPACE;
1307 return(1);
1308 }
1309
1310
1311 /* ARGSUSED */
1312 static void
1313 mdoc_sq_post(MDOC_ARGS)
1314 {
1315
1316 if (MDOC_BODY != n->type)
1317 return;
1318 h->flags |= HTML_NOSPACE;
1319 print_text(h, "\\(aq");
1320 }
1321
1322
1323 /* ARGSUSED */
1324 static int
1325 mdoc_em_pre(MDOC_ARGS)
1326 {
1327 struct htmlpair tag;
1328
1329 PAIR_CLASS_INIT(&tag, "emph");
1330 print_otag(h, TAG_SPAN, 1, &tag);
1331 return(1);
1332 }
1333
1334
1335 /* ARGSUSED */
1336 static int
1337 mdoc_d1_pre(MDOC_ARGS)
1338 {
1339 struct htmlpair tag[2];
1340 struct roffsu su;
1341
1342 if (MDOC_BLOCK != n->type)
1343 return(1);
1344
1345 /* FIXME: D1 shouldn't be literal. */
1346
1347 SCALE_VS_INIT(&su, INDENT - 2);
1348 bufcat_su(h, "margin-left", &su);
1349 PAIR_CLASS_INIT(&tag[0], "lit");
1350 PAIR_STYLE_INIT(&tag[1], h);
1351 print_otag(h, TAG_DIV, 2, tag);
1352 return(1);
1353 }
1354
1355
1356 /* ARGSUSED */
1357 static int
1358 mdoc_sx_pre(MDOC_ARGS)
1359 {
1360 struct htmlpair tag[2];
1361 const struct mdoc_node *nn;
1362 char buf[BUFSIZ];
1363
1364 strlcpy(buf, "#", BUFSIZ);
1365 for (nn = n->child; nn; nn = nn->next) {
1366 html_idcat(buf, nn->string, BUFSIZ);
1367 if (nn->next)
1368 html_idcat(buf, " ", BUFSIZ);
1369 }
1370
1371 PAIR_CLASS_INIT(&tag[0], "link-sec");
1372 PAIR_HREF_INIT(&tag[1], buf);
1373
1374 print_otag(h, TAG_A, 2, tag);
1375 return(1);
1376 }
1377
1378
1379 /* ARGSUSED */
1380 static int
1381 mdoc_aq_pre(MDOC_ARGS)
1382 {
1383
1384 if (MDOC_BODY != n->type)
1385 return(1);
1386 print_text(h, "\\(la");
1387 h->flags |= HTML_NOSPACE;
1388 return(1);
1389 }
1390
1391
1392 /* ARGSUSED */
1393 static void
1394 mdoc_aq_post(MDOC_ARGS)
1395 {
1396
1397 if (MDOC_BODY != n->type)
1398 return;
1399 h->flags |= HTML_NOSPACE;
1400 print_text(h, "\\(ra");
1401 }
1402
1403
1404 /* ARGSUSED */
1405 static int
1406 mdoc_bd_pre(MDOC_ARGS)
1407 {
1408 struct htmlpair tag[2];
1409 int comp;
1410 const struct mdoc_node *nn;
1411 struct roffsu su;
1412
1413 if (MDOC_HEAD == n->type)
1414 return(0);
1415
1416 SCALE_VS_INIT(&su, 0);
1417
1418 assert(n->data.Bd);
1419 if (n->data.Bd->offs)
1420 a2offs(n->data.Bd->offs, &su);
1421
1422 comp = n->data.Bd->comp;
1423
1424 /* FIXME: -centered, etc. formatting. */
1425 /* FIXME: does not respect -offset ??? */
1426
1427 if (MDOC_BLOCK == n->type) {
1428 bufcat_su(h, "margin-left", &su);
1429 for (nn = n; nn && ! comp; nn = nn->parent) {
1430 if (MDOC_BLOCK != nn->type)
1431 continue;
1432 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1433 comp = 1;
1434 if (nn->prev)
1435 break;
1436 }
1437 if (comp) {
1438 PAIR_STYLE_INIT(&tag[0], h);
1439 print_otag(h, TAG_DIV, 1, tag);
1440 return(1);
1441 }
1442 SCALE_VS_INIT(&su, 1);
1443 bufcat_su(h, "margin-top", &su);
1444 PAIR_STYLE_INIT(&tag[0], h);
1445 print_otag(h, TAG_DIV, 1, tag);
1446 return(1);
1447 }
1448
1449 if (DISP_unfilled != n->data.Bd->type &&
1450 DISP_literal != n->data.Bd->type)
1451 return(1);
1452
1453 PAIR_CLASS_INIT(&tag[0], "lit");
1454 bufcat_style(h, "white-space", "pre");
1455 PAIR_STYLE_INIT(&tag[1], h);
1456 print_otag(h, TAG_DIV, 2, tag);
1457
1458 for (nn = n->child; nn; nn = nn->next) {
1459 h->flags |= HTML_NOSPACE;
1460 print_mdoc_node(m, nn, h);
1461 if (NULL == nn->next)
1462 continue;
1463 if (nn->prev && nn->prev->line < nn->line)
1464 print_text(h, "\n");
1465 else if (NULL == nn->prev)
1466 print_text(h, "\n");
1467 }
1468
1469 return(0);
1470 }
1471
1472
1473 /* ARGSUSED */
1474 static int
1475 mdoc_pa_pre(MDOC_ARGS)
1476 {
1477 struct htmlpair tag;
1478
1479 PAIR_CLASS_INIT(&tag, "file");
1480 print_otag(h, TAG_SPAN, 1, &tag);
1481 return(1);
1482 }
1483
1484
1485 /* ARGSUSED */
1486 static int
1487 mdoc_ad_pre(MDOC_ARGS)
1488 {
1489 struct htmlpair tag;
1490
1491 PAIR_CLASS_INIT(&tag, "addr");
1492 print_otag(h, TAG_SPAN, 1, &tag);
1493 return(1);
1494 }
1495
1496
1497 /* ARGSUSED */
1498 static int
1499 mdoc_an_pre(MDOC_ARGS)
1500 {
1501 struct htmlpair tag;
1502
1503 /* TODO: -split and -nosplit (see termp_an_pre()). */
1504
1505 PAIR_CLASS_INIT(&tag, "author");
1506 print_otag(h, TAG_SPAN, 1, &tag);
1507 return(1);
1508 }
1509
1510
1511 /* ARGSUSED */
1512 static int
1513 mdoc_cd_pre(MDOC_ARGS)
1514 {
1515 struct htmlpair tag;
1516
1517 synopsis_pre(h, n);
1518 PAIR_CLASS_INIT(&tag, "config");
1519 print_otag(h, TAG_SPAN, 1, &tag);
1520 return(1);
1521 }
1522
1523
1524 /* ARGSUSED */
1525 static int
1526 mdoc_dv_pre(MDOC_ARGS)
1527 {
1528 struct htmlpair tag;
1529
1530 PAIR_CLASS_INIT(&tag, "define");
1531 print_otag(h, TAG_SPAN, 1, &tag);
1532 return(1);
1533 }
1534
1535
1536 /* ARGSUSED */
1537 static int
1538 mdoc_ev_pre(MDOC_ARGS)
1539 {
1540 struct htmlpair tag;
1541
1542 PAIR_CLASS_INIT(&tag, "env");
1543 print_otag(h, TAG_SPAN, 1, &tag);
1544 return(1);
1545 }
1546
1547
1548 /* ARGSUSED */
1549 static int
1550 mdoc_er_pre(MDOC_ARGS)
1551 {
1552 struct htmlpair tag;
1553
1554 PAIR_CLASS_INIT(&tag, "errno");
1555 print_otag(h, TAG_SPAN, 1, &tag);
1556 return(1);
1557 }
1558
1559
1560 /* ARGSUSED */
1561 static int
1562 mdoc_fa_pre(MDOC_ARGS)
1563 {
1564 const struct mdoc_node *nn;
1565 struct htmlpair tag;
1566 struct tag *t;
1567
1568 PAIR_CLASS_INIT(&tag, "farg");
1569 if (n->parent->tok != MDOC_Fo) {
1570 print_otag(h, TAG_SPAN, 1, &tag);
1571 return(1);
1572 }
1573
1574 for (nn = n->child; nn; nn = nn->next) {
1575 t = print_otag(h, TAG_SPAN, 1, &tag);
1576 print_text(h, nn->string);
1577 print_tagq(h, t);
1578 if (nn->next)
1579 print_text(h, ",");
1580 }
1581
1582 if (n->child && n->next && n->next->tok == MDOC_Fa)
1583 print_text(h, ",");
1584
1585 return(0);
1586 }
1587
1588
1589 /* ARGSUSED */
1590 static int
1591 mdoc_fd_pre(MDOC_ARGS)
1592 {
1593 struct htmlpair tag;
1594
1595 synopsis_pre(h, n);
1596
1597 PAIR_CLASS_INIT(&tag, "macro");
1598 print_otag(h, TAG_SPAN, 1, &tag);
1599 return(1);
1600 }
1601
1602
1603 /* ARGSUSED */
1604 static int
1605 mdoc_vt_pre(MDOC_ARGS)
1606 {
1607 struct htmlpair tag;
1608
1609 if (MDOC_BLOCK == n->type) {
1610 synopsis_pre(h, n);
1611 return(1);
1612 } else if (MDOC_ELEM == n->type) {
1613 synopsis_pre(h, n);
1614 } else if (MDOC_HEAD == n->type)
1615 return(0);
1616
1617 PAIR_CLASS_INIT(&tag, "type");
1618 print_otag(h, TAG_SPAN, 1, &tag);
1619 return(1);
1620 }
1621
1622
1623 /* ARGSUSED */
1624 static int
1625 mdoc_ft_pre(MDOC_ARGS)
1626 {
1627 struct htmlpair tag;
1628
1629 synopsis_pre(h, n);
1630 PAIR_CLASS_INIT(&tag, "ftype");
1631 print_otag(h, TAG_SPAN, 1, &tag);
1632 return(1);
1633 }
1634
1635
1636 /* ARGSUSED */
1637 static int
1638 mdoc_fn_pre(MDOC_ARGS)
1639 {
1640 struct tag *t;
1641 struct htmlpair tag[2];
1642 const struct mdoc_node *nn;
1643 char nbuf[BUFSIZ];
1644 const char *sp, *ep;
1645 int sz, i;
1646
1647 synopsis_pre(h, n);
1648
1649 /* Split apart into type and name. */
1650 assert(n->child->string);
1651 sp = n->child->string;
1652
1653 ep = strchr(sp, ' ');
1654 if (NULL != ep) {
1655 PAIR_CLASS_INIT(&tag[0], "ftype");
1656 t = print_otag(h, TAG_SPAN, 1, tag);
1657
1658 while (ep) {
1659 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1660 (void)memcpy(nbuf, sp, (size_t)sz);
1661 nbuf[sz] = '\0';
1662 print_text(h, nbuf);
1663 sp = ++ep;
1664 ep = strchr(sp, ' ');
1665 }
1666 print_tagq(h, t);
1667 }
1668
1669 PAIR_CLASS_INIT(&tag[0], "fname");
1670
1671 /*
1672 * FIXME: only refer to IDs that we know exist.
1673 */
1674
1675 #if 0
1676 if (MDOC_SYNPRETTY & n->flags) {
1677 nbuf[0] = '\0';
1678 html_idcat(nbuf, sp, BUFSIZ);
1679 PAIR_ID_INIT(&tag[1], nbuf);
1680 } else {
1681 strlcpy(nbuf, "#", BUFSIZ);
1682 html_idcat(nbuf, sp, BUFSIZ);
1683 PAIR_HREF_INIT(&tag[1], nbuf);
1684 }
1685 #endif
1686
1687 t = print_otag(h, TAG_SPAN, 1, tag);
1688
1689 if (sp) {
1690 strlcpy(nbuf, sp, BUFSIZ);
1691 print_text(h, nbuf);
1692 }
1693
1694 print_tagq(h, t);
1695
1696 h->flags |= HTML_NOSPACE;
1697 print_text(h, "(");
1698
1699 bufinit(h);
1700 PAIR_CLASS_INIT(&tag[0], "farg");
1701 bufcat_style(h, "white-space", "nowrap");
1702 PAIR_STYLE_INIT(&tag[1], h);
1703
1704 for (nn = n->child->next; nn; nn = nn->next) {
1705 i = 1;
1706 if (MDOC_SYNPRETTY & n->flags)
1707 i = 2;
1708 t = print_otag(h, TAG_SPAN, i, tag);
1709 print_text(h, nn->string);
1710 print_tagq(h, t);
1711 if (nn->next)
1712 print_text(h, ",");
1713 }
1714
1715 print_text(h, ")");
1716 if (MDOC_SYNPRETTY & n->flags)
1717 print_text(h, ";");
1718
1719 return(0);
1720 }
1721
1722
1723 /* ARGSUSED */
1724 static int
1725 mdoc_sp_pre(MDOC_ARGS)
1726 {
1727 int len;
1728 struct htmlpair tag;
1729 struct roffsu su;
1730
1731 switch (n->tok) {
1732 case (MDOC_sp):
1733 /* FIXME: can this have a scaling indicator? */
1734 len = n->child ? atoi(n->child->string) : 1;
1735 break;
1736 case (MDOC_br):
1737 len = 0;
1738 break;
1739 default:
1740 assert(n->parent);
1741 if ((NULL == n->next || NULL == n->prev) &&
1742 (MDOC_Ss == n->parent->tok ||
1743 MDOC_Sh == n->parent->tok))
1744 return(0);
1745 len = 1;
1746 break;
1747 }
1748
1749 SCALE_VS_INIT(&su, len);
1750 bufcat_su(h, "height", &su);
1751 PAIR_STYLE_INIT(&tag, h);
1752 print_otag(h, TAG_DIV, 1, &tag);
1753 /* So the div isn't empty: */
1754 print_text(h, "\\~");
1755
1756 return(0);
1757
1758 }
1759
1760
1761 /* ARGSUSED */
1762 static int
1763 mdoc_brq_pre(MDOC_ARGS)
1764 {
1765
1766 if (MDOC_BODY != n->type)
1767 return(1);
1768 print_text(h, "\\(lC");
1769 h->flags |= HTML_NOSPACE;
1770 return(1);
1771 }
1772
1773
1774 /* ARGSUSED */
1775 static void
1776 mdoc_brq_post(MDOC_ARGS)
1777 {
1778
1779 if (MDOC_BODY != n->type)
1780 return;
1781 h->flags |= HTML_NOSPACE;
1782 print_text(h, "\\(rC");
1783 }
1784
1785
1786 /* ARGSUSED */
1787 static int
1788 mdoc_lk_pre(MDOC_ARGS)
1789 {
1790 const struct mdoc_node *nn;
1791 struct htmlpair tag[2];
1792
1793 nn = n->child;
1794
1795 PAIR_CLASS_INIT(&tag[0], "link-ext");
1796 PAIR_HREF_INIT(&tag[1], nn->string);
1797 print_otag(h, TAG_A, 2, tag);
1798
1799 if (NULL == nn->next)
1800 return(1);
1801
1802 for (nn = nn->next; nn; nn = nn->next)
1803 print_text(h, nn->string);
1804
1805 return(0);
1806 }
1807
1808
1809 /* ARGSUSED */
1810 static int
1811 mdoc_mt_pre(MDOC_ARGS)
1812 {
1813 struct htmlpair tag[2];
1814 struct tag *t;
1815 const struct mdoc_node *nn;
1816
1817 PAIR_CLASS_INIT(&tag[0], "link-mail");
1818
1819 for (nn = n->child; nn; nn = nn->next) {
1820 bufinit(h);
1821 bufcat(h, "mailto:");
1822 bufcat(h, nn->string);
1823 PAIR_HREF_INIT(&tag[1], h->buf);
1824 t = print_otag(h, TAG_A, 2, tag);
1825 print_text(h, nn->string);
1826 print_tagq(h, t);
1827 }
1828
1829 return(0);
1830 }
1831
1832
1833 /* ARGSUSED */
1834 static int
1835 mdoc_fo_pre(MDOC_ARGS)
1836 {
1837 struct htmlpair tag;
1838 struct tag *t;
1839
1840 if (MDOC_BODY == n->type) {
1841 h->flags |= HTML_NOSPACE;
1842 print_text(h, "(");
1843 h->flags |= HTML_NOSPACE;
1844 return(1);
1845 } else if (MDOC_BLOCK == n->type) {
1846 synopsis_pre(h, n);
1847 return(1);
1848 }
1849
1850 /* XXX: we drop non-initial arguments as per groff. */
1851
1852 assert(n->child);
1853 assert(n->child->string);
1854
1855 PAIR_CLASS_INIT(&tag, "fname");
1856 t = print_otag(h, TAG_SPAN, 1, &tag);
1857 print_text(h, n->child->string);
1858 print_tagq(h, t);
1859 return(0);
1860 }
1861
1862
1863 /* ARGSUSED */
1864 static void
1865 mdoc_fo_post(MDOC_ARGS)
1866 {
1867
1868 if (MDOC_BODY != n->type)
1869 return;
1870 h->flags |= HTML_NOSPACE;
1871 print_text(h, ")");
1872 h->flags |= HTML_NOSPACE;
1873 print_text(h, ";");
1874 }
1875
1876
1877 /* ARGSUSED */
1878 static int
1879 mdoc_in_pre(MDOC_ARGS)
1880 {
1881 const struct mdoc_node *nn;
1882 struct tag *t;
1883 struct htmlpair tag[2];
1884 int i;
1885
1886 synopsis_pre(h, n);
1887
1888 PAIR_CLASS_INIT(&tag[0], "includes");
1889 print_otag(h, TAG_SPAN, 1, tag);
1890
1891 if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1892 print_text(h, "#include");
1893
1894 print_text(h, "<");
1895 h->flags |= HTML_NOSPACE;
1896
1897 for (nn = n->child; nn; nn = nn->next) {
1898 PAIR_CLASS_INIT(&tag[0], "link-includes");
1899 i = 1;
1900 bufinit(h);
1901 if (h->base_includes) {
1902 buffmt_includes(h, nn->string);
1903 PAIR_HREF_INIT(&tag[i], h->buf);
1904 i++;
1905 }
1906 t = print_otag(h, TAG_A, i, tag);
1907 print_mdoc_node(m, nn, h);
1908 print_tagq(h, t);
1909 }
1910
1911 h->flags |= HTML_NOSPACE;
1912 print_text(h, ">");
1913
1914 return(0);
1915 }
1916
1917
1918 /* ARGSUSED */
1919 static int
1920 mdoc_ic_pre(MDOC_ARGS)
1921 {
1922 struct htmlpair tag;
1923
1924 PAIR_CLASS_INIT(&tag, "cmd");
1925 print_otag(h, TAG_SPAN, 1, &tag);
1926 return(1);
1927 }
1928
1929
1930 /* ARGSUSED */
1931 static int
1932 mdoc_rv_pre(MDOC_ARGS)
1933 {
1934 const struct mdoc_node *nn;
1935 struct htmlpair tag;
1936 struct tag *t;
1937
1938 print_otag(h, TAG_DIV, 0, NULL);
1939 print_text(h, "The");
1940
1941 for (nn = n->child; nn; nn = nn->next) {
1942 PAIR_CLASS_INIT(&tag, "fname");
1943 t = print_otag(h, TAG_SPAN, 1, &tag);
1944 print_text(h, nn->string);
1945 print_tagq(h, t);
1946
1947 h->flags |= HTML_NOSPACE;
1948 if (nn->next && NULL == nn->next->next)
1949 print_text(h, "(), and");
1950 else if (nn->next)
1951 print_text(h, "(),");
1952 else
1953 print_text(h, "()");
1954 }
1955
1956 if (n->child && n->child->next)
1957 print_text(h, "functions return");
1958 else
1959 print_text(h, "function returns");
1960
1961 print_text(h, "the value 0 if successful; otherwise the value "
1962 "-1 is returned and the global variable");
1963
1964 PAIR_CLASS_INIT(&tag, "var");
1965 t = print_otag(h, TAG_SPAN, 1, &tag);
1966 print_text(h, "errno");
1967 print_tagq(h, t);
1968 print_text(h, "is set to indicate the error.");
1969 return(0);
1970 }
1971
1972
1973 /* ARGSUSED */
1974 static int
1975 mdoc_va_pre(MDOC_ARGS)
1976 {
1977 struct htmlpair tag;
1978
1979 PAIR_CLASS_INIT(&tag, "var");
1980 print_otag(h, TAG_SPAN, 1, &tag);
1981 return(1);
1982 }
1983
1984
1985 /* ARGSUSED */
1986 static int
1987 mdoc_bq_pre(MDOC_ARGS)
1988 {
1989
1990 if (MDOC_BODY != n->type)
1991 return(1);
1992 print_text(h, "\\(lB");
1993 h->flags |= HTML_NOSPACE;
1994 return(1);
1995 }
1996
1997
1998 /* ARGSUSED */
1999 static void
2000 mdoc_bq_post(MDOC_ARGS)
2001 {
2002
2003 if (MDOC_BODY != n->type)
2004 return;
2005 h->flags |= HTML_NOSPACE;
2006 print_text(h, "\\(rB");
2007 }
2008
2009
2010 /* ARGSUSED */
2011 static int
2012 mdoc_ap_pre(MDOC_ARGS)
2013 {
2014
2015 h->flags |= HTML_NOSPACE;
2016 print_text(h, "\\(aq");
2017 h->flags |= HTML_NOSPACE;
2018 return(1);
2019 }
2020
2021
2022 /* ARGSUSED */
2023 static int
2024 mdoc_bf_pre(MDOC_ARGS)
2025 {
2026 struct htmlpair tag[2];
2027 struct roffsu su;
2028
2029 if (MDOC_HEAD == n->type)
2030 return(0);
2031 else if (MDOC_BODY != n->type)
2032 return(1);
2033
2034 assert(n->data.Bf);
2035
2036 if (FONT_Em == n->data.Bf->font)
2037 PAIR_CLASS_INIT(&tag[0], "emph");
2038 else if (FONT_Sy == n->data.Bf->font)
2039 PAIR_CLASS_INIT(&tag[0], "symb");
2040 else if (FONT_Li == n->data.Bf->font)
2041 PAIR_CLASS_INIT(&tag[0], "lit");
2042 else
2043 PAIR_CLASS_INIT(&tag[0], "none");
2044
2045 /*
2046 * We want this to be inline-formatted, but needs to be div to
2047 * accept block children.
2048 */
2049 bufcat_style(h, "display", "inline");
2050 SCALE_HS_INIT(&su, 1);
2051 /* Needs a left-margin for spacing. */
2052 bufcat_su(h, "margin-left", &su);
2053 PAIR_STYLE_INIT(&tag[1], h);
2054 print_otag(h, TAG_DIV, 2, tag);
2055 return(1);
2056 }
2057
2058
2059 /* ARGSUSED */
2060 static int
2061 mdoc_ms_pre(MDOC_ARGS)
2062 {
2063 struct htmlpair tag;
2064
2065 PAIR_CLASS_INIT(&tag, "symb");
2066 print_otag(h, TAG_SPAN, 1, &tag);
2067 return(1);
2068 }
2069
2070
2071 /* ARGSUSED */
2072 static int
2073 mdoc_pf_pre(MDOC_ARGS)
2074 {
2075
2076 h->flags |= HTML_IGNDELIM;
2077 return(1);
2078 }
2079
2080
2081 /* ARGSUSED */
2082 static void
2083 mdoc_pf_post(MDOC_ARGS)
2084 {
2085
2086 h->flags &= ~HTML_IGNDELIM;
2087 h->flags |= HTML_NOSPACE;
2088 }
2089
2090
2091 /* ARGSUSED */
2092 static int
2093 mdoc_rs_pre(MDOC_ARGS)
2094 {
2095 struct htmlpair tag;
2096 struct roffsu su;
2097
2098 if (MDOC_BLOCK != n->type)
2099 return(1);
2100
2101 if (n->prev && SEC_SEE_ALSO == n->sec) {
2102 SCALE_VS_INIT(&su, 1);
2103 bufcat_su(h, "margin-top", &su);
2104 PAIR_STYLE_INIT(&tag, h);
2105 print_otag(h, TAG_DIV, 1, &tag);
2106 }
2107
2108 PAIR_CLASS_INIT(&tag, "ref");
2109 print_otag(h, TAG_SPAN, 1, &tag);
2110 return(1);
2111 }
2112
2113
2114
2115 /* ARGSUSED */
2116 static int
2117 mdoc_li_pre(MDOC_ARGS)
2118 {
2119 struct htmlpair tag;
2120
2121 PAIR_CLASS_INIT(&tag, "lit");
2122 print_otag(h, TAG_SPAN, 1, &tag);
2123 return(1);
2124 }
2125
2126
2127 /* ARGSUSED */
2128 static int
2129 mdoc_sy_pre(MDOC_ARGS)
2130 {
2131 struct htmlpair tag;
2132
2133 PAIR_CLASS_INIT(&tag, "symb");
2134 print_otag(h, TAG_SPAN, 1, &tag);
2135 return(1);
2136 }
2137
2138
2139 /* ARGSUSED */
2140 static int
2141 mdoc_bt_pre(MDOC_ARGS)
2142 {
2143
2144 print_text(h, "is currently in beta test.");
2145 return(0);
2146 }
2147
2148
2149 /* ARGSUSED */
2150 static int
2151 mdoc_ud_pre(MDOC_ARGS)
2152 {
2153
2154 print_text(h, "currently under development.");
2155 return(0);
2156 }
2157
2158
2159 /* ARGSUSED */
2160 static int
2161 mdoc_lb_pre(MDOC_ARGS)
2162 {
2163 struct htmlpair tag;
2164
2165 if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
2166 print_otag(h, TAG_DIV, 0, NULL);
2167 PAIR_CLASS_INIT(&tag, "lib");
2168 print_otag(h, TAG_SPAN, 1, &tag);
2169 return(1);
2170 }
2171
2172
2173 /* ARGSUSED */
2174 static int
2175 mdoc__x_pre(MDOC_ARGS)
2176 {
2177 struct htmlpair tag[2];
2178
2179 switch (n->tok) {
2180 case(MDOC__A):
2181 PAIR_CLASS_INIT(&tag[0], "ref-auth");
2182 break;
2183 case(MDOC__B):
2184 PAIR_CLASS_INIT(&tag[0], "ref-book");
2185 break;
2186 case(MDOC__C):
2187 PAIR_CLASS_INIT(&tag[0], "ref-city");
2188 break;
2189 case(MDOC__D):
2190 PAIR_CLASS_INIT(&tag[0], "ref-date");
2191 break;
2192 case(MDOC__I):
2193 PAIR_CLASS_INIT(&tag[0], "ref-issue");
2194 break;
2195 case(MDOC__J):
2196 PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
2197 break;
2198 case(MDOC__N):
2199 PAIR_CLASS_INIT(&tag[0], "ref-num");
2200 break;
2201 case(MDOC__O):
2202 PAIR_CLASS_INIT(&tag[0], "ref-opt");
2203 break;
2204 case(MDOC__P):
2205 PAIR_CLASS_INIT(&tag[0], "ref-page");
2206 break;
2207 case(MDOC__Q):
2208 PAIR_CLASS_INIT(&tag[0], "ref-corp");
2209 break;
2210 case(MDOC__R):
2211 PAIR_CLASS_INIT(&tag[0], "ref-rep");
2212 break;
2213 case(MDOC__T):
2214 PAIR_CLASS_INIT(&tag[0], "ref-title");
2215 break;
2216 case(MDOC__U):
2217 PAIR_CLASS_INIT(&tag[0], "link-ref");
2218 break;
2219 case(MDOC__V):
2220 PAIR_CLASS_INIT(&tag[0], "ref-vol");
2221 break;
2222 default:
2223 abort();
2224 /* NOTREACHED */
2225 }
2226
2227 if (MDOC__U != n->tok) {
2228 print_otag(h, TAG_SPAN, 1, tag);
2229 return(1);
2230 }
2231
2232 PAIR_HREF_INIT(&tag[1], n->child->string);
2233 print_otag(h, TAG_A, 2, tag);
2234 return(1);
2235 }
2236
2237
2238 /* ARGSUSED */
2239 static void
2240 mdoc__x_post(MDOC_ARGS)
2241 {
2242
2243 /* TODO: %U */
2244
2245 h->flags |= HTML_NOSPACE;
2246 print_text(h, n->next ? "," : ".");
2247 }
2248
2249
2250 /* ARGSUSED */
2251 static int
2252 mdoc_bk_pre(MDOC_ARGS)
2253 {
2254
2255 switch (n->type) {
2256 case (MDOC_BLOCK):
2257 break;
2258 case (MDOC_HEAD):
2259 return(0);
2260 case (MDOC_BODY):
2261 h->flags |= HTML_PREKEEP;
2262 break;
2263 default:
2264 abort();
2265 /* NOTREACHED */
2266 }
2267
2268 return(1);
2269 }
2270
2271
2272 /* ARGSUSED */
2273 static void
2274 mdoc_bk_post(MDOC_ARGS)
2275 {
2276
2277 if (MDOC_BODY == n->type)
2278 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
2279 }