1 /* $Id: mdoc_html.c,v 1.327 2019/01/18 14:36:21 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014-2019 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
!= NULL
&& 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
);
357 n
->flags
&= ~NODE_ENDED
;
363 /* No tables in this mode... */
364 assert(NULL
== h
->tblt
);
367 * Make sure that if we're in a literal mode already
368 * (i.e., within a <PRE>) don't print the newline.
370 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
371 (h
->flags
& HTML_NONEWLINE
) == 0 &&
372 (n
->flags
& NODE_NOFILL
) == 0)
373 print_otag(h
, TAG_BR
, "");
374 if (NODE_DELIMC
& n
->flags
)
375 h
->flags
|= HTML_NOSPACE
;
376 print_text(h
, n
->string
);
377 if (NODE_DELIMO
& n
->flags
)
378 h
->flags
|= HTML_NOSPACE
;
383 print_eqn(h
, n
->eqn
);
387 * This will take care of initialising all of the table
388 * state data for the first table, then tearing it down
391 print_tbl(h
, n
->span
);
395 * Close out the current table, if it's open, and unset
396 * the "meta" table state. This will be reopened on the
397 * next table element.
401 assert(h
->tblt
== NULL
);
404 if (n
->tok
< ROFF_MAX
) {
410 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
411 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
!= NULL
&&
412 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
413 child
= (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
)(meta
,
418 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
419 h
->flags
&= ~HTML_KEEP
;
420 h
->flags
|= HTML_PREKEEP
;
423 if (child
&& n
->child
!= NULL
)
424 print_mdoc_nodelist(meta
, n
->child
, h
);
434 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
== NULL
||
435 n
->flags
& NODE_ENDED
)
437 (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
)(meta
, n
, h
);
438 if (n
->end
!= ENDBODY_NOT
)
439 n
->body
->flags
|= NODE_ENDED
;
443 if (n
->flags
& NODE_NOFILL
&&
444 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
451 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
455 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
456 tt
= print_otag(h
, TAG_TR
, "");
458 print_otag(h
, TAG_TD
, "c", "foot-date");
459 print_text(h
, meta
->date
);
462 print_otag(h
, TAG_TD
, "c", "foot-os");
463 print_text(h
, meta
->os
);
468 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
471 char *volume
, *title
;
473 if (NULL
== meta
->arch
)
474 volume
= mandoc_strdup(meta
->vol
);
476 mandoc_asprintf(&volume
, "%s (%s)",
477 meta
->vol
, meta
->arch
);
479 if (NULL
== meta
->msec
)
480 title
= mandoc_strdup(meta
->title
);
482 mandoc_asprintf(&title
, "%s(%s)",
483 meta
->title
, meta
->msec
);
485 t
= print_otag(h
, TAG_TABLE
, "c", "head");
486 tt
= print_otag(h
, TAG_TR
, "");
488 print_otag(h
, TAG_TD
, "c", "head-ltitle");
489 print_text(h
, title
);
492 print_otag(h
, TAG_TD
, "c", "head-vol");
493 print_text(h
, volume
);
496 print_otag(h
, TAG_TD
, "c", "head-rtitle");
497 print_text(h
, title
);
506 cond_id(const struct roff_node
*n
)
508 if (n
->child
!= NULL
&&
509 n
->child
->type
== ROFFT_TEXT
&&
511 (n
->prev
->type
== ROFFT_TEXT
&&
512 strcmp(n
->prev
->string
, "|") == 0)) &&
513 (n
->parent
->tok
== MDOC_It
||
514 (n
->parent
->tok
== MDOC_Xo
&&
515 n
->parent
->parent
->prev
== NULL
&&
516 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
517 return html_make_id(n
, 1);
522 mdoc_sh_pre(MDOC_ARGS
)
524 struct roff_node
*sn
, *subn
;
525 struct tag
*t
, *tsec
, *tsub
;
531 html_close_paragraph(h
);
532 if ((h
->oflags
& HTML_TOC
) == 0 ||
533 h
->flags
& HTML_TOCDONE
||
534 n
->sec
<= SEC_SYNOPSIS
)
536 h
->flags
|= HTML_TOCDONE
;
538 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
539 if (sn
->sec
== SEC_CUSTOM
)
544 t
= print_otag(h
, TAG_H1
, "c", "Sh");
545 print_text(h
, "TABLE OF CONTENTS");
547 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
548 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
549 tsec
= print_otag(h
, TAG_LI
, "");
550 id
= html_make_id(sn
->head
, 0);
551 tsub
= print_otag(h
, TAG_A
, "hR", id
);
553 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
556 for (subn
= sn
->body
->child
; subn
!= NULL
;
558 if (subn
->tok
!= MDOC_Ss
)
560 id
= html_make_id(subn
->head
, 0);
564 print_otag(h
, TAG_UL
,
566 tsub
= print_otag(h
, TAG_LI
, "");
567 print_otag(h
, TAG_A
, "hR", id
);
569 print_mdoc_nodelist(meta
,
570 subn
->head
->child
, h
);
578 id
= html_make_id(n
, 1);
579 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
581 print_otag(h
, TAG_A
, "chR", "permalink", id
);
584 if (n
->sec
== SEC_AUTHORS
)
585 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
594 mdoc_ss_pre(MDOC_ARGS
)
600 html_close_paragraph(h
);
610 id
= html_make_id(n
, 1);
611 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
613 print_otag(h
, TAG_A
, "chR", "permalink", id
);
618 mdoc_fl_pre(MDOC_ARGS
)
622 if ((id
= cond_id(n
)) != NULL
)
623 print_otag(h
, TAG_A
, "chR", "permalink", id
);
624 print_otag(h
, TAG_CODE
, "ci", "Fl", id
);
626 print_text(h
, "\\-");
627 if (!(n
->child
== NULL
&&
629 n
->next
->type
== ROFFT_TEXT
||
630 n
->next
->flags
& NODE_LINE
)))
631 h
->flags
|= HTML_NOSPACE
;
637 mdoc_cm_pre(MDOC_ARGS
)
641 if ((id
= cond_id(n
)) != NULL
)
642 print_otag(h
, TAG_A
, "chR", "permalink", id
);
643 print_otag(h
, TAG_CODE
, "ci", "Cm", id
);
648 mdoc_nd_pre(MDOC_ARGS
)
652 html_close_paragraph(h
);
661 print_text(h
, "\\(em");
662 /* Cannot use TAG_SPAN because it may contain blocks. */
663 print_otag(h
, TAG_DIV
, "c", "Nd");
668 mdoc_nm_pre(MDOC_ARGS
)
674 print_otag(h
, TAG_TD
, "");
677 print_otag(h
, TAG_CODE
, "c", "Nm");
680 print_otag(h
, TAG_TD
, "");
685 html_close_paragraph(h
);
687 print_otag(h
, TAG_TABLE
, "c", "Nm");
688 print_otag(h
, TAG_TR
, "");
693 mdoc_xr_pre(MDOC_ARGS
)
695 if (NULL
== n
->child
)
699 print_otag(h
, TAG_A
, "chM", "Xr",
700 n
->child
->string
, n
->child
->next
== NULL
?
701 NULL
: n
->child
->next
->string
);
703 print_otag(h
, TAG_A
, "c", "Xr");
706 print_text(h
, n
->string
);
708 if (NULL
== (n
= n
->next
))
711 h
->flags
|= HTML_NOSPACE
;
713 h
->flags
|= HTML_NOSPACE
;
714 print_text(h
, n
->string
);
715 h
->flags
|= HTML_NOSPACE
;
721 mdoc_ns_pre(MDOC_ARGS
)
724 if ( ! (NODE_LINE
& n
->flags
))
725 h
->flags
|= HTML_NOSPACE
;
730 mdoc_ar_pre(MDOC_ARGS
)
732 print_otag(h
, TAG_VAR
, "c", "Ar");
737 mdoc_xx_pre(MDOC_ARGS
)
739 print_otag(h
, TAG_SPAN
, "c", "Ux");
744 mdoc_it_pre(MDOC_ARGS
)
746 const struct roff_node
*bl
;
750 while (bl
->tok
!= MDOC_Bl
)
752 type
= bl
->norm
->Bl
.type
;
764 print_otag(h
, TAG_LI
, "");
776 print_otag(h
, TAG_DT
, "");
779 print_otag(h
, TAG_DD
, "");
788 print_otag(h
, TAG_DT
, "");
791 if (n
->child
== NULL
) {
792 print_otag(h
, TAG_DD
, "s", "width", "auto");
793 print_text(h
, "\\ ");
795 print_otag(h
, TAG_DD
, "");
806 print_otag(h
, TAG_TD
, "");
809 print_otag(h
, TAG_TR
, "");
819 mdoc_bl_pre(MDOC_ARGS
)
823 enum htmltag elemtype
;
827 html_close_paragraph(h
);
841 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
846 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
850 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
854 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
858 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
862 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
866 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
870 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
874 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
875 print_otag(h
, TAG_DL
, "c", bl
->comp
?
876 "Bl-tag Bl-compact" : "Bl-tag");
879 elemtype
= TAG_TABLE
;
880 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
885 if (bl
->offs
!= NULL
)
886 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
888 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
889 print_otag(h
, elemtype
, "c", cattr
);
894 mdoc_ex_pre(MDOC_ARGS
)
897 print_otag(h
, TAG_BR
, "");
902 mdoc_st_pre(MDOC_ARGS
)
904 print_otag(h
, TAG_SPAN
, "c", "St");
909 mdoc_em_pre(MDOC_ARGS
)
911 print_otag(h
, TAG_I
, "c", "Em");
916 mdoc_d1_pre(MDOC_ARGS
)
920 html_close_paragraph(h
);
929 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
930 if (n
->tok
== MDOC_Dl
)
931 print_otag(h
, TAG_CODE
, "c", "Li");
936 mdoc_sx_pre(MDOC_ARGS
)
940 id
= html_make_id(n
, 0);
941 print_otag(h
, TAG_A
, "chR", "Sx", id
);
947 mdoc_bd_pre(MDOC_ARGS
)
950 struct roff_node
*nn
;
955 html_close_paragraph(h
);
965 /* Handle preceding whitespace. */
967 comp
= n
->norm
->Bd
.comp
;
968 for (nn
= n
; nn
!= NULL
&& comp
== 0; nn
= nn
->parent
) {
969 if (nn
->type
!= ROFFT_BLOCK
)
971 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
973 if (nn
->prev
!= NULL
)
976 (void)strlcpy(buf
, "Bd", sizeof(buf
));
978 (void)strlcat(buf
, " Pp", sizeof(buf
));
980 /* Handle the -offset argument. */
982 if (n
->norm
->Bd
.offs
!= NULL
&&
983 strcmp(n
->norm
->Bd
.offs
, "left") != 0)
984 (void)strlcat(buf
, " Bd-indent", sizeof(buf
));
986 print_otag(h
, TAG_DIV
, "c", buf
);
991 mdoc_pa_pre(MDOC_ARGS
)
993 print_otag(h
, TAG_SPAN
, "c", "Pa");
998 mdoc_ad_pre(MDOC_ARGS
)
1000 print_otag(h
, TAG_SPAN
, "c", "Ad");
1005 mdoc_an_pre(MDOC_ARGS
)
1007 if (n
->norm
->An
.auth
== AUTH_split
) {
1008 h
->flags
&= ~HTML_NOSPLIT
;
1009 h
->flags
|= HTML_SPLIT
;
1012 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1013 h
->flags
&= ~HTML_SPLIT
;
1014 h
->flags
|= HTML_NOSPLIT
;
1018 if (h
->flags
& HTML_SPLIT
)
1019 print_otag(h
, TAG_BR
, "");
1021 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1022 h
->flags
|= HTML_SPLIT
;
1024 print_otag(h
, TAG_SPAN
, "c", "An");
1029 mdoc_cd_pre(MDOC_ARGS
)
1032 print_otag(h
, TAG_CODE
, "c", "Cd");
1037 mdoc_dv_pre(MDOC_ARGS
)
1041 if ((id
= cond_id(n
)) != NULL
)
1042 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1043 print_otag(h
, TAG_CODE
, "ci", "Dv", id
);
1048 mdoc_ev_pre(MDOC_ARGS
)
1052 if ((id
= cond_id(n
)) != NULL
)
1053 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1054 print_otag(h
, TAG_CODE
, "ci", "Ev", id
);
1059 mdoc_er_pre(MDOC_ARGS
)
1063 id
= n
->sec
== SEC_ERRORS
&&
1064 (n
->parent
->tok
== MDOC_It
||
1065 (n
->parent
->tok
== MDOC_Bq
&&
1066 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1067 html_make_id(n
, 1) : NULL
;
1070 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1071 print_otag(h
, TAG_CODE
, "ci", "Er", id
);
1076 mdoc_fa_pre(MDOC_ARGS
)
1078 const struct roff_node
*nn
;
1081 if (n
->parent
->tok
!= MDOC_Fo
) {
1082 print_otag(h
, TAG_VAR
, "c", "Fa");
1086 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1087 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1088 print_text(h
, nn
->string
);
1091 h
->flags
|= HTML_NOSPACE
;
1096 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1097 h
->flags
|= HTML_NOSPACE
;
1105 mdoc_fd_pre(MDOC_ARGS
)
1112 if (NULL
== (n
= n
->child
))
1115 assert(n
->type
== ROFFT_TEXT
);
1117 if (strcmp(n
->string
, "#include")) {
1118 print_otag(h
, TAG_CODE
, "c", "Fd");
1122 print_otag(h
, TAG_CODE
, "c", "In");
1123 print_text(h
, n
->string
);
1125 if (NULL
!= (n
= n
->next
)) {
1126 assert(n
->type
== ROFFT_TEXT
);
1128 if (h
->base_includes
) {
1130 if (*cp
== '<' || *cp
== '"')
1132 buf
= mandoc_strdup(cp
);
1133 cp
= strchr(buf
, '\0') - 1;
1134 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1136 t
= print_otag(h
, TAG_A
, "chI", "In", buf
);
1139 t
= print_otag(h
, TAG_A
, "c", "In");
1141 print_text(h
, n
->string
);
1147 for ( ; n
; n
= n
->next
) {
1148 assert(n
->type
== ROFFT_TEXT
);
1149 print_text(h
, n
->string
);
1156 mdoc_vt_pre(MDOC_ARGS
)
1158 if (n
->type
== ROFFT_BLOCK
) {
1161 } else if (n
->type
== ROFFT_ELEM
) {
1163 } else if (n
->type
== ROFFT_HEAD
)
1166 print_otag(h
, TAG_VAR
, "c", "Vt");
1171 mdoc_ft_pre(MDOC_ARGS
)
1174 print_otag(h
, TAG_VAR
, "c", "Ft");
1179 mdoc_fn_pre(MDOC_ARGS
)
1183 const char *sp
, *ep
;
1186 pretty
= NODE_SYNPRETTY
& n
->flags
;
1189 /* Split apart into type and name. */
1190 assert(n
->child
->string
);
1191 sp
= n
->child
->string
;
1193 ep
= strchr(sp
, ' ');
1195 t
= print_otag(h
, TAG_VAR
, "c", "Ft");
1198 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1199 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1201 print_text(h
, nbuf
);
1203 ep
= strchr(sp
, ' ');
1208 t
= print_otag(h
, TAG_CODE
, "c", "Fn");
1215 h
->flags
|= HTML_NOSPACE
;
1217 h
->flags
|= HTML_NOSPACE
;
1219 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1220 if (NODE_SYNPRETTY
& n
->flags
)
1221 t
= print_otag(h
, TAG_VAR
, "cs", "Fa",
1222 "white-space", "nowrap");
1224 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1225 print_text(h
, n
->string
);
1228 h
->flags
|= HTML_NOSPACE
;
1233 h
->flags
|= HTML_NOSPACE
;
1237 h
->flags
|= HTML_NOSPACE
;
1245 mdoc_sm_pre(MDOC_ARGS
)
1248 if (NULL
== n
->child
)
1249 h
->flags
^= HTML_NONOSPACE
;
1250 else if (0 == strcmp("on", n
->child
->string
))
1251 h
->flags
&= ~HTML_NONOSPACE
;
1253 h
->flags
|= HTML_NONOSPACE
;
1255 if ( ! (HTML_NONOSPACE
& h
->flags
))
1256 h
->flags
&= ~HTML_NOSPACE
;
1262 mdoc_skip_pre(MDOC_ARGS
)
1269 mdoc_pp_pre(MDOC_ARGS
)
1271 if ((n
->flags
& NODE_NOFILL
) == 0) {
1272 html_close_paragraph(h
);
1273 print_otag(h
, TAG_P
, "c", "Pp");
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
, "ch", "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
, "ch", "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
, "c", "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
, "c", "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
, "chI", "In", n
->string
);
1398 t
= print_otag(h
, TAG_A
, "c", "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
, "ci", "Ic", id
);
1428 mdoc_va_pre(MDOC_ARGS
)
1430 print_otag(h
, TAG_VAR
, "c", "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
)
1451 html_close_paragraph(h
);
1461 if (FONT_Em
== n
->norm
->Bf
.font
)
1463 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1465 else if (FONT_Li
== n
->norm
->Bf
.font
)
1470 /* Cannot use TAG_SPAN because it may contain blocks. */
1471 print_otag(h
, TAG_DIV
, "c", cattr
);
1476 mdoc_ms_pre(MDOC_ARGS
)
1480 if ((id
= cond_id(n
)) != NULL
)
1481 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1482 print_otag(h
, TAG_SPAN
, "ci", "Ms", id
);
1487 mdoc_igndelim_pre(MDOC_ARGS
)
1490 h
->flags
|= HTML_IGNDELIM
;
1495 mdoc_pf_post(MDOC_ARGS
)
1498 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1499 h
->flags
|= HTML_NOSPACE
;
1503 mdoc_rs_pre(MDOC_ARGS
)
1507 if (n
->sec
== SEC_SEE_ALSO
)
1508 html_close_paragraph(h
);
1513 if (n
->sec
== SEC_SEE_ALSO
)
1514 print_otag(h
, TAG_P
, "c", "Pp");
1515 print_otag(h
, TAG_CITE
, "c", "Rs");
1524 mdoc_no_pre(MDOC_ARGS
)
1528 if ((id
= cond_id(n
)) != NULL
)
1529 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1530 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1535 mdoc_li_pre(MDOC_ARGS
)
1539 if ((id
= cond_id(n
)) != NULL
)
1540 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1541 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1546 mdoc_sy_pre(MDOC_ARGS
)
1548 print_otag(h
, TAG_B
, "c", "Sy");
1553 mdoc_lb_pre(MDOC_ARGS
)
1555 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1556 print_otag(h
, TAG_BR
, "");
1558 print_otag(h
, TAG_SPAN
, "c", "Lb");
1563 mdoc__x_pre(MDOC_ARGS
)
1573 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1574 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1575 print_text(h
, "and");
1614 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1623 print_otag(h
, t
, "c", cattr
);
1628 mdoc__x_post(MDOC_ARGS
)
1631 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1632 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1633 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1638 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1641 h
->flags
|= HTML_NOSPACE
;
1642 print_text(h
, n
->next
? "," : ".");
1646 mdoc_bk_pre(MDOC_ARGS
)
1655 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1656 h
->flags
|= HTML_PREKEEP
;
1666 mdoc_bk_post(MDOC_ARGS
)
1669 if (n
->type
== ROFFT_BODY
)
1670 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1674 mdoc_quote_pre(MDOC_ARGS
)
1676 if (n
->type
!= ROFFT_BODY
)
1682 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1683 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1687 print_text(h
, "\\(lC");
1691 print_text(h
, "\\(lB");
1695 print_text(h
, "\\(lB");
1697 * Give up on semantic markup for now.
1698 * We cannot use TAG_SPAN because .Oo may contain blocks.
1699 * We cannot use TAG_IDIV because we might be in a
1700 * phrasing context (like .Dl or .Pp); we cannot
1701 * close out a .Pp at this point either because
1702 * that would break the line.
1704 /* XXX print_otag(h, TAG_???, "c", "Op"); */
1707 if (NULL
== n
->norm
->Es
||
1708 NULL
== n
->norm
->Es
->child
)
1710 print_text(h
, n
->norm
->Es
->child
->string
);
1716 print_text(h
, "\\(lq");
1723 print_text(h
, "\\(oq");
1724 h
->flags
|= HTML_NOSPACE
;
1725 print_otag(h
, TAG_CODE
, "c", "Li");
1729 print_text(h
, "\\(oq");
1735 h
->flags
|= HTML_NOSPACE
;
1740 mdoc_quote_post(MDOC_ARGS
)
1743 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1746 h
->flags
|= HTML_NOSPACE
;
1751 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1752 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1756 print_text(h
, "\\(rC");
1762 print_text(h
, "\\(rB");
1765 if (n
->norm
->Es
== NULL
||
1766 n
->norm
->Es
->child
== NULL
||
1767 n
->norm
->Es
->child
->next
== NULL
)
1768 h
->flags
&= ~HTML_NOSPACE
;
1770 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1776 print_text(h
, "\\(rq");
1785 print_text(h
, "\\(cq");
1793 mdoc_eo_pre(MDOC_ARGS
)
1796 if (n
->type
!= ROFFT_BODY
)
1799 if (n
->end
== ENDBODY_NOT
&&
1800 n
->parent
->head
->child
== NULL
&&
1802 n
->child
->end
!= ENDBODY_NOT
)
1803 print_text(h
, "\\&");
1804 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1805 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1806 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1807 h
->flags
|= HTML_NOSPACE
;
1812 mdoc_eo_post(MDOC_ARGS
)
1816 if (n
->type
!= ROFFT_BODY
)
1819 if (n
->end
!= ENDBODY_NOT
) {
1820 h
->flags
&= ~HTML_NOSPACE
;
1824 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1825 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1828 h
->flags
|= HTML_NOSPACE
;
1830 h
->flags
&= ~HTML_NOSPACE
;
1834 mdoc_abort_pre(MDOC_ARGS
)