]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.301 2018/05/21 00:00:37 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"
39 #define MDOC_ARGS const struct roff_meta *meta, \
40 struct roff_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static char *cond_id(const struct roff_node
*);
53 static void print_mdoc_head(const struct roff_meta
*,
55 static void print_mdoc_node(MDOC_ARGS
);
56 static void print_mdoc_nodelist(MDOC_ARGS
);
57 static void synopsis_pre(struct html
*,
58 const struct roff_node
*);
60 static void mdoc_root_post(const struct roff_meta
*,
62 static int mdoc_root_pre(const struct roff_meta
*,
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_cm_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_pre(MDOC_ARGS
);
86 static void mdoc_eo_post(MDOC_ARGS
);
87 static int mdoc_eo_pre(MDOC_ARGS
);
88 static int mdoc_er_pre(MDOC_ARGS
);
89 static int mdoc_ev_pre(MDOC_ARGS
);
90 static int mdoc_ex_pre(MDOC_ARGS
);
91 static void mdoc_fo_post(MDOC_ARGS
);
92 static int mdoc_fo_pre(MDOC_ARGS
);
93 static int mdoc_ic_pre(MDOC_ARGS
);
94 static int mdoc_igndelim_pre(MDOC_ARGS
);
95 static int mdoc_in_pre(MDOC_ARGS
);
96 static int mdoc_it_pre(MDOC_ARGS
);
97 static int mdoc_lb_pre(MDOC_ARGS
);
98 static int mdoc_li_pre(MDOC_ARGS
);
99 static int mdoc_lk_pre(MDOC_ARGS
);
100 static int mdoc_mt_pre(MDOC_ARGS
);
101 static int mdoc_ms_pre(MDOC_ARGS
);
102 static int mdoc_nd_pre(MDOC_ARGS
);
103 static int mdoc_nm_pre(MDOC_ARGS
);
104 static int mdoc_no_pre(MDOC_ARGS
);
105 static int mdoc_ns_pre(MDOC_ARGS
);
106 static int mdoc_pa_pre(MDOC_ARGS
);
107 static void mdoc_pf_post(MDOC_ARGS
);
108 static int mdoc_pp_pre(MDOC_ARGS
);
109 static void mdoc_quote_post(MDOC_ARGS
);
110 static int mdoc_quote_pre(MDOC_ARGS
);
111 static int mdoc_rs_pre(MDOC_ARGS
);
112 static int mdoc_sh_pre(MDOC_ARGS
);
113 static int mdoc_skip_pre(MDOC_ARGS
);
114 static int mdoc_sm_pre(MDOC_ARGS
);
115 static int mdoc_ss_pre(MDOC_ARGS
);
116 static int mdoc_st_pre(MDOC_ARGS
);
117 static int mdoc_sx_pre(MDOC_ARGS
);
118 static int mdoc_sy_pre(MDOC_ARGS
);
119 static int mdoc_va_pre(MDOC_ARGS
);
120 static int mdoc_vt_pre(MDOC_ARGS
);
121 static int mdoc_xr_pre(MDOC_ARGS
);
122 static int mdoc_xx_pre(MDOC_ARGS
);
124 static const struct htmlmdoc __mdocs
[MDOC_MAX
- MDOC_Dd
] = {
125 {NULL
, NULL
}, /* Dd */
126 {NULL
, NULL
}, /* Dt */
127 {NULL
, NULL
}, /* Os */
128 {mdoc_sh_pre
, NULL
}, /* Sh */
129 {mdoc_ss_pre
, NULL
}, /* Ss */
130 {mdoc_pp_pre
, NULL
}, /* Pp */
131 {mdoc_d1_pre
, NULL
}, /* D1 */
132 {mdoc_d1_pre
, NULL
}, /* Dl */
133 {mdoc_bd_pre
, NULL
}, /* Bd */
134 {NULL
, NULL
}, /* Ed */
135 {mdoc_bl_pre
, NULL
}, /* Bl */
136 {NULL
, NULL
}, /* El */
137 {mdoc_it_pre
, NULL
}, /* It */
138 {mdoc_ad_pre
, NULL
}, /* Ad */
139 {mdoc_an_pre
, NULL
}, /* An */
140 {mdoc_ap_pre
, NULL
}, /* Ap */
141 {mdoc_ar_pre
, NULL
}, /* Ar */
142 {mdoc_cd_pre
, NULL
}, /* Cd */
143 {mdoc_cm_pre
, NULL
}, /* Cm */
144 {mdoc_dv_pre
, NULL
}, /* Dv */
145 {mdoc_er_pre
, NULL
}, /* Er */
146 {mdoc_ev_pre
, NULL
}, /* Ev */
147 {mdoc_ex_pre
, NULL
}, /* Ex */
148 {mdoc_fa_pre
, NULL
}, /* Fa */
149 {mdoc_fd_pre
, NULL
}, /* Fd */
150 {mdoc_fl_pre
, NULL
}, /* Fl */
151 {mdoc_fn_pre
, NULL
}, /* Fn */
152 {mdoc_ft_pre
, NULL
}, /* Ft */
153 {mdoc_ic_pre
, NULL
}, /* Ic */
154 {mdoc_in_pre
, NULL
}, /* In */
155 {mdoc_li_pre
, NULL
}, /* Li */
156 {mdoc_nd_pre
, NULL
}, /* Nd */
157 {mdoc_nm_pre
, NULL
}, /* Nm */
158 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
159 {mdoc_ft_pre
, NULL
}, /* Ot */
160 {mdoc_pa_pre
, NULL
}, /* Pa */
161 {mdoc_ex_pre
, NULL
}, /* Rv */
162 {mdoc_st_pre
, NULL
}, /* St */
163 {mdoc_va_pre
, NULL
}, /* Va */
164 {mdoc_vt_pre
, NULL
}, /* Vt */
165 {mdoc_xr_pre
, NULL
}, /* Xr */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
177 {NULL
, NULL
}, /* Ac */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
180 {mdoc_xx_pre
, NULL
}, /* At */
181 {NULL
, NULL
}, /* Bc */
182 {mdoc_bf_pre
, NULL
}, /* Bf */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
185 {mdoc_xx_pre
, NULL
}, /* Bsx */
186 {mdoc_xx_pre
, NULL
}, /* Bx */
187 {mdoc_skip_pre
, NULL
}, /* Db */
188 {NULL
, NULL
}, /* Dc */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
191 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
192 {NULL
, NULL
}, /* Ef */
193 {mdoc_em_pre
, NULL
}, /* Em */
194 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
195 {mdoc_xx_pre
, NULL
}, /* Fx */
196 {mdoc_ms_pre
, NULL
}, /* Ms */
197 {mdoc_no_pre
, NULL
}, /* No */
198 {mdoc_ns_pre
, NULL
}, /* Ns */
199 {mdoc_xx_pre
, NULL
}, /* Nx */
200 {mdoc_xx_pre
, NULL
}, /* Ox */
201 {NULL
, NULL
}, /* Pc */
202 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
205 {NULL
, NULL
}, /* Qc */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
209 {NULL
, NULL
}, /* Re */
210 {mdoc_rs_pre
, NULL
}, /* Rs */
211 {NULL
, NULL
}, /* Sc */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
214 {mdoc_sm_pre
, NULL
}, /* Sm */
215 {mdoc_sx_pre
, NULL
}, /* Sx */
216 {mdoc_sy_pre
, NULL
}, /* Sy */
217 {NULL
, NULL
}, /* Tn */
218 {mdoc_xx_pre
, NULL
}, /* Ux */
219 {NULL
, NULL
}, /* Xc */
220 {NULL
, NULL
}, /* Xo */
221 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
222 {NULL
, NULL
}, /* Fc */
223 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
224 {NULL
, NULL
}, /* Oc */
225 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
226 {NULL
, NULL
}, /* Ek */
227 {NULL
, NULL
}, /* Bt */
228 {NULL
, NULL
}, /* Hf */
229 {mdoc_em_pre
, NULL
}, /* Fr */
230 {NULL
, NULL
}, /* Ud */
231 {mdoc_lb_pre
, NULL
}, /* Lb */
232 {mdoc_pp_pre
, NULL
}, /* Lp */
233 {mdoc_lk_pre
, NULL
}, /* Lk */
234 {mdoc_mt_pre
, NULL
}, /* Mt */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
237 {NULL
, NULL
}, /* Brc */
238 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
239 {mdoc_skip_pre
, NULL
}, /* Es */
240 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
241 {mdoc_xx_pre
, NULL
}, /* Dx */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
246 static const struct htmlmdoc
*const mdocs
= __mdocs
- MDOC_Dd
;
250 * See the same function in mdoc_term.c for documentation.
253 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
256 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
259 if (n
->prev
->tok
== n
->tok
&&
263 print_otag(h
, TAG_BR
, "");
267 switch (n
->prev
->tok
) {
276 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
282 print_otag(h
, TAG_BR
, "");
288 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
294 h
= (struct html
*)arg
;
295 n
= mdoc
->first
->child
;
297 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
299 print_otag(h
, TAG_HTML
, "");
300 if (n
->type
== ROFFT_COMMENT
)
301 print_gen_comment(h
, n
);
302 t
= print_otag(h
, TAG_HEAD
, "");
303 print_mdoc_head(&mdoc
->meta
, h
);
305 print_otag(h
, TAG_BODY
, "");
308 mdoc_root_pre(&mdoc
->meta
, h
);
309 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
310 print_mdoc_nodelist(&mdoc
->meta
, n
, h
);
312 mdoc_root_post(&mdoc
->meta
, h
);
317 print_mdoc_head(const struct roff_meta
*meta
, struct html
*h
)
323 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
324 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
325 meta
->msec
, meta
->arch
);
326 else if (meta
->msec
!= NULL
)
327 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
328 else if (meta
->arch
!= NULL
)
329 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
331 cp
= mandoc_strdup(meta
->title
);
333 print_otag(h
, TAG_TITLE
, "");
339 print_mdoc_nodelist(MDOC_ARGS
)
343 print_mdoc_node(meta
, n
, h
);
349 print_mdoc_node(MDOC_ARGS
)
354 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
359 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_LITERAL
| HTML_NONEWLINE
)) == 0)
372 print_otag(h
, TAG_BR
, "");
373 if (NODE_DELIMC
& n
->flags
)
374 h
->flags
|= HTML_NOSPACE
;
375 print_text(h
, n
->string
);
376 if (NODE_DELIMO
& n
->flags
)
377 h
->flags
|= HTML_NOSPACE
;
380 print_eqn(h
, n
->eqn
);
384 * This will take care of initialising all of the table
385 * state data for the first table, then tearing it down
388 print_tbl(h
, n
->span
);
392 * Close out the current table, if it's open, and unset
393 * the "meta" table state. This will be reopened on the
394 * next table element.
396 if (h
->tblt
!= NULL
) {
400 assert(h
->tblt
== NULL
);
401 if (n
->tok
< ROFF_MAX
) {
406 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
407 if (mdocs
[n
->tok
].pre
!= NULL
&&
408 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
409 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
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 mdocs
[n
->tok
].post
== NULL
||
429 n
->flags
& NODE_ENDED
)
431 (*mdocs
[n
->tok
].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
);
510 mdoc_sh_pre(MDOC_ARGS
)
516 id
= html_make_id(n
);
517 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
519 print_otag(h
, TAG_A
, "chR", "permalink", id
);
523 if (n
->sec
== SEC_AUTHORS
)
524 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
533 mdoc_ss_pre(MDOC_ARGS
)
537 if (n
->type
!= ROFFT_HEAD
)
540 id
= html_make_id(n
);
541 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
543 print_otag(h
, TAG_A
, "chR", "permalink", id
);
549 mdoc_fl_pre(MDOC_ARGS
)
553 if ((id
= cond_id(n
)) != NULL
)
554 print_otag(h
, TAG_A
, "chR", "permalink", id
);
555 print_otag(h
, TAG_CODE
, "cTi", "Fl", id
);
558 print_text(h
, "\\-");
559 if (!(n
->child
== NULL
&&
561 n
->next
->type
== ROFFT_TEXT
||
562 n
->next
->flags
& NODE_LINE
)))
563 h
->flags
|= HTML_NOSPACE
;
569 mdoc_cm_pre(MDOC_ARGS
)
573 if ((id
= cond_id(n
)) != NULL
)
574 print_otag(h
, TAG_A
, "chR", "permalink", id
);
575 print_otag(h
, TAG_CODE
, "cTi", "Cm", id
);
581 mdoc_nd_pre(MDOC_ARGS
)
583 if (n
->type
!= ROFFT_BODY
)
586 print_text(h
, "\\(em");
587 /* Cannot use TAG_SPAN because it may contain blocks. */
588 print_otag(h
, TAG_DIV
, "cT", "Nd");
593 mdoc_nm_pre(MDOC_ARGS
)
597 print_otag(h
, TAG_TD
, "");
600 print_otag(h
, TAG_CODE
, "cT", "Nm");
603 print_otag(h
, TAG_TD
, "");
609 print_otag(h
, TAG_TABLE
, "c", "Nm");
610 print_otag(h
, TAG_TR
, "");
615 mdoc_xr_pre(MDOC_ARGS
)
617 if (NULL
== n
->child
)
621 print_otag(h
, TAG_A
, "cThM", "Xr",
622 n
->child
->string
, n
->child
->next
== NULL
?
623 NULL
: n
->child
->next
->string
);
625 print_otag(h
, TAG_A
, "cT", "Xr");
628 print_text(h
, n
->string
);
630 if (NULL
== (n
= n
->next
))
633 h
->flags
|= HTML_NOSPACE
;
635 h
->flags
|= HTML_NOSPACE
;
636 print_text(h
, n
->string
);
637 h
->flags
|= HTML_NOSPACE
;
643 mdoc_ns_pre(MDOC_ARGS
)
646 if ( ! (NODE_LINE
& n
->flags
))
647 h
->flags
|= HTML_NOSPACE
;
652 mdoc_ar_pre(MDOC_ARGS
)
654 print_otag(h
, TAG_VAR
, "cT", "Ar");
659 mdoc_xx_pre(MDOC_ARGS
)
661 print_otag(h
, TAG_SPAN
, "c", "Ux");
666 mdoc_it_pre(MDOC_ARGS
)
668 const struct roff_node
*bl
;
673 while (bl
->tok
!= MDOC_Bl
)
675 type
= bl
->norm
->Bl
.type
;
687 print_otag(h
, TAG_LI
, "");
699 print_otag(h
, TAG_DT
, "");
702 print_otag(h
, TAG_DD
, "sw*+l", bl
->norm
->Bl
.width
);
711 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
712 (n
->parent
->prev
== NULL
||
713 n
->parent
->prev
->body
== NULL
||
714 n
->parent
->prev
->body
->child
!= NULL
)) {
715 t
= print_otag(h
, TAG_DT
, "sw*+-l",
717 print_text(h
, "\\ ");
719 t
= print_otag(h
, TAG_DD
, "");
720 print_text(h
, "\\ ");
723 print_otag(h
, TAG_DT
, "sw*+-l", bl
->norm
->Bl
.width
);
726 if (n
->child
== NULL
) {
727 print_otag(h
, TAG_DD
, "ss?",
729 print_text(h
, "\\ ");
731 print_otag(h
, TAG_DD
, "");
742 print_otag(h
, TAG_TD
, "");
745 print_otag(h
, TAG_TR
, "");
755 mdoc_bl_pre(MDOC_ARGS
)
761 enum htmltag elemtype
;
770 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
774 * For each column, print out the <COL> tag with our
775 * suggested width. The last column gets min-width, as
776 * in terminal mode it auto-sizes to the width of the
777 * screen and we want to preserve that behaviour.
780 t
= print_otag(h
, TAG_COLGROUP
, "");
781 for (i
= 0; i
< bl
->ncols
- 1; i
++)
782 print_otag(h
, TAG_COL
, "sw+w", bl
->cols
[i
]);
783 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
794 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
799 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
803 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
807 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
811 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
815 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
819 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
823 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
827 print_otag(h
, TAG_DIV
, "cswl", "Bl-tag", bl
->offs
);
828 print_otag(h
, TAG_DL
, "csw*+l", bl
->comp
?
829 "Bl-tag Bl-compact" : "Bl-tag", bl
->width
);
832 elemtype
= TAG_TABLE
;
833 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
839 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
840 print_otag(h
, elemtype
, "cswl", cattr
, bl
->offs
);
845 mdoc_ex_pre(MDOC_ARGS
)
848 print_otag(h
, TAG_BR
, "");
853 mdoc_st_pre(MDOC_ARGS
)
855 print_otag(h
, TAG_SPAN
, "cT", "St");
860 mdoc_em_pre(MDOC_ARGS
)
862 print_otag(h
, TAG_I
, "cT", "Em");
867 mdoc_d1_pre(MDOC_ARGS
)
869 if (n
->type
!= ROFFT_BLOCK
)
872 print_otag(h
, TAG_DIV
, "c", "D1");
874 if (n
->tok
== MDOC_Dl
)
875 print_otag(h
, TAG_CODE
, "c", "Li");
881 mdoc_sx_pre(MDOC_ARGS
)
885 id
= html_make_id(n
);
886 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
892 mdoc_bd_pre(MDOC_ARGS
)
895 struct roff_node
*nn
;
897 if (n
->type
== ROFFT_HEAD
)
900 if (n
->type
== ROFFT_BLOCK
) {
901 comp
= n
->norm
->Bd
.comp
;
902 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
903 if (nn
->type
!= ROFFT_BLOCK
)
905 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
915 /* Handle the -offset argument. */
917 if (n
->norm
->Bd
.offs
== NULL
||
918 ! strcmp(n
->norm
->Bd
.offs
, "left"))
920 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
922 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
928 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
930 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
932 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
933 n
->norm
->Bd
.type
!= DISP_literal
)
936 print_otag(h
, TAG_PRE
, "c", "Li");
938 /* This can be recursive: save & set our literal state. */
940 sv
= h
->flags
& HTML_LITERAL
;
941 h
->flags
|= HTML_LITERAL
;
943 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
944 print_mdoc_node(meta
, nn
, h
);
946 * If the printed node flushes its own line, then we
947 * needn't do it here as well. This is hacky, but the
948 * notion of selective eoln whitespace is pretty dumb
949 * anyway, so don't sweat it.
964 if (h
->flags
& HTML_NONEWLINE
||
965 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
970 h
->flags
|= HTML_NOSPACE
;
974 h
->flags
&= ~HTML_LITERAL
;
980 mdoc_pa_pre(MDOC_ARGS
)
982 print_otag(h
, TAG_SPAN
, "cT", "Pa");
987 mdoc_ad_pre(MDOC_ARGS
)
989 print_otag(h
, TAG_I
, "c", "Ad");
994 mdoc_an_pre(MDOC_ARGS
)
996 if (n
->norm
->An
.auth
== AUTH_split
) {
997 h
->flags
&= ~HTML_NOSPLIT
;
998 h
->flags
|= HTML_SPLIT
;
1001 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1002 h
->flags
&= ~HTML_SPLIT
;
1003 h
->flags
|= HTML_NOSPLIT
;
1007 if (h
->flags
& HTML_SPLIT
)
1008 print_otag(h
, TAG_BR
, "");
1010 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1011 h
->flags
|= HTML_SPLIT
;
1013 print_otag(h
, TAG_SPAN
, "cT", "An");
1018 mdoc_cd_pre(MDOC_ARGS
)
1021 print_otag(h
, TAG_CODE
, "cT", "Cd");
1026 mdoc_dv_pre(MDOC_ARGS
)
1030 if ((id
= cond_id(n
)) != NULL
)
1031 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1032 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1038 mdoc_ev_pre(MDOC_ARGS
)
1042 if ((id
= cond_id(n
)) != NULL
)
1043 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1044 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1050 mdoc_er_pre(MDOC_ARGS
)
1054 id
= n
->sec
== SEC_ERRORS
&&
1055 (n
->parent
->tok
== MDOC_It
||
1056 (n
->parent
->tok
== MDOC_Bq
&&
1057 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1058 html_make_id(n
) : NULL
;
1061 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1062 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1068 mdoc_fa_pre(MDOC_ARGS
)
1070 const struct roff_node
*nn
;
1073 if (n
->parent
->tok
!= MDOC_Fo
) {
1074 print_otag(h
, TAG_VAR
, "cT", "Fa");
1078 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1079 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1080 print_text(h
, nn
->string
);
1083 h
->flags
|= HTML_NOSPACE
;
1088 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1089 h
->flags
|= HTML_NOSPACE
;
1097 mdoc_fd_pre(MDOC_ARGS
)
1104 if (NULL
== (n
= n
->child
))
1107 assert(n
->type
== ROFFT_TEXT
);
1109 if (strcmp(n
->string
, "#include")) {
1110 print_otag(h
, TAG_CODE
, "cT", "Fd");
1114 print_otag(h
, TAG_CODE
, "cT", "In");
1115 print_text(h
, n
->string
);
1117 if (NULL
!= (n
= n
->next
)) {
1118 assert(n
->type
== ROFFT_TEXT
);
1120 if (h
->base_includes
) {
1122 if (*cp
== '<' || *cp
== '"')
1124 buf
= mandoc_strdup(cp
);
1125 cp
= strchr(buf
, '\0') - 1;
1126 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1128 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1131 t
= print_otag(h
, TAG_A
, "cT", "In");
1133 print_text(h
, n
->string
);
1139 for ( ; n
; n
= n
->next
) {
1140 assert(n
->type
== ROFFT_TEXT
);
1141 print_text(h
, n
->string
);
1148 mdoc_vt_pre(MDOC_ARGS
)
1150 if (n
->type
== ROFFT_BLOCK
) {
1153 } else if (n
->type
== ROFFT_ELEM
) {
1155 } else if (n
->type
== ROFFT_HEAD
)
1158 print_otag(h
, TAG_VAR
, "cT", "Vt");
1163 mdoc_ft_pre(MDOC_ARGS
)
1166 print_otag(h
, TAG_VAR
, "cT", "Ft");
1171 mdoc_fn_pre(MDOC_ARGS
)
1175 const char *sp
, *ep
;
1178 pretty
= NODE_SYNPRETTY
& n
->flags
;
1181 /* Split apart into type and name. */
1182 assert(n
->child
->string
);
1183 sp
= n
->child
->string
;
1185 ep
= strchr(sp
, ' ');
1187 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1190 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1191 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1193 print_text(h
, nbuf
);
1195 ep
= strchr(sp
, ' ');
1200 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1207 h
->flags
|= HTML_NOSPACE
;
1209 h
->flags
|= HTML_NOSPACE
;
1211 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1212 if (NODE_SYNPRETTY
& n
->flags
)
1213 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1214 "white-space", "nowrap");
1216 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1217 print_text(h
, n
->string
);
1220 h
->flags
|= HTML_NOSPACE
;
1225 h
->flags
|= HTML_NOSPACE
;
1229 h
->flags
|= HTML_NOSPACE
;
1237 mdoc_sm_pre(MDOC_ARGS
)
1240 if (NULL
== n
->child
)
1241 h
->flags
^= HTML_NONOSPACE
;
1242 else if (0 == strcmp("on", n
->child
->string
))
1243 h
->flags
&= ~HTML_NONOSPACE
;
1245 h
->flags
|= HTML_NONOSPACE
;
1247 if ( ! (HTML_NONOSPACE
& h
->flags
))
1248 h
->flags
&= ~HTML_NOSPACE
;
1254 mdoc_skip_pre(MDOC_ARGS
)
1261 mdoc_pp_pre(MDOC_ARGS
)
1269 mdoc_lk_pre(MDOC_ARGS
)
1271 const struct roff_node
*link
, *descr
, *punct
;
1274 if ((link
= n
->child
) == NULL
)
1277 /* Find beginning of trailing punctuation. */
1279 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1280 punct
= punct
->prev
;
1281 punct
= punct
->next
;
1283 /* Link target and link text. */
1286 descr
= link
; /* no text */
1287 t
= print_otag(h
, TAG_A
, "cTh", "Lk", link
->string
);
1289 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1290 h
->flags
|= HTML_NOSPACE
;
1291 print_text(h
, descr
->string
);
1292 descr
= descr
->next
;
1293 } while (descr
!= punct
);
1296 /* Trailing punctuation. */
1297 while (punct
!= NULL
) {
1298 h
->flags
|= HTML_NOSPACE
;
1299 print_text(h
, punct
->string
);
1300 punct
= punct
->next
;
1306 mdoc_mt_pre(MDOC_ARGS
)
1311 for (n
= n
->child
; n
; n
= n
->next
) {
1312 assert(n
->type
== ROFFT_TEXT
);
1314 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1315 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1316 print_text(h
, n
->string
);
1325 mdoc_fo_pre(MDOC_ARGS
)
1329 if (n
->type
== ROFFT_BODY
) {
1330 h
->flags
|= HTML_NOSPACE
;
1332 h
->flags
|= HTML_NOSPACE
;
1334 } else if (n
->type
== ROFFT_BLOCK
) {
1339 if (n
->child
== NULL
)
1342 assert(n
->child
->string
);
1343 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1344 print_text(h
, n
->child
->string
);
1350 mdoc_fo_post(MDOC_ARGS
)
1353 if (n
->type
!= ROFFT_BODY
)
1355 h
->flags
|= HTML_NOSPACE
;
1357 h
->flags
|= HTML_NOSPACE
;
1362 mdoc_in_pre(MDOC_ARGS
)
1367 print_otag(h
, TAG_CODE
, "cT", "In");
1370 * The first argument of the `In' gets special treatment as
1371 * being a linked value. Subsequent values are printed
1372 * afterward. groff does similarly. This also handles the case
1376 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1377 print_text(h
, "#include");
1380 h
->flags
|= HTML_NOSPACE
;
1382 if (NULL
!= (n
= n
->child
)) {
1383 assert(n
->type
== ROFFT_TEXT
);
1385 if (h
->base_includes
)
1386 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1388 t
= print_otag(h
, TAG_A
, "cT", "In");
1389 print_text(h
, n
->string
);
1395 h
->flags
|= HTML_NOSPACE
;
1398 for ( ; n
; n
= n
->next
) {
1399 assert(n
->type
== ROFFT_TEXT
);
1400 print_text(h
, n
->string
);
1407 mdoc_ic_pre(MDOC_ARGS
)
1411 if ((id
= cond_id(n
)) != NULL
)
1412 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1413 print_otag(h
, TAG_CODE
, "cTi", "Ic", id
);
1419 mdoc_va_pre(MDOC_ARGS
)
1421 print_otag(h
, TAG_VAR
, "cT", "Va");
1426 mdoc_ap_pre(MDOC_ARGS
)
1429 h
->flags
|= HTML_NOSPACE
;
1430 print_text(h
, "\\(aq");
1431 h
->flags
|= HTML_NOSPACE
;
1436 mdoc_bf_pre(MDOC_ARGS
)
1440 if (n
->type
== ROFFT_HEAD
)
1442 else if (n
->type
!= ROFFT_BODY
)
1445 if (FONT_Em
== n
->norm
->Bf
.font
)
1447 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1449 else if (FONT_Li
== n
->norm
->Bf
.font
)
1454 /* Cannot use TAG_SPAN because it may contain blocks. */
1455 print_otag(h
, TAG_DIV
, "cshl", cattr
, 1);
1460 mdoc_ms_pre(MDOC_ARGS
)
1464 if ((id
= cond_id(n
)) != NULL
)
1465 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1466 print_otag(h
, TAG_B
, "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
);
1513 mdoc_li_pre(MDOC_ARGS
)
1517 if ((id
= cond_id(n
)) != NULL
)
1518 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1519 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1525 mdoc_sy_pre(MDOC_ARGS
)
1527 print_otag(h
, TAG_B
, "cT", "Sy");
1532 mdoc_lb_pre(MDOC_ARGS
)
1534 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1535 print_otag(h
, TAG_BR
, "");
1537 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1542 mdoc__x_pre(MDOC_ARGS
)
1552 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1553 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1554 print_text(h
, "and");
1593 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1602 print_otag(h
, t
, "c", cattr
);
1607 mdoc__x_post(MDOC_ARGS
)
1610 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1611 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1612 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1617 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1620 h
->flags
|= HTML_NOSPACE
;
1621 print_text(h
, n
->next
? "," : ".");
1625 mdoc_bk_pre(MDOC_ARGS
)
1634 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1635 h
->flags
|= HTML_PREKEEP
;
1645 mdoc_bk_post(MDOC_ARGS
)
1648 if (n
->type
== ROFFT_BODY
)
1649 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1653 mdoc_quote_pre(MDOC_ARGS
)
1655 if (n
->type
!= ROFFT_BODY
)
1661 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1662 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1666 print_text(h
, "\\(lC");
1670 print_text(h
, "\\(lB");
1674 print_text(h
, "\\(lB");
1675 h
->flags
|= HTML_NOSPACE
;
1676 /* Cannot use TAG_SPAN because it may contain blocks. */
1677 print_otag(h
, TAG_IDIV
, "c", "Op");
1680 if (NULL
== n
->norm
->Es
||
1681 NULL
== n
->norm
->Es
->child
)
1683 print_text(h
, n
->norm
->Es
->child
->string
);
1689 print_text(h
, "\\(lq");
1696 print_text(h
, "\\(oq");
1697 h
->flags
|= HTML_NOSPACE
;
1698 print_otag(h
, TAG_CODE
, "c", "Li");
1702 print_text(h
, "\\(oq");
1708 h
->flags
|= HTML_NOSPACE
;
1713 mdoc_quote_post(MDOC_ARGS
)
1716 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1719 h
->flags
|= HTML_NOSPACE
;
1724 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1725 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1729 print_text(h
, "\\(rC");
1735 print_text(h
, "\\(rB");
1738 if (n
->norm
->Es
== NULL
||
1739 n
->norm
->Es
->child
== NULL
||
1740 n
->norm
->Es
->child
->next
== NULL
)
1741 h
->flags
&= ~HTML_NOSPACE
;
1743 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1749 print_text(h
, "\\(rq");
1758 print_text(h
, "\\(cq");
1766 mdoc_eo_pre(MDOC_ARGS
)
1769 if (n
->type
!= ROFFT_BODY
)
1772 if (n
->end
== ENDBODY_NOT
&&
1773 n
->parent
->head
->child
== NULL
&&
1775 n
->child
->end
!= ENDBODY_NOT
)
1776 print_text(h
, "\\&");
1777 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1778 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1779 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1780 h
->flags
|= HTML_NOSPACE
;
1785 mdoc_eo_post(MDOC_ARGS
)
1789 if (n
->type
!= ROFFT_BODY
)
1792 if (n
->end
!= ENDBODY_NOT
) {
1793 h
->flags
&= ~HTML_NOSPACE
;
1797 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1798 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1801 h
->flags
|= HTML_NOSPACE
;
1803 h
->flags
&= ~HTML_NOSPACE
;