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