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