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