]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
For -man -Thtml, ignore author-specified .HP widths because they
[mandoc.git] / mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.306 2018/06/10 16:15:43 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
28
29 #include "mandoc_aux.h"
30 #include "mandoc.h"
31 #include "roff.h"
32 #include "mdoc.h"
33 #include "out.h"
34 #include "html.h"
35 #include "main.h"
36
37 #define INDENT 5
38
39 #define MDOC_ARGS const struct roff_meta *meta, \
40 struct roff_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 char *cond_id(const struct roff_node *);
53 static void print_mdoc_head(const struct roff_meta *,
54 struct html *);
55 static void print_mdoc_node(MDOC_ARGS);
56 static void print_mdoc_nodelist(MDOC_ARGS);
57 static void synopsis_pre(struct html *,
58 const struct roff_node *);
59
60 static void mdoc_root_post(const struct roff_meta *,
61 struct html *);
62 static int mdoc_root_pre(const struct roff_meta *,
63 struct html *);
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_cd_pre(MDOC_ARGS);
77 static int mdoc_cm_pre(MDOC_ARGS);
78 static int mdoc_d1_pre(MDOC_ARGS);
79 static int mdoc_dv_pre(MDOC_ARGS);
80 static int mdoc_fa_pre(MDOC_ARGS);
81 static int mdoc_fd_pre(MDOC_ARGS);
82 static int mdoc_fl_pre(MDOC_ARGS);
83 static int mdoc_fn_pre(MDOC_ARGS);
84 static int mdoc_ft_pre(MDOC_ARGS);
85 static int mdoc_em_pre(MDOC_ARGS);
86 static void mdoc_eo_post(MDOC_ARGS);
87 static int mdoc_eo_pre(MDOC_ARGS);
88 static int mdoc_er_pre(MDOC_ARGS);
89 static int mdoc_ev_pre(MDOC_ARGS);
90 static int mdoc_ex_pre(MDOC_ARGS);
91 static void mdoc_fo_post(MDOC_ARGS);
92 static int mdoc_fo_pre(MDOC_ARGS);
93 static int mdoc_ic_pre(MDOC_ARGS);
94 static int mdoc_igndelim_pre(MDOC_ARGS);
95 static int mdoc_in_pre(MDOC_ARGS);
96 static int mdoc_it_pre(MDOC_ARGS);
97 static int mdoc_lb_pre(MDOC_ARGS);
98 static int mdoc_li_pre(MDOC_ARGS);
99 static int mdoc_lk_pre(MDOC_ARGS);
100 static int mdoc_mt_pre(MDOC_ARGS);
101 static int mdoc_ms_pre(MDOC_ARGS);
102 static int mdoc_nd_pre(MDOC_ARGS);
103 static int mdoc_nm_pre(MDOC_ARGS);
104 static int mdoc_no_pre(MDOC_ARGS);
105 static int mdoc_ns_pre(MDOC_ARGS);
106 static int mdoc_pa_pre(MDOC_ARGS);
107 static void mdoc_pf_post(MDOC_ARGS);
108 static int mdoc_pp_pre(MDOC_ARGS);
109 static void mdoc_quote_post(MDOC_ARGS);
110 static int mdoc_quote_pre(MDOC_ARGS);
111 static int mdoc_rs_pre(MDOC_ARGS);
112 static int mdoc_sh_pre(MDOC_ARGS);
113 static int mdoc_skip_pre(MDOC_ARGS);
114 static int mdoc_sm_pre(MDOC_ARGS);
115 static int mdoc_ss_pre(MDOC_ARGS);
116 static int mdoc_st_pre(MDOC_ARGS);
117 static int mdoc_sx_pre(MDOC_ARGS);
118 static int mdoc_sy_pre(MDOC_ARGS);
119 static int mdoc_va_pre(MDOC_ARGS);
120 static int mdoc_vt_pre(MDOC_ARGS);
121 static int mdoc_xr_pre(MDOC_ARGS);
122 static int mdoc_xx_pre(MDOC_ARGS);
123
124 static const struct htmlmdoc __mdocs[MDOC_MAX - MDOC_Dd] = {
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_ap_pre, NULL}, /* Ap */
141 {mdoc_ar_pre, NULL}, /* Ar */
142 {mdoc_cd_pre, NULL}, /* Cd */
143 {mdoc_cm_pre, NULL}, /* Cm */
144 {mdoc_dv_pre, NULL}, /* Dv */
145 {mdoc_er_pre, NULL}, /* Er */
146 {mdoc_ev_pre, NULL}, /* Ev */
147 {mdoc_ex_pre, NULL}, /* Ex */
148 {mdoc_fa_pre, NULL}, /* Fa */
149 {mdoc_fd_pre, NULL}, /* Fd */
150 {mdoc_fl_pre, NULL}, /* Fl */
151 {mdoc_fn_pre, NULL}, /* Fn */
152 {mdoc_ft_pre, NULL}, /* Ft */
153 {mdoc_ic_pre, NULL}, /* Ic */
154 {mdoc_in_pre, NULL}, /* In */
155 {mdoc_li_pre, NULL}, /* Li */
156 {mdoc_nd_pre, NULL}, /* Nd */
157 {mdoc_nm_pre, NULL}, /* Nm */
158 {mdoc_quote_pre, mdoc_quote_post}, /* Op */
159 {mdoc_ft_pre, NULL}, /* Ot */
160 {mdoc_pa_pre, NULL}, /* Pa */
161 {mdoc_ex_pre, NULL}, /* Rv */
162 {mdoc_st_pre, NULL}, /* St */
163 {mdoc_va_pre, NULL}, /* Va */
164 {mdoc_vt_pre, NULL}, /* Vt */
165 {mdoc_xr_pre, NULL}, /* Xr */
166 {mdoc__x_pre, mdoc__x_post}, /* %A */
167 {mdoc__x_pre, mdoc__x_post}, /* %B */
168 {mdoc__x_pre, mdoc__x_post}, /* %D */
169 {mdoc__x_pre, mdoc__x_post}, /* %I */
170 {mdoc__x_pre, mdoc__x_post}, /* %J */
171 {mdoc__x_pre, mdoc__x_post}, /* %N */
172 {mdoc__x_pre, mdoc__x_post}, /* %O */
173 {mdoc__x_pre, mdoc__x_post}, /* %P */
174 {mdoc__x_pre, mdoc__x_post}, /* %R */
175 {mdoc__x_pre, mdoc__x_post}, /* %T */
176 {mdoc__x_pre, mdoc__x_post}, /* %V */
177 {NULL, NULL}, /* Ac */
178 {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
179 {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
180 {mdoc_xx_pre, NULL}, /* At */
181 {NULL, NULL}, /* Bc */
182 {mdoc_bf_pre, NULL}, /* Bf */
183 {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
184 {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
185 {mdoc_xx_pre, NULL}, /* Bsx */
186 {mdoc_xx_pre, NULL}, /* Bx */
187 {mdoc_skip_pre, NULL}, /* Db */
188 {NULL, NULL}, /* Dc */
189 {mdoc_quote_pre, mdoc_quote_post}, /* Do */
190 {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
191 {NULL, NULL}, /* Ec */ /* FIXME: no space */
192 {NULL, NULL}, /* Ef */
193 {mdoc_em_pre, NULL}, /* Em */
194 {mdoc_eo_pre, mdoc_eo_post}, /* Eo */
195 {mdoc_xx_pre, NULL}, /* Fx */
196 {mdoc_ms_pre, NULL}, /* Ms */
197 {mdoc_no_pre, NULL}, /* No */
198 {mdoc_ns_pre, NULL}, /* Ns */
199 {mdoc_xx_pre, NULL}, /* Nx */
200 {mdoc_xx_pre, NULL}, /* Ox */
201 {NULL, NULL}, /* Pc */
202 {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
203 {mdoc_quote_pre, mdoc_quote_post}, /* Po */
204 {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
205 {NULL, NULL}, /* Qc */
206 {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
207 {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
208 {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
209 {NULL, NULL}, /* Re */
210 {mdoc_rs_pre, NULL}, /* Rs */
211 {NULL, NULL}, /* Sc */
212 {mdoc_quote_pre, mdoc_quote_post}, /* So */
213 {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
214 {mdoc_sm_pre, NULL}, /* Sm */
215 {mdoc_sx_pre, NULL}, /* Sx */
216 {mdoc_sy_pre, NULL}, /* Sy */
217 {NULL, NULL}, /* Tn */
218 {mdoc_xx_pre, NULL}, /* Ux */
219 {NULL, NULL}, /* Xc */
220 {NULL, NULL}, /* Xo */
221 {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
222 {NULL, NULL}, /* Fc */
223 {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
224 {NULL, NULL}, /* Oc */
225 {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
226 {NULL, NULL}, /* Ek */
227 {NULL, NULL}, /* Bt */
228 {NULL, NULL}, /* Hf */
229 {mdoc_em_pre, NULL}, /* Fr */
230 {NULL, NULL}, /* Ud */
231 {mdoc_lb_pre, NULL}, /* Lb */
232 {mdoc_pp_pre, NULL}, /* Lp */
233 {mdoc_lk_pre, NULL}, /* Lk */
234 {mdoc_mt_pre, NULL}, /* Mt */
235 {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
236 {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
237 {NULL, NULL}, /* Brc */
238 {mdoc__x_pre, mdoc__x_post}, /* %C */
239 {mdoc_skip_pre, NULL}, /* Es */
240 {mdoc_quote_pre, mdoc_quote_post}, /* En */
241 {mdoc_xx_pre, NULL}, /* Dx */
242 {mdoc__x_pre, mdoc__x_post}, /* %Q */
243 {mdoc__x_pre, mdoc__x_post}, /* %U */
244 {NULL, NULL}, /* Ta */
245 };
246 static const struct htmlmdoc *const mdocs = __mdocs - MDOC_Dd;
247
248
249 /*
250 * See the same function in mdoc_term.c for documentation.
251 */
252 static void
253 synopsis_pre(struct html *h, const struct roff_node *n)
254 {
255
256 if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
257 return;
258
259 if (n->prev->tok == n->tok &&
260 MDOC_Fo != n->tok &&
261 MDOC_Ft != n->tok &&
262 MDOC_Fn != n->tok) {
263 print_otag(h, TAG_BR, "");
264 return;
265 }
266
267 switch (n->prev->tok) {
268 case MDOC_Fd:
269 case MDOC_Fn:
270 case MDOC_Fo:
271 case MDOC_In:
272 case MDOC_Vt:
273 print_paragraph(h);
274 break;
275 case MDOC_Ft:
276 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
277 print_paragraph(h);
278 break;
279 }
280 /* FALLTHROUGH */
281 default:
282 print_otag(h, TAG_BR, "");
283 break;
284 }
285 }
286
287 void
288 html_mdoc(void *arg, const struct roff_man *mdoc)
289 {
290 struct html *h;
291 struct roff_node *n;
292 struct tag *t;
293
294 h = (struct html *)arg;
295 n = mdoc->first->child;
296
297 if ((h->oflags & HTML_FRAGMENT) == 0) {
298 print_gen_decls(h);
299 print_otag(h, TAG_HTML, "");
300 if (n->type == ROFFT_COMMENT)
301 print_gen_comment(h, n);
302 t = print_otag(h, TAG_HEAD, "");
303 print_mdoc_head(&mdoc->meta, h);
304 print_tagq(h, t);
305 print_otag(h, TAG_BODY, "");
306 }
307
308 mdoc_root_pre(&mdoc->meta, h);
309 t = print_otag(h, TAG_DIV, "c", "manual-text");
310 print_mdoc_nodelist(&mdoc->meta, n, h);
311 print_tagq(h, t);
312 mdoc_root_post(&mdoc->meta, h);
313 print_tagq(h, NULL);
314 }
315
316 static void
317 print_mdoc_head(const struct roff_meta *meta, struct html *h)
318 {
319 char *cp;
320
321 print_gen_head(h);
322
323 if (meta->arch != NULL && meta->msec != NULL)
324 mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title,
325 meta->msec, meta->arch);
326 else if (meta->msec != NULL)
327 mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec);
328 else if (meta->arch != NULL)
329 mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch);
330 else
331 cp = mandoc_strdup(meta->title);
332
333 print_otag(h, TAG_TITLE, "");
334 print_text(h, cp);
335 free(cp);
336 }
337
338 static void
339 print_mdoc_nodelist(MDOC_ARGS)
340 {
341
342 while (n != NULL) {
343 print_mdoc_node(meta, n, h);
344 n = n->next;
345 }
346 }
347
348 static void
349 print_mdoc_node(MDOC_ARGS)
350 {
351 int child;
352 struct tag *t;
353
354 if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
355 return;
356
357 child = 1;
358 t = h->tag;
359 n->flags &= ~NODE_ENDED;
360
361 switch (n->type) {
362 case ROFFT_TEXT:
363 /* No tables in this mode... */
364 assert(NULL == h->tblt);
365
366 /*
367 * Make sure that if we're in a literal mode already
368 * (i.e., within a <PRE>) don't print the newline.
369 */
370 if (*n->string == ' ' && n->flags & NODE_LINE &&
371 (h->flags & (HTML_LITERAL | HTML_NONEWLINE)) == 0)
372 print_otag(h, TAG_BR, "");
373 if (NODE_DELIMC & n->flags)
374 h->flags |= HTML_NOSPACE;
375 print_text(h, n->string);
376 if (NODE_DELIMO & n->flags)
377 h->flags |= HTML_NOSPACE;
378 return;
379 case ROFFT_EQN:
380 print_eqn(h, n->eqn);
381 break;
382 case ROFFT_TBL:
383 /*
384 * This will take care of initialising all of the table
385 * state data for the first table, then tearing it down
386 * for the last one.
387 */
388 print_tbl(h, n->span);
389 return;
390 default:
391 /*
392 * Close out the current table, if it's open, and unset
393 * the "meta" table state. This will be reopened on the
394 * next table element.
395 */
396 if (h->tblt != NULL) {
397 print_tblclose(h);
398 t = h->tag;
399 }
400 assert(h->tblt == NULL);
401 if (n->tok < ROFF_MAX) {
402 roff_html_pre(h, n);
403 child = 0;
404 break;
405 }
406 assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
407 if (mdocs[n->tok].pre != NULL &&
408 (n->end == ENDBODY_NOT || n->child != NULL))
409 child = (*mdocs[n->tok].pre)(meta, n, h);
410 break;
411 }
412
413 if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
414 h->flags &= ~HTML_KEEP;
415 h->flags |= HTML_PREKEEP;
416 }
417
418 if (child && n->child)
419 print_mdoc_nodelist(meta, n->child, h);
420
421 print_stagq(h, t);
422
423 switch (n->type) {
424 case ROFFT_EQN:
425 break;
426 default:
427 if (n->tok < ROFF_MAX ||
428 mdocs[n->tok].post == NULL ||
429 n->flags & NODE_ENDED)
430 break;
431 (*mdocs[n->tok].post)(meta, n, h);
432 if (n->end != ENDBODY_NOT)
433 n->body->flags |= NODE_ENDED;
434 break;
435 }
436 }
437
438 static void
439 mdoc_root_post(const struct roff_meta *meta, struct html *h)
440 {
441 struct tag *t, *tt;
442
443 t = print_otag(h, TAG_TABLE, "c", "foot");
444 tt = print_otag(h, TAG_TR, "");
445
446 print_otag(h, TAG_TD, "c", "foot-date");
447 print_text(h, meta->date);
448 print_stagq(h, tt);
449
450 print_otag(h, TAG_TD, "c", "foot-os");
451 print_text(h, meta->os);
452 print_tagq(h, t);
453 }
454
455 static int
456 mdoc_root_pre(const struct roff_meta *meta, struct html *h)
457 {
458 struct tag *t, *tt;
459 char *volume, *title;
460
461 if (NULL == meta->arch)
462 volume = mandoc_strdup(meta->vol);
463 else
464 mandoc_asprintf(&volume, "%s (%s)",
465 meta->vol, meta->arch);
466
467 if (NULL == meta->msec)
468 title = mandoc_strdup(meta->title);
469 else
470 mandoc_asprintf(&title, "%s(%s)",
471 meta->title, meta->msec);
472
473 t = print_otag(h, TAG_TABLE, "c", "head");
474 tt = print_otag(h, TAG_TR, "");
475
476 print_otag(h, TAG_TD, "c", "head-ltitle");
477 print_text(h, title);
478 print_stagq(h, tt);
479
480 print_otag(h, TAG_TD, "c", "head-vol");
481 print_text(h, volume);
482 print_stagq(h, tt);
483
484 print_otag(h, TAG_TD, "c", "head-rtitle");
485 print_text(h, title);
486 print_tagq(h, t);
487
488 free(title);
489 free(volume);
490 return 1;
491 }
492
493 static char *
494 cond_id(const struct roff_node *n)
495 {
496 if (n->child != NULL &&
497 n->child->type == ROFFT_TEXT &&
498 (n->prev == NULL ||
499 (n->prev->type == ROFFT_TEXT &&
500 strcmp(n->prev->string, "|") == 0)) &&
501 (n->parent->tok == MDOC_It ||
502 (n->parent->tok == MDOC_Xo &&
503 n->parent->parent->prev == NULL &&
504 n->parent->parent->parent->tok == MDOC_It)))
505 return html_make_id(n, 1);
506 return NULL;
507 }
508
509 static int
510 mdoc_sh_pre(MDOC_ARGS)
511 {
512 char *id;
513
514 switch (n->type) {
515 case ROFFT_HEAD:
516 id = html_make_id(n, 1);
517 print_otag(h, TAG_H1, "cTi", "Sh", id);
518 if (id != NULL)
519 print_otag(h, TAG_A, "chR", "permalink", id);
520 break;
521 case ROFFT_BODY:
522 if (n->sec == SEC_AUTHORS)
523 h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
524 break;
525 default:
526 break;
527 }
528 return 1;
529 }
530
531 static int
532 mdoc_ss_pre(MDOC_ARGS)
533 {
534 char *id;
535
536 if (n->type != ROFFT_HEAD)
537 return 1;
538
539 id = html_make_id(n, 1);
540 print_otag(h, TAG_H2, "cTi", "Ss", id);
541 if (id != NULL)
542 print_otag(h, TAG_A, "chR", "permalink", id);
543 return 1;
544 }
545
546 static int
547 mdoc_fl_pre(MDOC_ARGS)
548 {
549 char *id;
550
551 if ((id = cond_id(n)) != NULL)
552 print_otag(h, TAG_A, "chR", "permalink", id);
553 print_otag(h, TAG_CODE, "cTi", "Fl", id);
554
555 print_text(h, "\\-");
556 if (!(n->child == NULL &&
557 (n->next == NULL ||
558 n->next->type == ROFFT_TEXT ||
559 n->next->flags & NODE_LINE)))
560 h->flags |= HTML_NOSPACE;
561
562 return 1;
563 }
564
565 static int
566 mdoc_cm_pre(MDOC_ARGS)
567 {
568 char *id;
569
570 if ((id = cond_id(n)) != NULL)
571 print_otag(h, TAG_A, "chR", "permalink", id);
572 print_otag(h, TAG_CODE, "cTi", "Cm", id);
573 return 1;
574 }
575
576 static int
577 mdoc_nd_pre(MDOC_ARGS)
578 {
579 if (n->type != ROFFT_BODY)
580 return 1;
581
582 print_text(h, "\\(em");
583 /* Cannot use TAG_SPAN because it may contain blocks. */
584 print_otag(h, TAG_DIV, "cT", "Nd");
585 return 1;
586 }
587
588 static int
589 mdoc_nm_pre(MDOC_ARGS)
590 {
591 switch (n->type) {
592 case ROFFT_HEAD:
593 print_otag(h, TAG_TD, "");
594 /* FALLTHROUGH */
595 case ROFFT_ELEM:
596 print_otag(h, TAG_CODE, "cT", "Nm");
597 return 1;
598 case ROFFT_BODY:
599 print_otag(h, TAG_TD, "");
600 return 1;
601 default:
602 break;
603 }
604 synopsis_pre(h, n);
605 print_otag(h, TAG_TABLE, "c", "Nm");
606 print_otag(h, TAG_TR, "");
607 return 1;
608 }
609
610 static int
611 mdoc_xr_pre(MDOC_ARGS)
612 {
613 if (NULL == n->child)
614 return 0;
615
616 if (h->base_man)
617 print_otag(h, TAG_A, "cThM", "Xr",
618 n->child->string, n->child->next == NULL ?
619 NULL : n->child->next->string);
620 else
621 print_otag(h, TAG_A, "cT", "Xr");
622
623 n = n->child;
624 print_text(h, n->string);
625
626 if (NULL == (n = n->next))
627 return 0;
628
629 h->flags |= HTML_NOSPACE;
630 print_text(h, "(");
631 h->flags |= HTML_NOSPACE;
632 print_text(h, n->string);
633 h->flags |= HTML_NOSPACE;
634 print_text(h, ")");
635 return 0;
636 }
637
638 static int
639 mdoc_ns_pre(MDOC_ARGS)
640 {
641
642 if ( ! (NODE_LINE & n->flags))
643 h->flags |= HTML_NOSPACE;
644 return 1;
645 }
646
647 static int
648 mdoc_ar_pre(MDOC_ARGS)
649 {
650 print_otag(h, TAG_VAR, "cT", "Ar");
651 return 1;
652 }
653
654 static int
655 mdoc_xx_pre(MDOC_ARGS)
656 {
657 print_otag(h, TAG_SPAN, "c", "Ux");
658 return 1;
659 }
660
661 static int
662 mdoc_it_pre(MDOC_ARGS)
663 {
664 const struct roff_node *bl;
665 struct tag *t;
666 enum mdoc_list type;
667
668 bl = n->parent;
669 while (bl->tok != MDOC_Bl)
670 bl = bl->parent;
671 type = bl->norm->Bl.type;
672
673 switch (type) {
674 case LIST_bullet:
675 case LIST_dash:
676 case LIST_hyphen:
677 case LIST_item:
678 case LIST_enum:
679 switch (n->type) {
680 case ROFFT_HEAD:
681 return 0;
682 case ROFFT_BODY:
683 print_otag(h, TAG_LI, "");
684 break;
685 default:
686 break;
687 }
688 break;
689 case LIST_diag:
690 case LIST_hang:
691 case LIST_inset:
692 case LIST_ohang:
693 switch (n->type) {
694 case ROFFT_HEAD:
695 print_otag(h, TAG_DT, "");
696 break;
697 case ROFFT_BODY:
698 print_otag(h, TAG_DD, "");
699 break;
700 default:
701 break;
702 }
703 break;
704 case LIST_tag:
705 switch (n->type) {
706 case ROFFT_HEAD:
707 if (h->style != NULL && !bl->norm->Bl.comp &&
708 (n->parent->prev == NULL ||
709 n->parent->prev->body == NULL ||
710 n->parent->prev->body->child != NULL)) {
711 t = print_otag(h, TAG_DT, "");
712 print_text(h, "\\ ");
713 print_tagq(h, t);
714 t = print_otag(h, TAG_DD, "");
715 print_text(h, "\\ ");
716 print_tagq(h, t);
717 }
718 print_otag(h, TAG_DT, "");
719 break;
720 case ROFFT_BODY:
721 if (n->child == NULL) {
722 print_otag(h, TAG_DD, "ss?",
723 "width", "auto");
724 print_text(h, "\\ ");
725 } else
726 print_otag(h, TAG_DD, "");
727 break;
728 default:
729 break;
730 }
731 break;
732 case LIST_column:
733 switch (n->type) {
734 case ROFFT_HEAD:
735 break;
736 case ROFFT_BODY:
737 print_otag(h, TAG_TD, "");
738 break;
739 default:
740 print_otag(h, TAG_TR, "");
741 }
742 default:
743 break;
744 }
745
746 return 1;
747 }
748
749 static int
750 mdoc_bl_pre(MDOC_ARGS)
751 {
752 char cattr[28];
753 struct tag *t;
754 struct mdoc_bl *bl;
755 size_t i;
756 enum htmltag elemtype;
757
758 bl = &n->norm->Bl;
759
760 switch (n->type) {
761 case ROFFT_BODY:
762 return 1;
763
764 case ROFFT_HEAD:
765 if (bl->type != LIST_column || bl->ncols == 0)
766 return 0;
767
768 /*
769 * For each column, print out the <COL> tag with our
770 * suggested width. The last column gets min-width, as
771 * in terminal mode it auto-sizes to the width of the
772 * screen and we want to preserve that behaviour.
773 */
774
775 t = print_otag(h, TAG_COLGROUP, "");
776 for (i = 0; i < bl->ncols - 1; i++)
777 print_otag(h, TAG_COL, "sw+w", bl->cols[i]);
778 print_otag(h, TAG_COL, "swW", bl->cols[i]);
779 print_tagq(h, t);
780 return 0;
781
782 default:
783 break;
784 }
785
786 switch (bl->type) {
787 case LIST_bullet:
788 elemtype = TAG_UL;
789 (void)strlcpy(cattr, "Bl-bullet", sizeof(cattr));
790 break;
791 case LIST_dash:
792 case LIST_hyphen:
793 elemtype = TAG_UL;
794 (void)strlcpy(cattr, "Bl-dash", sizeof(cattr));
795 break;
796 case LIST_item:
797 elemtype = TAG_UL;
798 (void)strlcpy(cattr, "Bl-item", sizeof(cattr));
799 break;
800 case LIST_enum:
801 elemtype = TAG_OL;
802 (void)strlcpy(cattr, "Bl-enum", sizeof(cattr));
803 break;
804 case LIST_diag:
805 elemtype = TAG_DL;
806 (void)strlcpy(cattr, "Bl-diag", sizeof(cattr));
807 break;
808 case LIST_hang:
809 elemtype = TAG_DL;
810 (void)strlcpy(cattr, "Bl-hang", sizeof(cattr));
811 break;
812 case LIST_inset:
813 elemtype = TAG_DL;
814 (void)strlcpy(cattr, "Bl-inset", sizeof(cattr));
815 break;
816 case LIST_ohang:
817 elemtype = TAG_DL;
818 (void)strlcpy(cattr, "Bl-ohang", sizeof(cattr));
819 break;
820 case LIST_tag:
821 if (bl->offs)
822 print_otag(h, TAG_DIV, "c", "Bd-indent");
823 print_otag(h, TAG_DL, "c", bl->comp ?
824 "Bl-tag Bl-compact" : "Bl-tag");
825 return 1;
826 case LIST_column:
827 elemtype = TAG_TABLE;
828 (void)strlcpy(cattr, "Bl-column", sizeof(cattr));
829 break;
830 default:
831 abort();
832 }
833 if (bl->offs != NULL)
834 (void)strlcat(cattr, " Bd-indent", sizeof(cattr));
835 if (bl->comp)
836 (void)strlcat(cattr, " Bl-compact", sizeof(cattr));
837 print_otag(h, elemtype, "c", cattr);
838 return 1;
839 }
840
841 static int
842 mdoc_ex_pre(MDOC_ARGS)
843 {
844 if (n->prev)
845 print_otag(h, TAG_BR, "");
846 return 1;
847 }
848
849 static int
850 mdoc_st_pre(MDOC_ARGS)
851 {
852 print_otag(h, TAG_SPAN, "cT", "St");
853 return 1;
854 }
855
856 static int
857 mdoc_em_pre(MDOC_ARGS)
858 {
859 print_otag(h, TAG_I, "cT", "Em");
860 return 1;
861 }
862
863 static int
864 mdoc_d1_pre(MDOC_ARGS)
865 {
866 if (n->type != ROFFT_BLOCK)
867 return 1;
868
869 print_otag(h, TAG_DIV, "c", "Bd Bd-indent");
870
871 if (n->tok == MDOC_Dl)
872 print_otag(h, TAG_CODE, "c", "Li");
873
874 return 1;
875 }
876
877 static int
878 mdoc_sx_pre(MDOC_ARGS)
879 {
880 char *id;
881
882 id = html_make_id(n, 0);
883 print_otag(h, TAG_A, "cThR", "Sx", id);
884 free(id);
885 return 1;
886 }
887
888 static int
889 mdoc_bd_pre(MDOC_ARGS)
890 {
891 int comp, sv;
892 struct roff_node *nn;
893
894 if (n->type == ROFFT_HEAD)
895 return 0;
896
897 if (n->type == ROFFT_BLOCK) {
898 comp = n->norm->Bd.comp;
899 for (nn = n; nn && ! comp; nn = nn->parent) {
900 if (nn->type != ROFFT_BLOCK)
901 continue;
902 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
903 comp = 1;
904 if (nn->prev)
905 break;
906 }
907 if ( ! comp)
908 print_paragraph(h);
909 return 1;
910 }
911
912 /* Handle the -offset argument. */
913
914 if (n->norm->Bd.offs == NULL ||
915 ! strcmp(n->norm->Bd.offs, "left"))
916 print_otag(h, TAG_DIV, "c", "Bd");
917 else
918 print_otag(h, TAG_DIV, "c", "Bd Bd-indent");
919
920 if (n->norm->Bd.type != DISP_unfilled &&
921 n->norm->Bd.type != DISP_literal)
922 return 1;
923
924 print_otag(h, TAG_PRE, "c", "Li");
925
926 /* This can be recursive: save & set our literal state. */
927
928 sv = h->flags & HTML_LITERAL;
929 h->flags |= HTML_LITERAL;
930
931 for (nn = n->child; nn; nn = nn->next) {
932 print_mdoc_node(meta, nn, h);
933 /*
934 * If the printed node flushes its own line, then we
935 * needn't do it here as well. This is hacky, but the
936 * notion of selective eoln whitespace is pretty dumb
937 * anyway, so don't sweat it.
938 */
939 switch (nn->tok) {
940 case ROFF_br:
941 case ROFF_sp:
942 case MDOC_Sm:
943 case MDOC_Bl:
944 case MDOC_D1:
945 case MDOC_Dl:
946 case MDOC_Lp:
947 case MDOC_Pp:
948 continue;
949 default:
950 break;
951 }
952 if (h->flags & HTML_NONEWLINE ||
953 (nn->next && ! (nn->next->flags & NODE_LINE)))
954 continue;
955 else if (nn->next)
956 print_text(h, "\n");
957
958 h->flags |= HTML_NOSPACE;
959 }
960
961 if (0 == sv)
962 h->flags &= ~HTML_LITERAL;
963
964 return 0;
965 }
966
967 static int
968 mdoc_pa_pre(MDOC_ARGS)
969 {
970 print_otag(h, TAG_SPAN, "cT", "Pa");
971 return 1;
972 }
973
974 static int
975 mdoc_ad_pre(MDOC_ARGS)
976 {
977 print_otag(h, TAG_SPAN, "c", "Ad");
978 return 1;
979 }
980
981 static int
982 mdoc_an_pre(MDOC_ARGS)
983 {
984 if (n->norm->An.auth == AUTH_split) {
985 h->flags &= ~HTML_NOSPLIT;
986 h->flags |= HTML_SPLIT;
987 return 0;
988 }
989 if (n->norm->An.auth == AUTH_nosplit) {
990 h->flags &= ~HTML_SPLIT;
991 h->flags |= HTML_NOSPLIT;
992 return 0;
993 }
994
995 if (h->flags & HTML_SPLIT)
996 print_otag(h, TAG_BR, "");
997
998 if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
999 h->flags |= HTML_SPLIT;
1000
1001 print_otag(h, TAG_SPAN, "cT", "An");
1002 return 1;
1003 }
1004
1005 static int
1006 mdoc_cd_pre(MDOC_ARGS)
1007 {
1008 synopsis_pre(h, n);
1009 print_otag(h, TAG_CODE, "cT", "Cd");
1010 return 1;
1011 }
1012
1013 static int
1014 mdoc_dv_pre(MDOC_ARGS)
1015 {
1016 char *id;
1017
1018 if ((id = cond_id(n)) != NULL)
1019 print_otag(h, TAG_A, "chR", "permalink", id);
1020 print_otag(h, TAG_CODE, "cTi", "Dv", id);
1021 return 1;
1022 }
1023
1024 static int
1025 mdoc_ev_pre(MDOC_ARGS)
1026 {
1027 char *id;
1028
1029 if ((id = cond_id(n)) != NULL)
1030 print_otag(h, TAG_A, "chR", "permalink", id);
1031 print_otag(h, TAG_CODE, "cTi", "Ev", id);
1032 return 1;
1033 }
1034
1035 static int
1036 mdoc_er_pre(MDOC_ARGS)
1037 {
1038 char *id;
1039
1040 id = n->sec == SEC_ERRORS &&
1041 (n->parent->tok == MDOC_It ||
1042 (n->parent->tok == MDOC_Bq &&
1043 n->parent->parent->parent->tok == MDOC_It)) ?
1044 html_make_id(n, 1) : NULL;
1045
1046 if (id != NULL)
1047 print_otag(h, TAG_A, "chR", "permalink", id);
1048 print_otag(h, TAG_CODE, "cTi", "Er", id);
1049 return 1;
1050 }
1051
1052 static int
1053 mdoc_fa_pre(MDOC_ARGS)
1054 {
1055 const struct roff_node *nn;
1056 struct tag *t;
1057
1058 if (n->parent->tok != MDOC_Fo) {
1059 print_otag(h, TAG_VAR, "cT", "Fa");
1060 return 1;
1061 }
1062
1063 for (nn = n->child; nn; nn = nn->next) {
1064 t = print_otag(h, TAG_VAR, "cT", "Fa");
1065 print_text(h, nn->string);
1066 print_tagq(h, t);
1067 if (nn->next) {
1068 h->flags |= HTML_NOSPACE;
1069 print_text(h, ",");
1070 }
1071 }
1072
1073 if (n->child && n->next && n->next->tok == MDOC_Fa) {
1074 h->flags |= HTML_NOSPACE;
1075 print_text(h, ",");
1076 }
1077
1078 return 0;
1079 }
1080
1081 static int
1082 mdoc_fd_pre(MDOC_ARGS)
1083 {
1084 struct tag *t;
1085 char *buf, *cp;
1086
1087 synopsis_pre(h, n);
1088
1089 if (NULL == (n = n->child))
1090 return 0;
1091
1092 assert(n->type == ROFFT_TEXT);
1093
1094 if (strcmp(n->string, "#include")) {
1095 print_otag(h, TAG_CODE, "cT", "Fd");
1096 return 1;
1097 }
1098
1099 print_otag(h, TAG_CODE, "cT", "In");
1100 print_text(h, n->string);
1101
1102 if (NULL != (n = n->next)) {
1103 assert(n->type == ROFFT_TEXT);
1104
1105 if (h->base_includes) {
1106 cp = n->string;
1107 if (*cp == '<' || *cp == '"')
1108 cp++;
1109 buf = mandoc_strdup(cp);
1110 cp = strchr(buf, '\0') - 1;
1111 if (cp >= buf && (*cp == '>' || *cp == '"'))
1112 *cp = '\0';
1113 t = print_otag(h, TAG_A, "cThI", "In", buf);
1114 free(buf);
1115 } else
1116 t = print_otag(h, TAG_A, "cT", "In");
1117
1118 print_text(h, n->string);
1119 print_tagq(h, t);
1120
1121 n = n->next;
1122 }
1123
1124 for ( ; n; n = n->next) {
1125 assert(n->type == ROFFT_TEXT);
1126 print_text(h, n->string);
1127 }
1128
1129 return 0;
1130 }
1131
1132 static int
1133 mdoc_vt_pre(MDOC_ARGS)
1134 {
1135 if (n->type == ROFFT_BLOCK) {
1136 synopsis_pre(h, n);
1137 return 1;
1138 } else if (n->type == ROFFT_ELEM) {
1139 synopsis_pre(h, n);
1140 } else if (n->type == ROFFT_HEAD)
1141 return 0;
1142
1143 print_otag(h, TAG_VAR, "cT", "Vt");
1144 return 1;
1145 }
1146
1147 static int
1148 mdoc_ft_pre(MDOC_ARGS)
1149 {
1150 synopsis_pre(h, n);
1151 print_otag(h, TAG_VAR, "cT", "Ft");
1152 return 1;
1153 }
1154
1155 static int
1156 mdoc_fn_pre(MDOC_ARGS)
1157 {
1158 struct tag *t;
1159 char nbuf[BUFSIZ];
1160 const char *sp, *ep;
1161 int sz, pretty;
1162
1163 pretty = NODE_SYNPRETTY & n->flags;
1164 synopsis_pre(h, n);
1165
1166 /* Split apart into type and name. */
1167 assert(n->child->string);
1168 sp = n->child->string;
1169
1170 ep = strchr(sp, ' ');
1171 if (NULL != ep) {
1172 t = print_otag(h, TAG_VAR, "cT", "Ft");
1173
1174 while (ep) {
1175 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1176 (void)memcpy(nbuf, sp, (size_t)sz);
1177 nbuf[sz] = '\0';
1178 print_text(h, nbuf);
1179 sp = ++ep;
1180 ep = strchr(sp, ' ');
1181 }
1182 print_tagq(h, t);
1183 }
1184
1185 t = print_otag(h, TAG_CODE, "cT", "Fn");
1186
1187 if (sp)
1188 print_text(h, sp);
1189
1190 print_tagq(h, t);
1191
1192 h->flags |= HTML_NOSPACE;
1193 print_text(h, "(");
1194 h->flags |= HTML_NOSPACE;
1195
1196 for (n = n->child->next; n; n = n->next) {
1197 if (NODE_SYNPRETTY & n->flags)
1198 t = print_otag(h, TAG_VAR, "cTss?", "Fa",
1199 "white-space", "nowrap");
1200 else
1201 t = print_otag(h, TAG_VAR, "cT", "Fa");
1202 print_text(h, n->string);
1203 print_tagq(h, t);
1204 if (n->next) {
1205 h->flags |= HTML_NOSPACE;
1206 print_text(h, ",");
1207 }
1208 }
1209
1210 h->flags |= HTML_NOSPACE;
1211 print_text(h, ")");
1212
1213 if (pretty) {
1214 h->flags |= HTML_NOSPACE;
1215 print_text(h, ";");
1216 }
1217
1218 return 0;
1219 }
1220
1221 static int
1222 mdoc_sm_pre(MDOC_ARGS)
1223 {
1224
1225 if (NULL == n->child)
1226 h->flags ^= HTML_NONOSPACE;
1227 else if (0 == strcmp("on", n->child->string))
1228 h->flags &= ~HTML_NONOSPACE;
1229 else
1230 h->flags |= HTML_NONOSPACE;
1231
1232 if ( ! (HTML_NONOSPACE & h->flags))
1233 h->flags &= ~HTML_NOSPACE;
1234
1235 return 0;
1236 }
1237
1238 static int
1239 mdoc_skip_pre(MDOC_ARGS)
1240 {
1241
1242 return 0;
1243 }
1244
1245 static int
1246 mdoc_pp_pre(MDOC_ARGS)
1247 {
1248
1249 print_paragraph(h);
1250 return 0;
1251 }
1252
1253 static int
1254 mdoc_lk_pre(MDOC_ARGS)
1255 {
1256 const struct roff_node *link, *descr, *punct;
1257 struct tag *t;
1258
1259 if ((link = n->child) == NULL)
1260 return 0;
1261
1262 /* Find beginning of trailing punctuation. */
1263 punct = n->last;
1264 while (punct != link && punct->flags & NODE_DELIMC)
1265 punct = punct->prev;
1266 punct = punct->next;
1267
1268 /* Link target and link text. */
1269 descr = link->next;
1270 if (descr == punct)
1271 descr = link; /* no text */
1272 t = print_otag(h, TAG_A, "cTh", "Lk", link->string);
1273 do {
1274 if (descr->flags & (NODE_DELIMC | NODE_DELIMO))
1275 h->flags |= HTML_NOSPACE;
1276 print_text(h, descr->string);
1277 descr = descr->next;
1278 } while (descr != punct);
1279 print_tagq(h, t);
1280
1281 /* Trailing punctuation. */
1282 while (punct != NULL) {
1283 h->flags |= HTML_NOSPACE;
1284 print_text(h, punct->string);
1285 punct = punct->next;
1286 }
1287 return 0;
1288 }
1289
1290 static int
1291 mdoc_mt_pre(MDOC_ARGS)
1292 {
1293 struct tag *t;
1294 char *cp;
1295
1296 for (n = n->child; n; n = n->next) {
1297 assert(n->type == ROFFT_TEXT);
1298
1299 mandoc_asprintf(&cp, "mailto:%s", n->string);
1300 t = print_otag(h, TAG_A, "cTh", "Mt", cp);
1301 print_text(h, n->string);
1302 print_tagq(h, t);
1303 free(cp);
1304 }
1305
1306 return 0;
1307 }
1308
1309 static int
1310 mdoc_fo_pre(MDOC_ARGS)
1311 {
1312 struct tag *t;
1313
1314 if (n->type == ROFFT_BODY) {
1315 h->flags |= HTML_NOSPACE;
1316 print_text(h, "(");
1317 h->flags |= HTML_NOSPACE;
1318 return 1;
1319 } else if (n->type == ROFFT_BLOCK) {
1320 synopsis_pre(h, n);
1321 return 1;
1322 }
1323
1324 if (n->child == NULL)
1325 return 0;
1326
1327 assert(n->child->string);
1328 t = print_otag(h, TAG_CODE, "cT", "Fn");
1329 print_text(h, n->child->string);
1330 print_tagq(h, t);
1331 return 0;
1332 }
1333
1334 static void
1335 mdoc_fo_post(MDOC_ARGS)
1336 {
1337
1338 if (n->type != ROFFT_BODY)
1339 return;
1340 h->flags |= HTML_NOSPACE;
1341 print_text(h, ")");
1342 h->flags |= HTML_NOSPACE;
1343 print_text(h, ";");
1344 }
1345
1346 static int
1347 mdoc_in_pre(MDOC_ARGS)
1348 {
1349 struct tag *t;
1350
1351 synopsis_pre(h, n);
1352 print_otag(h, TAG_CODE, "cT", "In");
1353
1354 /*
1355 * The first argument of the `In' gets special treatment as
1356 * being a linked value. Subsequent values are printed
1357 * afterward. groff does similarly. This also handles the case
1358 * of no children.
1359 */
1360
1361 if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
1362 print_text(h, "#include");
1363
1364 print_text(h, "<");
1365 h->flags |= HTML_NOSPACE;
1366
1367 if (NULL != (n = n->child)) {
1368 assert(n->type == ROFFT_TEXT);
1369
1370 if (h->base_includes)
1371 t = print_otag(h, TAG_A, "cThI", "In", n->string);
1372 else
1373 t = print_otag(h, TAG_A, "cT", "In");
1374 print_text(h, n->string);
1375 print_tagq(h, t);
1376
1377 n = n->next;
1378 }
1379
1380 h->flags |= HTML_NOSPACE;
1381 print_text(h, ">");
1382
1383 for ( ; n; n = n->next) {
1384 assert(n->type == ROFFT_TEXT);
1385 print_text(h, n->string);
1386 }
1387
1388 return 0;
1389 }
1390
1391 static int
1392 mdoc_ic_pre(MDOC_ARGS)
1393 {
1394 char *id;
1395
1396 if ((id = cond_id(n)) != NULL)
1397 print_otag(h, TAG_A, "chR", "permalink", id);
1398 print_otag(h, TAG_CODE, "cTi", "Ic", id);
1399 return 1;
1400 }
1401
1402 static int
1403 mdoc_va_pre(MDOC_ARGS)
1404 {
1405 print_otag(h, TAG_VAR, "cT", "Va");
1406 return 1;
1407 }
1408
1409 static int
1410 mdoc_ap_pre(MDOC_ARGS)
1411 {
1412
1413 h->flags |= HTML_NOSPACE;
1414 print_text(h, "\\(aq");
1415 h->flags |= HTML_NOSPACE;
1416 return 1;
1417 }
1418
1419 static int
1420 mdoc_bf_pre(MDOC_ARGS)
1421 {
1422 const char *cattr;
1423
1424 if (n->type == ROFFT_HEAD)
1425 return 0;
1426 else if (n->type != ROFFT_BODY)
1427 return 1;
1428
1429 if (FONT_Em == n->norm->Bf.font)
1430 cattr = "Bf Em";
1431 else if (FONT_Sy == n->norm->Bf.font)
1432 cattr = "Bf Sy";
1433 else if (FONT_Li == n->norm->Bf.font)
1434 cattr = "Bf Li";
1435 else
1436 cattr = "Bf No";
1437
1438 /* Cannot use TAG_SPAN because it may contain blocks. */
1439 print_otag(h, TAG_DIV, "cshl", cattr, 1);
1440 return 1;
1441 }
1442
1443 static int
1444 mdoc_ms_pre(MDOC_ARGS)
1445 {
1446 char *id;
1447
1448 if ((id = cond_id(n)) != NULL)
1449 print_otag(h, TAG_A, "chR", "permalink", id);
1450 print_otag(h, TAG_SPAN, "cTi", "Ms", id);
1451 return 1;
1452 }
1453
1454 static int
1455 mdoc_igndelim_pre(MDOC_ARGS)
1456 {
1457
1458 h->flags |= HTML_IGNDELIM;
1459 return 1;
1460 }
1461
1462 static void
1463 mdoc_pf_post(MDOC_ARGS)
1464 {
1465
1466 if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1467 h->flags |= HTML_NOSPACE;
1468 }
1469
1470 static int
1471 mdoc_rs_pre(MDOC_ARGS)
1472 {
1473 if (n->type != ROFFT_BLOCK)
1474 return 1;
1475
1476 if (n->prev && SEC_SEE_ALSO == n->sec)
1477 print_paragraph(h);
1478
1479 print_otag(h, TAG_CITE, "cT", "Rs");
1480 return 1;
1481 }
1482
1483 static int
1484 mdoc_no_pre(MDOC_ARGS)
1485 {
1486 char *id;
1487
1488 if ((id = cond_id(n)) != NULL)
1489 print_otag(h, TAG_A, "chR", "permalink", id);
1490 print_otag(h, TAG_SPAN, "ci", "No", id);
1491 return 1;
1492 }
1493
1494 static int
1495 mdoc_li_pre(MDOC_ARGS)
1496 {
1497 char *id;
1498
1499 if ((id = cond_id(n)) != NULL)
1500 print_otag(h, TAG_A, "chR", "permalink", id);
1501 print_otag(h, TAG_CODE, "ci", "Li", id);
1502 return 1;
1503 }
1504
1505 static int
1506 mdoc_sy_pre(MDOC_ARGS)
1507 {
1508 print_otag(h, TAG_B, "cT", "Sy");
1509 return 1;
1510 }
1511
1512 static int
1513 mdoc_lb_pre(MDOC_ARGS)
1514 {
1515 if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
1516 print_otag(h, TAG_BR, "");
1517
1518 print_otag(h, TAG_SPAN, "cT", "Lb");
1519 return 1;
1520 }
1521
1522 static int
1523 mdoc__x_pre(MDOC_ARGS)
1524 {
1525 const char *cattr;
1526 enum htmltag t;
1527
1528 t = TAG_SPAN;
1529
1530 switch (n->tok) {
1531 case MDOC__A:
1532 cattr = "RsA";
1533 if (n->prev && MDOC__A == n->prev->tok)
1534 if (NULL == n->next || MDOC__A != n->next->tok)
1535 print_text(h, "and");
1536 break;
1537 case MDOC__B:
1538 t = TAG_I;
1539 cattr = "RsB";
1540 break;
1541 case MDOC__C:
1542 cattr = "RsC";
1543 break;
1544 case MDOC__D:
1545 cattr = "RsD";
1546 break;
1547 case MDOC__I:
1548 t = TAG_I;
1549 cattr = "RsI";
1550 break;
1551 case MDOC__J:
1552 t = TAG_I;
1553 cattr = "RsJ";
1554 break;
1555 case MDOC__N:
1556 cattr = "RsN";
1557 break;
1558 case MDOC__O:
1559 cattr = "RsO";
1560 break;
1561 case MDOC__P:
1562 cattr = "RsP";
1563 break;
1564 case MDOC__Q:
1565 cattr = "RsQ";
1566 break;
1567 case MDOC__R:
1568 cattr = "RsR";
1569 break;
1570 case MDOC__T:
1571 cattr = "RsT";
1572 break;
1573 case MDOC__U:
1574 print_otag(h, TAG_A, "ch", "RsU", n->child->string);
1575 return 1;
1576 case MDOC__V:
1577 cattr = "RsV";
1578 break;
1579 default:
1580 abort();
1581 }
1582
1583 print_otag(h, t, "c", cattr);
1584 return 1;
1585 }
1586
1587 static void
1588 mdoc__x_post(MDOC_ARGS)
1589 {
1590
1591 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1592 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1593 if (NULL == n->prev || MDOC__A != n->prev->tok)
1594 return;
1595
1596 /* TODO: %U */
1597
1598 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1599 return;
1600
1601 h->flags |= HTML_NOSPACE;
1602 print_text(h, n->next ? "," : ".");
1603 }
1604
1605 static int
1606 mdoc_bk_pre(MDOC_ARGS)
1607 {
1608
1609 switch (n->type) {
1610 case ROFFT_BLOCK:
1611 break;
1612 case ROFFT_HEAD:
1613 return 0;
1614 case ROFFT_BODY:
1615 if (n->parent->args != NULL || n->prev->child == NULL)
1616 h->flags |= HTML_PREKEEP;
1617 break;
1618 default:
1619 abort();
1620 }
1621
1622 return 1;
1623 }
1624
1625 static void
1626 mdoc_bk_post(MDOC_ARGS)
1627 {
1628
1629 if (n->type == ROFFT_BODY)
1630 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1631 }
1632
1633 static int
1634 mdoc_quote_pre(MDOC_ARGS)
1635 {
1636 if (n->type != ROFFT_BODY)
1637 return 1;
1638
1639 switch (n->tok) {
1640 case MDOC_Ao:
1641 case MDOC_Aq:
1642 print_text(h, n->child != NULL && n->child->next == NULL &&
1643 n->child->tok == MDOC_Mt ? "<" : "\\(la");
1644 break;
1645 case MDOC_Bro:
1646 case MDOC_Brq:
1647 print_text(h, "\\(lC");
1648 break;
1649 case MDOC_Bo:
1650 case MDOC_Bq:
1651 print_text(h, "\\(lB");
1652 break;
1653 case MDOC_Oo:
1654 case MDOC_Op:
1655 print_text(h, "\\(lB");
1656 h->flags |= HTML_NOSPACE;
1657 /* Cannot use TAG_SPAN because it may contain blocks. */
1658 print_otag(h, TAG_IDIV, "c", "Op");
1659 break;
1660 case MDOC_En:
1661 if (NULL == n->norm->Es ||
1662 NULL == n->norm->Es->child)
1663 return 1;
1664 print_text(h, n->norm->Es->child->string);
1665 break;
1666 case MDOC_Do:
1667 case MDOC_Dq:
1668 case MDOC_Qo:
1669 case MDOC_Qq:
1670 print_text(h, "\\(lq");
1671 break;
1672 case MDOC_Po:
1673 case MDOC_Pq:
1674 print_text(h, "(");
1675 break;
1676 case MDOC_Ql:
1677 print_text(h, "\\(oq");
1678 h->flags |= HTML_NOSPACE;
1679 print_otag(h, TAG_CODE, "c", "Li");
1680 break;
1681 case MDOC_So:
1682 case MDOC_Sq:
1683 print_text(h, "\\(oq");
1684 break;
1685 default:
1686 abort();
1687 }
1688
1689 h->flags |= HTML_NOSPACE;
1690 return 1;
1691 }
1692
1693 static void
1694 mdoc_quote_post(MDOC_ARGS)
1695 {
1696
1697 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1698 return;
1699
1700 h->flags |= HTML_NOSPACE;
1701
1702 switch (n->tok) {
1703 case MDOC_Ao:
1704 case MDOC_Aq:
1705 print_text(h, n->child != NULL && n->child->next == NULL &&
1706 n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1707 break;
1708 case MDOC_Bro:
1709 case MDOC_Brq:
1710 print_text(h, "\\(rC");
1711 break;
1712 case MDOC_Oo:
1713 case MDOC_Op:
1714 case MDOC_Bo:
1715 case MDOC_Bq:
1716 print_text(h, "\\(rB");
1717 break;
1718 case MDOC_En:
1719 if (n->norm->Es == NULL ||
1720 n->norm->Es->child == NULL ||
1721 n->norm->Es->child->next == NULL)
1722 h->flags &= ~HTML_NOSPACE;
1723 else
1724 print_text(h, n->norm->Es->child->next->string);
1725 break;
1726 case MDOC_Qo:
1727 case MDOC_Qq:
1728 case MDOC_Do:
1729 case MDOC_Dq:
1730 print_text(h, "\\(rq");
1731 break;
1732 case MDOC_Po:
1733 case MDOC_Pq:
1734 print_text(h, ")");
1735 break;
1736 case MDOC_Ql:
1737 case MDOC_So:
1738 case MDOC_Sq:
1739 print_text(h, "\\(cq");
1740 break;
1741 default:
1742 abort();
1743 }
1744 }
1745
1746 static int
1747 mdoc_eo_pre(MDOC_ARGS)
1748 {
1749
1750 if (n->type != ROFFT_BODY)
1751 return 1;
1752
1753 if (n->end == ENDBODY_NOT &&
1754 n->parent->head->child == NULL &&
1755 n->child != NULL &&
1756 n->child->end != ENDBODY_NOT)
1757 print_text(h, "\\&");
1758 else if (n->end != ENDBODY_NOT ? n->child != NULL :
1759 n->parent->head->child != NULL && (n->child != NULL ||
1760 (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1761 h->flags |= HTML_NOSPACE;
1762 return 1;
1763 }
1764
1765 static void
1766 mdoc_eo_post(MDOC_ARGS)
1767 {
1768 int body, tail;
1769
1770 if (n->type != ROFFT_BODY)
1771 return;
1772
1773 if (n->end != ENDBODY_NOT) {
1774 h->flags &= ~HTML_NOSPACE;
1775 return;
1776 }
1777
1778 body = n->child != NULL || n->parent->head->child != NULL;
1779 tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1780
1781 if (body && tail)
1782 h->flags |= HTML_NOSPACE;
1783 else if ( ! tail)
1784 h->flags &= ~HTML_NOSPACE;
1785 }