1 /* $Id: mdoc_html.c,v 1.315 2018/10/04 13:23:04 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_ad_pre(MDOC_ARGS
);
66 static int mdoc_an_pre(MDOC_ARGS
);
67 static int mdoc_ap_pre(MDOC_ARGS
);
68 static int mdoc_ar_pre(MDOC_ARGS
);
69 static int mdoc_bd_pre(MDOC_ARGS
);
70 static int mdoc_bf_pre(MDOC_ARGS
);
71 static void mdoc_bk_post(MDOC_ARGS
);
72 static int mdoc_bk_pre(MDOC_ARGS
);
73 static int mdoc_bl_pre(MDOC_ARGS
);
74 static int mdoc_cd_pre(MDOC_ARGS
);
75 static int mdoc_cm_pre(MDOC_ARGS
);
76 static int mdoc_d1_pre(MDOC_ARGS
);
77 static int mdoc_dv_pre(MDOC_ARGS
);
78 static int mdoc_fa_pre(MDOC_ARGS
);
79 static int mdoc_fd_pre(MDOC_ARGS
);
80 static int mdoc_fl_pre(MDOC_ARGS
);
81 static int mdoc_fn_pre(MDOC_ARGS
);
82 static int mdoc_ft_pre(MDOC_ARGS
);
83 static int mdoc_em_pre(MDOC_ARGS
);
84 static void mdoc_eo_post(MDOC_ARGS
);
85 static int mdoc_eo_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_no_pre(MDOC_ARGS
);
103 static int mdoc_ns_pre(MDOC_ARGS
);
104 static int mdoc_pa_pre(MDOC_ARGS
);
105 static void mdoc_pf_post(MDOC_ARGS
);
106 static int mdoc_pp_pre(MDOC_ARGS
);
107 static void mdoc_quote_post(MDOC_ARGS
);
108 static int mdoc_quote_pre(MDOC_ARGS
);
109 static int mdoc_rs_pre(MDOC_ARGS
);
110 static int mdoc_sh_pre(MDOC_ARGS
);
111 static int mdoc_skip_pre(MDOC_ARGS
);
112 static int mdoc_sm_pre(MDOC_ARGS
);
113 static int mdoc_ss_pre(MDOC_ARGS
);
114 static int mdoc_st_pre(MDOC_ARGS
);
115 static int mdoc_sx_pre(MDOC_ARGS
);
116 static int mdoc_sy_pre(MDOC_ARGS
);
117 static int mdoc_va_pre(MDOC_ARGS
);
118 static int mdoc_vt_pre(MDOC_ARGS
);
119 static int mdoc_xr_pre(MDOC_ARGS
);
120 static int mdoc_xx_pre(MDOC_ARGS
);
122 static const struct mdoc_html_act mdoc_html_acts
[MDOC_MAX
- MDOC_Dd
] = {
123 {NULL
, NULL
}, /* Dd */
124 {NULL
, NULL
}, /* Dt */
125 {NULL
, NULL
}, /* Os */
126 {mdoc_sh_pre
, NULL
}, /* Sh */
127 {mdoc_ss_pre
, NULL
}, /* Ss */
128 {mdoc_pp_pre
, NULL
}, /* Pp */
129 {mdoc_d1_pre
, NULL
}, /* D1 */
130 {mdoc_d1_pre
, NULL
}, /* Dl */
131 {mdoc_bd_pre
, NULL
}, /* Bd */
132 {NULL
, NULL
}, /* Ed */
133 {mdoc_bl_pre
, NULL
}, /* Bl */
134 {NULL
, NULL
}, /* El */
135 {mdoc_it_pre
, NULL
}, /* It */
136 {mdoc_ad_pre
, NULL
}, /* Ad */
137 {mdoc_an_pre
, NULL
}, /* An */
138 {mdoc_ap_pre
, NULL
}, /* Ap */
139 {mdoc_ar_pre
, NULL
}, /* Ar */
140 {mdoc_cd_pre
, NULL
}, /* Cd */
141 {mdoc_cm_pre
, NULL
}, /* Cm */
142 {mdoc_dv_pre
, NULL
}, /* Dv */
143 {mdoc_er_pre
, NULL
}, /* Er */
144 {mdoc_ev_pre
, NULL
}, /* Ev */
145 {mdoc_ex_pre
, NULL
}, /* Ex */
146 {mdoc_fa_pre
, NULL
}, /* Fa */
147 {mdoc_fd_pre
, NULL
}, /* Fd */
148 {mdoc_fl_pre
, NULL
}, /* Fl */
149 {mdoc_fn_pre
, NULL
}, /* Fn */
150 {mdoc_ft_pre
, NULL
}, /* Ft */
151 {mdoc_ic_pre
, NULL
}, /* Ic */
152 {mdoc_in_pre
, NULL
}, /* In */
153 {mdoc_li_pre
, NULL
}, /* Li */
154 {mdoc_nd_pre
, NULL
}, /* Nd */
155 {mdoc_nm_pre
, NULL
}, /* Nm */
156 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
157 {mdoc_ft_pre
, NULL
}, /* Ot */
158 {mdoc_pa_pre
, NULL
}, /* Pa */
159 {mdoc_ex_pre
, NULL
}, /* Rv */
160 {mdoc_st_pre
, NULL
}, /* St */
161 {mdoc_va_pre
, NULL
}, /* Va */
162 {mdoc_vt_pre
, NULL
}, /* Vt */
163 {mdoc_xr_pre
, NULL
}, /* Xr */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
175 {NULL
, NULL
}, /* Ac */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
178 {mdoc_xx_pre
, NULL
}, /* At */
179 {NULL
, NULL
}, /* Bc */
180 {mdoc_bf_pre
, NULL
}, /* Bf */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
183 {mdoc_xx_pre
, NULL
}, /* Bsx */
184 {mdoc_xx_pre
, NULL
}, /* Bx */
185 {mdoc_skip_pre
, NULL
}, /* Db */
186 {NULL
, NULL
}, /* Dc */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
189 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
190 {NULL
, NULL
}, /* Ef */
191 {mdoc_em_pre
, NULL
}, /* Em */
192 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
193 {mdoc_xx_pre
, NULL
}, /* Fx */
194 {mdoc_ms_pre
, NULL
}, /* Ms */
195 {mdoc_no_pre
, NULL
}, /* No */
196 {mdoc_ns_pre
, NULL
}, /* Ns */
197 {mdoc_xx_pre
, NULL
}, /* Nx */
198 {mdoc_xx_pre
, NULL
}, /* Ox */
199 {NULL
, NULL
}, /* Pc */
200 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
203 {NULL
, NULL
}, /* Qc */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
207 {NULL
, NULL
}, /* Re */
208 {mdoc_rs_pre
, NULL
}, /* Rs */
209 {NULL
, NULL
}, /* Sc */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
212 {mdoc_sm_pre
, NULL
}, /* Sm */
213 {mdoc_sx_pre
, NULL
}, /* Sx */
214 {mdoc_sy_pre
, NULL
}, /* Sy */
215 {NULL
, NULL
}, /* Tn */
216 {mdoc_xx_pre
, NULL
}, /* Ux */
217 {NULL
, NULL
}, /* Xc */
218 {NULL
, NULL
}, /* Xo */
219 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
220 {NULL
, NULL
}, /* Fc */
221 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
222 {NULL
, NULL
}, /* Oc */
223 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
224 {NULL
, NULL
}, /* Ek */
225 {NULL
, NULL
}, /* Bt */
226 {NULL
, NULL
}, /* Hf */
227 {mdoc_em_pre
, NULL
}, /* Fr */
228 {NULL
, NULL
}, /* Ud */
229 {mdoc_lb_pre
, NULL
}, /* Lb */
230 {mdoc_pp_pre
, NULL
}, /* Lp */
231 {mdoc_lk_pre
, NULL
}, /* Lk */
232 {mdoc_mt_pre
, NULL
}, /* Mt */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
235 {NULL
, NULL
}, /* Brc */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
237 {mdoc_skip_pre
, NULL
}, /* Es */
238 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
239 {mdoc_xx_pre
, NULL
}, /* Dx */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
242 {NULL
, NULL
}, /* Ta */
247 * See the same function in mdoc_term.c for documentation.
250 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
253 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
256 if (n
->prev
->tok
== n
->tok
&&
260 print_otag(h
, TAG_BR
, "");
264 switch (n
->prev
->tok
) {
273 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
279 print_otag(h
, TAG_BR
, "");
285 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
291 h
= (struct html
*)arg
;
292 n
= mdoc
->first
->child
;
294 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
296 print_otag(h
, TAG_HTML
, "");
297 if (n
->type
== ROFFT_COMMENT
)
298 print_gen_comment(h
, n
);
299 t
= print_otag(h
, TAG_HEAD
, "");
300 print_mdoc_head(&mdoc
->meta
, h
);
302 print_otag(h
, TAG_BODY
, "");
305 mdoc_root_pre(&mdoc
->meta
, h
);
306 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
307 print_mdoc_nodelist(&mdoc
->meta
, n
, h
);
309 mdoc_root_post(&mdoc
->meta
, h
);
314 print_mdoc_head(const struct roff_meta
*meta
, struct html
*h
)
320 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
321 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
322 meta
->msec
, meta
->arch
);
323 else if (meta
->msec
!= NULL
)
324 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
325 else if (meta
->arch
!= NULL
)
326 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
328 cp
= mandoc_strdup(meta
->title
);
330 print_otag(h
, TAG_TITLE
, "");
336 print_mdoc_nodelist(MDOC_ARGS
)
340 print_mdoc_node(meta
, n
, h
);
346 print_mdoc_node(MDOC_ARGS
)
351 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
356 n
->flags
&= ~NODE_ENDED
;
360 /* No tables in this mode... */
361 assert(NULL
== h
->tblt
);
364 * Make sure that if we're in a literal mode already
365 * (i.e., within a <PRE>) don't print the newline.
367 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
368 (h
->flags
& (HTML_LITERAL
| HTML_NONEWLINE
)) == 0)
369 print_otag(h
, TAG_BR
, "");
370 if (NODE_DELIMC
& n
->flags
)
371 h
->flags
|= HTML_NOSPACE
;
372 print_text(h
, n
->string
);
373 if (NODE_DELIMO
& n
->flags
)
374 h
->flags
|= HTML_NOSPACE
;
377 print_eqn(h
, n
->eqn
);
381 * This will take care of initialising all of the table
382 * state data for the first table, then tearing it down
385 print_tbl(h
, n
->span
);
389 * Close out the current table, if it's open, and unset
390 * the "meta" table state. This will be reopened on the
391 * next table element.
393 if (h
->tblt
!= NULL
) {
397 assert(h
->tblt
== NULL
);
398 if (n
->tok
< ROFF_MAX
) {
403 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
404 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
!= NULL
&&
405 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
406 child
= (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
)(meta
,
411 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
412 h
->flags
&= ~HTML_KEEP
;
413 h
->flags
|= HTML_PREKEEP
;
416 if (child
&& n
->child
)
417 print_mdoc_nodelist(meta
, n
->child
, h
);
425 if (n
->tok
< ROFF_MAX
||
426 mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
== NULL
||
427 n
->flags
& NODE_ENDED
)
429 (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
)(meta
, n
, h
);
430 if (n
->end
!= ENDBODY_NOT
)
431 n
->body
->flags
|= NODE_ENDED
;
437 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
441 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
442 tt
= print_otag(h
, TAG_TR
, "");
444 print_otag(h
, TAG_TD
, "c", "foot-date");
445 print_text(h
, meta
->date
);
448 print_otag(h
, TAG_TD
, "c", "foot-os");
449 print_text(h
, meta
->os
);
454 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
457 char *volume
, *title
;
459 if (NULL
== meta
->arch
)
460 volume
= mandoc_strdup(meta
->vol
);
462 mandoc_asprintf(&volume
, "%s (%s)",
463 meta
->vol
, meta
->arch
);
465 if (NULL
== meta
->msec
)
466 title
= mandoc_strdup(meta
->title
);
468 mandoc_asprintf(&title
, "%s(%s)",
469 meta
->title
, meta
->msec
);
471 t
= print_otag(h
, TAG_TABLE
, "c", "head");
472 tt
= print_otag(h
, TAG_TR
, "");
474 print_otag(h
, TAG_TD
, "c", "head-ltitle");
475 print_text(h
, title
);
478 print_otag(h
, TAG_TD
, "c", "head-vol");
479 print_text(h
, volume
);
482 print_otag(h
, TAG_TD
, "c", "head-rtitle");
483 print_text(h
, title
);
492 cond_id(const struct roff_node
*n
)
494 if (n
->child
!= NULL
&&
495 n
->child
->type
== ROFFT_TEXT
&&
497 (n
->prev
->type
== ROFFT_TEXT
&&
498 strcmp(n
->prev
->string
, "|") == 0)) &&
499 (n
->parent
->tok
== MDOC_It
||
500 (n
->parent
->tok
== MDOC_Xo
&&
501 n
->parent
->parent
->prev
== NULL
&&
502 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
503 return html_make_id(n
, 1);
508 mdoc_sh_pre(MDOC_ARGS
)
510 struct roff_node
*sn
, *subn
;
511 struct tag
*t
, *tsec
, *tsub
;
517 if ((h
->oflags
& HTML_TOC
) == 0 ||
518 h
->flags
& HTML_TOCDONE
||
519 n
->sec
<= SEC_SYNOPSIS
)
521 h
->flags
|= HTML_TOCDONE
;
523 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
524 if (sn
->sec
== SEC_CUSTOM
)
529 t
= print_otag(h
, TAG_H1
, "c", "Sh");
530 print_text(h
, "TABLE OF CONTENTS");
532 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
533 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
534 tsec
= print_otag(h
, TAG_LI
, "");
535 id
= html_make_id(sn
->head
, 0);
536 print_otag(h
, TAG_A
, "hR", id
);
538 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
540 for (subn
= sn
->body
->child
; subn
!= NULL
;
542 if (subn
->tok
!= MDOC_Ss
)
544 id
= html_make_id(subn
->head
, 0);
548 print_otag(h
, TAG_UL
,
550 tsub
= print_otag(h
, TAG_LI
, "");
551 print_otag(h
, TAG_A
, "hR", id
);
553 print_mdoc_nodelist(meta
,
554 subn
->head
->child
, h
);
562 id
= html_make_id(n
, 1);
563 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
565 print_otag(h
, TAG_A
, "chR", "permalink", id
);
568 if (n
->sec
== SEC_AUTHORS
)
569 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
578 mdoc_ss_pre(MDOC_ARGS
)
582 if (n
->type
!= ROFFT_HEAD
)
585 id
= html_make_id(n
, 1);
586 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
588 print_otag(h
, TAG_A
, "chR", "permalink", id
);
593 mdoc_fl_pre(MDOC_ARGS
)
597 if ((id
= cond_id(n
)) != NULL
)
598 print_otag(h
, TAG_A
, "chR", "permalink", id
);
599 print_otag(h
, TAG_CODE
, "cTi", "Fl", id
);
601 print_text(h
, "\\-");
602 if (!(n
->child
== NULL
&&
604 n
->next
->type
== ROFFT_TEXT
||
605 n
->next
->flags
& NODE_LINE
)))
606 h
->flags
|= HTML_NOSPACE
;
612 mdoc_cm_pre(MDOC_ARGS
)
616 if ((id
= cond_id(n
)) != NULL
)
617 print_otag(h
, TAG_A
, "chR", "permalink", id
);
618 print_otag(h
, TAG_CODE
, "cTi", "Cm", id
);
623 mdoc_nd_pre(MDOC_ARGS
)
625 if (n
->type
!= ROFFT_BODY
)
628 print_text(h
, "\\(em");
629 /* Cannot use TAG_SPAN because it may contain blocks. */
630 print_otag(h
, TAG_DIV
, "cT", "Nd");
635 mdoc_nm_pre(MDOC_ARGS
)
639 print_otag(h
, TAG_TD
, "");
642 print_otag(h
, TAG_CODE
, "cT", "Nm");
645 print_otag(h
, TAG_TD
, "");
651 print_otag(h
, TAG_TABLE
, "c", "Nm");
652 print_otag(h
, TAG_TR
, "");
657 mdoc_xr_pre(MDOC_ARGS
)
659 if (NULL
== n
->child
)
663 print_otag(h
, TAG_A
, "cThM", "Xr",
664 n
->child
->string
, n
->child
->next
== NULL
?
665 NULL
: n
->child
->next
->string
);
667 print_otag(h
, TAG_A
, "cT", "Xr");
670 print_text(h
, n
->string
);
672 if (NULL
== (n
= n
->next
))
675 h
->flags
|= HTML_NOSPACE
;
677 h
->flags
|= HTML_NOSPACE
;
678 print_text(h
, n
->string
);
679 h
->flags
|= HTML_NOSPACE
;
685 mdoc_ns_pre(MDOC_ARGS
)
688 if ( ! (NODE_LINE
& n
->flags
))
689 h
->flags
|= HTML_NOSPACE
;
694 mdoc_ar_pre(MDOC_ARGS
)
696 print_otag(h
, TAG_VAR
, "cT", "Ar");
701 mdoc_xx_pre(MDOC_ARGS
)
703 print_otag(h
, TAG_SPAN
, "c", "Ux");
708 mdoc_it_pre(MDOC_ARGS
)
710 const struct roff_node
*bl
;
715 while (bl
->tok
!= MDOC_Bl
)
717 type
= bl
->norm
->Bl
.type
;
729 print_otag(h
, TAG_LI
, "");
741 print_otag(h
, TAG_DT
, "");
744 print_otag(h
, TAG_DD
, "");
753 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
754 (n
->parent
->prev
== NULL
||
755 n
->parent
->prev
->body
== NULL
||
756 n
->parent
->prev
->body
->child
!= NULL
)) {
757 t
= print_otag(h
, TAG_DT
, "");
758 print_text(h
, "\\ ");
760 t
= print_otag(h
, TAG_DD
, "");
761 print_text(h
, "\\ ");
764 print_otag(h
, TAG_DT
, "");
767 if (n
->child
== NULL
) {
768 print_otag(h
, TAG_DD
, "s", "width", "auto");
769 print_text(h
, "\\ ");
771 print_otag(h
, TAG_DD
, "");
782 print_otag(h
, TAG_TD
, "");
785 print_otag(h
, TAG_TR
, "");
795 mdoc_bl_pre(MDOC_ARGS
)
799 enum htmltag elemtype
;
814 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
819 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
823 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
827 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
831 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
835 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
839 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
843 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
847 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
848 print_otag(h
, TAG_DL
, "c", bl
->comp
?
849 "Bl-tag Bl-compact" : "Bl-tag");
852 elemtype
= TAG_TABLE
;
853 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
858 if (bl
->offs
!= NULL
)
859 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
861 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
862 print_otag(h
, elemtype
, "c", cattr
);
867 mdoc_ex_pre(MDOC_ARGS
)
870 print_otag(h
, TAG_BR
, "");
875 mdoc_st_pre(MDOC_ARGS
)
877 print_otag(h
, TAG_SPAN
, "cT", "St");
882 mdoc_em_pre(MDOC_ARGS
)
884 print_otag(h
, TAG_I
, "cT", "Em");
889 mdoc_d1_pre(MDOC_ARGS
)
891 if (n
->type
!= ROFFT_BLOCK
)
894 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
896 if (n
->tok
== MDOC_Dl
)
897 print_otag(h
, TAG_CODE
, "c", "Li");
903 mdoc_sx_pre(MDOC_ARGS
)
907 id
= html_make_id(n
, 0);
908 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
914 mdoc_bd_pre(MDOC_ARGS
)
917 struct roff_node
*nn
;
919 if (n
->type
== ROFFT_HEAD
)
922 if (n
->type
== ROFFT_BLOCK
) {
923 comp
= n
->norm
->Bd
.comp
;
924 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
925 if (nn
->type
!= ROFFT_BLOCK
)
927 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
937 /* Handle the -offset argument. */
939 if (n
->norm
->Bd
.offs
== NULL
||
940 ! strcmp(n
->norm
->Bd
.offs
, "left"))
941 print_otag(h
, TAG_DIV
, "c", "Bd");
943 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
945 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
946 n
->norm
->Bd
.type
!= DISP_literal
)
949 print_otag(h
, TAG_PRE
, "c", "Li");
951 /* This can be recursive: save & set our literal state. */
953 sv
= h
->flags
& HTML_LITERAL
;
954 h
->flags
|= HTML_LITERAL
;
956 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
957 print_mdoc_node(meta
, nn
, h
);
959 * If the printed node flushes its own line, then we
960 * needn't do it here as well. This is hacky, but the
961 * notion of selective eoln whitespace is pretty dumb
962 * 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
;