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