]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
Use <span> rather than abusing <i> for .Pa;
[mandoc.git] / mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.301 2018/05/21 00:00:37 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);
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);
517 print_otag(h, TAG_H1, "cTi", "Sh", id);
518 if (id != NULL)
519 print_otag(h, TAG_A, "chR", "permalink", id);
520 free(id);
521 break;
522 case ROFFT_BODY:
523 if (n->sec == SEC_AUTHORS)
524 h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
525 break;
526 default:
527 break;
528 }
529 return 1;
530 }
531
532 static int
533 mdoc_ss_pre(MDOC_ARGS)
534 {
535 char *id;
536
537 if (n->type != ROFFT_HEAD)
538 return 1;
539
540 id = html_make_id(n);
541 print_otag(h, TAG_H2, "cTi", "Ss", id);
542 if (id != NULL)
543 print_otag(h, TAG_A, "chR", "permalink", id);
544 free(id);
545 return 1;
546 }
547
548 static int
549 mdoc_fl_pre(MDOC_ARGS)
550 {
551 char *id;
552
553 if ((id = cond_id(n)) != NULL)
554 print_otag(h, TAG_A, "chR", "permalink", id);
555 print_otag(h, TAG_CODE, "cTi", "Fl", id);
556 free(id);
557
558 print_text(h, "\\-");
559 if (!(n->child == NULL &&
560 (n->next == NULL ||
561 n->next->type == ROFFT_TEXT ||
562 n->next->flags & NODE_LINE)))
563 h->flags |= HTML_NOSPACE;
564
565 return 1;
566 }
567
568 static int
569 mdoc_cm_pre(MDOC_ARGS)
570 {
571 char *id;
572
573 if ((id = cond_id(n)) != NULL)
574 print_otag(h, TAG_A, "chR", "permalink", id);
575 print_otag(h, TAG_CODE, "cTi", "Cm", id);
576 free(id);
577 return 1;
578 }
579
580 static int
581 mdoc_nd_pre(MDOC_ARGS)
582 {
583 if (n->type != ROFFT_BODY)
584 return 1;
585
586 print_text(h, "\\(em");
587 /* Cannot use TAG_SPAN because it may contain blocks. */
588 print_otag(h, TAG_DIV, "cT", "Nd");
589 return 1;
590 }
591
592 static int
593 mdoc_nm_pre(MDOC_ARGS)
594 {
595 switch (n->type) {
596 case ROFFT_HEAD:
597 print_otag(h, TAG_TD, "");
598 /* FALLTHROUGH */
599 case ROFFT_ELEM:
600 print_otag(h, TAG_CODE, "cT", "Nm");
601 return 1;
602 case ROFFT_BODY:
603 print_otag(h, TAG_TD, "");
604 return 1;
605 default:
606 break;
607 }
608 synopsis_pre(h, n);
609 print_otag(h, TAG_TABLE, "c", "Nm");
610 print_otag(h, TAG_TR, "");
611 return 1;
612 }
613
614 static int
615 mdoc_xr_pre(MDOC_ARGS)
616 {
617 if (NULL == n->child)
618 return 0;
619
620 if (h->base_man)
621 print_otag(h, TAG_A, "cThM", "Xr",
622 n->child->string, n->child->next == NULL ?
623 NULL : n->child->next->string);
624 else
625 print_otag(h, TAG_A, "cT", "Xr");
626
627 n = n->child;
628 print_text(h, n->string);
629
630 if (NULL == (n = n->next))
631 return 0;
632
633 h->flags |= HTML_NOSPACE;
634 print_text(h, "(");
635 h->flags |= HTML_NOSPACE;
636 print_text(h, n->string);
637 h->flags |= HTML_NOSPACE;
638 print_text(h, ")");
639 return 0;
640 }
641
642 static int
643 mdoc_ns_pre(MDOC_ARGS)
644 {
645
646 if ( ! (NODE_LINE & n->flags))
647 h->flags |= HTML_NOSPACE;
648 return 1;
649 }
650
651 static int
652 mdoc_ar_pre(MDOC_ARGS)
653 {
654 print_otag(h, TAG_VAR, "cT", "Ar");
655 return 1;
656 }
657
658 static int
659 mdoc_xx_pre(MDOC_ARGS)
660 {
661 print_otag(h, TAG_SPAN, "c", "Ux");
662 return 1;
663 }
664
665 static int
666 mdoc_it_pre(MDOC_ARGS)
667 {
668 const struct roff_node *bl;
669 struct tag *t;
670 enum mdoc_list type;
671
672 bl = n->parent;
673 while (bl->tok != MDOC_Bl)
674 bl = bl->parent;
675 type = bl->norm->Bl.type;
676
677 switch (type) {
678 case LIST_bullet:
679 case LIST_dash:
680 case LIST_hyphen:
681 case LIST_item:
682 case LIST_enum:
683 switch (n->type) {
684 case ROFFT_HEAD:
685 return 0;
686 case ROFFT_BODY:
687 print_otag(h, TAG_LI, "");
688 break;
689 default:
690 break;
691 }
692 break;
693 case LIST_diag:
694 case LIST_hang:
695 case LIST_inset:
696 case LIST_ohang:
697 switch (n->type) {
698 case ROFFT_HEAD:
699 print_otag(h, TAG_DT, "");
700 break;
701 case ROFFT_BODY:
702 print_otag(h, TAG_DD, "sw*+l", bl->norm->Bl.width);
703 break;
704 default:
705 break;
706 }
707 break;
708 case LIST_tag:
709 switch (n->type) {
710 case ROFFT_HEAD:
711 if (h->style != NULL && !bl->norm->Bl.comp &&
712 (n->parent->prev == NULL ||
713 n->parent->prev->body == NULL ||
714 n->parent->prev->body->child != NULL)) {
715 t = print_otag(h, TAG_DT, "sw*+-l",
716 bl->norm->Bl.width);
717 print_text(h, "\\ ");
718 print_tagq(h, t);
719 t = print_otag(h, TAG_DD, "");
720 print_text(h, "\\ ");
721 print_tagq(h, t);
722 }
723 print_otag(h, TAG_DT, "sw*+-l", bl->norm->Bl.width);
724 break;
725 case ROFFT_BODY:
726 if (n->child == NULL) {
727 print_otag(h, TAG_DD, "ss?",
728 "width", "auto");
729 print_text(h, "\\ ");
730 } else
731 print_otag(h, TAG_DD, "");
732 break;
733 default:
734 break;
735 }
736 break;
737 case LIST_column:
738 switch (n->type) {
739 case ROFFT_HEAD:
740 break;
741 case ROFFT_BODY:
742 print_otag(h, TAG_TD, "");
743 break;
744 default:
745 print_otag(h, TAG_TR, "");
746 }
747 default:
748 break;
749 }
750
751 return 1;
752 }
753
754 static int
755 mdoc_bl_pre(MDOC_ARGS)
756 {
757 char cattr[21];
758 struct tag *t;
759 struct mdoc_bl *bl;
760 size_t i;
761 enum htmltag elemtype;
762
763 bl = &n->norm->Bl;
764
765 switch (n->type) {
766 case ROFFT_BODY:
767 return 1;
768
769 case ROFFT_HEAD:
770 if (bl->type != LIST_column || bl->ncols == 0)
771 return 0;
772
773 /*
774 * For each column, print out the <COL> tag with our
775 * suggested width. The last column gets min-width, as
776 * in terminal mode it auto-sizes to the width of the
777 * screen and we want to preserve that behaviour.
778 */
779
780 t = print_otag(h, TAG_COLGROUP, "");
781 for (i = 0; i < bl->ncols - 1; i++)
782 print_otag(h, TAG_COL, "sw+w", bl->cols[i]);
783 print_otag(h, TAG_COL, "swW", bl->cols[i]);
784 print_tagq(h, t);
785 return 0;
786
787 default:
788 break;
789 }
790
791 switch (bl->type) {
792 case LIST_bullet:
793 elemtype = TAG_UL;
794 (void)strlcpy(cattr, "Bl-bullet", sizeof(cattr));
795 break;
796 case LIST_dash:
797 case LIST_hyphen:
798 elemtype = TAG_UL;
799 (void)strlcpy(cattr, "Bl-dash", sizeof(cattr));
800 break;
801 case LIST_item:
802 elemtype = TAG_UL;
803 (void)strlcpy(cattr, "Bl-item", sizeof(cattr));
804 break;
805 case LIST_enum:
806 elemtype = TAG_OL;
807 (void)strlcpy(cattr, "Bl-enum", sizeof(cattr));
808 break;
809 case LIST_diag:
810 elemtype = TAG_DL;
811 (void)strlcpy(cattr, "Bl-diag", sizeof(cattr));
812 break;
813 case LIST_hang:
814 elemtype = TAG_DL;
815 (void)strlcpy(cattr, "Bl-hang", sizeof(cattr));
816 break;
817 case LIST_inset:
818 elemtype = TAG_DL;
819 (void)strlcpy(cattr, "Bl-inset", sizeof(cattr));
820 break;
821 case LIST_ohang:
822 elemtype = TAG_DL;
823 (void)strlcpy(cattr, "Bl-ohang", sizeof(cattr));
824 break;
825 case LIST_tag:
826 if (bl->offs)
827 print_otag(h, TAG_DIV, "cswl", "Bl-tag", bl->offs);
828 print_otag(h, TAG_DL, "csw*+l", bl->comp ?
829 "Bl-tag Bl-compact" : "Bl-tag", bl->width);
830 return 1;
831 case LIST_column:
832 elemtype = TAG_TABLE;
833 (void)strlcpy(cattr, "Bl-column", sizeof(cattr));
834 break;
835 default:
836 abort();
837 }
838 if (bl->comp)
839 (void)strlcat(cattr, " Bl-compact", sizeof(cattr));
840 print_otag(h, elemtype, "cswl", cattr, bl->offs);
841 return 1;
842 }
843
844 static int
845 mdoc_ex_pre(MDOC_ARGS)
846 {
847 if (n->prev)
848 print_otag(h, TAG_BR, "");
849 return 1;
850 }
851
852 static int
853 mdoc_st_pre(MDOC_ARGS)
854 {
855 print_otag(h, TAG_SPAN, "cT", "St");
856 return 1;
857 }
858
859 static int
860 mdoc_em_pre(MDOC_ARGS)
861 {
862 print_otag(h, TAG_I, "cT", "Em");
863 return 1;
864 }
865
866 static int
867 mdoc_d1_pre(MDOC_ARGS)
868 {
869 if (n->type != ROFFT_BLOCK)
870 return 1;
871
872 print_otag(h, TAG_DIV, "c", "D1");
873
874 if (n->tok == MDOC_Dl)
875 print_otag(h, TAG_CODE, "c", "Li");
876
877 return 1;
878 }
879
880 static int
881 mdoc_sx_pre(MDOC_ARGS)
882 {
883 char *id;
884
885 id = html_make_id(n);
886 print_otag(h, TAG_A, "cThR", "Sx", id);
887 free(id);
888 return 1;
889 }
890
891 static int
892 mdoc_bd_pre(MDOC_ARGS)
893 {
894 int comp, offs, sv;
895 struct roff_node *nn;
896
897 if (n->type == ROFFT_HEAD)
898 return 0;
899
900 if (n->type == ROFFT_BLOCK) {
901 comp = n->norm->Bd.comp;
902 for (nn = n; nn && ! comp; nn = nn->parent) {
903 if (nn->type != ROFFT_BLOCK)
904 continue;
905 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
906 comp = 1;
907 if (nn->prev)
908 break;
909 }
910 if ( ! comp)
911 print_paragraph(h);
912 return 1;
913 }
914
915 /* Handle the -offset argument. */
916
917 if (n->norm->Bd.offs == NULL ||
918 ! strcmp(n->norm->Bd.offs, "left"))
919 offs = 0;
920 else if ( ! strcmp(n->norm->Bd.offs, "indent"))
921 offs = INDENT;
922 else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
923 offs = INDENT * 2;
924 else
925 offs = -1;
926
927 if (offs == -1)
928 print_otag(h, TAG_DIV, "cswl", "Bd", n->norm->Bd.offs);
929 else
930 print_otag(h, TAG_DIV, "cshl", "Bd", offs);
931
932 if (n->norm->Bd.type != DISP_unfilled &&
933 n->norm->Bd.type != DISP_literal)
934 return 1;
935
936 print_otag(h, TAG_PRE, "c", "Li");
937
938 /* This can be recursive: save & set our literal state. */
939
940 sv = h->flags & HTML_LITERAL;
941 h->flags |= HTML_LITERAL;
942
943 for (nn = n->child; nn; nn = nn->next) {
944 print_mdoc_node(meta, nn, h);
945 /*
946 * If the printed node flushes its own line, then we
947 * needn't do it here as well. This is hacky, but the
948 * notion of selective eoln whitespace is pretty dumb
949 * anyway, so don't sweat it.
950 */
951 switch (nn->tok) {
952 case ROFF_br:
953 case ROFF_sp:
954 case MDOC_Sm:
955 case MDOC_Bl:
956 case MDOC_D1:
957 case MDOC_Dl:
958 case MDOC_Lp:
959 case MDOC_Pp:
960 continue;
961 default:
962 break;
963 }
964 if (h->flags & HTML_NONEWLINE ||
965 (nn->next && ! (nn->next->flags & NODE_LINE)))
966 continue;
967 else if (nn->next)
968 print_text(h, "\n");
969
970 h->flags |= HTML_NOSPACE;
971 }
972
973 if (0 == sv)
974 h->flags &= ~HTML_LITERAL;
975
976 return 0;
977 }
978
979 static int
980 mdoc_pa_pre(MDOC_ARGS)
981 {
982 print_otag(h, TAG_SPAN, "cT", "Pa");
983 return 1;
984 }
985
986 static int
987 mdoc_ad_pre(MDOC_ARGS)
988 {
989 print_otag(h, TAG_I, "c", "Ad");
990 return 1;
991 }
992
993 static int
994 mdoc_an_pre(MDOC_ARGS)
995 {
996 if (n->norm->An.auth == AUTH_split) {
997 h->flags &= ~HTML_NOSPLIT;
998 h->flags |= HTML_SPLIT;
999 return 0;
1000 }
1001 if (n->norm->An.auth == AUTH_nosplit) {
1002 h->flags &= ~HTML_SPLIT;
1003 h->flags |= HTML_NOSPLIT;
1004 return 0;
1005 }
1006
1007 if (h->flags & HTML_SPLIT)
1008 print_otag(h, TAG_BR, "");
1009
1010 if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
1011 h->flags |= HTML_SPLIT;
1012
1013 print_otag(h, TAG_SPAN, "cT", "An");
1014 return 1;
1015 }
1016
1017 static int
1018 mdoc_cd_pre(MDOC_ARGS)
1019 {
1020 synopsis_pre(h, n);
1021 print_otag(h, TAG_CODE, "cT", "Cd");
1022 return 1;
1023 }
1024
1025 static int
1026 mdoc_dv_pre(MDOC_ARGS)
1027 {
1028 char *id;
1029
1030 if ((id = cond_id(n)) != NULL)
1031 print_otag(h, TAG_A, "chR", "permalink", id);
1032 print_otag(h, TAG_CODE, "cTi", "Dv", id);
1033 free(id);
1034 return 1;
1035 }
1036
1037 static int
1038 mdoc_ev_pre(MDOC_ARGS)
1039 {
1040 char *id;
1041
1042 if ((id = cond_id(n)) != NULL)
1043 print_otag(h, TAG_A, "chR", "permalink", id);
1044 print_otag(h, TAG_CODE, "cTi", "Ev", id);
1045 free(id);
1046 return 1;
1047 }
1048
1049 static int
1050 mdoc_er_pre(MDOC_ARGS)
1051 {
1052 char *id;
1053
1054 id = n->sec == SEC_ERRORS &&
1055 (n->parent->tok == MDOC_It ||
1056 (n->parent->tok == MDOC_Bq &&
1057 n->parent->parent->parent->tok == MDOC_It)) ?
1058 html_make_id(n) : NULL;
1059
1060 if (id != NULL)
1061 print_otag(h, TAG_A, "chR", "permalink", id);
1062 print_otag(h, TAG_CODE, "cTi", "Er", id);
1063 free(id);
1064 return 1;
1065 }
1066
1067 static int
1068 mdoc_fa_pre(MDOC_ARGS)
1069 {
1070 const struct roff_node *nn;
1071 struct tag *t;
1072
1073 if (n->parent->tok != MDOC_Fo) {
1074 print_otag(h, TAG_VAR, "cT", "Fa");
1075 return 1;
1076 }
1077
1078 for (nn = n->child; nn; nn = nn->next) {
1079 t = print_otag(h, TAG_VAR, "cT", "Fa");
1080 print_text(h, nn->string);
1081 print_tagq(h, t);
1082 if (nn->next) {
1083 h->flags |= HTML_NOSPACE;
1084 print_text(h, ",");
1085 }
1086 }
1087
1088 if (n->child && n->next && n->next->tok == MDOC_Fa) {
1089 h->flags |= HTML_NOSPACE;
1090 print_text(h, ",");
1091 }
1092
1093 return 0;
1094 }
1095
1096 static int
1097 mdoc_fd_pre(MDOC_ARGS)
1098 {
1099 struct tag *t;
1100 char *buf, *cp;
1101
1102 synopsis_pre(h, n);
1103
1104 if (NULL == (n = n->child))
1105 return 0;
1106
1107 assert(n->type == ROFFT_TEXT);
1108
1109 if (strcmp(n->string, "#include")) {
1110 print_otag(h, TAG_CODE, "cT", "Fd");
1111 return 1;
1112 }
1113
1114 print_otag(h, TAG_CODE, "cT", "In");
1115 print_text(h, n->string);
1116
1117 if (NULL != (n = n->next)) {
1118 assert(n->type == ROFFT_TEXT);
1119
1120 if (h->base_includes) {
1121 cp = n->string;
1122 if (*cp == '<' || *cp == '"')
1123 cp++;
1124 buf = mandoc_strdup(cp);
1125 cp = strchr(buf, '\0') - 1;
1126 if (cp >= buf && (*cp == '>' || *cp == '"'))
1127 *cp = '\0';
1128 t = print_otag(h, TAG_A, "cThI", "In", buf);
1129 free(buf);
1130 } else
1131 t = print_otag(h, TAG_A, "cT", "In");
1132
1133 print_text(h, n->string);
1134 print_tagq(h, t);
1135
1136 n = n->next;
1137 }
1138
1139 for ( ; n; n = n->next) {
1140 assert(n->type == ROFFT_TEXT);
1141 print_text(h, n->string);
1142 }
1143
1144 return 0;
1145 }
1146
1147 static int
1148 mdoc_vt_pre(MDOC_ARGS)
1149 {
1150 if (n->type == ROFFT_BLOCK) {
1151 synopsis_pre(h, n);
1152 return 1;
1153 } else if (n->type == ROFFT_ELEM) {
1154 synopsis_pre(h, n);
1155 } else if (n->type == ROFFT_HEAD)
1156 return 0;
1157
1158 print_otag(h, TAG_VAR, "cT", "Vt");
1159 return 1;
1160 }
1161
1162 static int
1163 mdoc_ft_pre(MDOC_ARGS)
1164 {
1165 synopsis_pre(h, n);
1166 print_otag(h, TAG_VAR, "cT", "Ft");
1167 return 1;
1168 }
1169
1170 static int
1171 mdoc_fn_pre(MDOC_ARGS)
1172 {
1173 struct tag *t;
1174 char nbuf[BUFSIZ];
1175 const char *sp, *ep;
1176 int sz, pretty;
1177
1178 pretty = NODE_SYNPRETTY & n->flags;
1179 synopsis_pre(h, n);
1180
1181 /* Split apart into type and name. */
1182 assert(n->child->string);
1183 sp = n->child->string;
1184
1185 ep = strchr(sp, ' ');
1186 if (NULL != ep) {
1187 t = print_otag(h, TAG_VAR, "cT", "Ft");
1188
1189 while (ep) {
1190 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1191 (void)memcpy(nbuf, sp, (size_t)sz);
1192 nbuf[sz] = '\0';
1193 print_text(h, nbuf);
1194 sp = ++ep;
1195 ep = strchr(sp, ' ');
1196 }
1197 print_tagq(h, t);
1198 }
1199
1200 t = print_otag(h, TAG_CODE, "cT", "Fn");
1201
1202 if (sp)
1203 print_text(h, sp);
1204
1205 print_tagq(h, t);
1206
1207 h->flags |= HTML_NOSPACE;
1208 print_text(h, "(");
1209 h->flags |= HTML_NOSPACE;
1210
1211 for (n = n->child->next; n; n = n->next) {
1212 if (NODE_SYNPRETTY & n->flags)
1213 t = print_otag(h, TAG_VAR, "cTss?", "Fa",
1214 "white-space", "nowrap");
1215 else
1216 t = print_otag(h, TAG_VAR, "cT", "Fa");
1217 print_text(h, n->string);
1218 print_tagq(h, t);
1219 if (n->next) {
1220 h->flags |= HTML_NOSPACE;
1221 print_text(h, ",");
1222 }
1223 }
1224
1225 h->flags |= HTML_NOSPACE;
1226 print_text(h, ")");
1227
1228 if (pretty) {
1229 h->flags |= HTML_NOSPACE;
1230 print_text(h, ";");
1231 }
1232
1233 return 0;
1234 }
1235
1236 static int
1237 mdoc_sm_pre(MDOC_ARGS)
1238 {
1239
1240 if (NULL == n->child)
1241 h->flags ^= HTML_NONOSPACE;
1242 else if (0 == strcmp("on", n->child->string))
1243 h->flags &= ~HTML_NONOSPACE;
1244 else
1245 h->flags |= HTML_NONOSPACE;
1246
1247 if ( ! (HTML_NONOSPACE & h->flags))
1248 h->flags &= ~HTML_NOSPACE;
1249
1250 return 0;
1251 }
1252
1253 static int
1254 mdoc_skip_pre(MDOC_ARGS)
1255 {
1256
1257 return 0;
1258 }
1259
1260 static int
1261 mdoc_pp_pre(MDOC_ARGS)
1262 {
1263
1264 print_paragraph(h);
1265 return 0;
1266 }
1267
1268 static int
1269 mdoc_lk_pre(MDOC_ARGS)
1270 {
1271 const struct roff_node *link, *descr, *punct;
1272 struct tag *t;
1273
1274 if ((link = n->child) == NULL)
1275 return 0;
1276
1277 /* Find beginning of trailing punctuation. */
1278 punct = n->last;
1279 while (punct != link && punct->flags & NODE_DELIMC)
1280 punct = punct->prev;
1281 punct = punct->next;
1282
1283 /* Link target and link text. */
1284 descr = link->next;
1285 if (descr == punct)
1286 descr = link; /* no text */
1287 t = print_otag(h, TAG_A, "cTh", "Lk", link->string);
1288 do {
1289 if (descr->flags & (NODE_DELIMC | NODE_DELIMO))
1290 h->flags |= HTML_NOSPACE;
1291 print_text(h, descr->string);
1292 descr = descr->next;
1293 } while (descr != punct);
1294 print_tagq(h, t);
1295
1296 /* Trailing punctuation. */
1297 while (punct != NULL) {
1298 h->flags |= HTML_NOSPACE;
1299 print_text(h, punct->string);
1300 punct = punct->next;
1301 }
1302 return 0;
1303 }
1304
1305 static int
1306 mdoc_mt_pre(MDOC_ARGS)
1307 {
1308 struct tag *t;
1309 char *cp;
1310
1311 for (n = n->child; n; n = n->next) {
1312 assert(n->type == ROFFT_TEXT);
1313
1314 mandoc_asprintf(&cp, "mailto:%s", n->string);
1315 t = print_otag(h, TAG_A, "cTh", "Mt", cp);
1316 print_text(h, n->string);
1317 print_tagq(h, t);
1318 free(cp);
1319 }
1320
1321 return 0;
1322 }
1323
1324 static int
1325 mdoc_fo_pre(MDOC_ARGS)
1326 {
1327 struct tag *t;
1328
1329 if (n->type == ROFFT_BODY) {
1330 h->flags |= HTML_NOSPACE;
1331 print_text(h, "(");
1332 h->flags |= HTML_NOSPACE;
1333 return 1;
1334 } else if (n->type == ROFFT_BLOCK) {
1335 synopsis_pre(h, n);
1336 return 1;
1337 }
1338
1339 if (n->child == NULL)
1340 return 0;
1341
1342 assert(n->child->string);
1343 t = print_otag(h, TAG_CODE, "cT", "Fn");
1344 print_text(h, n->child->string);
1345 print_tagq(h, t);
1346 return 0;
1347 }
1348
1349 static void
1350 mdoc_fo_post(MDOC_ARGS)
1351 {
1352
1353 if (n->type != ROFFT_BODY)
1354 return;
1355 h->flags |= HTML_NOSPACE;
1356 print_text(h, ")");
1357 h->flags |= HTML_NOSPACE;
1358 print_text(h, ";");
1359 }
1360
1361 static int
1362 mdoc_in_pre(MDOC_ARGS)
1363 {
1364 struct tag *t;
1365
1366 synopsis_pre(h, n);
1367 print_otag(h, TAG_CODE, "cT", "In");
1368
1369 /*
1370 * The first argument of the `In' gets special treatment as
1371 * being a linked value. Subsequent values are printed
1372 * afterward. groff does similarly. This also handles the case
1373 * of no children.
1374 */
1375
1376 if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
1377 print_text(h, "#include");
1378
1379 print_text(h, "<");
1380 h->flags |= HTML_NOSPACE;
1381
1382 if (NULL != (n = n->child)) {
1383 assert(n->type == ROFFT_TEXT);
1384
1385 if (h->base_includes)
1386 t = print_otag(h, TAG_A, "cThI", "In", n->string);
1387 else
1388 t = print_otag(h, TAG_A, "cT", "In");
1389 print_text(h, n->string);
1390 print_tagq(h, t);
1391
1392 n = n->next;
1393 }
1394
1395 h->flags |= HTML_NOSPACE;
1396 print_text(h, ">");
1397
1398 for ( ; n; n = n->next) {
1399 assert(n->type == ROFFT_TEXT);
1400 print_text(h, n->string);
1401 }
1402
1403 return 0;
1404 }
1405
1406 static int
1407 mdoc_ic_pre(MDOC_ARGS)
1408 {
1409 char *id;
1410
1411 if ((id = cond_id(n)) != NULL)
1412 print_otag(h, TAG_A, "chR", "permalink", id);
1413 print_otag(h, TAG_CODE, "cTi", "Ic", id);
1414 free(id);
1415 return 1;
1416 }
1417
1418 static int
1419 mdoc_va_pre(MDOC_ARGS)
1420 {
1421 print_otag(h, TAG_VAR, "cT", "Va");
1422 return 1;
1423 }
1424
1425 static int
1426 mdoc_ap_pre(MDOC_ARGS)
1427 {
1428
1429 h->flags |= HTML_NOSPACE;
1430 print_text(h, "\\(aq");
1431 h->flags |= HTML_NOSPACE;
1432 return 1;
1433 }
1434
1435 static int
1436 mdoc_bf_pre(MDOC_ARGS)
1437 {
1438 const char *cattr;
1439
1440 if (n->type == ROFFT_HEAD)
1441 return 0;
1442 else if (n->type != ROFFT_BODY)
1443 return 1;
1444
1445 if (FONT_Em == n->norm->Bf.font)
1446 cattr = "Bf Em";
1447 else if (FONT_Sy == n->norm->Bf.font)
1448 cattr = "Bf Sy";
1449 else if (FONT_Li == n->norm->Bf.font)
1450 cattr = "Bf Li";
1451 else
1452 cattr = "Bf No";
1453
1454 /* Cannot use TAG_SPAN because it may contain blocks. */
1455 print_otag(h, TAG_DIV, "cshl", cattr, 1);
1456 return 1;
1457 }
1458
1459 static int
1460 mdoc_ms_pre(MDOC_ARGS)
1461 {
1462 char *id;
1463
1464 if ((id = cond_id(n)) != NULL)
1465 print_otag(h, TAG_A, "chR", "permalink", id);
1466 print_otag(h, TAG_B, "cTi", "Ms", id);
1467 free(id);
1468 return 1;
1469 }
1470
1471 static int
1472 mdoc_igndelim_pre(MDOC_ARGS)
1473 {
1474
1475 h->flags |= HTML_IGNDELIM;
1476 return 1;
1477 }
1478
1479 static void
1480 mdoc_pf_post(MDOC_ARGS)
1481 {
1482
1483 if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1484 h->flags |= HTML_NOSPACE;
1485 }
1486
1487 static int
1488 mdoc_rs_pre(MDOC_ARGS)
1489 {
1490 if (n->type != ROFFT_BLOCK)
1491 return 1;
1492
1493 if (n->prev && SEC_SEE_ALSO == n->sec)
1494 print_paragraph(h);
1495
1496 print_otag(h, TAG_CITE, "cT", "Rs");
1497 return 1;
1498 }
1499
1500 static int
1501 mdoc_no_pre(MDOC_ARGS)
1502 {
1503 char *id;
1504
1505 if ((id = cond_id(n)) != NULL)
1506 print_otag(h, TAG_A, "chR", "permalink", id);
1507 print_otag(h, TAG_SPAN, "ci", "No", id);
1508 free(id);
1509 return 1;
1510 }
1511
1512 static int
1513 mdoc_li_pre(MDOC_ARGS)
1514 {
1515 char *id;
1516
1517 if ((id = cond_id(n)) != NULL)
1518 print_otag(h, TAG_A, "chR", "permalink", id);
1519 print_otag(h, TAG_CODE, "ci", "Li", id);
1520 free(id);
1521 return 1;
1522 }
1523
1524 static int
1525 mdoc_sy_pre(MDOC_ARGS)
1526 {
1527 print_otag(h, TAG_B, "cT", "Sy");
1528 return 1;
1529 }
1530
1531 static int
1532 mdoc_lb_pre(MDOC_ARGS)
1533 {
1534 if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
1535 print_otag(h, TAG_BR, "");
1536
1537 print_otag(h, TAG_SPAN, "cT", "Lb");
1538 return 1;
1539 }
1540
1541 static int
1542 mdoc__x_pre(MDOC_ARGS)
1543 {
1544 const char *cattr;
1545 enum htmltag t;
1546
1547 t = TAG_SPAN;
1548
1549 switch (n->tok) {
1550 case MDOC__A:
1551 cattr = "RsA";
1552 if (n->prev && MDOC__A == n->prev->tok)
1553 if (NULL == n->next || MDOC__A != n->next->tok)
1554 print_text(h, "and");
1555 break;
1556 case MDOC__B:
1557 t = TAG_I;
1558 cattr = "RsB";
1559 break;
1560 case MDOC__C:
1561 cattr = "RsC";
1562 break;
1563 case MDOC__D:
1564 cattr = "RsD";
1565 break;
1566 case MDOC__I:
1567 t = TAG_I;
1568 cattr = "RsI";
1569 break;
1570 case MDOC__J:
1571 t = TAG_I;
1572 cattr = "RsJ";
1573 break;
1574 case MDOC__N:
1575 cattr = "RsN";
1576 break;
1577 case MDOC__O:
1578 cattr = "RsO";
1579 break;
1580 case MDOC__P:
1581 cattr = "RsP";
1582 break;
1583 case MDOC__Q:
1584 cattr = "RsQ";
1585 break;
1586 case MDOC__R:
1587 cattr = "RsR";
1588 break;
1589 case MDOC__T:
1590 cattr = "RsT";
1591 break;
1592 case MDOC__U:
1593 print_otag(h, TAG_A, "ch", "RsU", n->child->string);
1594 return 1;
1595 case MDOC__V:
1596 cattr = "RsV";
1597 break;
1598 default:
1599 abort();
1600 }
1601
1602 print_otag(h, t, "c", cattr);
1603 return 1;
1604 }
1605
1606 static void
1607 mdoc__x_post(MDOC_ARGS)
1608 {
1609
1610 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1611 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1612 if (NULL == n->prev || MDOC__A != n->prev->tok)
1613 return;
1614
1615 /* TODO: %U */
1616
1617 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1618 return;
1619
1620 h->flags |= HTML_NOSPACE;
1621 print_text(h, n->next ? "," : ".");
1622 }
1623
1624 static int
1625 mdoc_bk_pre(MDOC_ARGS)
1626 {
1627
1628 switch (n->type) {
1629 case ROFFT_BLOCK:
1630 break;
1631 case ROFFT_HEAD:
1632 return 0;
1633 case ROFFT_BODY:
1634 if (n->parent->args != NULL || n->prev->child == NULL)
1635 h->flags |= HTML_PREKEEP;
1636 break;
1637 default:
1638 abort();
1639 }
1640
1641 return 1;
1642 }
1643
1644 static void
1645 mdoc_bk_post(MDOC_ARGS)
1646 {
1647
1648 if (n->type == ROFFT_BODY)
1649 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1650 }
1651
1652 static int
1653 mdoc_quote_pre(MDOC_ARGS)
1654 {
1655 if (n->type != ROFFT_BODY)
1656 return 1;
1657
1658 switch (n->tok) {
1659 case MDOC_Ao:
1660 case MDOC_Aq:
1661 print_text(h, n->child != NULL && n->child->next == NULL &&
1662 n->child->tok == MDOC_Mt ? "<" : "\\(la");
1663 break;
1664 case MDOC_Bro:
1665 case MDOC_Brq:
1666 print_text(h, "\\(lC");
1667 break;
1668 case MDOC_Bo:
1669 case MDOC_Bq:
1670 print_text(h, "\\(lB");
1671 break;
1672 case MDOC_Oo:
1673 case MDOC_Op:
1674 print_text(h, "\\(lB");
1675 h->flags |= HTML_NOSPACE;
1676 /* Cannot use TAG_SPAN because it may contain blocks. */
1677 print_otag(h, TAG_IDIV, "c", "Op");
1678 break;
1679 case MDOC_En:
1680 if (NULL == n->norm->Es ||
1681 NULL == n->norm->Es->child)
1682 return 1;
1683 print_text(h, n->norm->Es->child->string);
1684 break;
1685 case MDOC_Do:
1686 case MDOC_Dq:
1687 case MDOC_Qo:
1688 case MDOC_Qq:
1689 print_text(h, "\\(lq");
1690 break;
1691 case MDOC_Po:
1692 case MDOC_Pq:
1693 print_text(h, "(");
1694 break;
1695 case MDOC_Ql:
1696 print_text(h, "\\(oq");
1697 h->flags |= HTML_NOSPACE;
1698 print_otag(h, TAG_CODE, "c", "Li");
1699 break;
1700 case MDOC_So:
1701 case MDOC_Sq:
1702 print_text(h, "\\(oq");
1703 break;
1704 default:
1705 abort();
1706 }
1707
1708 h->flags |= HTML_NOSPACE;
1709 return 1;
1710 }
1711
1712 static void
1713 mdoc_quote_post(MDOC_ARGS)
1714 {
1715
1716 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1717 return;
1718
1719 h->flags |= HTML_NOSPACE;
1720
1721 switch (n->tok) {
1722 case MDOC_Ao:
1723 case MDOC_Aq:
1724 print_text(h, n->child != NULL && n->child->next == NULL &&
1725 n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1726 break;
1727 case MDOC_Bro:
1728 case MDOC_Brq:
1729 print_text(h, "\\(rC");
1730 break;
1731 case MDOC_Oo:
1732 case MDOC_Op:
1733 case MDOC_Bo:
1734 case MDOC_Bq:
1735 print_text(h, "\\(rB");
1736 break;
1737 case MDOC_En:
1738 if (n->norm->Es == NULL ||
1739 n->norm->Es->child == NULL ||
1740 n->norm->Es->child->next == NULL)
1741 h->flags &= ~HTML_NOSPACE;
1742 else
1743 print_text(h, n->norm->Es->child->next->string);
1744 break;
1745 case MDOC_Qo:
1746 case MDOC_Qq:
1747 case MDOC_Do:
1748 case MDOC_Dq:
1749 print_text(h, "\\(rq");
1750 break;
1751 case MDOC_Po:
1752 case MDOC_Pq:
1753 print_text(h, ")");
1754 break;
1755 case MDOC_Ql:
1756 case MDOC_So:
1757 case MDOC_Sq:
1758 print_text(h, "\\(cq");
1759 break;
1760 default:
1761 abort();
1762 }
1763 }
1764
1765 static int
1766 mdoc_eo_pre(MDOC_ARGS)
1767 {
1768
1769 if (n->type != ROFFT_BODY)
1770 return 1;
1771
1772 if (n->end == ENDBODY_NOT &&
1773 n->parent->head->child == NULL &&
1774 n->child != NULL &&
1775 n->child->end != ENDBODY_NOT)
1776 print_text(h, "\\&");
1777 else if (n->end != ENDBODY_NOT ? n->child != NULL :
1778 n->parent->head->child != NULL && (n->child != NULL ||
1779 (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1780 h->flags |= HTML_NOSPACE;
1781 return 1;
1782 }
1783
1784 static void
1785 mdoc_eo_post(MDOC_ARGS)
1786 {
1787 int body, tail;
1788
1789 if (n->type != ROFFT_BODY)
1790 return;
1791
1792 if (n->end != ENDBODY_NOT) {
1793 h->flags &= ~HTML_NOSPACE;
1794 return;
1795 }
1796
1797 body = n->child != NULL || n->parent->head->child != NULL;
1798 tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1799
1800 if (body && tail)
1801 h->flags |= HTML_NOSPACE;
1802 else if ( ! tail)
1803 h->flags &= ~HTML_NOSPACE;
1804 }