1 /* $Id: mdoc_html.c,v 1.325 2019/01/11 12:56:43 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
) {
273 if (n
->tok
!= MDOC_Fn
&& n
->tok
!= MDOC_Fo
)
277 print_otag(h
, TAG_BR
, "");
280 html_close_paragraph(h
);
281 print_otag(h
, TAG_P
, "c", "Pp");
285 html_mdoc(void *arg
, const struct roff_meta
*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
, h
);
302 print_otag(h
, TAG_BODY
, "");
305 mdoc_root_pre(mdoc
, h
);
306 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
307 print_mdoc_nodelist(mdoc
, n
, h
);
309 mdoc_root_post(mdoc
, 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
)
354 html_fillmode(h
, n
->flags
& NODE_NOFILL
? ROFF_nf
: ROFF_fi
);
358 if (t
->tag
== TAG_P
|| t
->tag
== TAG_PRE
)
361 n
->flags
&= ~NODE_ENDED
;
364 /* No tables in this mode... */
365 assert(NULL
== h
->tblt
);
368 * Make sure that if we're in a literal mode already
369 * (i.e., within a <PRE>) don't print the newline.
371 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
372 (h
->flags
& HTML_NONEWLINE
) == 0 &&
373 (n
->flags
& NODE_NOFILL
) == 0)
374 print_otag(h
, TAG_BR
, "");
375 if (NODE_DELIMC
& n
->flags
)
376 h
->flags
|= HTML_NOSPACE
;
377 print_text(h
, n
->string
);
378 if (NODE_DELIMO
& n
->flags
)
379 h
->flags
|= HTML_NOSPACE
;
382 print_eqn(h
, n
->eqn
);
386 * This will take care of initialising all of the table
387 * state data for the first table, then tearing it down
390 print_tbl(h
, n
->span
);
394 * Close out the current table, if it's open, and unset
395 * the "meta" table state. This will be reopened on the
396 * next table element.
398 if (h
->tblt
!= NULL
) {
402 assert(h
->tblt
== NULL
);
403 if (n
->tok
< ROFF_MAX
) {
408 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
409 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
!= NULL
&&
410 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
411 child
= (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
)(meta
,
416 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
417 h
->flags
&= ~HTML_KEEP
;
418 h
->flags
|= HTML_PREKEEP
;
421 if (child
&& n
->child
!= NULL
)
422 print_mdoc_nodelist(meta
, n
->child
, h
);
431 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
== NULL
||
432 n
->flags
& NODE_ENDED
)
434 (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
)(meta
, n
, h
);
435 if (n
->end
!= ENDBODY_NOT
)
436 n
->body
->flags
|= NODE_ENDED
;
440 if (n
->flags
& NODE_NOFILL
&&
441 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
448 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
452 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
453 tt
= print_otag(h
, TAG_TR
, "");
455 print_otag(h
, TAG_TD
, "c", "foot-date");
456 print_text(h
, meta
->date
);
459 print_otag(h
, TAG_TD
, "c", "foot-os");
460 print_text(h
, meta
->os
);
465 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
468 char *volume
, *title
;
470 if (NULL
== meta
->arch
)
471 volume
= mandoc_strdup(meta
->vol
);
473 mandoc_asprintf(&volume
, "%s (%s)",
474 meta
->vol
, meta
->arch
);
476 if (NULL
== meta
->msec
)
477 title
= mandoc_strdup(meta
->title
);
479 mandoc_asprintf(&title
, "%s(%s)",
480 meta
->title
, meta
->msec
);
482 t
= print_otag(h
, TAG_TABLE
, "c", "head");
483 tt
= print_otag(h
, TAG_TR
, "");
485 print_otag(h
, TAG_TD
, "c", "head-ltitle");
486 print_text(h
, title
);
489 print_otag(h
, TAG_TD
, "c", "head-vol");
490 print_text(h
, volume
);
493 print_otag(h
, TAG_TD
, "c", "head-rtitle");
494 print_text(h
, title
);
503 cond_id(const struct roff_node
*n
)
505 if (n
->child
!= NULL
&&
506 n
->child
->type
== ROFFT_TEXT
&&
508 (n
->prev
->type
== ROFFT_TEXT
&&
509 strcmp(n
->prev
->string
, "|") == 0)) &&
510 (n
->parent
->tok
== MDOC_It
||
511 (n
->parent
->tok
== MDOC_Xo
&&
512 n
->parent
->parent
->prev
== NULL
&&
513 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
514 return html_make_id(n
, 1);
519 mdoc_sh_pre(MDOC_ARGS
)
521 struct roff_node
*sn
, *subn
;
522 struct tag
*t
, *tsec
, *tsub
;
528 html_close_paragraph(h
);
529 if ((h
->oflags
& HTML_TOC
) == 0 ||
530 h
->flags
& HTML_TOCDONE
||
531 n
->sec
<= SEC_SYNOPSIS
)
533 h
->flags
|= HTML_TOCDONE
;
535 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
536 if (sn
->sec
== SEC_CUSTOM
)
541 t
= print_otag(h
, TAG_H1
, "c", "Sh");
542 print_text(h
, "TABLE OF CONTENTS");
544 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
545 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
546 tsec
= print_otag(h
, TAG_LI
, "");
547 id
= html_make_id(sn
->head
, 0);
548 tsub
= print_otag(h
, TAG_A
, "hR", id
);
550 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
553 for (subn
= sn
->body
->child
; subn
!= NULL
;
555 if (subn
->tok
!= MDOC_Ss
)
557 id
= html_make_id(subn
->head
, 0);
561 print_otag(h
, TAG_UL
,
563 tsub
= print_otag(h
, TAG_LI
, "");
564 print_otag(h
, TAG_A
, "hR", id
);
566 print_mdoc_nodelist(meta
,
567 subn
->head
->child
, h
);
575 id
= html_make_id(n
, 1);
576 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
578 print_otag(h
, TAG_A
, "chR", "permalink", id
);
581 if (n
->sec
== SEC_AUTHORS
)
582 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
591 mdoc_ss_pre(MDOC_ARGS
)
597 html_close_paragraph(h
);
607 id
= html_make_id(n
, 1);
608 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
610 print_otag(h
, TAG_A
, "chR", "permalink", id
);
615 mdoc_fl_pre(MDOC_ARGS
)
619 if ((id
= cond_id(n
)) != NULL
)
620 print_otag(h
, TAG_A
, "chR", "permalink", id
);
621 print_otag(h
, TAG_CODE
, "ci", "Fl", id
);
623 print_text(h
, "\\-");
624 if (!(n
->child
== NULL
&&
626 n
->next
->type
== ROFFT_TEXT
||
627 n
->next
->flags
& NODE_LINE
)))
628 h
->flags
|= HTML_NOSPACE
;
634 mdoc_cm_pre(MDOC_ARGS
)
638 if ((id
= cond_id(n
)) != NULL
)
639 print_otag(h
, TAG_A
, "chR", "permalink", id
);
640 print_otag(h
, TAG_CODE
, "ci", "Cm", id
);
645 mdoc_nd_pre(MDOC_ARGS
)
649 html_close_paragraph(h
);
658 print_text(h
, "\\(em");
659 /* Cannot use TAG_SPAN because it may contain blocks. */
660 print_otag(h
, TAG_DIV
, "c", "Nd");
665 mdoc_nm_pre(MDOC_ARGS
)
671 print_otag(h
, TAG_TD
, "");
674 print_otag(h
, TAG_CODE
, "c", "Nm");
677 print_otag(h
, TAG_TD
, "");
682 html_close_paragraph(h
);
684 print_otag(h
, TAG_TABLE
, "c", "Nm");
685 print_otag(h
, TAG_TR
, "");
690 mdoc_xr_pre(MDOC_ARGS
)
692 if (NULL
== n
->child
)
696 print_otag(h
, TAG_A
, "chM", "Xr",
697 n
->child
->string
, n
->child
->next
== NULL
?
698 NULL
: n
->child
->next
->string
);
700 print_otag(h
, TAG_A
, "c", "Xr");
703 print_text(h
, n
->string
);
705 if (NULL
== (n
= n
->next
))
708 h
->flags
|= HTML_NOSPACE
;
710 h
->flags
|= HTML_NOSPACE
;
711 print_text(h
, n
->string
);
712 h
->flags
|= HTML_NOSPACE
;
718 mdoc_ns_pre(MDOC_ARGS
)
721 if ( ! (NODE_LINE
& n
->flags
))
722 h
->flags
|= HTML_NOSPACE
;
727 mdoc_ar_pre(MDOC_ARGS
)
729 print_otag(h
, TAG_VAR
, "c", "Ar");
734 mdoc_xx_pre(MDOC_ARGS
)
736 print_otag(h
, TAG_SPAN
, "c", "Ux");
741 mdoc_it_pre(MDOC_ARGS
)
743 const struct roff_node
*bl
;
747 while (bl
->tok
!= MDOC_Bl
)
749 type
= bl
->norm
->Bl
.type
;
761 print_otag(h
, TAG_LI
, "");
773 print_otag(h
, TAG_DT
, "");
776 print_otag(h
, TAG_DD
, "");
785 print_otag(h
, TAG_DT
, "");
788 if (n
->child
== NULL
) {
789 print_otag(h
, TAG_DD
, "s", "width", "auto");
790 print_text(h
, "\\ ");
792 print_otag(h
, TAG_DD
, "");
803 print_otag(h
, TAG_TD
, "");
806 print_otag(h
, TAG_TR
, "");
816 mdoc_bl_pre(MDOC_ARGS
)
820 enum htmltag elemtype
;
824 html_close_paragraph(h
);
838 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
843 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
847 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
851 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
855 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
859 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
863 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
867 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
871 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
872 print_otag(h
, TAG_DL
, "c", bl
->comp
?
873 "Bl-tag Bl-compact" : "Bl-tag");
876 elemtype
= TAG_TABLE
;
877 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
882 if (bl
->offs
!= NULL
)
883 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
885 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
886 print_otag(h
, elemtype
, "c", cattr
);
891 mdoc_ex_pre(MDOC_ARGS
)
894 print_otag(h
, TAG_BR
, "");
899 mdoc_st_pre(MDOC_ARGS
)
901 print_otag(h
, TAG_SPAN
, "c", "St");
906 mdoc_em_pre(MDOC_ARGS
)
908 print_otag(h
, TAG_I
, "c", "Em");
913 mdoc_d1_pre(MDOC_ARGS
)
917 html_close_paragraph(h
);
926 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
927 if (n
->tok
== MDOC_Dl
)
928 print_otag(h
, TAG_CODE
, "c", "Li");
933 mdoc_sx_pre(MDOC_ARGS
)
937 id
= html_make_id(n
, 0);
938 print_otag(h
, TAG_A
, "chR", "Sx", id
);
944 mdoc_bd_pre(MDOC_ARGS
)
947 struct roff_node
*nn
;
952 html_close_paragraph(h
);
962 /* Handle preceding whitespace. */
964 comp
= n
->norm
->Bd
.comp
;
965 for (nn
= n
; nn
!= NULL
&& comp
== 0; nn
= nn
->parent
) {
966 if (nn
->type
!= ROFFT_BLOCK
)
968 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
970 if (nn
->prev
!= NULL
)
973 (void)strlcpy(buf
, "Bd", sizeof(buf
));
975 (void)strlcat(buf
, " Pp", sizeof(buf
));
977 /* Handle the -offset argument. */
979 if (n
->norm
->Bd
.offs
!= NULL
&&
980 strcmp(n
->norm
->Bd
.offs
, "left") != 0)
981 (void)strlcat(buf
, " Bd-indent", sizeof(buf
));
983 print_otag(h
, TAG_DIV
, "c", buf
);
988 mdoc_pa_pre(MDOC_ARGS
)
990 print_otag(h
, TAG_SPAN
, "c", "Pa");
995 mdoc_ad_pre(MDOC_ARGS
)
997 print_otag(h
, TAG_SPAN
, "c", "Ad");
1002 mdoc_an_pre(MDOC_ARGS
)
1004 if (n
->norm
->An
.auth
== AUTH_split
) {
1005 h
->flags
&= ~HTML_NOSPLIT
;
1006 h
->flags
|= HTML_SPLIT
;
1009 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1010 h
->flags
&= ~HTML_SPLIT
;
1011 h
->flags
|= HTML_NOSPLIT
;
1015 if (h
->flags
& HTML_SPLIT
)
1016 print_otag(h
, TAG_BR
, "");
1018 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1019 h
->flags
|= HTML_SPLIT
;
1021 print_otag(h
, TAG_SPAN
, "c", "An");
1026 mdoc_cd_pre(MDOC_ARGS
)
1029 print_otag(h
, TAG_CODE
, "c", "Cd");
1034 mdoc_dv_pre(MDOC_ARGS
)
1038 if ((id
= cond_id(n
)) != NULL
)
1039 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1040 print_otag(h
, TAG_CODE
, "ci", "Dv", id
);
1045 mdoc_ev_pre(MDOC_ARGS
)
1049 if ((id
= cond_id(n
)) != NULL
)
1050 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1051 print_otag(h
, TAG_CODE
, "ci", "Ev", id
);
1056 mdoc_er_pre(MDOC_ARGS
)
1060 id
= n
->sec
== SEC_ERRORS
&&
1061 (n
->parent
->tok
== MDOC_It
||
1062 (n
->parent
->tok
== MDOC_Bq
&&
1063 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1064 html_make_id(n
, 1) : NULL
;
1067 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1068 print_otag(h
, TAG_CODE
, "ci", "Er", id
);
1073 mdoc_fa_pre(MDOC_ARGS
)
1075 const struct roff_node
*nn
;
1078 if (n
->parent
->tok
!= MDOC_Fo
) {
1079 print_otag(h
, TAG_VAR
, "c", "Fa");
1083 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1084 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1085 print_text(h
, nn
->string
);
1088 h
->flags
|= HTML_NOSPACE
;
1093 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1094 h
->flags
|= HTML_NOSPACE
;
1102 mdoc_fd_pre(MDOC_ARGS
)
1109 if (NULL
== (n
= n
->child
))
1112 assert(n
->type
== ROFFT_TEXT
);
1114 if (strcmp(n
->string
, "#include")) {
1115 print_otag(h
, TAG_CODE
, "c", "Fd");
1119 print_otag(h
, TAG_CODE
, "c", "In");
1120 print_text(h
, n
->string
);
1122 if (NULL
!= (n
= n
->next
)) {
1123 assert(n
->type
== ROFFT_TEXT
);
1125 if (h
->base_includes
) {
1127 if (*cp
== '<' || *cp
== '"')
1129 buf
= mandoc_strdup(cp
);
1130 cp
= strchr(buf
, '\0') - 1;
1131 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1133 t
= print_otag(h
, TAG_A
, "chI", "In", buf
);
1136 t
= print_otag(h
, TAG_A
, "c", "In");
1138 print_text(h
, n
->string
);
1144 for ( ; n
; n
= n
->next
) {
1145 assert(n
->type
== ROFFT_TEXT
);
1146 print_text(h
, n
->string
);
1153 mdoc_vt_pre(MDOC_ARGS
)
1155 if (n
->type
== ROFFT_BLOCK
) {
1158 } else if (n
->type
== ROFFT_ELEM
) {
1160 } else if (n
->type
== ROFFT_HEAD
)
1163 print_otag(h
, TAG_VAR
, "c", "Vt");
1168 mdoc_ft_pre(MDOC_ARGS
)
1171 print_otag(h
, TAG_VAR
, "c", "Ft");
1176 mdoc_fn_pre(MDOC_ARGS
)
1180 const char *sp
, *ep
;
1183 pretty
= NODE_SYNPRETTY
& n
->flags
;
1186 /* Split apart into type and name. */
1187 assert(n
->child
->string
);
1188 sp
= n
->child
->string
;
1190 ep
= strchr(sp
, ' ');
1192 t
= print_otag(h
, TAG_VAR
, "c", "Ft");
1195 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1196 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1198 print_text(h
, nbuf
);
1200 ep
= strchr(sp
, ' ');
1205 t
= print_otag(h
, TAG_CODE
, "c", "Fn");
1212 h
->flags
|= HTML_NOSPACE
;
1214 h
->flags
|= HTML_NOSPACE
;
1216 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1217 if (NODE_SYNPRETTY
& n
->flags
)
1218 t
= print_otag(h
, TAG_VAR
, "cs", "Fa",
1219 "white-space", "nowrap");
1221 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1222 print_text(h
, n
->string
);
1225 h
->flags
|= HTML_NOSPACE
;
1230 h
->flags
|= HTML_NOSPACE
;
1234 h
->flags
|= HTML_NOSPACE
;
1242 mdoc_sm_pre(MDOC_ARGS
)
1245 if (NULL
== n
->child
)
1246 h
->flags
^= HTML_NONOSPACE
;
1247 else if (0 == strcmp("on", n
->child
->string
))
1248 h
->flags
&= ~HTML_NONOSPACE
;
1250 h
->flags
|= HTML_NONOSPACE
;
1252 if ( ! (HTML_NONOSPACE
& h
->flags
))
1253 h
->flags
&= ~HTML_NOSPACE
;
1259 mdoc_skip_pre(MDOC_ARGS
)
1266 mdoc_pp_pre(MDOC_ARGS
)
1268 if ((n
->flags
& NODE_NOFILL
) == 0) {
1269 html_close_paragraph(h
);
1270 print_otag(h
, TAG_P
, "c", "Pp");
1276 mdoc_lk_pre(MDOC_ARGS
)
1278 const struct roff_node
*link
, *descr
, *punct
;
1281 if ((link
= n
->child
) == NULL
)
1284 /* Find beginning of trailing punctuation. */
1286 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1287 punct
= punct
->prev
;
1288 punct
= punct
->next
;
1290 /* Link target and link text. */
1293 descr
= link
; /* no text */
1294 t
= print_otag(h
, TAG_A
, "ch", "Lk", link
->string
);
1296 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1297 h
->flags
|= HTML_NOSPACE
;
1298 print_text(h
, descr
->string
);
1299 descr
= descr
->next
;
1300 } while (descr
!= punct
);
1303 /* Trailing punctuation. */
1304 while (punct
!= NULL
) {
1305 h
->flags
|= HTML_NOSPACE
;
1306 print_text(h
, punct
->string
);
1307 punct
= punct
->next
;
1313 mdoc_mt_pre(MDOC_ARGS
)
1318 for (n
= n
->child
; n
; n
= n
->next
) {
1319 assert(n
->type
== ROFFT_TEXT
);
1321 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1322 t
= print_otag(h
, TAG_A
, "ch", "Mt", cp
);
1323 print_text(h
, n
->string
);
1332 mdoc_fo_pre(MDOC_ARGS
)
1336 if (n
->type
== ROFFT_BODY
) {
1337 h
->flags
|= HTML_NOSPACE
;
1339 h
->flags
|= HTML_NOSPACE
;
1341 } else if (n
->type
== ROFFT_BLOCK
) {
1346 if (n
->child
== NULL
)
1349 assert(n
->child
->string
);
1350 t
= print_otag(h
, TAG_CODE
, "c", "Fn");
1351 print_text(h
, n
->child
->string
);
1357 mdoc_fo_post(MDOC_ARGS
)
1360 if (n
->type
!= ROFFT_BODY
)
1362 h
->flags
|= HTML_NOSPACE
;
1364 h
->flags
|= HTML_NOSPACE
;
1369 mdoc_in_pre(MDOC_ARGS
)
1374 print_otag(h
, TAG_CODE
, "c", "In");
1377 * The first argument of the `In' gets special treatment as
1378 * being a linked value. Subsequent values are printed
1379 * afterward. groff does similarly. This also handles the case
1383 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1384 print_text(h
, "#include");
1387 h
->flags
|= HTML_NOSPACE
;
1389 if (NULL
!= (n
= n
->child
)) {
1390 assert(n
->type
== ROFFT_TEXT
);
1392 if (h
->base_includes
)
1393 t
= print_otag(h
, TAG_A
, "chI", "In", n
->string
);
1395 t
= print_otag(h
, TAG_A
, "c", "In");
1396 print_text(h
, n
->string
);
1402 h
->flags
|= HTML_NOSPACE
;
1405 for ( ; n
; n
= n
->next
) {
1406 assert(n
->type
== ROFFT_TEXT
);
1407 print_text(h
, n
->string
);
1414 mdoc_ic_pre(MDOC_ARGS
)
1418 if ((id
= cond_id(n
)) != NULL
)
1419 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1420 print_otag(h
, TAG_CODE
, "ci", "Ic", id
);
1425 mdoc_va_pre(MDOC_ARGS
)
1427 print_otag(h
, TAG_VAR
, "c", "Va");
1432 mdoc_ap_pre(MDOC_ARGS
)
1435 h
->flags
|= HTML_NOSPACE
;
1436 print_text(h
, "\\(aq");
1437 h
->flags
|= HTML_NOSPACE
;
1442 mdoc_bf_pre(MDOC_ARGS
)
1448 html_close_paragraph(h
);
1458 if (FONT_Em
== n
->norm
->Bf
.font
)
1460 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1462 else if (FONT_Li
== n
->norm
->Bf
.font
)
1467 /* Cannot use TAG_SPAN because it may contain blocks. */
1468 print_otag(h
, TAG_DIV
, "c", cattr
);
1473 mdoc_ms_pre(MDOC_ARGS
)
1477 if ((id
= cond_id(n
)) != NULL
)
1478 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1479 print_otag(h
, TAG_SPAN
, "ci", "Ms", id
);
1484 mdoc_igndelim_pre(MDOC_ARGS
)
1487 h
->flags
|= HTML_IGNDELIM
;
1492 mdoc_pf_post(MDOC_ARGS
)
1495 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1496 h
->flags
|= HTML_NOSPACE
;
1500 mdoc_rs_pre(MDOC_ARGS
)
1504 if (n
->sec
== SEC_SEE_ALSO
)
1505 html_close_paragraph(h
);
1510 if (n
->sec
== SEC_SEE_ALSO
)
1511 print_otag(h
, TAG_P
, "c", "Pp");
1512 print_otag(h
, TAG_CITE
, "c", "Rs");
1521 mdoc_no_pre(MDOC_ARGS
)
1525 if ((id
= cond_id(n
)) != NULL
)
1526 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1527 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1532 mdoc_li_pre(MDOC_ARGS
)
1536 if ((id
= cond_id(n
)) != NULL
)
1537 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1538 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1543 mdoc_sy_pre(MDOC_ARGS
)
1545 print_otag(h
, TAG_B
, "c", "Sy");
1550 mdoc_lb_pre(MDOC_ARGS
)
1552 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1553 print_otag(h
, TAG_BR
, "");
1555 print_otag(h
, TAG_SPAN
, "c", "Lb");
1560 mdoc__x_pre(MDOC_ARGS
)
1570 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1571 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1572 print_text(h
, "and");
1611 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1620 print_otag(h
, t
, "c", cattr
);
1625 mdoc__x_post(MDOC_ARGS
)
1628 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1629 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1630 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1635 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1638 h
->flags
|= HTML_NOSPACE
;
1639 print_text(h
, n
->next
? "," : ".");
1643 mdoc_bk_pre(MDOC_ARGS
)
1652 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1653 h
->flags
|= HTML_PREKEEP
;
1663 mdoc_bk_post(MDOC_ARGS
)
1666 if (n
->type
== ROFFT_BODY
)
1667 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1671 mdoc_quote_pre(MDOC_ARGS
)
1673 if (n
->type
!= ROFFT_BODY
)
1679 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1680 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1684 print_text(h
, "\\(lC");
1688 print_text(h
, "\\(lB");
1692 print_text(h
, "\\(lB");
1694 * Give up on semantic markup for now.
1695 * We cannot use TAG_SPAN because .Oo may contain blocks.
1696 * We cannot use TAG_IDIV because we might be in a
1697 * phrasing context (like .Dl or .Pp); we cannot
1698 * close out a .Pp at this point either because
1699 * that would break the line.
1701 /* XXX print_otag(h, TAG_???, "c", "Op"); */
1704 if (NULL
== n
->norm
->Es
||
1705 NULL
== n
->norm
->Es
->child
)
1707 print_text(h
, n
->norm
->Es
->child
->string
);
1713 print_text(h
, "\\(lq");
1720 print_text(h
, "\\(oq");
1721 h
->flags
|= HTML_NOSPACE
;
1722 print_otag(h
, TAG_CODE
, "c", "Li");
1726 print_text(h
, "\\(oq");
1732 h
->flags
|= HTML_NOSPACE
;
1737 mdoc_quote_post(MDOC_ARGS
)
1740 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1743 h
->flags
|= HTML_NOSPACE
;
1748 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1749 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1753 print_text(h
, "\\(rC");
1759 print_text(h
, "\\(rB");
1762 if (n
->norm
->Es
== NULL
||
1763 n
->norm
->Es
->child
== NULL
||
1764 n
->norm
->Es
->child
->next
== NULL
)
1765 h
->flags
&= ~HTML_NOSPACE
;
1767 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1773 print_text(h
, "\\(rq");
1782 print_text(h
, "\\(cq");
1790 mdoc_eo_pre(MDOC_ARGS
)
1793 if (n
->type
!= ROFFT_BODY
)
1796 if (n
->end
== ENDBODY_NOT
&&
1797 n
->parent
->head
->child
== NULL
&&
1799 n
->child
->end
!= ENDBODY_NOT
)
1800 print_text(h
, "\\&");
1801 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1802 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1803 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1804 h
->flags
|= HTML_NOSPACE
;
1809 mdoc_eo_post(MDOC_ARGS
)
1813 if (n
->type
!= ROFFT_BODY
)
1816 if (n
->end
!= ENDBODY_NOT
) {
1817 h
->flags
&= ~HTML_NOSPACE
;
1821 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1822 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1825 h
->flags
|= HTML_NOSPACE
;
1827 h
->flags
&= ~HTML_NOSPACE
;
1831 mdoc_abort_pre(MDOC_ARGS
)