1 /* $Id: mdoc_html.c,v 1.316 2018/12/03 21:00:10 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
37 #define MDOC_ARGS const struct roff_meta *meta, \
38 struct roff_node *n, \
42 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
45 struct mdoc_html_act
{
46 int (*pre
)(MDOC_ARGS
);
47 void (*post
)(MDOC_ARGS
);
50 static char *cond_id(const struct roff_node
*);
51 static void print_mdoc_head(const struct roff_meta
*,
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 roff_node
*);
58 static void mdoc_root_post(const struct roff_meta
*,
60 static int mdoc_root_pre(const struct roff_meta
*,
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_abort_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_cd_pre(MDOC_ARGS
);
76 static int mdoc_cm_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static int mdoc_dv_pre(MDOC_ARGS
);
79 static int mdoc_fa_pre(MDOC_ARGS
);
80 static int mdoc_fd_pre(MDOC_ARGS
);
81 static int mdoc_fl_pre(MDOC_ARGS
);
82 static int mdoc_fn_pre(MDOC_ARGS
);
83 static int mdoc_ft_pre(MDOC_ARGS
);
84 static int mdoc_em_pre(MDOC_ARGS
);
85 static void mdoc_eo_post(MDOC_ARGS
);
86 static int mdoc_eo_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_no_pre(MDOC_ARGS
);
104 static int mdoc_ns_pre(MDOC_ARGS
);
105 static int mdoc_pa_pre(MDOC_ARGS
);
106 static void mdoc_pf_post(MDOC_ARGS
);
107 static int mdoc_pp_pre(MDOC_ARGS
);
108 static void mdoc_quote_post(MDOC_ARGS
);
109 static int mdoc_quote_pre(MDOC_ARGS
);
110 static int mdoc_rs_pre(MDOC_ARGS
);
111 static int mdoc_sh_pre(MDOC_ARGS
);
112 static int mdoc_skip_pre(MDOC_ARGS
);
113 static int mdoc_sm_pre(MDOC_ARGS
);
114 static int mdoc_ss_pre(MDOC_ARGS
);
115 static int mdoc_st_pre(MDOC_ARGS
);
116 static int mdoc_sx_pre(MDOC_ARGS
);
117 static int mdoc_sy_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
);
123 static const struct mdoc_html_act mdoc_html_acts
[MDOC_MAX
- MDOC_Dd
] = {
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ap_pre
, NULL
}, /* Ap */
140 {mdoc_ar_pre
, NULL
}, /* Ar */
141 {mdoc_cd_pre
, NULL
}, /* Cd */
142 {mdoc_cm_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_abort_pre
, NULL
}, /* Ot */
159 {mdoc_pa_pre
, NULL
}, /* Pa */
160 {mdoc_ex_pre
, NULL
}, /* Rv */
161 {mdoc_st_pre
, 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 {mdoc_xx_pre
, 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_xx_pre
, NULL
}, /* Bx */
186 {mdoc_skip_pre
, 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_eo_pre
, mdoc_eo_post
}, /* Eo */
194 {mdoc_xx_pre
, NULL
}, /* Fx */
195 {mdoc_ms_pre
, NULL
}, /* Ms */
196 {mdoc_no_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 {NULL
, NULL
}, /* Bt */
227 {NULL
, NULL
}, /* Hf */
228 {mdoc_em_pre
, NULL
}, /* Fr */
229 {NULL
, NULL
}, /* Ud */
230 {mdoc_lb_pre
, NULL
}, /* Lb */
231 {mdoc_abort_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__x_pre
, mdoc__x_post
}, /* %U */
243 {NULL
, NULL
}, /* Ta */
248 * See the same function in mdoc_term.c for documentation.
251 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
254 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
257 if (n
->prev
->tok
== n
->tok
&&
261 print_otag(h
, TAG_BR
, "");
265 switch (n
->prev
->tok
) {
274 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
280 print_otag(h
, TAG_BR
, "");
286 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
292 h
= (struct html
*)arg
;
293 n
= mdoc
->first
->child
;
295 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
297 print_otag(h
, TAG_HTML
, "");
298 if (n
->type
== ROFFT_COMMENT
)
299 print_gen_comment(h
, n
);
300 t
= print_otag(h
, TAG_HEAD
, "");
301 print_mdoc_head(&mdoc
->meta
, h
);
303 print_otag(h
, TAG_BODY
, "");
306 mdoc_root_pre(&mdoc
->meta
, h
);
307 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
308 print_mdoc_nodelist(&mdoc
->meta
, n
, h
);
310 mdoc_root_post(&mdoc
->meta
, h
);
315 print_mdoc_head(const struct roff_meta
*meta
, struct html
*h
)
321 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
322 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
323 meta
->msec
, meta
->arch
);
324 else if (meta
->msec
!= NULL
)
325 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
326 else if (meta
->arch
!= NULL
)
327 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
329 cp
= mandoc_strdup(meta
->title
);
331 print_otag(h
, TAG_TITLE
, "");
337 print_mdoc_nodelist(MDOC_ARGS
)
341 print_mdoc_node(meta
, n
, h
);
347 print_mdoc_node(MDOC_ARGS
)
352 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
357 n
->flags
&= ~NODE_ENDED
;
361 /* No tables in this mode... */
362 assert(NULL
== h
->tblt
);
365 * Make sure that if we're in a literal mode already
366 * (i.e., within a <PRE>) don't print the newline.
368 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
369 (h
->flags
& (HTML_LITERAL
| HTML_NONEWLINE
)) == 0)
370 print_otag(h
, TAG_BR
, "");
371 if (NODE_DELIMC
& n
->flags
)
372 h
->flags
|= HTML_NOSPACE
;
373 print_text(h
, n
->string
);
374 if (NODE_DELIMO
& n
->flags
)
375 h
->flags
|= HTML_NOSPACE
;
378 print_eqn(h
, n
->eqn
);
382 * This will take care of initialising all of the table
383 * state data for the first table, then tearing it down
386 print_tbl(h
, n
->span
);
390 * Close out the current table, if it's open, and unset
391 * the "meta" table state. This will be reopened on the
392 * next table element.
394 if (h
->tblt
!= NULL
) {
398 assert(h
->tblt
== NULL
);
399 if (n
->tok
< ROFF_MAX
) {
404 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
405 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
!= NULL
&&
406 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
407 child
= (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
)(meta
,
412 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
413 h
->flags
&= ~HTML_KEEP
;
414 h
->flags
|= HTML_PREKEEP
;
417 if (child
&& n
->child
)
418 print_mdoc_nodelist(meta
, n
->child
, h
);
426 if (n
->tok
< ROFF_MAX
||
427 mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
== NULL
||
428 n
->flags
& NODE_ENDED
)
430 (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
)(meta
, n
, h
);
431 if (n
->end
!= ENDBODY_NOT
)
432 n
->body
->flags
|= NODE_ENDED
;
438 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
442 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
443 tt
= print_otag(h
, TAG_TR
, "");
445 print_otag(h
, TAG_TD
, "c", "foot-date");
446 print_text(h
, meta
->date
);
449 print_otag(h
, TAG_TD
, "c", "foot-os");
450 print_text(h
, meta
->os
);
455 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
458 char *volume
, *title
;
460 if (NULL
== meta
->arch
)
461 volume
= mandoc_strdup(meta
->vol
);
463 mandoc_asprintf(&volume
, "%s (%s)",
464 meta
->vol
, meta
->arch
);
466 if (NULL
== meta
->msec
)
467 title
= mandoc_strdup(meta
->title
);
469 mandoc_asprintf(&title
, "%s(%s)",
470 meta
->title
, meta
->msec
);
472 t
= print_otag(h
, TAG_TABLE
, "c", "head");
473 tt
= print_otag(h
, TAG_TR
, "");
475 print_otag(h
, TAG_TD
, "c", "head-ltitle");
476 print_text(h
, title
);
479 print_otag(h
, TAG_TD
, "c", "head-vol");
480 print_text(h
, volume
);
483 print_otag(h
, TAG_TD
, "c", "head-rtitle");
484 print_text(h
, title
);
493 cond_id(const struct roff_node
*n
)
495 if (n
->child
!= NULL
&&
496 n
->child
->type
== ROFFT_TEXT
&&
498 (n
->prev
->type
== ROFFT_TEXT
&&
499 strcmp(n
->prev
->string
, "|") == 0)) &&
500 (n
->parent
->tok
== MDOC_It
||
501 (n
->parent
->tok
== MDOC_Xo
&&
502 n
->parent
->parent
->prev
== NULL
&&
503 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
504 return html_make_id(n
, 1);
509 mdoc_sh_pre(MDOC_ARGS
)
511 struct roff_node
*sn
, *subn
;
512 struct tag
*t
, *tsec
, *tsub
;
518 if ((h
->oflags
& HTML_TOC
) == 0 ||
519 h
->flags
& HTML_TOCDONE
||
520 n
->sec
<= SEC_SYNOPSIS
)
522 h
->flags
|= HTML_TOCDONE
;
524 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
525 if (sn
->sec
== SEC_CUSTOM
)
530 t
= print_otag(h
, TAG_H1
, "c", "Sh");
531 print_text(h
, "TABLE OF CONTENTS");
533 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
534 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
535 tsec
= print_otag(h
, TAG_LI
, "");
536 id
= html_make_id(sn
->head
, 0);
537 print_otag(h
, TAG_A
, "hR", id
);
539 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
541 for (subn
= sn
->body
->child
; subn
!= NULL
;
543 if (subn
->tok
!= MDOC_Ss
)
545 id
= html_make_id(subn
->head
, 0);
549 print_otag(h
, TAG_UL
,
551 tsub
= print_otag(h
, TAG_LI
, "");
552 print_otag(h
, TAG_A
, "hR", id
);
554 print_mdoc_nodelist(meta
,
555 subn
->head
->child
, h
);
563 id
= html_make_id(n
, 1);
564 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
566 print_otag(h
, TAG_A
, "chR", "permalink", id
);
569 if (n
->sec
== SEC_AUTHORS
)
570 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
579 mdoc_ss_pre(MDOC_ARGS
)
583 if (n
->type
!= ROFFT_HEAD
)
586 id
= html_make_id(n
, 1);
587 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
589 print_otag(h
, TAG_A
, "chR", "permalink", id
);
594 mdoc_fl_pre(MDOC_ARGS
)
598 if ((id
= cond_id(n
)) != NULL
)
599 print_otag(h
, TAG_A
, "chR", "permalink", id
);
600 print_otag(h
, TAG_CODE
, "cTi", "Fl", id
);
602 print_text(h
, "\\-");
603 if (!(n
->child
== NULL
&&
605 n
->next
->type
== ROFFT_TEXT
||
606 n
->next
->flags
& NODE_LINE
)))
607 h
->flags
|= HTML_NOSPACE
;
613 mdoc_cm_pre(MDOC_ARGS
)
617 if ((id
= cond_id(n
)) != NULL
)
618 print_otag(h
, TAG_A
, "chR", "permalink", id
);
619 print_otag(h
, TAG_CODE
, "cTi", "Cm", id
);
624 mdoc_nd_pre(MDOC_ARGS
)
626 if (n
->type
!= ROFFT_BODY
)
629 print_text(h
, "\\(em");
630 /* Cannot use TAG_SPAN because it may contain blocks. */
631 print_otag(h
, TAG_DIV
, "cT", "Nd");
636 mdoc_nm_pre(MDOC_ARGS
)
640 print_otag(h
, TAG_TD
, "");
643 print_otag(h
, TAG_CODE
, "cT", "Nm");
646 print_otag(h
, TAG_TD
, "");
652 print_otag(h
, TAG_TABLE
, "c", "Nm");
653 print_otag(h
, TAG_TR
, "");
658 mdoc_xr_pre(MDOC_ARGS
)
660 if (NULL
== n
->child
)
664 print_otag(h
, TAG_A
, "cThM", "Xr",
665 n
->child
->string
, n
->child
->next
== NULL
?
666 NULL
: n
->child
->next
->string
);
668 print_otag(h
, TAG_A
, "cT", "Xr");
671 print_text(h
, n
->string
);
673 if (NULL
== (n
= n
->next
))
676 h
->flags
|= HTML_NOSPACE
;
678 h
->flags
|= HTML_NOSPACE
;
679 print_text(h
, n
->string
);
680 h
->flags
|= HTML_NOSPACE
;
686 mdoc_ns_pre(MDOC_ARGS
)
689 if ( ! (NODE_LINE
& n
->flags
))
690 h
->flags
|= HTML_NOSPACE
;
695 mdoc_ar_pre(MDOC_ARGS
)
697 print_otag(h
, TAG_VAR
, "cT", "Ar");
702 mdoc_xx_pre(MDOC_ARGS
)
704 print_otag(h
, TAG_SPAN
, "c", "Ux");
709 mdoc_it_pre(MDOC_ARGS
)
711 const struct roff_node
*bl
;
716 while (bl
->tok
!= MDOC_Bl
)
718 type
= bl
->norm
->Bl
.type
;
730 print_otag(h
, TAG_LI
, "");
742 print_otag(h
, TAG_DT
, "");
745 print_otag(h
, TAG_DD
, "");
754 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
755 (n
->parent
->prev
== NULL
||
756 n
->parent
->prev
->body
== NULL
||
757 n
->parent
->prev
->body
->child
!= NULL
)) {
758 t
= print_otag(h
, TAG_DT
, "");
759 print_text(h
, "\\ ");
761 t
= print_otag(h
, TAG_DD
, "");
762 print_text(h
, "\\ ");
765 print_otag(h
, TAG_DT
, "");
768 if (n
->child
== NULL
) {
769 print_otag(h
, TAG_DD
, "s", "width", "auto");
770 print_text(h
, "\\ ");
772 print_otag(h
, TAG_DD
, "");
783 print_otag(h
, TAG_TD
, "");
786 print_otag(h
, TAG_TR
, "");
796 mdoc_bl_pre(MDOC_ARGS
)
800 enum htmltag elemtype
;
815 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
820 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
824 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
828 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
832 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
836 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
840 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
844 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
848 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
849 print_otag(h
, TAG_DL
, "c", bl
->comp
?
850 "Bl-tag Bl-compact" : "Bl-tag");
853 elemtype
= TAG_TABLE
;
854 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
859 if (bl
->offs
!= NULL
)
860 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
862 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
863 print_otag(h
, elemtype
, "c", cattr
);
868 mdoc_ex_pre(MDOC_ARGS
)
871 print_otag(h
, TAG_BR
, "");
876 mdoc_st_pre(MDOC_ARGS
)
878 print_otag(h
, TAG_SPAN
, "cT", "St");
883 mdoc_em_pre(MDOC_ARGS
)
885 print_otag(h
, TAG_I
, "cT", "Em");
890 mdoc_d1_pre(MDOC_ARGS
)
892 if (n
->type
!= ROFFT_BLOCK
)
895 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
897 if (n
->tok
== MDOC_Dl
)
898 print_otag(h
, TAG_CODE
, "c", "Li");
904 mdoc_sx_pre(MDOC_ARGS
)
908 id
= html_make_id(n
, 0);
909 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
915 mdoc_bd_pre(MDOC_ARGS
)
918 struct roff_node
*nn
;
920 if (n
->type
== ROFFT_HEAD
)
923 if (n
->type
== ROFFT_BLOCK
) {
924 comp
= n
->norm
->Bd
.comp
;
925 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
926 if (nn
->type
!= ROFFT_BLOCK
)
928 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
938 /* Handle the -offset argument. */
940 if (n
->norm
->Bd
.offs
== NULL
||
941 ! strcmp(n
->norm
->Bd
.offs
, "left"))
942 print_otag(h
, TAG_DIV
, "c", "Bd");
944 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
946 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
947 n
->norm
->Bd
.type
!= DISP_literal
)
950 print_otag(h
, TAG_PRE
, "c", "Li");
952 /* This can be recursive: save & set our literal state. */
954 sv
= h
->flags
& HTML_LITERAL
;
955 h
->flags
|= HTML_LITERAL
;
957 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
958 print_mdoc_node(meta
, nn
, h
);
960 * If the printed node flushes its own line, then we
961 * needn't do it here as well. This is hacky, but the
962 * notion of selective eoln whitespace is pretty dumb
963 * anyway, so don't sweat it.
977 if (h
->flags
& HTML_NONEWLINE
||
978 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
983 h
->flags
|= HTML_NOSPACE
;
987 h
->flags
&= ~HTML_LITERAL
;
993 mdoc_pa_pre(MDOC_ARGS
)
995 print_otag(h
, TAG_SPAN
, "cT", "Pa");
1000 mdoc_ad_pre(MDOC_ARGS
)
1002 print_otag(h
, TAG_SPAN
, "c", "Ad");
1007 mdoc_an_pre(MDOC_ARGS
)
1009 if (n
->norm
->An
.auth
== AUTH_split
) {
1010 h
->flags
&= ~HTML_NOSPLIT
;
1011 h
->flags
|= HTML_SPLIT
;
1014 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1015 h
->flags
&= ~HTML_SPLIT
;
1016 h
->flags
|= HTML_NOSPLIT
;
1020 if (h
->flags
& HTML_SPLIT
)
1021 print_otag(h
, TAG_BR
, "");
1023 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1024 h
->flags
|= HTML_SPLIT
;
1026 print_otag(h
, TAG_SPAN
, "cT", "An");
1031 mdoc_cd_pre(MDOC_ARGS
)
1034 print_otag(h
, TAG_CODE
, "cT", "Cd");
1039 mdoc_dv_pre(MDOC_ARGS
)
1043 if ((id
= cond_id(n
)) != NULL
)
1044 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1045 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1050 mdoc_ev_pre(MDOC_ARGS
)
1054 if ((id
= cond_id(n
)) != NULL
)
1055 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1056 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1061 mdoc_er_pre(MDOC_ARGS
)
1065 id
= n
->sec
== SEC_ERRORS
&&
1066 (n
->parent
->tok
== MDOC_It
||
1067 (n
->parent
->tok
== MDOC_Bq
&&
1068 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1069 html_make_id(n
, 1) : NULL
;
1072 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1073 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1078 mdoc_fa_pre(MDOC_ARGS
)
1080 const struct roff_node
*nn
;
1083 if (n
->parent
->tok
!= MDOC_Fo
) {
1084 print_otag(h
, TAG_VAR
, "cT", "Fa");
1088 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1089 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1090 print_text(h
, nn
->string
);
1093 h
->flags
|= HTML_NOSPACE
;
1098 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1099 h
->flags
|= HTML_NOSPACE
;
1107 mdoc_fd_pre(MDOC_ARGS
)
1114 if (NULL
== (n
= n
->child
))
1117 assert(n
->type
== ROFFT_TEXT
);
1119 if (strcmp(n
->string
, "#include")) {
1120 print_otag(h
, TAG_CODE
, "cT", "Fd");
1124 print_otag(h
, TAG_CODE
, "cT", "In");
1125 print_text(h
, n
->string
);
1127 if (NULL
!= (n
= n
->next
)) {
1128 assert(n
->type
== ROFFT_TEXT
);
1130 if (h
->base_includes
) {
1132 if (*cp
== '<' || *cp
== '"')
1134 buf
= mandoc_strdup(cp
);
1135 cp
= strchr(buf
, '\0') - 1;
1136 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1138 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1141 t
= print_otag(h
, TAG_A
, "cT", "In");
1143 print_text(h
, n
->string
);
1149 for ( ; n
; n
= n
->next
) {
1150 assert(n
->type
== ROFFT_TEXT
);
1151 print_text(h
, n
->string
);
1158 mdoc_vt_pre(MDOC_ARGS
)
1160 if (n
->type
== ROFFT_BLOCK
) {
1163 } else if (n
->type
== ROFFT_ELEM
) {
1165 } else if (n
->type
== ROFFT_HEAD
)
1168 print_otag(h
, TAG_VAR
, "cT", "Vt");
1173 mdoc_ft_pre(MDOC_ARGS
)
1176 print_otag(h
, TAG_VAR
, "cT", "Ft");
1181 mdoc_fn_pre(MDOC_ARGS
)
1185 const char *sp
, *ep
;
1188 pretty
= NODE_SYNPRETTY
& n
->flags
;
1191 /* Split apart into type and name. */
1192 assert(n
->child
->string
);
1193 sp
= n
->child
->string
;
1195 ep
= strchr(sp
, ' ');
1197 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1200 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1201 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1203 print_text(h
, nbuf
);
1205 ep
= strchr(sp
, ' ');
1210 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1217 h
->flags
|= HTML_NOSPACE
;
1219 h
->flags
|= HTML_NOSPACE
;
1221 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1222 if (NODE_SYNPRETTY
& n
->flags
)
1223 t
= print_otag(h
, TAG_VAR
, "cTs", "Fa",
1224 "white-space", "nowrap");
1226 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1227 print_text(h
, n
->string
);
1230 h
->flags
|= HTML_NOSPACE
;
1235 h
->flags
|= HTML_NOSPACE
;
1239 h
->flags
|= HTML_NOSPACE
;
1247 mdoc_sm_pre(MDOC_ARGS
)
1250 if (NULL
== n
->child
)
1251 h
->flags
^= HTML_NONOSPACE
;
1252 else if (0 == strcmp("on", n
->child
->string
))
1253 h
->flags
&= ~HTML_NONOSPACE
;
1255 h
->flags
|= HTML_NONOSPACE
;
1257 if ( ! (HTML_NONOSPACE
& h
->flags
))
1258 h
->flags
&= ~HTML_NOSPACE
;
1264 mdoc_skip_pre(MDOC_ARGS
)
1271 mdoc_pp_pre(MDOC_ARGS
)
1279 mdoc_lk_pre(MDOC_ARGS
)
1281 const struct roff_node
*link
, *descr
, *punct
;
1284 if ((link
= n
->child
) == NULL
)
1287 /* Find beginning of trailing punctuation. */
1289 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1290 punct
= punct
->prev
;
1291 punct
= punct
->next
;
1293 /* Link target and link text. */
1296 descr
= link
; /* no text */
1297 t
= print_otag(h
, TAG_A
, "cTh", "Lk", link
->string
);
1299 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1300 h
->flags
|= HTML_NOSPACE
;
1301 print_text(h
, descr
->string
);
1302 descr
= descr
->next
;
1303 } while (descr
!= punct
);
1306 /* Trailing punctuation. */
1307 while (punct
!= NULL
) {
1308 h
->flags
|= HTML_NOSPACE
;
1309 print_text(h
, punct
->string
);
1310 punct
= punct
->next
;
1316 mdoc_mt_pre(MDOC_ARGS
)
1321 for (n
= n
->child
; n
; n
= n
->next
) {
1322 assert(n
->type
== ROFFT_TEXT
);
1324 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1325 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1326 print_text(h
, n
->string
);
1335 mdoc_fo_pre(MDOC_ARGS
)
1339 if (n
->type
== ROFFT_BODY
) {
1340 h
->flags
|= HTML_NOSPACE
;
1342 h
->flags
|= HTML_NOSPACE
;
1344 } else if (n
->type
== ROFFT_BLOCK
) {
1349 if (n
->child
== NULL
)
1352 assert(n
->child
->string
);
1353 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1354 print_text(h
, n
->child
->string
);
1360 mdoc_fo_post(MDOC_ARGS
)
1363 if (n
->type
!= ROFFT_BODY
)
1365 h
->flags
|= HTML_NOSPACE
;
1367 h
->flags
|= HTML_NOSPACE
;
1372 mdoc_in_pre(MDOC_ARGS
)
1377 print_otag(h
, TAG_CODE
, "cT", "In");
1380 * The first argument of the `In' gets special treatment as
1381 * being a linked value. Subsequent values are printed
1382 * afterward. groff does similarly. This also handles the case
1386 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1387 print_text(h
, "#include");
1390 h
->flags
|= HTML_NOSPACE
;
1392 if (NULL
!= (n
= n
->child
)) {
1393 assert(n
->type
== ROFFT_TEXT
);
1395 if (h
->base_includes
)
1396 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1398 t
= print_otag(h
, TAG_A
, "cT", "In");
1399 print_text(h
, n
->string
);
1405 h
->flags
|= HTML_NOSPACE
;
1408 for ( ; n
; n
= n
->next
) {
1409 assert(n
->type
== ROFFT_TEXT
);
1410 print_text(h
, n
->string
);
1417 mdoc_ic_pre(MDOC_ARGS
)
1421 if ((id
= cond_id(n
)) != NULL
)
1422 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1423 print_otag(h
, TAG_CODE
, "cTi", "Ic", id
);
1428 mdoc_va_pre(MDOC_ARGS
)
1430 print_otag(h
, TAG_VAR
, "cT", "Va");
1435 mdoc_ap_pre(MDOC_ARGS
)
1438 h
->flags
|= HTML_NOSPACE
;
1439 print_text(h
, "\\(aq");
1440 h
->flags
|= HTML_NOSPACE
;
1445 mdoc_bf_pre(MDOC_ARGS
)
1449 if (n
->type
== ROFFT_HEAD
)
1451 else if (n
->type
!= ROFFT_BODY
)
1454 if (FONT_Em
== n
->norm
->Bf
.font
)
1456 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1458 else if (FONT_Li
== n
->norm
->Bf
.font
)
1463 /* Cannot use TAG_SPAN because it may contain blocks. */
1464 print_otag(h
, TAG_DIV
, "c", cattr
);
1469 mdoc_ms_pre(MDOC_ARGS
)
1473 if ((id
= cond_id(n
)) != NULL
)
1474 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1475 print_otag(h
, TAG_SPAN
, "cTi", "Ms", id
);
1480 mdoc_igndelim_pre(MDOC_ARGS
)
1483 h
->flags
|= HTML_IGNDELIM
;
1488 mdoc_pf_post(MDOC_ARGS
)
1491 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1492 h
->flags
|= HTML_NOSPACE
;
1496 mdoc_rs_pre(MDOC_ARGS
)
1498 if (n
->type
!= ROFFT_BLOCK
)
1501 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1504 print_otag(h
, TAG_CITE
, "cT", "Rs");
1509 mdoc_no_pre(MDOC_ARGS
)
1513 if ((id
= cond_id(n
)) != NULL
)
1514 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1515 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1520 mdoc_li_pre(MDOC_ARGS
)
1524 if ((id
= cond_id(n
)) != NULL
)
1525 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1526 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1531 mdoc_sy_pre(MDOC_ARGS
)
1533 print_otag(h
, TAG_B
, "cT", "Sy");
1538 mdoc_lb_pre(MDOC_ARGS
)
1540 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1541 print_otag(h
, TAG_BR
, "");
1543 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1548 mdoc__x_pre(MDOC_ARGS
)
1558 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1559 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1560 print_text(h
, "and");
1599 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1608 print_otag(h
, t
, "c", cattr
);
1613 mdoc__x_post(MDOC_ARGS
)
1616 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1617 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1618 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1623 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1626 h
->flags
|= HTML_NOSPACE
;
1627 print_text(h
, n
->next
? "," : ".");
1631 mdoc_bk_pre(MDOC_ARGS
)
1640 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1641 h
->flags
|= HTML_PREKEEP
;
1651 mdoc_bk_post(MDOC_ARGS
)
1654 if (n
->type
== ROFFT_BODY
)
1655 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1659 mdoc_quote_pre(MDOC_ARGS
)
1661 if (n
->type
!= ROFFT_BODY
)
1667 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1668 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1672 print_text(h
, "\\(lC");
1676 print_text(h
, "\\(lB");
1680 print_text(h
, "\\(lB");
1681 h
->flags
|= HTML_NOSPACE
;
1682 /* Cannot use TAG_SPAN because it may contain blocks. */
1683 print_otag(h
, TAG_IDIV
, "c", "Op");
1686 if (NULL
== n
->norm
->Es
||
1687 NULL
== n
->norm
->Es
->child
)
1689 print_text(h
, n
->norm
->Es
->child
->string
);
1695 print_text(h
, "\\(lq");
1702 print_text(h
, "\\(oq");
1703 h
->flags
|= HTML_NOSPACE
;
1704 print_otag(h
, TAG_CODE
, "c", "Li");
1708 print_text(h
, "\\(oq");
1714 h
->flags
|= HTML_NOSPACE
;
1719 mdoc_quote_post(MDOC_ARGS
)
1722 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1725 h
->flags
|= HTML_NOSPACE
;
1730 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1731 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1735 print_text(h
, "\\(rC");
1741 print_text(h
, "\\(rB");
1744 if (n
->norm
->Es
== NULL
||
1745 n
->norm
->Es
->child
== NULL
||
1746 n
->norm
->Es
->child
->next
== NULL
)
1747 h
->flags
&= ~HTML_NOSPACE
;
1749 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1755 print_text(h
, "\\(rq");
1764 print_text(h
, "\\(cq");
1772 mdoc_eo_pre(MDOC_ARGS
)
1775 if (n
->type
!= ROFFT_BODY
)
1778 if (n
->end
== ENDBODY_NOT
&&
1779 n
->parent
->head
->child
== NULL
&&
1781 n
->child
->end
!= ENDBODY_NOT
)
1782 print_text(h
, "\\&");
1783 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1784 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1785 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1786 h
->flags
|= HTML_NOSPACE
;
1791 mdoc_eo_post(MDOC_ARGS
)
1795 if (n
->type
!= ROFFT_BODY
)
1798 if (n
->end
!= ENDBODY_NOT
) {
1799 h
->flags
&= ~HTML_NOSPACE
;
1803 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1804 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1807 h
->flags
|= HTML_NOSPACE
;
1809 h
->flags
&= ~HTML_NOSPACE
;
1813 mdoc_abort_pre(MDOC_ARGS
)