1 /* $Id: mdoc_html.c,v 1.328 2019/03/01 10:57:18 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
) {
535 print_otag(h
, TAG_SECTION
, "c", "Sh");
538 h
->flags
|= HTML_TOCDONE
;
540 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
541 if (sn
->sec
== SEC_CUSTOM
)
546 t
= print_otag(h
, TAG_H1
, "c", "Sh");
547 print_text(h
, "TABLE OF CONTENTS");
549 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
550 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
551 tsec
= print_otag(h
, TAG_LI
, "");
552 id
= html_make_id(sn
->head
, 0);
553 tsub
= print_otag(h
, TAG_A
, "hR", id
);
555 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
558 for (subn
= sn
->body
->child
; subn
!= NULL
;
560 if (subn
->tok
!= MDOC_Ss
)
562 id
= html_make_id(subn
->head
, 0);
566 print_otag(h
, TAG_UL
,
568 tsub
= print_otag(h
, TAG_LI
, "");
569 print_otag(h
, TAG_A
, "hR", id
);
571 print_mdoc_nodelist(meta
,
572 subn
->head
->child
, h
);
578 print_otag(h
, TAG_SECTION
, "c", "Sh");
581 id
= html_make_id(n
, 1);
582 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
584 print_otag(h
, TAG_A
, "chR", "permalink", id
);
587 if (n
->sec
== SEC_AUTHORS
)
588 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
597 mdoc_ss_pre(MDOC_ARGS
)
603 html_close_paragraph(h
);
604 print_otag(h
, TAG_SECTION
, "c", "Ss");
614 id
= html_make_id(n
, 1);
615 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
617 print_otag(h
, TAG_A
, "chR", "permalink", id
);
622 mdoc_fl_pre(MDOC_ARGS
)
626 if ((id
= cond_id(n
)) != NULL
)
627 print_otag(h
, TAG_A
, "chR", "permalink", id
);
628 print_otag(h
, TAG_CODE
, "ci", "Fl", id
);
630 print_text(h
, "\\-");
631 if (!(n
->child
== NULL
&&
633 n
->next
->type
== ROFFT_TEXT
||
634 n
->next
->flags
& NODE_LINE
)))
635 h
->flags
|= HTML_NOSPACE
;
641 mdoc_cm_pre(MDOC_ARGS
)
645 if ((id
= cond_id(n
)) != NULL
)
646 print_otag(h
, TAG_A
, "chR", "permalink", id
);
647 print_otag(h
, TAG_CODE
, "ci", "Cm", id
);
652 mdoc_nd_pre(MDOC_ARGS
)
656 html_close_paragraph(h
);
665 print_text(h
, "\\(em");
666 /* Cannot use TAG_SPAN because it may contain blocks. */
667 print_otag(h
, TAG_DIV
, "c", "Nd");
672 mdoc_nm_pre(MDOC_ARGS
)
678 print_otag(h
, TAG_TD
, "");
681 print_otag(h
, TAG_CODE
, "c", "Nm");
684 print_otag(h
, TAG_TD
, "");
689 html_close_paragraph(h
);
691 print_otag(h
, TAG_TABLE
, "c", "Nm");
692 print_otag(h
, TAG_TR
, "");
697 mdoc_xr_pre(MDOC_ARGS
)
699 if (NULL
== n
->child
)
703 print_otag(h
, TAG_A
, "chM", "Xr",
704 n
->child
->string
, n
->child
->next
== NULL
?
705 NULL
: n
->child
->next
->string
);
707 print_otag(h
, TAG_A
, "c", "Xr");
710 print_text(h
, n
->string
);
712 if (NULL
== (n
= n
->next
))
715 h
->flags
|= HTML_NOSPACE
;
717 h
->flags
|= HTML_NOSPACE
;
718 print_text(h
, n
->string
);
719 h
->flags
|= HTML_NOSPACE
;
725 mdoc_ns_pre(MDOC_ARGS
)
728 if ( ! (NODE_LINE
& n
->flags
))
729 h
->flags
|= HTML_NOSPACE
;
734 mdoc_ar_pre(MDOC_ARGS
)
736 print_otag(h
, TAG_VAR
, "c", "Ar");
741 mdoc_xx_pre(MDOC_ARGS
)
743 print_otag(h
, TAG_SPAN
, "c", "Ux");
748 mdoc_it_pre(MDOC_ARGS
)
750 const struct roff_node
*bl
;
754 while (bl
->tok
!= MDOC_Bl
)
756 type
= bl
->norm
->Bl
.type
;
768 print_otag(h
, TAG_LI
, "");
780 print_otag(h
, TAG_DT
, "");
783 print_otag(h
, TAG_DD
, "");
792 print_otag(h
, TAG_DT
, "");
795 if (n
->child
== NULL
) {
796 print_otag(h
, TAG_DD
, "s", "width", "auto");
797 print_text(h
, "\\ ");
799 print_otag(h
, TAG_DD
, "");
810 print_otag(h
, TAG_TD
, "");
813 print_otag(h
, TAG_TR
, "");
823 mdoc_bl_pre(MDOC_ARGS
)
827 enum htmltag elemtype
;
831 html_close_paragraph(h
);
845 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
850 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
854 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
858 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
862 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
866 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
870 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
874 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
878 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
879 print_otag(h
, TAG_DL
, "c", bl
->comp
?
880 "Bl-tag Bl-compact" : "Bl-tag");
883 elemtype
= TAG_TABLE
;
884 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
889 if (bl
->offs
!= NULL
)
890 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
892 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
893 print_otag(h
, elemtype
, "c", cattr
);
898 mdoc_ex_pre(MDOC_ARGS
)
901 print_otag(h
, TAG_BR
, "");
906 mdoc_st_pre(MDOC_ARGS
)
908 print_otag(h
, TAG_SPAN
, "c", "St");
913 mdoc_em_pre(MDOC_ARGS
)
915 print_otag(h
, TAG_I
, "c", "Em");
920 mdoc_d1_pre(MDOC_ARGS
)
924 html_close_paragraph(h
);
933 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
934 if (n
->tok
== MDOC_Dl
)
935 print_otag(h
, TAG_CODE
, "c", "Li");
940 mdoc_sx_pre(MDOC_ARGS
)
944 id
= html_make_id(n
, 0);
945 print_otag(h
, TAG_A
, "chR", "Sx", id
);
951 mdoc_bd_pre(MDOC_ARGS
)
954 struct roff_node
*nn
;
959 html_close_paragraph(h
);
969 /* Handle preceding whitespace. */
971 comp
= n
->norm
->Bd
.comp
;
972 for (nn
= n
; nn
!= NULL
&& comp
== 0; nn
= nn
->parent
) {
973 if (nn
->type
!= ROFFT_BLOCK
)
975 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
977 if (nn
->prev
!= NULL
)
980 (void)strlcpy(buf
, "Bd", sizeof(buf
));
982 (void)strlcat(buf
, " Pp", sizeof(buf
));
984 /* Handle the -offset argument. */
986 if (n
->norm
->Bd
.offs
!= NULL
&&
987 strcmp(n
->norm
->Bd
.offs
, "left") != 0)
988 (void)strlcat(buf
, " Bd-indent", sizeof(buf
));
990 print_otag(h
, TAG_DIV
, "c", buf
);
995 mdoc_pa_pre(MDOC_ARGS
)
997 print_otag(h
, TAG_SPAN
, "c", "Pa");
1002 mdoc_ad_pre(MDOC_ARGS
)
1004 print_otag(h
, TAG_SPAN
, "c", "Ad");
1009 mdoc_an_pre(MDOC_ARGS
)
1011 if (n
->norm
->An
.auth
== AUTH_split
) {
1012 h
->flags
&= ~HTML_NOSPLIT
;
1013 h
->flags
|= HTML_SPLIT
;
1016 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1017 h
->flags
&= ~HTML_SPLIT
;
1018 h
->flags
|= HTML_NOSPLIT
;
1022 if (h
->flags
& HTML_SPLIT
)
1023 print_otag(h
, TAG_BR
, "");
1025 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1026 h
->flags
|= HTML_SPLIT
;
1028 print_otag(h
, TAG_SPAN
, "c", "An");
1033 mdoc_cd_pre(MDOC_ARGS
)
1036 print_otag(h
, TAG_CODE
, "c", "Cd");
1041 mdoc_dv_pre(MDOC_ARGS
)
1045 if ((id
= cond_id(n
)) != NULL
)
1046 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1047 print_otag(h
, TAG_CODE
, "ci", "Dv", id
);
1052 mdoc_ev_pre(MDOC_ARGS
)
1056 if ((id
= cond_id(n
)) != NULL
)
1057 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1058 print_otag(h
, TAG_CODE
, "ci", "Ev", id
);
1063 mdoc_er_pre(MDOC_ARGS
)
1067 id
= n
->sec
== SEC_ERRORS
&&
1068 (n
->parent
->tok
== MDOC_It
||
1069 (n
->parent
->tok
== MDOC_Bq
&&
1070 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1071 html_make_id(n
, 1) : NULL
;
1074 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1075 print_otag(h
, TAG_CODE
, "ci", "Er", id
);
1080 mdoc_fa_pre(MDOC_ARGS
)
1082 const struct roff_node
*nn
;
1085 if (n
->parent
->tok
!= MDOC_Fo
) {
1086 print_otag(h
, TAG_VAR
, "c", "Fa");
1090 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1091 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1092 print_text(h
, nn
->string
);
1095 h
->flags
|= HTML_NOSPACE
;
1100 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1101 h
->flags
|= HTML_NOSPACE
;
1109 mdoc_fd_pre(MDOC_ARGS
)
1116 if (NULL
== (n
= n
->child
))
1119 assert(n
->type
== ROFFT_TEXT
);
1121 if (strcmp(n
->string
, "#include")) {
1122 print_otag(h
, TAG_CODE
, "c", "Fd");
1126 print_otag(h
, TAG_CODE
, "c", "In");
1127 print_text(h
, n
->string
);
1129 if (NULL
!= (n
= n
->next
)) {
1130 assert(n
->type
== ROFFT_TEXT
);
1132 if (h
->base_includes
) {
1134 if (*cp
== '<' || *cp
== '"')
1136 buf
= mandoc_strdup(cp
);
1137 cp
= strchr(buf
, '\0') - 1;
1138 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1140 t
= print_otag(h
, TAG_A
, "chI", "In", buf
);
1143 t
= print_otag(h
, TAG_A
, "c", "In");
1145 print_text(h
, n
->string
);
1151 for ( ; n
; n
= n
->next
) {
1152 assert(n
->type
== ROFFT_TEXT
);
1153 print_text(h
, n
->string
);
1160 mdoc_vt_pre(MDOC_ARGS
)
1162 if (n
->type
== ROFFT_BLOCK
) {
1165 } else if (n
->type
== ROFFT_ELEM
) {
1167 } else if (n
->type
== ROFFT_HEAD
)
1170 print_otag(h
, TAG_VAR
, "c", "Vt");
1175 mdoc_ft_pre(MDOC_ARGS
)
1178 print_otag(h
, TAG_VAR
, "c", "Ft");
1183 mdoc_fn_pre(MDOC_ARGS
)
1187 const char *sp
, *ep
;
1190 pretty
= NODE_SYNPRETTY
& n
->flags
;
1193 /* Split apart into type and name. */
1194 assert(n
->child
->string
);
1195 sp
= n
->child
->string
;
1197 ep
= strchr(sp
, ' ');
1199 t
= print_otag(h
, TAG_VAR
, "c", "Ft");
1202 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1203 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1205 print_text(h
, nbuf
);
1207 ep
= strchr(sp
, ' ');
1212 t
= print_otag(h
, TAG_CODE
, "c", "Fn");
1219 h
->flags
|= HTML_NOSPACE
;
1221 h
->flags
|= HTML_NOSPACE
;
1223 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1224 if (NODE_SYNPRETTY
& n
->flags
)
1225 t
= print_otag(h
, TAG_VAR
, "cs", "Fa",
1226 "white-space", "nowrap");
1228 t
= print_otag(h
, TAG_VAR
, "c", "Fa");
1229 print_text(h
, n
->string
);
1232 h
->flags
|= HTML_NOSPACE
;
1237 h
->flags
|= HTML_NOSPACE
;
1241 h
->flags
|= HTML_NOSPACE
;
1249 mdoc_sm_pre(MDOC_ARGS
)
1252 if (NULL
== n
->child
)
1253 h
->flags
^= HTML_NONOSPACE
;
1254 else if (0 == strcmp("on", n
->child
->string
))
1255 h
->flags
&= ~HTML_NONOSPACE
;
1257 h
->flags
|= HTML_NONOSPACE
;
1259 if ( ! (HTML_NONOSPACE
& h
->flags
))
1260 h
->flags
&= ~HTML_NOSPACE
;
1266 mdoc_skip_pre(MDOC_ARGS
)
1273 mdoc_pp_pre(MDOC_ARGS
)
1275 if ((n
->flags
& NODE_NOFILL
) == 0) {
1276 html_close_paragraph(h
);
1277 print_otag(h
, TAG_P
, "c", "Pp");
1283 mdoc_lk_pre(MDOC_ARGS
)
1285 const struct roff_node
*link
, *descr
, *punct
;
1288 if ((link
= n
->child
) == NULL
)
1291 /* Find beginning of trailing punctuation. */
1293 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1294 punct
= punct
->prev
;
1295 punct
= punct
->next
;
1297 /* Link target and link text. */
1300 descr
= link
; /* no text */
1301 t
= print_otag(h
, TAG_A
, "ch", "Lk", link
->string
);
1303 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1304 h
->flags
|= HTML_NOSPACE
;
1305 print_text(h
, descr
->string
);
1306 descr
= descr
->next
;
1307 } while (descr
!= punct
);
1310 /* Trailing punctuation. */
1311 while (punct
!= NULL
) {
1312 h
->flags
|= HTML_NOSPACE
;
1313 print_text(h
, punct
->string
);
1314 punct
= punct
->next
;
1320 mdoc_mt_pre(MDOC_ARGS
)
1325 for (n
= n
->child
; n
; n
= n
->next
) {
1326 assert(n
->type
== ROFFT_TEXT
);
1328 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1329 t
= print_otag(h
, TAG_A
, "ch", "Mt", cp
);
1330 print_text(h
, n
->string
);
1339 mdoc_fo_pre(MDOC_ARGS
)
1343 if (n
->type
== ROFFT_BODY
) {
1344 h
->flags
|= HTML_NOSPACE
;
1346 h
->flags
|= HTML_NOSPACE
;
1348 } else if (n
->type
== ROFFT_BLOCK
) {
1353 if (n
->child
== NULL
)
1356 assert(n
->child
->string
);
1357 t
= print_otag(h
, TAG_CODE
, "c", "Fn");
1358 print_text(h
, n
->child
->string
);
1364 mdoc_fo_post(MDOC_ARGS
)
1367 if (n
->type
!= ROFFT_BODY
)
1369 h
->flags
|= HTML_NOSPACE
;
1371 h
->flags
|= HTML_NOSPACE
;
1376 mdoc_in_pre(MDOC_ARGS
)
1381 print_otag(h
, TAG_CODE
, "c", "In");
1384 * The first argument of the `In' gets special treatment as
1385 * being a linked value. Subsequent values are printed
1386 * afterward. groff does similarly. This also handles the case
1390 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1391 print_text(h
, "#include");
1394 h
->flags
|= HTML_NOSPACE
;
1396 if (NULL
!= (n
= n
->child
)) {
1397 assert(n
->type
== ROFFT_TEXT
);
1399 if (h
->base_includes
)
1400 t
= print_otag(h
, TAG_A
, "chI", "In", n
->string
);
1402 t
= print_otag(h
, TAG_A
, "c", "In");
1403 print_text(h
, n
->string
);
1409 h
->flags
|= HTML_NOSPACE
;
1412 for ( ; n
; n
= n
->next
) {
1413 assert(n
->type
== ROFFT_TEXT
);
1414 print_text(h
, n
->string
);
1421 mdoc_ic_pre(MDOC_ARGS
)
1425 if ((id
= cond_id(n
)) != NULL
)
1426 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1427 print_otag(h
, TAG_CODE
, "ci", "Ic", id
);
1432 mdoc_va_pre(MDOC_ARGS
)
1434 print_otag(h
, TAG_VAR
, "c", "Va");
1439 mdoc_ap_pre(MDOC_ARGS
)
1442 h
->flags
|= HTML_NOSPACE
;
1443 print_text(h
, "\\(aq");
1444 h
->flags
|= HTML_NOSPACE
;
1449 mdoc_bf_pre(MDOC_ARGS
)
1455 html_close_paragraph(h
);
1465 if (FONT_Em
== n
->norm
->Bf
.font
)
1467 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1469 else if (FONT_Li
== n
->norm
->Bf
.font
)
1474 /* Cannot use TAG_SPAN because it may contain blocks. */
1475 print_otag(h
, TAG_DIV
, "c", cattr
);
1480 mdoc_ms_pre(MDOC_ARGS
)
1484 if ((id
= cond_id(n
)) != NULL
)
1485 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1486 print_otag(h
, TAG_SPAN
, "ci", "Ms", id
);
1491 mdoc_igndelim_pre(MDOC_ARGS
)
1494 h
->flags
|= HTML_IGNDELIM
;
1499 mdoc_pf_post(MDOC_ARGS
)
1502 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1503 h
->flags
|= HTML_NOSPACE
;
1507 mdoc_rs_pre(MDOC_ARGS
)
1511 if (n
->sec
== SEC_SEE_ALSO
)
1512 html_close_paragraph(h
);
1517 if (n
->sec
== SEC_SEE_ALSO
)
1518 print_otag(h
, TAG_P
, "c", "Pp");
1519 print_otag(h
, TAG_CITE
, "c", "Rs");
1528 mdoc_no_pre(MDOC_ARGS
)
1532 if ((id
= cond_id(n
)) != NULL
)
1533 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1534 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1539 mdoc_li_pre(MDOC_ARGS
)
1543 if ((id
= cond_id(n
)) != NULL
)
1544 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1545 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1550 mdoc_sy_pre(MDOC_ARGS
)
1552 print_otag(h
, TAG_B
, "c", "Sy");
1557 mdoc_lb_pre(MDOC_ARGS
)
1559 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1560 print_otag(h
, TAG_BR
, "");
1562 print_otag(h
, TAG_SPAN
, "c", "Lb");
1567 mdoc__x_pre(MDOC_ARGS
)
1577 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1578 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1579 print_text(h
, "and");
1618 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1627 print_otag(h
, t
, "c", cattr
);
1632 mdoc__x_post(MDOC_ARGS
)
1635 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1636 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1637 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1642 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1645 h
->flags
|= HTML_NOSPACE
;
1646 print_text(h
, n
->next
? "," : ".");
1650 mdoc_bk_pre(MDOC_ARGS
)
1659 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1660 h
->flags
|= HTML_PREKEEP
;
1670 mdoc_bk_post(MDOC_ARGS
)
1673 if (n
->type
== ROFFT_BODY
)
1674 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1678 mdoc_quote_pre(MDOC_ARGS
)
1680 if (n
->type
!= ROFFT_BODY
)
1686 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1687 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1691 print_text(h
, "\\(lC");
1695 print_text(h
, "\\(lB");
1699 print_text(h
, "\\(lB");
1701 * Give up on semantic markup for now.
1702 * We cannot use TAG_SPAN because .Oo may contain blocks.
1703 * We cannot use TAG_IDIV because we might be in a
1704 * phrasing context (like .Dl or .Pp); we cannot
1705 * close out a .Pp at this point either because
1706 * that would break the line.
1708 /* XXX print_otag(h, TAG_???, "c", "Op"); */
1711 if (NULL
== n
->norm
->Es
||
1712 NULL
== n
->norm
->Es
->child
)
1714 print_text(h
, n
->norm
->Es
->child
->string
);
1720 print_text(h
, "\\(lq");
1727 print_text(h
, "\\(oq");
1728 h
->flags
|= HTML_NOSPACE
;
1729 print_otag(h
, TAG_CODE
, "c", "Li");
1733 print_text(h
, "\\(oq");
1739 h
->flags
|= HTML_NOSPACE
;
1744 mdoc_quote_post(MDOC_ARGS
)
1747 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1750 h
->flags
|= HTML_NOSPACE
;
1755 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1756 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1760 print_text(h
, "\\(rC");
1766 print_text(h
, "\\(rB");
1769 if (n
->norm
->Es
== NULL
||
1770 n
->norm
->Es
->child
== NULL
||
1771 n
->norm
->Es
->child
->next
== NULL
)
1772 h
->flags
&= ~HTML_NOSPACE
;
1774 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1780 print_text(h
, "\\(rq");
1789 print_text(h
, "\\(cq");
1797 mdoc_eo_pre(MDOC_ARGS
)
1800 if (n
->type
!= ROFFT_BODY
)
1803 if (n
->end
== ENDBODY_NOT
&&
1804 n
->parent
->head
->child
== NULL
&&
1806 n
->child
->end
!= ENDBODY_NOT
)
1807 print_text(h
, "\\&");
1808 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1809 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1810 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1811 h
->flags
|= HTML_NOSPACE
;
1816 mdoc_eo_post(MDOC_ARGS
)
1820 if (n
->type
!= ROFFT_BODY
)
1823 if (n
->end
!= ENDBODY_NOT
) {
1824 h
->flags
&= ~HTML_NOSPACE
;
1828 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1829 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1832 h
->flags
|= HTML_NOSPACE
;
1834 h
->flags
&= ~HTML_NOSPACE
;
1838 mdoc_abort_pre(MDOC_ARGS
)