1 /* $Id: mdoc_html.c,v 1.322 2018/12/31 10:35:56 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
37 #define MDOC_ARGS const struct roff_meta *meta, \
38 struct roff_node *n, \
42 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
45 struct mdoc_html_act
{
46 int (*pre
)(MDOC_ARGS
);
47 void (*post
)(MDOC_ARGS
);
50 static char *cond_id(const struct roff_node
*);
51 static void print_mdoc_head(const struct roff_meta
*,
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
55 static void synopsis_pre(struct html
*,
56 const struct roff_node
*);
58 static void mdoc_root_post(const struct roff_meta
*,
60 static int mdoc_root_pre(const struct roff_meta
*,
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_abort_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static int mdoc_ar_pre(MDOC_ARGS
);
70 static int mdoc_bd_pre(MDOC_ARGS
);
71 static int mdoc_bf_pre(MDOC_ARGS
);
72 static void mdoc_bk_post(MDOC_ARGS
);
73 static int mdoc_bk_pre(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static int mdoc_cd_pre(MDOC_ARGS
);
76 static int mdoc_cm_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static int mdoc_dv_pre(MDOC_ARGS
);
79 static int mdoc_fa_pre(MDOC_ARGS
);
80 static int mdoc_fd_pre(MDOC_ARGS
);
81 static int mdoc_fl_pre(MDOC_ARGS
);
82 static int mdoc_fn_pre(MDOC_ARGS
);
83 static int mdoc_ft_pre(MDOC_ARGS
);
84 static int mdoc_em_pre(MDOC_ARGS
);
85 static void mdoc_eo_post(MDOC_ARGS
);
86 static int mdoc_eo_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_no_pre(MDOC_ARGS
);
104 static int mdoc_ns_pre(MDOC_ARGS
);
105 static int mdoc_pa_pre(MDOC_ARGS
);
106 static void mdoc_pf_post(MDOC_ARGS
);
107 static int mdoc_pp_pre(MDOC_ARGS
);
108 static void mdoc_quote_post(MDOC_ARGS
);
109 static int mdoc_quote_pre(MDOC_ARGS
);
110 static int mdoc_rs_pre(MDOC_ARGS
);
111 static int mdoc_sh_pre(MDOC_ARGS
);
112 static int mdoc_skip_pre(MDOC_ARGS
);
113 static int mdoc_sm_pre(MDOC_ARGS
);
114 static int mdoc_ss_pre(MDOC_ARGS
);
115 static int mdoc_st_pre(MDOC_ARGS
);
116 static int mdoc_sx_pre(MDOC_ARGS
);
117 static int mdoc_sy_pre(MDOC_ARGS
);
118 static int mdoc_va_pre(MDOC_ARGS
);
119 static int mdoc_vt_pre(MDOC_ARGS
);
120 static int mdoc_xr_pre(MDOC_ARGS
);
121 static int mdoc_xx_pre(MDOC_ARGS
);
123 static const struct mdoc_html_act mdoc_html_acts
[MDOC_MAX
- MDOC_Dd
] = {
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ap_pre
, NULL
}, /* Ap */
140 {mdoc_ar_pre
, NULL
}, /* Ar */
141 {mdoc_cd_pre
, NULL
}, /* Cd */
142 {mdoc_cm_pre
, NULL
}, /* Cm */
143 {mdoc_dv_pre
, NULL
}, /* Dv */
144 {mdoc_er_pre
, NULL
}, /* Er */
145 {mdoc_ev_pre
, NULL
}, /* Ev */
146 {mdoc_ex_pre
, NULL
}, /* Ex */
147 {mdoc_fa_pre
, NULL
}, /* Fa */
148 {mdoc_fd_pre
, NULL
}, /* Fd */
149 {mdoc_fl_pre
, NULL
}, /* Fl */
150 {mdoc_fn_pre
, NULL
}, /* Fn */
151 {mdoc_ft_pre
, NULL
}, /* Ft */
152 {mdoc_ic_pre
, NULL
}, /* Ic */
153 {mdoc_in_pre
, NULL
}, /* In */
154 {mdoc_li_pre
, NULL
}, /* Li */
155 {mdoc_nd_pre
, NULL
}, /* Nd */
156 {mdoc_nm_pre
, NULL
}, /* Nm */
157 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
158 {mdoc_abort_pre
, NULL
}, /* Ot */
159 {mdoc_pa_pre
, NULL
}, /* Pa */
160 {mdoc_ex_pre
, NULL
}, /* Rv */
161 {mdoc_st_pre
, NULL
}, /* St */
162 {mdoc_va_pre
, NULL
}, /* Va */
163 {mdoc_vt_pre
, NULL
}, /* Vt */
164 {mdoc_xr_pre
, NULL
}, /* Xr */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
176 {NULL
, NULL
}, /* Ac */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
179 {mdoc_xx_pre
, NULL
}, /* At */
180 {NULL
, NULL
}, /* Bc */
181 {mdoc_bf_pre
, NULL
}, /* Bf */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
184 {mdoc_xx_pre
, NULL
}, /* Bsx */
185 {mdoc_xx_pre
, NULL
}, /* Bx */
186 {mdoc_skip_pre
, NULL
}, /* Db */
187 {NULL
, NULL
}, /* Dc */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
190 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 {NULL
, NULL
}, /* Ef */
192 {mdoc_em_pre
, NULL
}, /* Em */
193 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
194 {mdoc_xx_pre
, NULL
}, /* Fx */
195 {mdoc_ms_pre
, NULL
}, /* Ms */
196 {mdoc_no_pre
, NULL
}, /* No */
197 {mdoc_ns_pre
, NULL
}, /* Ns */
198 {mdoc_xx_pre
, NULL
}, /* Nx */
199 {mdoc_xx_pre
, NULL
}, /* Ox */
200 {NULL
, NULL
}, /* Pc */
201 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
204 {NULL
, NULL
}, /* Qc */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
208 {NULL
, NULL
}, /* Re */
209 {mdoc_rs_pre
, NULL
}, /* Rs */
210 {NULL
, NULL
}, /* Sc */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
213 {mdoc_sm_pre
, NULL
}, /* Sm */
214 {mdoc_sx_pre
, NULL
}, /* Sx */
215 {mdoc_sy_pre
, NULL
}, /* Sy */
216 {NULL
, NULL
}, /* Tn */
217 {mdoc_xx_pre
, NULL
}, /* Ux */
218 {NULL
, NULL
}, /* Xc */
219 {NULL
, NULL
}, /* Xo */
220 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
221 {NULL
, NULL
}, /* Fc */
222 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
223 {NULL
, NULL
}, /* Oc */
224 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
225 {NULL
, NULL
}, /* Ek */
226 {NULL
, NULL
}, /* Bt */
227 {NULL
, NULL
}, /* Hf */
228 {mdoc_em_pre
, NULL
}, /* Fr */
229 {NULL
, NULL
}, /* Ud */
230 {mdoc_lb_pre
, NULL
}, /* Lb */
231 {mdoc_abort_pre
, NULL
}, /* Lp */
232 {mdoc_lk_pre
, NULL
}, /* Lk */
233 {mdoc_mt_pre
, NULL
}, /* Mt */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
236 {NULL
, NULL
}, /* Brc */
237 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
238 {mdoc_skip_pre
, NULL
}, /* Es */
239 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
240 {mdoc_xx_pre
, NULL
}, /* Dx */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
243 {NULL
, NULL
}, /* Ta */
248 * See the same function in mdoc_term.c for documentation.
251 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
254 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
257 if (n
->prev
->tok
== n
->tok
&&
261 print_otag(h
, TAG_BR
, "");
265 switch (n
->prev
->tok
) {
274 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
280 print_otag(h
, TAG_BR
, "");
286 html_mdoc(void *arg
, const struct roff_meta
*mdoc
)
292 h
= (struct html
*)arg
;
293 n
= mdoc
->first
->child
;
295 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
297 print_otag(h
, TAG_HTML
, "");
298 if (n
->type
== ROFFT_COMMENT
)
299 print_gen_comment(h
, n
);
300 t
= print_otag(h
, TAG_HEAD
, "");
301 print_mdoc_head(mdoc
, h
);
303 print_otag(h
, TAG_BODY
, "");
306 mdoc_root_pre(mdoc
, h
);
307 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
308 print_mdoc_nodelist(mdoc
, n
, h
);
310 mdoc_root_post(mdoc
, h
);
315 print_mdoc_head(const struct roff_meta
*meta
, struct html
*h
)
321 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
322 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
323 meta
->msec
, meta
->arch
);
324 else if (meta
->msec
!= NULL
)
325 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
326 else if (meta
->arch
!= NULL
)
327 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
329 cp
= mandoc_strdup(meta
->title
);
331 print_otag(h
, TAG_TITLE
, "");
337 print_mdoc_nodelist(MDOC_ARGS
)
341 print_mdoc_node(meta
, n
, h
);
347 print_mdoc_node(MDOC_ARGS
)
352 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
357 n
->flags
&= ~NODE_ENDED
;
361 /* No tables in this mode... */
362 assert(NULL
== h
->tblt
);
365 * Make sure that if we're in a literal mode already
366 * (i.e., within a <PRE>) don't print the newline.
368 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
369 (h
->flags
& HTML_NONEWLINE
) == 0 &&
370 (n
->flags
& NODE_NOFILL
) == 0)
371 print_otag(h
, TAG_BR
, "");
372 if (NODE_DELIMC
& n
->flags
)
373 h
->flags
|= HTML_NOSPACE
;
374 print_text(h
, n
->string
);
375 if (NODE_DELIMO
& n
->flags
)
376 h
->flags
|= HTML_NOSPACE
;
379 print_eqn(h
, n
->eqn
);
383 * This will take care of initialising all of the table
384 * state data for the first table, then tearing it down
387 print_tbl(h
, n
->span
);
391 * Close out the current table, if it's open, and unset
392 * the "meta" table state. This will be reopened on the
393 * next table element.
395 if (h
->tblt
!= NULL
) {
399 assert(h
->tblt
== NULL
);
400 if (n
->tok
< ROFF_MAX
) {
405 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
406 if (mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
!= NULL
&&
407 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
408 child
= (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].pre
)(meta
,
413 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
414 h
->flags
&= ~HTML_KEEP
;
415 h
->flags
|= HTML_PREKEEP
;
418 if (child
&& n
->child
)
419 print_mdoc_nodelist(meta
, n
->child
, h
);
427 if (n
->tok
< ROFF_MAX
||
428 mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
== NULL
||
429 n
->flags
& NODE_ENDED
)
431 (*mdoc_html_acts
[n
->tok
- MDOC_Dd
].post
)(meta
, n
, h
);
432 if (n
->end
!= ENDBODY_NOT
)
433 n
->body
->flags
|= NODE_ENDED
;
439 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
443 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
444 tt
= print_otag(h
, TAG_TR
, "");
446 print_otag(h
, TAG_TD
, "c", "foot-date");
447 print_text(h
, meta
->date
);
450 print_otag(h
, TAG_TD
, "c", "foot-os");
451 print_text(h
, meta
->os
);
456 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
459 char *volume
, *title
;
461 if (NULL
== meta
->arch
)
462 volume
= mandoc_strdup(meta
->vol
);
464 mandoc_asprintf(&volume
, "%s (%s)",
465 meta
->vol
, meta
->arch
);
467 if (NULL
== meta
->msec
)
468 title
= mandoc_strdup(meta
->title
);
470 mandoc_asprintf(&title
, "%s(%s)",
471 meta
->title
, meta
->msec
);
473 t
= print_otag(h
, TAG_TABLE
, "c", "head");
474 tt
= print_otag(h
, TAG_TR
, "");
476 print_otag(h
, TAG_TD
, "c", "head-ltitle");
477 print_text(h
, title
);
480 print_otag(h
, TAG_TD
, "c", "head-vol");
481 print_text(h
, volume
);
484 print_otag(h
, TAG_TD
, "c", "head-rtitle");
485 print_text(h
, title
);
494 cond_id(const struct roff_node
*n
)
496 if (n
->child
!= NULL
&&
497 n
->child
->type
== ROFFT_TEXT
&&
499 (n
->prev
->type
== ROFFT_TEXT
&&
500 strcmp(n
->prev
->string
, "|") == 0)) &&
501 (n
->parent
->tok
== MDOC_It
||
502 (n
->parent
->tok
== MDOC_Xo
&&
503 n
->parent
->parent
->prev
== NULL
&&
504 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
505 return html_make_id(n
, 1);
510 mdoc_sh_pre(MDOC_ARGS
)
512 struct roff_node
*sn
, *subn
;
513 struct tag
*t
, *tsec
, *tsub
;
519 if ((h
->oflags
& HTML_TOC
) == 0 ||
520 h
->flags
& HTML_TOCDONE
||
521 n
->sec
<= SEC_SYNOPSIS
)
523 h
->flags
|= HTML_TOCDONE
;
525 for (sn
= n
->next
; sn
!= NULL
; sn
= sn
->next
)
526 if (sn
->sec
== SEC_CUSTOM
)
531 t
= print_otag(h
, TAG_H1
, "c", "Sh");
532 print_text(h
, "TABLE OF CONTENTS");
534 t
= print_otag(h
, TAG_UL
, "c", "Bl-compact");
535 for (sn
= n
; sn
!= NULL
; sn
= sn
->next
) {
536 tsec
= print_otag(h
, TAG_LI
, "");
537 id
= html_make_id(sn
->head
, 0);
538 tsub
= print_otag(h
, TAG_A
, "hR", id
);
540 print_mdoc_nodelist(meta
, sn
->head
->child
, h
);
543 for (subn
= sn
->body
->child
; subn
!= NULL
;
545 if (subn
->tok
!= MDOC_Ss
)
547 id
= html_make_id(subn
->head
, 0);
551 print_otag(h
, TAG_UL
,
553 tsub
= print_otag(h
, TAG_LI
, "");
554 print_otag(h
, TAG_A
, "hR", id
);
556 print_mdoc_nodelist(meta
,
557 subn
->head
->child
, h
);
565 id
= html_make_id(n
, 1);
566 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
568 print_otag(h
, TAG_A
, "chR", "permalink", id
);
571 if (n
->sec
== SEC_AUTHORS
)
572 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
581 mdoc_ss_pre(MDOC_ARGS
)
585 if (n
->type
!= ROFFT_HEAD
)
588 id
= html_make_id(n
, 1);
589 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
591 print_otag(h
, TAG_A
, "chR", "permalink", id
);
596 mdoc_fl_pre(MDOC_ARGS
)
600 if ((id
= cond_id(n
)) != NULL
)
601 print_otag(h
, TAG_A
, "chR", "permalink", id
);
602 print_otag(h
, TAG_CODE
, "cTi", "Fl", id
);
604 print_text(h
, "\\-");
605 if (!(n
->child
== NULL
&&
607 n
->next
->type
== ROFFT_TEXT
||
608 n
->next
->flags
& NODE_LINE
)))
609 h
->flags
|= HTML_NOSPACE
;
615 mdoc_cm_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
, "cTi", "Cm", id
);
626 mdoc_nd_pre(MDOC_ARGS
)
628 if (n
->type
!= ROFFT_BODY
)
631 print_text(h
, "\\(em");
632 /* Cannot use TAG_SPAN because it may contain blocks. */
633 print_otag(h
, TAG_DIV
, "cT", "Nd");
638 mdoc_nm_pre(MDOC_ARGS
)
642 print_otag(h
, TAG_TD
, "");
645 print_otag(h
, TAG_CODE
, "cT", "Nm");
648 print_otag(h
, TAG_TD
, "");
654 print_otag(h
, TAG_TABLE
, "c", "Nm");
655 print_otag(h
, TAG_TR
, "");
660 mdoc_xr_pre(MDOC_ARGS
)
662 if (NULL
== n
->child
)
666 print_otag(h
, TAG_A
, "cThM", "Xr",
667 n
->child
->string
, n
->child
->next
== NULL
?
668 NULL
: n
->child
->next
->string
);
670 print_otag(h
, TAG_A
, "cT", "Xr");
673 print_text(h
, n
->string
);
675 if (NULL
== (n
= n
->next
))
678 h
->flags
|= HTML_NOSPACE
;
680 h
->flags
|= HTML_NOSPACE
;
681 print_text(h
, n
->string
);
682 h
->flags
|= HTML_NOSPACE
;
688 mdoc_ns_pre(MDOC_ARGS
)
691 if ( ! (NODE_LINE
& n
->flags
))
692 h
->flags
|= HTML_NOSPACE
;
697 mdoc_ar_pre(MDOC_ARGS
)
699 print_otag(h
, TAG_VAR
, "cT", "Ar");
704 mdoc_xx_pre(MDOC_ARGS
)
706 print_otag(h
, TAG_SPAN
, "c", "Ux");
711 mdoc_it_pre(MDOC_ARGS
)
713 const struct roff_node
*bl
;
718 while (bl
->tok
!= MDOC_Bl
)
720 type
= bl
->norm
->Bl
.type
;
732 print_otag(h
, TAG_LI
, "");
744 print_otag(h
, TAG_DT
, "");
747 print_otag(h
, TAG_DD
, "");
756 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
757 (n
->parent
->prev
== NULL
||
758 n
->parent
->prev
->body
== NULL
||
759 n
->parent
->prev
->body
->child
!= NULL
)) {
760 t
= print_otag(h
, TAG_DT
, "");
761 print_text(h
, "\\ ");
763 t
= print_otag(h
, TAG_DD
, "");
764 print_text(h
, "\\ ");
767 print_otag(h
, TAG_DT
, "");
770 if (n
->child
== NULL
) {
771 print_otag(h
, TAG_DD
, "s", "width", "auto");
772 print_text(h
, "\\ ");
774 print_otag(h
, TAG_DD
, "");
785 print_otag(h
, TAG_TD
, "");
788 print_otag(h
, TAG_TR
, "");
798 mdoc_bl_pre(MDOC_ARGS
)
802 enum htmltag elemtype
;
817 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
822 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
826 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
830 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
834 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
838 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
842 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
846 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
850 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
851 print_otag(h
, TAG_DL
, "c", bl
->comp
?
852 "Bl-tag Bl-compact" : "Bl-tag");
855 elemtype
= TAG_TABLE
;
856 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
861 if (bl
->offs
!= NULL
)
862 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
864 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
865 print_otag(h
, elemtype
, "c", cattr
);
870 mdoc_ex_pre(MDOC_ARGS
)
873 print_otag(h
, TAG_BR
, "");
878 mdoc_st_pre(MDOC_ARGS
)
880 print_otag(h
, TAG_SPAN
, "cT", "St");
885 mdoc_em_pre(MDOC_ARGS
)
887 print_otag(h
, TAG_I
, "cT", "Em");
892 mdoc_d1_pre(MDOC_ARGS
)
894 if (n
->type
!= ROFFT_BLOCK
)
897 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
899 if (n
->tok
== MDOC_Dl
)
900 print_otag(h
, TAG_CODE
, "c", "Li");
906 mdoc_sx_pre(MDOC_ARGS
)
910 id
= html_make_id(n
, 0);
911 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
917 mdoc_bd_pre(MDOC_ARGS
)
920 struct roff_node
*nn
;
922 if (n
->type
== ROFFT_HEAD
)
925 if (n
->type
== ROFFT_BLOCK
) {
926 comp
= n
->norm
->Bd
.comp
;
927 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
928 if (nn
->type
!= ROFFT_BLOCK
)
930 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
940 /* Handle the -offset argument. */
942 if (n
->norm
->Bd
.offs
== NULL
||
943 ! strcmp(n
->norm
->Bd
.offs
, "left"))
944 print_otag(h
, TAG_DIV
, "c", "Bd");
946 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
948 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
949 n
->norm
->Bd
.type
!= DISP_literal
)
952 print_otag(h
, TAG_PRE
, "c", "Li");
953 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
954 print_mdoc_node(meta
, nn
, h
);
956 * If the printed node flushes its own line, then we
957 * needn't do it here as well. This is hacky, but the
958 * notion of selective eoln whitespace is pretty dumb
959 * anyway, so don't sweat it.
973 if (h
->flags
& HTML_NONEWLINE
||
974 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
979 h
->flags
|= HTML_NOSPACE
;
985 mdoc_pa_pre(MDOC_ARGS
)
987 print_otag(h
, TAG_SPAN
, "cT", "Pa");
992 mdoc_ad_pre(MDOC_ARGS
)
994 print_otag(h
, TAG_SPAN
, "c", "Ad");
999 mdoc_an_pre(MDOC_ARGS
)
1001 if (n
->norm
->An
.auth
== AUTH_split
) {
1002 h
->flags
&= ~HTML_NOSPLIT
;
1003 h
->flags
|= HTML_SPLIT
;
1006 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1007 h
->flags
&= ~HTML_SPLIT
;
1008 h
->flags
|= HTML_NOSPLIT
;
1012 if (h
->flags
& HTML_SPLIT
)
1013 print_otag(h
, TAG_BR
, "");
1015 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1016 h
->flags
|= HTML_SPLIT
;
1018 print_otag(h
, TAG_SPAN
, "cT", "An");
1023 mdoc_cd_pre(MDOC_ARGS
)
1026 print_otag(h
, TAG_CODE
, "cT", "Cd");
1031 mdoc_dv_pre(MDOC_ARGS
)
1035 if ((id
= cond_id(n
)) != NULL
)
1036 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1037 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1042 mdoc_ev_pre(MDOC_ARGS
)
1046 if ((id
= cond_id(n
)) != NULL
)
1047 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1048 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1053 mdoc_er_pre(MDOC_ARGS
)
1057 id
= n
->sec
== SEC_ERRORS
&&
1058 (n
->parent
->tok
== MDOC_It
||
1059 (n
->parent
->tok
== MDOC_Bq
&&
1060 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1061 html_make_id(n
, 1) : NULL
;
1064 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1065 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1070 mdoc_fa_pre(MDOC_ARGS
)
1072 const struct roff_node
*nn
;
1075 if (n
->parent
->tok
!= MDOC_Fo
) {
1076 print_otag(h
, TAG_VAR
, "cT", "Fa");
1080 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1081 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1082 print_text(h
, nn
->string
);
1085 h
->flags
|= HTML_NOSPACE
;
1090 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1091 h
->flags
|= HTML_NOSPACE
;
1099 mdoc_fd_pre(MDOC_ARGS
)
1106 if (NULL
== (n
= n
->child
))
1109 assert(n
->type
== ROFFT_TEXT
);
1111 if (strcmp(n
->string
, "#include")) {
1112 print_otag(h
, TAG_CODE
, "cT", "Fd");
1116 print_otag(h
, TAG_CODE
, "cT", "In");
1117 print_text(h
, n
->string
);
1119 if (NULL
!= (n
= n
->next
)) {
1120 assert(n
->type
== ROFFT_TEXT
);
1122 if (h
->base_includes
) {
1124 if (*cp
== '<' || *cp
== '"')
1126 buf
= mandoc_strdup(cp
);
1127 cp
= strchr(buf
, '\0') - 1;
1128 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1130 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1133 t
= print_otag(h
, TAG_A
, "cT", "In");
1135 print_text(h
, n
->string
);
1141 for ( ; n
; n
= n
->next
) {
1142 assert(n
->type
== ROFFT_TEXT
);
1143 print_text(h
, n
->string
);
1150 mdoc_vt_pre(MDOC_ARGS
)
1152 if (n
->type
== ROFFT_BLOCK
) {
1155 } else if (n
->type
== ROFFT_ELEM
) {
1157 } else if (n
->type
== ROFFT_HEAD
)
1160 print_otag(h
, TAG_VAR
, "cT", "Vt");
1165 mdoc_ft_pre(MDOC_ARGS
)
1168 print_otag(h
, TAG_VAR
, "cT", "Ft");
1173 mdoc_fn_pre(MDOC_ARGS
)
1177 const char *sp
, *ep
;
1180 pretty
= NODE_SYNPRETTY
& n
->flags
;
1183 /* Split apart into type and name. */
1184 assert(n
->child
->string
);
1185 sp
= n
->child
->string
;
1187 ep
= strchr(sp
, ' ');
1189 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1192 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1193 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1195 print_text(h
, nbuf
);
1197 ep
= strchr(sp
, ' ');
1202 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1209 h
->flags
|= HTML_NOSPACE
;
1211 h
->flags
|= HTML_NOSPACE
;
1213 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1214 if (NODE_SYNPRETTY
& n
->flags
)
1215 t
= print_otag(h
, TAG_VAR
, "cTs", "Fa",
1216 "white-space", "nowrap");
1218 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1219 print_text(h
, n
->string
);
1222 h
->flags
|= HTML_NOSPACE
;
1227 h
->flags
|= HTML_NOSPACE
;
1231 h
->flags
|= HTML_NOSPACE
;
1239 mdoc_sm_pre(MDOC_ARGS
)
1242 if (NULL
== n
->child
)
1243 h
->flags
^= HTML_NONOSPACE
;
1244 else if (0 == strcmp("on", n
->child
->string
))
1245 h
->flags
&= ~HTML_NONOSPACE
;
1247 h
->flags
|= HTML_NONOSPACE
;
1249 if ( ! (HTML_NONOSPACE
& h
->flags
))
1250 h
->flags
&= ~HTML_NOSPACE
;
1256 mdoc_skip_pre(MDOC_ARGS
)
1263 mdoc_pp_pre(MDOC_ARGS
)
1271 mdoc_lk_pre(MDOC_ARGS
)
1273 const struct roff_node
*link
, *descr
, *punct
;
1276 if ((link
= n
->child
) == NULL
)
1279 /* Find beginning of trailing punctuation. */
1281 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1282 punct
= punct
->prev
;
1283 punct
= punct
->next
;
1285 /* Link target and link text. */
1288 descr
= link
; /* no text */
1289 t
= print_otag(h
, TAG_A
, "cTh", "Lk", link
->string
);
1291 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1292 h
->flags
|= HTML_NOSPACE
;
1293 print_text(h
, descr
->string
);
1294 descr
= descr
->next
;
1295 } while (descr
!= punct
);
1298 /* Trailing punctuation. */
1299 while (punct
!= NULL
) {
1300 h
->flags
|= HTML_NOSPACE
;
1301 print_text(h
, punct
->string
);
1302 punct
= punct
->next
;
1308 mdoc_mt_pre(MDOC_ARGS
)
1313 for (n
= n
->child
; n
; n
= n
->next
) {
1314 assert(n
->type
== ROFFT_TEXT
);
1316 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1317 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1318 print_text(h
, n
->string
);
1327 mdoc_fo_pre(MDOC_ARGS
)
1331 if (n
->type
== ROFFT_BODY
) {
1332 h
->flags
|= HTML_NOSPACE
;
1334 h
->flags
|= HTML_NOSPACE
;
1336 } else if (n
->type
== ROFFT_BLOCK
) {
1341 if (n
->child
== NULL
)
1344 assert(n
->child
->string
);
1345 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1346 print_text(h
, n
->child
->string
);
1352 mdoc_fo_post(MDOC_ARGS
)
1355 if (n
->type
!= ROFFT_BODY
)
1357 h
->flags
|= HTML_NOSPACE
;
1359 h
->flags
|= HTML_NOSPACE
;
1364 mdoc_in_pre(MDOC_ARGS
)
1369 print_otag(h
, TAG_CODE
, "cT", "In");
1372 * The first argument of the `In' gets special treatment as
1373 * being a linked value. Subsequent values are printed
1374 * afterward. groff does similarly. This also handles the case
1378 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1379 print_text(h
, "#include");
1382 h
->flags
|= HTML_NOSPACE
;
1384 if (NULL
!= (n
= n
->child
)) {
1385 assert(n
->type
== ROFFT_TEXT
);
1387 if (h
->base_includes
)
1388 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1390 t
= print_otag(h
, TAG_A
, "cT", "In");
1391 print_text(h
, n
->string
);
1397 h
->flags
|= HTML_NOSPACE
;
1400 for ( ; n
; n
= n
->next
) {
1401 assert(n
->type
== ROFFT_TEXT
);
1402 print_text(h
, n
->string
);
1409 mdoc_ic_pre(MDOC_ARGS
)
1413 if ((id
= cond_id(n
)) != NULL
)
1414 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1415 print_otag(h
, TAG_CODE
, "cTi", "Ic", id
);
1420 mdoc_va_pre(MDOC_ARGS
)
1422 print_otag(h
, TAG_VAR
, "cT", "Va");
1427 mdoc_ap_pre(MDOC_ARGS
)
1430 h
->flags
|= HTML_NOSPACE
;
1431 print_text(h
, "\\(aq");
1432 h
->flags
|= HTML_NOSPACE
;
1437 mdoc_bf_pre(MDOC_ARGS
)
1441 if (n
->type
== ROFFT_HEAD
)
1443 else if (n
->type
!= ROFFT_BODY
)
1446 if (FONT_Em
== n
->norm
->Bf
.font
)
1448 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1450 else if (FONT_Li
== n
->norm
->Bf
.font
)
1455 /* Cannot use TAG_SPAN because it may contain blocks. */
1456 print_otag(h
, TAG_DIV
, "c", cattr
);
1461 mdoc_ms_pre(MDOC_ARGS
)
1465 if ((id
= cond_id(n
)) != NULL
)
1466 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1467 print_otag(h
, TAG_SPAN
, "cTi", "Ms", id
);
1472 mdoc_igndelim_pre(MDOC_ARGS
)
1475 h
->flags
|= HTML_IGNDELIM
;
1480 mdoc_pf_post(MDOC_ARGS
)
1483 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1484 h
->flags
|= HTML_NOSPACE
;
1488 mdoc_rs_pre(MDOC_ARGS
)
1490 if (n
->type
!= ROFFT_BLOCK
)
1493 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1496 print_otag(h
, TAG_CITE
, "cT", "Rs");
1501 mdoc_no_pre(MDOC_ARGS
)
1505 if ((id
= cond_id(n
)) != NULL
)
1506 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1507 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1512 mdoc_li_pre(MDOC_ARGS
)
1516 if ((id
= cond_id(n
)) != NULL
)
1517 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1518 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1523 mdoc_sy_pre(MDOC_ARGS
)
1525 print_otag(h
, TAG_B
, "cT", "Sy");
1530 mdoc_lb_pre(MDOC_ARGS
)
1532 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1533 print_otag(h
, TAG_BR
, "");
1535 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1540 mdoc__x_pre(MDOC_ARGS
)
1550 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1551 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1552 print_text(h
, "and");
1591 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1600 print_otag(h
, t
, "c", cattr
);
1605 mdoc__x_post(MDOC_ARGS
)
1608 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1609 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1610 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1615 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1618 h
->flags
|= HTML_NOSPACE
;
1619 print_text(h
, n
->next
? "," : ".");
1623 mdoc_bk_pre(MDOC_ARGS
)
1632 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1633 h
->flags
|= HTML_PREKEEP
;
1643 mdoc_bk_post(MDOC_ARGS
)
1646 if (n
->type
== ROFFT_BODY
)
1647 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1651 mdoc_quote_pre(MDOC_ARGS
)
1653 if (n
->type
!= ROFFT_BODY
)
1659 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1660 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1664 print_text(h
, "\\(lC");
1668 print_text(h
, "\\(lB");
1672 print_text(h
, "\\(lB");
1673 h
->flags
|= HTML_NOSPACE
;
1674 /* Cannot use TAG_SPAN because it may contain blocks. */
1675 print_otag(h
, TAG_IDIV
, "c", "Op");
1678 if (NULL
== n
->norm
->Es
||
1679 NULL
== n
->norm
->Es
->child
)
1681 print_text(h
, n
->norm
->Es
->child
->string
);
1687 print_text(h
, "\\(lq");
1694 print_text(h
, "\\(oq");
1695 h
->flags
|= HTML_NOSPACE
;
1696 print_otag(h
, TAG_CODE
, "c", "Li");
1700 print_text(h
, "\\(oq");
1706 h
->flags
|= HTML_NOSPACE
;
1711 mdoc_quote_post(MDOC_ARGS
)
1714 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1717 h
->flags
|= HTML_NOSPACE
;
1722 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1723 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1727 print_text(h
, "\\(rC");
1733 print_text(h
, "\\(rB");
1736 if (n
->norm
->Es
== NULL
||
1737 n
->norm
->Es
->child
== NULL
||
1738 n
->norm
->Es
->child
->next
== NULL
)
1739 h
->flags
&= ~HTML_NOSPACE
;
1741 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1747 print_text(h
, "\\(rq");
1756 print_text(h
, "\\(cq");
1764 mdoc_eo_pre(MDOC_ARGS
)
1767 if (n
->type
!= ROFFT_BODY
)
1770 if (n
->end
== ENDBODY_NOT
&&
1771 n
->parent
->head
->child
== NULL
&&
1773 n
->child
->end
!= ENDBODY_NOT
)
1774 print_text(h
, "\\&");
1775 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1776 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1777 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1778 h
->flags
|= HTML_NOSPACE
;
1783 mdoc_eo_post(MDOC_ARGS
)
1787 if (n
->type
!= ROFFT_BODY
)
1790 if (n
->end
!= ENDBODY_NOT
) {
1791 h
->flags
&= ~HTML_NOSPACE
;
1795 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1796 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1799 h
->flags
|= HTML_NOSPACE
;
1801 h
->flags
&= ~HTML_NOSPACE
;
1805 mdoc_abort_pre(MDOC_ARGS
)