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