]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.288 2017/05/17 17:54:45 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2016, 2017 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"
38 #define MDOC_ARGS const struct roff_meta *meta, \
39 struct roff_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static char *cond_id(const struct roff_node
*);
52 static void print_mdoc_head(MDOC_ARGS
);
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(MDOC_ARGS
);
59 static int mdoc_root_pre(MDOC_ARGS
);
61 static void mdoc__x_post(MDOC_ARGS
);
62 static int mdoc__x_pre(MDOC_ARGS
);
63 static int mdoc_ad_pre(MDOC_ARGS
);
64 static int mdoc_an_pre(MDOC_ARGS
);
65 static int mdoc_ap_pre(MDOC_ARGS
);
66 static int mdoc_ar_pre(MDOC_ARGS
);
67 static int mdoc_bd_pre(MDOC_ARGS
);
68 static int mdoc_bf_pre(MDOC_ARGS
);
69 static void mdoc_bk_post(MDOC_ARGS
);
70 static int mdoc_bk_pre(MDOC_ARGS
);
71 static int mdoc_bl_pre(MDOC_ARGS
);
72 static int mdoc_cd_pre(MDOC_ARGS
);
73 static int mdoc_cm_pre(MDOC_ARGS
);
74 static int mdoc_d1_pre(MDOC_ARGS
);
75 static int mdoc_dv_pre(MDOC_ARGS
);
76 static int mdoc_fa_pre(MDOC_ARGS
);
77 static int mdoc_fd_pre(MDOC_ARGS
);
78 static int mdoc_fl_pre(MDOC_ARGS
);
79 static int mdoc_fn_pre(MDOC_ARGS
);
80 static int mdoc_ft_pre(MDOC_ARGS
);
81 static int mdoc_em_pre(MDOC_ARGS
);
82 static void mdoc_eo_post(MDOC_ARGS
);
83 static int mdoc_eo_pre(MDOC_ARGS
);
84 static int mdoc_er_pre(MDOC_ARGS
);
85 static int mdoc_ev_pre(MDOC_ARGS
);
86 static int mdoc_ex_pre(MDOC_ARGS
);
87 static void mdoc_fo_post(MDOC_ARGS
);
88 static int mdoc_fo_pre(MDOC_ARGS
);
89 static int mdoc_ic_pre(MDOC_ARGS
);
90 static int mdoc_igndelim_pre(MDOC_ARGS
);
91 static int mdoc_in_pre(MDOC_ARGS
);
92 static int mdoc_it_pre(MDOC_ARGS
);
93 static int mdoc_lb_pre(MDOC_ARGS
);
94 static int mdoc_li_pre(MDOC_ARGS
);
95 static int mdoc_lk_pre(MDOC_ARGS
);
96 static int mdoc_mt_pre(MDOC_ARGS
);
97 static int mdoc_ms_pre(MDOC_ARGS
);
98 static int mdoc_nd_pre(MDOC_ARGS
);
99 static int mdoc_nm_pre(MDOC_ARGS
);
100 static int mdoc_no_pre(MDOC_ARGS
);
101 static int mdoc_ns_pre(MDOC_ARGS
);
102 static int mdoc_pa_pre(MDOC_ARGS
);
103 static void mdoc_pf_post(MDOC_ARGS
);
104 static int mdoc_pp_pre(MDOC_ARGS
);
105 static void mdoc_quote_post(MDOC_ARGS
);
106 static int mdoc_quote_pre(MDOC_ARGS
);
107 static int mdoc_rs_pre(MDOC_ARGS
);
108 static int mdoc_sh_pre(MDOC_ARGS
);
109 static int mdoc_skip_pre(MDOC_ARGS
);
110 static int mdoc_sm_pre(MDOC_ARGS
);
111 static int mdoc_ss_pre(MDOC_ARGS
);
112 static int mdoc_st_pre(MDOC_ARGS
);
113 static int mdoc_sx_pre(MDOC_ARGS
);
114 static int mdoc_sy_pre(MDOC_ARGS
);
115 static int mdoc_va_pre(MDOC_ARGS
);
116 static int mdoc_vt_pre(MDOC_ARGS
);
117 static int mdoc_xr_pre(MDOC_ARGS
);
118 static int mdoc_xx_pre(MDOC_ARGS
);
120 static const struct htmlmdoc __mdocs
[MDOC_MAX
- MDOC_Dd
] = {
121 {NULL
, NULL
}, /* Dd */
122 {NULL
, NULL
}, /* Dt */
123 {NULL
, NULL
}, /* Os */
124 {mdoc_sh_pre
, NULL
}, /* Sh */
125 {mdoc_ss_pre
, NULL
}, /* Ss */
126 {mdoc_pp_pre
, NULL
}, /* Pp */
127 {mdoc_d1_pre
, NULL
}, /* D1 */
128 {mdoc_d1_pre
, NULL
}, /* Dl */
129 {mdoc_bd_pre
, NULL
}, /* Bd */
130 {NULL
, NULL
}, /* Ed */
131 {mdoc_bl_pre
, NULL
}, /* Bl */
132 {NULL
, NULL
}, /* El */
133 {mdoc_it_pre
, NULL
}, /* It */
134 {mdoc_ad_pre
, NULL
}, /* Ad */
135 {mdoc_an_pre
, NULL
}, /* An */
136 {mdoc_ap_pre
, NULL
}, /* Ap */
137 {mdoc_ar_pre
, NULL
}, /* Ar */
138 {mdoc_cd_pre
, NULL
}, /* Cd */
139 {mdoc_cm_pre
, NULL
}, /* Cm */
140 {mdoc_dv_pre
, NULL
}, /* Dv */
141 {mdoc_er_pre
, NULL
}, /* Er */
142 {mdoc_ev_pre
, NULL
}, /* Ev */
143 {mdoc_ex_pre
, NULL
}, /* Ex */
144 {mdoc_fa_pre
, NULL
}, /* Fa */
145 {mdoc_fd_pre
, NULL
}, /* Fd */
146 {mdoc_fl_pre
, NULL
}, /* Fl */
147 {mdoc_fn_pre
, NULL
}, /* Fn */
148 {mdoc_ft_pre
, NULL
}, /* Ft */
149 {mdoc_ic_pre
, NULL
}, /* Ic */
150 {mdoc_in_pre
, NULL
}, /* In */
151 {mdoc_li_pre
, NULL
}, /* Li */
152 {mdoc_nd_pre
, NULL
}, /* Nd */
153 {mdoc_nm_pre
, NULL
}, /* Nm */
154 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
155 {mdoc_ft_pre
, NULL
}, /* Ot */
156 {mdoc_pa_pre
, NULL
}, /* Pa */
157 {mdoc_ex_pre
, NULL
}, /* Rv */
158 {mdoc_st_pre
, NULL
}, /* St */
159 {mdoc_va_pre
, NULL
}, /* Va */
160 {mdoc_vt_pre
, NULL
}, /* Vt */
161 {mdoc_xr_pre
, NULL
}, /* Xr */
162 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
163 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
173 {NULL
, NULL
}, /* Ac */
174 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
175 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
176 {mdoc_xx_pre
, NULL
}, /* At */
177 {NULL
, NULL
}, /* Bc */
178 {mdoc_bf_pre
, NULL
}, /* Bf */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
180 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
181 {mdoc_xx_pre
, NULL
}, /* Bsx */
182 {mdoc_xx_pre
, NULL
}, /* Bx */
183 {mdoc_skip_pre
, NULL
}, /* Db */
184 {NULL
, NULL
}, /* Dc */
185 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
186 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
187 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
188 {NULL
, NULL
}, /* Ef */
189 {mdoc_em_pre
, NULL
}, /* Em */
190 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
191 {mdoc_xx_pre
, NULL
}, /* Fx */
192 {mdoc_ms_pre
, NULL
}, /* Ms */
193 {mdoc_no_pre
, NULL
}, /* No */
194 {mdoc_ns_pre
, NULL
}, /* Ns */
195 {mdoc_xx_pre
, NULL
}, /* Nx */
196 {mdoc_xx_pre
, NULL
}, /* Ox */
197 {NULL
, NULL
}, /* Pc */
198 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
199 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
200 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
201 {NULL
, NULL
}, /* Qc */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
205 {NULL
, NULL
}, /* Re */
206 {mdoc_rs_pre
, NULL
}, /* Rs */
207 {NULL
, NULL
}, /* Sc */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
209 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
210 {mdoc_sm_pre
, NULL
}, /* Sm */
211 {mdoc_sx_pre
, NULL
}, /* Sx */
212 {mdoc_sy_pre
, NULL
}, /* Sy */
213 {NULL
, NULL
}, /* Tn */
214 {mdoc_xx_pre
, NULL
}, /* Ux */
215 {NULL
, NULL
}, /* Xc */
216 {NULL
, NULL
}, /* Xo */
217 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
218 {NULL
, NULL
}, /* Fc */
219 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
220 {NULL
, NULL
}, /* Oc */
221 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
222 {NULL
, NULL
}, /* Ek */
223 {NULL
, NULL
}, /* Bt */
224 {NULL
, NULL
}, /* Hf */
225 {mdoc_em_pre
, NULL
}, /* Fr */
226 {NULL
, NULL
}, /* Ud */
227 {mdoc_lb_pre
, NULL
}, /* Lb */
228 {mdoc_pp_pre
, NULL
}, /* Lp */
229 {mdoc_lk_pre
, NULL
}, /* Lk */
230 {mdoc_mt_pre
, NULL
}, /* Mt */
231 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
232 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
233 {NULL
, NULL
}, /* Brc */
234 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
235 {mdoc_skip_pre
, NULL
}, /* Es */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
237 {mdoc_xx_pre
, NULL
}, /* Dx */
238 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
239 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
240 {NULL
, NULL
}, /* Ta */
242 static const struct htmlmdoc
*const mdocs
= __mdocs
- MDOC_Dd
;
246 * See the same function in mdoc_term.c for documentation.
249 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
252 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
255 if (n
->prev
->tok
== n
->tok
&&
259 print_otag(h
, TAG_BR
, "");
263 switch (n
->prev
->tok
) {
272 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
278 print_otag(h
, TAG_BR
, "");
284 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
289 h
= (struct html
*)arg
;
291 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
293 print_otag(h
, TAG_HTML
, "");
294 t
= print_otag(h
, TAG_HEAD
, "");
295 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
297 print_otag(h
, TAG_BODY
, "");
300 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
301 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
302 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
304 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
309 print_mdoc_head(MDOC_ARGS
)
315 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
316 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
317 meta
->msec
, meta
->arch
);
318 else if (meta
->msec
!= NULL
)
319 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
320 else if (meta
->arch
!= NULL
)
321 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
323 cp
= mandoc_strdup(meta
->title
);
325 print_otag(h
, TAG_TITLE
, "");
331 print_mdoc_nodelist(MDOC_ARGS
)
335 print_mdoc_node(meta
, n
, h
);
341 print_mdoc_node(MDOC_ARGS
)
346 if (n
->flags
& NODE_NOPRT
)
351 n
->flags
&= ~NODE_ENDED
;
355 /* No tables in this mode... */
356 assert(NULL
== h
->tblt
);
359 * Make sure that if we're in a literal mode already
360 * (i.e., within a <PRE>) don't print the newline.
362 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
363 (h
->flags
& (HTML_LITERAL
| HTML_NONEWLINE
)) == 0)
364 print_otag(h
, TAG_BR
, "");
365 if (NODE_DELIMC
& n
->flags
)
366 h
->flags
|= HTML_NOSPACE
;
367 print_text(h
, n
->string
);
368 if (NODE_DELIMO
& n
->flags
)
369 h
->flags
|= HTML_NOSPACE
;
372 print_eqn(h
, n
->eqn
);
376 * This will take care of initialising all of the table
377 * state data for the first table, then tearing it down
380 print_tbl(h
, n
->span
);
384 * Close out the current table, if it's open, and unset
385 * the "meta" table state. This will be reopened on the
386 * next table element.
388 if (h
->tblt
!= NULL
) {
392 assert(h
->tblt
== NULL
);
393 if (n
->tok
< ROFF_MAX
) {
398 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
399 if (mdocs
[n
->tok
].pre
!= NULL
&&
400 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
401 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
405 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
406 h
->flags
&= ~HTML_KEEP
;
407 h
->flags
|= HTML_PREKEEP
;
410 if (child
&& n
->child
)
411 print_mdoc_nodelist(meta
, n
->child
, h
);
419 if (n
->tok
< ROFF_MAX
||
420 mdocs
[n
->tok
].post
== NULL
||
421 n
->flags
& NODE_ENDED
)
423 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
424 if (n
->end
!= ENDBODY_NOT
)
425 n
->body
->flags
|= NODE_ENDED
;
431 mdoc_root_post(MDOC_ARGS
)
435 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
436 tt
= print_otag(h
, TAG_TR
, "");
438 print_otag(h
, TAG_TD
, "c", "foot-date");
439 print_text(h
, meta
->date
);
442 print_otag(h
, TAG_TD
, "c", "foot-os");
443 print_text(h
, meta
->os
);
448 mdoc_root_pre(MDOC_ARGS
)
451 char *volume
, *title
;
453 if (NULL
== meta
->arch
)
454 volume
= mandoc_strdup(meta
->vol
);
456 mandoc_asprintf(&volume
, "%s (%s)",
457 meta
->vol
, meta
->arch
);
459 if (NULL
== meta
->msec
)
460 title
= mandoc_strdup(meta
->title
);
462 mandoc_asprintf(&title
, "%s(%s)",
463 meta
->title
, meta
->msec
);
465 t
= print_otag(h
, TAG_TABLE
, "c", "head");
466 tt
= print_otag(h
, TAG_TR
, "");
468 print_otag(h
, TAG_TD
, "c", "head-ltitle");
469 print_text(h
, title
);
472 print_otag(h
, TAG_TD
, "c", "head-vol");
473 print_text(h
, volume
);
476 print_otag(h
, TAG_TD
, "c", "head-rtitle");
477 print_text(h
, title
);
486 cond_id(const struct roff_node
*n
)
488 if (n
->child
!= NULL
&&
489 n
->child
->type
== ROFFT_TEXT
&&
491 (n
->prev
->type
== ROFFT_TEXT
&&
492 strcmp(n
->prev
->string
, "|") == 0)) &&
493 (n
->parent
->tok
== MDOC_It
||
494 (n
->parent
->tok
== MDOC_Xo
&&
495 n
->parent
->parent
->prev
== NULL
&&
496 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
497 return html_make_id(n
);
502 mdoc_sh_pre(MDOC_ARGS
)
508 id
= html_make_id(n
);
509 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
511 print_otag(h
, TAG_A
, "chR", "selflink", id
);
515 if (n
->sec
== SEC_AUTHORS
)
516 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
525 mdoc_ss_pre(MDOC_ARGS
)
529 if (n
->type
!= ROFFT_HEAD
)
532 id
= html_make_id(n
);
533 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
535 print_otag(h
, TAG_A
, "chR", "selflink", id
);
541 mdoc_fl_pre(MDOC_ARGS
)
545 if ((id
= cond_id(n
)) != NULL
)
546 print_otag(h
, TAG_A
, "chR", "selflink", id
);
547 print_otag(h
, TAG_B
, "cTi", "Fl", id
);
550 print_text(h
, "\\-");
551 if (!(n
->child
== NULL
&&
553 n
->next
->type
== ROFFT_TEXT
||
554 n
->next
->flags
& NODE_LINE
)))
555 h
->flags
|= HTML_NOSPACE
;
561 mdoc_cm_pre(MDOC_ARGS
)
565 if ((id
= cond_id(n
)) != NULL
)
566 print_otag(h
, TAG_A
, "chR", "selflink", id
);
567 print_otag(h
, TAG_B
, "cTi", "Cm", id
);
573 mdoc_nd_pre(MDOC_ARGS
)
575 if (n
->type
!= ROFFT_BODY
)
578 /* XXX: this tag in theory can contain block elements. */
580 print_text(h
, "\\(em");
581 print_otag(h
, TAG_SPAN
, "cT", "Nd");
586 mdoc_nm_pre(MDOC_ARGS
)
590 print_otag(h
, TAG_TD
, "");
593 print_otag(h
, TAG_B
, "cT", "Nm");
596 print_otag(h
, TAG_TD
, "");
602 print_otag(h
, TAG_TABLE
, "c", "Nm");
603 print_otag(h
, TAG_TR
, "");
608 mdoc_xr_pre(MDOC_ARGS
)
610 if (NULL
== n
->child
)
614 print_otag(h
, TAG_A
, "cThM", "Xr",
615 n
->child
->string
, n
->child
->next
== NULL
?
616 NULL
: n
->child
->next
->string
);
618 print_otag(h
, TAG_A
, "cT", "Xr");
621 print_text(h
, n
->string
);
623 if (NULL
== (n
= n
->next
))
626 h
->flags
|= HTML_NOSPACE
;
628 h
->flags
|= HTML_NOSPACE
;
629 print_text(h
, n
->string
);
630 h
->flags
|= HTML_NOSPACE
;
636 mdoc_ns_pre(MDOC_ARGS
)
639 if ( ! (NODE_LINE
& n
->flags
))
640 h
->flags
|= HTML_NOSPACE
;
645 mdoc_ar_pre(MDOC_ARGS
)
647 print_otag(h
, TAG_VAR
, "cT", "Ar");
652 mdoc_xx_pre(MDOC_ARGS
)
654 print_otag(h
, TAG_SPAN
, "c", "Ux");
659 mdoc_it_pre(MDOC_ARGS
)
661 const struct roff_node
*bl
;
667 while (bl
->tok
!= MDOC_Bl
)
669 type
= bl
->norm
->Bl
.type
;
717 if (bl
->norm
->Bl
.comp
)
718 print_otag(h
, TAG_LI
, "csvt", cattr
, 0);
720 print_otag(h
, TAG_LI
, "c", cattr
);
732 if (bl
->norm
->Bl
.comp
)
733 print_otag(h
, TAG_DT
, "csvt", cattr
, 0);
735 print_otag(h
, TAG_DT
, "c", cattr
);
736 if (type
== LIST_diag
)
737 print_otag(h
, TAG_B
, "c", cattr
);
740 print_otag(h
, TAG_DD
, "cswl", cattr
,
750 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
751 (n
->parent
->prev
== NULL
||
752 n
->parent
->prev
->body
== NULL
||
753 n
->parent
->prev
->body
->child
!= NULL
)) {
754 t
= print_otag(h
, TAG_DT
, "csw+-l",
755 cattr
, bl
->norm
->Bl
.width
);
756 print_text(h
, "\\ ");
758 t
= print_otag(h
, TAG_DD
, "c", cattr
);
759 print_text(h
, "\\ ");
762 print_otag(h
, TAG_DT
, "csw+-l", cattr
,
766 if (n
->child
== NULL
) {
767 print_otag(h
, TAG_DD
, "css?", cattr
,
769 print_text(h
, "\\ ");
771 print_otag(h
, TAG_DD
, "c", cattr
);
782 if (bl
->norm
->Bl
.comp
)
783 print_otag(h
, TAG_TD
, "csvt", cattr
, 0);
785 print_otag(h
, TAG_TD
, "c", cattr
);
788 print_otag(h
, TAG_TR
, "c", cattr
);
798 mdoc_bl_pre(MDOC_ARGS
)
804 enum htmltag elemtype
;
813 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
817 * For each column, print out the <COL> tag with our
818 * suggested width. The last column gets min-width, as
819 * in terminal mode it auto-sizes to the width of the
820 * screen and we want to preserve that behaviour.
823 t
= print_otag(h
, TAG_COLGROUP
, "");
824 for (i
= 0; i
< bl
->ncols
- 1; i
++)
825 print_otag(h
, TAG_COL
, "sw+w", bl
->cols
[i
]);
826 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
871 print_otag(h
, TAG_DIV
, "cswl", cattr
, bl
->offs
);
872 print_otag(h
, TAG_DL
, "csw+l", cattr
, bl
->width
);
875 elemtype
= TAG_TABLE
;
881 print_otag(h
, elemtype
, "cswl", cattr
, bl
->offs
);
886 mdoc_ex_pre(MDOC_ARGS
)
889 print_otag(h
, TAG_BR
, "");
894 mdoc_st_pre(MDOC_ARGS
)
896 print_otag(h
, TAG_SPAN
, "cT", "St");
901 mdoc_em_pre(MDOC_ARGS
)
903 print_otag(h
, TAG_I
, "cT", "Em");
908 mdoc_d1_pre(MDOC_ARGS
)
910 if (n
->type
!= ROFFT_BLOCK
)
913 print_otag(h
, TAG_DIV
, "c", "D1");
915 if (n
->tok
== MDOC_Dl
)
916 print_otag(h
, TAG_CODE
, "c", "Li");
922 mdoc_sx_pre(MDOC_ARGS
)
926 id
= html_make_id(n
);
927 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
933 mdoc_bd_pre(MDOC_ARGS
)
936 struct roff_node
*nn
;
938 if (n
->type
== ROFFT_HEAD
)
941 if (n
->type
== ROFFT_BLOCK
) {
942 comp
= n
->norm
->Bd
.comp
;
943 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
944 if (nn
->type
!= ROFFT_BLOCK
)
946 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
956 /* Handle the -offset argument. */
958 if (n
->norm
->Bd
.offs
== NULL
||
959 ! strcmp(n
->norm
->Bd
.offs
, "left"))
961 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
963 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
969 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
971 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
973 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
974 n
->norm
->Bd
.type
!= DISP_literal
)
977 print_otag(h
, TAG_PRE
, "c", "Li");
979 /* This can be recursive: save & set our literal state. */
981 sv
= h
->flags
& HTML_LITERAL
;
982 h
->flags
|= HTML_LITERAL
;
984 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
985 print_mdoc_node(meta
, nn
, h
);
987 * If the printed node flushes its own line, then we
988 * needn't do it here as well. This is hacky, but the
989 * notion of selective eoln whitespace is pretty dumb
990 * anyway, so don't sweat it.
1005 if (h
->flags
& HTML_NONEWLINE
||
1006 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1009 print_text(h
, "\n");
1011 h
->flags
|= HTML_NOSPACE
;
1015 h
->flags
&= ~HTML_LITERAL
;
1021 mdoc_pa_pre(MDOC_ARGS
)
1023 print_otag(h
, TAG_I
, "cT", "Pa");
1028 mdoc_ad_pre(MDOC_ARGS
)
1030 print_otag(h
, TAG_I
, "c", "Ad");
1035 mdoc_an_pre(MDOC_ARGS
)
1037 if (n
->norm
->An
.auth
== AUTH_split
) {
1038 h
->flags
&= ~HTML_NOSPLIT
;
1039 h
->flags
|= HTML_SPLIT
;
1042 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1043 h
->flags
&= ~HTML_SPLIT
;
1044 h
->flags
|= HTML_NOSPLIT
;
1048 if (h
->flags
& HTML_SPLIT
)
1049 print_otag(h
, TAG_BR
, "");
1051 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1052 h
->flags
|= HTML_SPLIT
;
1054 print_otag(h
, TAG_SPAN
, "cT", "An");
1059 mdoc_cd_pre(MDOC_ARGS
)
1062 print_otag(h
, TAG_B
, "cT", "Cd");
1067 mdoc_dv_pre(MDOC_ARGS
)
1071 if ((id
= cond_id(n
)) != NULL
)
1072 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1073 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1079 mdoc_ev_pre(MDOC_ARGS
)
1083 if ((id
= cond_id(n
)) != NULL
)
1084 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1085 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1091 mdoc_er_pre(MDOC_ARGS
)
1095 id
= n
->sec
== SEC_ERRORS
&&
1096 (n
->parent
->tok
== MDOC_It
||
1097 (n
->parent
->tok
== MDOC_Bq
&&
1098 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1099 html_make_id(n
) : NULL
;
1102 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1103 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1109 mdoc_fa_pre(MDOC_ARGS
)
1111 const struct roff_node
*nn
;
1114 if (n
->parent
->tok
!= MDOC_Fo
) {
1115 print_otag(h
, TAG_VAR
, "cT", "Fa");
1119 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1120 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1121 print_text(h
, nn
->string
);
1124 h
->flags
|= HTML_NOSPACE
;
1129 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1130 h
->flags
|= HTML_NOSPACE
;
1138 mdoc_fd_pre(MDOC_ARGS
)
1145 if (NULL
== (n
= n
->child
))
1148 assert(n
->type
== ROFFT_TEXT
);
1150 if (strcmp(n
->string
, "#include")) {
1151 print_otag(h
, TAG_B
, "cT", "Fd");
1155 print_otag(h
, TAG_B
, "cT", "In");
1156 print_text(h
, n
->string
);
1158 if (NULL
!= (n
= n
->next
)) {
1159 assert(n
->type
== ROFFT_TEXT
);
1161 if (h
->base_includes
) {
1163 if (*cp
== '<' || *cp
== '"')
1165 buf
= mandoc_strdup(cp
);
1166 cp
= strchr(buf
, '\0') - 1;
1167 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1169 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1172 t
= print_otag(h
, TAG_A
, "cT", "In");
1174 print_text(h
, n
->string
);
1180 for ( ; n
; n
= n
->next
) {
1181 assert(n
->type
== ROFFT_TEXT
);
1182 print_text(h
, n
->string
);
1189 mdoc_vt_pre(MDOC_ARGS
)
1191 if (n
->type
== ROFFT_BLOCK
) {
1194 } else if (n
->type
== ROFFT_ELEM
) {
1196 } else if (n
->type
== ROFFT_HEAD
)
1199 print_otag(h
, TAG_VAR
, "cT", "Vt");
1204 mdoc_ft_pre(MDOC_ARGS
)
1207 print_otag(h
, TAG_VAR
, "cT", "Ft");
1212 mdoc_fn_pre(MDOC_ARGS
)
1216 const char *sp
, *ep
;
1219 pretty
= NODE_SYNPRETTY
& n
->flags
;
1222 /* Split apart into type and name. */
1223 assert(n
->child
->string
);
1224 sp
= n
->child
->string
;
1226 ep
= strchr(sp
, ' ');
1228 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1231 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1232 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1234 print_text(h
, nbuf
);
1236 ep
= strchr(sp
, ' ');
1241 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1248 h
->flags
|= HTML_NOSPACE
;
1250 h
->flags
|= HTML_NOSPACE
;
1252 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1253 if (NODE_SYNPRETTY
& n
->flags
)
1254 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1255 "white-space", "nowrap");
1257 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1258 print_text(h
, n
->string
);
1261 h
->flags
|= HTML_NOSPACE
;
1266 h
->flags
|= HTML_NOSPACE
;
1270 h
->flags
|= HTML_NOSPACE
;
1278 mdoc_sm_pre(MDOC_ARGS
)
1281 if (NULL
== n
->child
)
1282 h
->flags
^= HTML_NONOSPACE
;
1283 else if (0 == strcmp("on", n
->child
->string
))
1284 h
->flags
&= ~HTML_NONOSPACE
;
1286 h
->flags
|= HTML_NONOSPACE
;
1288 if ( ! (HTML_NONOSPACE
& h
->flags
))
1289 h
->flags
&= ~HTML_NOSPACE
;
1295 mdoc_skip_pre(MDOC_ARGS
)
1302 mdoc_pp_pre(MDOC_ARGS
)
1310 mdoc_lk_pre(MDOC_ARGS
)
1314 if ((n
= n
->child
) == NULL
)
1317 /* Link target and link text. */
1318 t
= print_otag(h
, TAG_A
, "cTh", "Lk", n
->string
);
1319 if (n
->next
== NULL
|| n
->next
->flags
& NODE_DELIMC
)
1320 print_text(h
, n
->string
);
1321 for (n
= n
->next
; n
!= NULL
&& !(n
->flags
& NODE_DELIMC
); n
= n
->next
)
1322 print_text(h
, n
->string
);
1325 /* Trailing punctuation. */
1327 h
->flags
|= HTML_NOSPACE
;
1328 print_text(h
, n
->string
);
1335 mdoc_mt_pre(MDOC_ARGS
)
1340 for (n
= n
->child
; n
; n
= n
->next
) {
1341 assert(n
->type
== ROFFT_TEXT
);
1343 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1344 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1345 print_text(h
, n
->string
);
1354 mdoc_fo_pre(MDOC_ARGS
)
1358 if (n
->type
== ROFFT_BODY
) {
1359 h
->flags
|= HTML_NOSPACE
;
1361 h
->flags
|= HTML_NOSPACE
;
1363 } else if (n
->type
== ROFFT_BLOCK
) {
1368 if (n
->child
== NULL
)
1371 assert(n
->child
->string
);
1372 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1373 print_text(h
, n
->child
->string
);
1379 mdoc_fo_post(MDOC_ARGS
)
1382 if (n
->type
!= ROFFT_BODY
)
1384 h
->flags
|= HTML_NOSPACE
;
1386 h
->flags
|= HTML_NOSPACE
;
1391 mdoc_in_pre(MDOC_ARGS
)
1396 print_otag(h
, TAG_B
, "cT", "In");
1399 * The first argument of the `In' gets special treatment as
1400 * being a linked value. Subsequent values are printed
1401 * afterward. groff does similarly. This also handles the case
1405 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1406 print_text(h
, "#include");
1409 h
->flags
|= HTML_NOSPACE
;
1411 if (NULL
!= (n
= n
->child
)) {
1412 assert(n
->type
== ROFFT_TEXT
);
1414 if (h
->base_includes
)
1415 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1417 t
= print_otag(h
, TAG_A
, "cT", "In");
1418 print_text(h
, n
->string
);
1424 h
->flags
|= HTML_NOSPACE
;
1427 for ( ; n
; n
= n
->next
) {
1428 assert(n
->type
== ROFFT_TEXT
);
1429 print_text(h
, n
->string
);
1436 mdoc_ic_pre(MDOC_ARGS
)
1440 if ((id
= cond_id(n
)) != NULL
)
1441 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1442 print_otag(h
, TAG_B
, "cTi", "Ic", id
);
1448 mdoc_va_pre(MDOC_ARGS
)
1450 print_otag(h
, TAG_VAR
, "cT", "Va");
1455 mdoc_ap_pre(MDOC_ARGS
)
1458 h
->flags
|= HTML_NOSPACE
;
1459 print_text(h
, "\\(aq");
1460 h
->flags
|= HTML_NOSPACE
;
1465 mdoc_bf_pre(MDOC_ARGS
)
1469 if (n
->type
== ROFFT_HEAD
)
1471 else if (n
->type
!= ROFFT_BODY
)
1474 if (FONT_Em
== n
->norm
->Bf
.font
)
1476 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1478 else if (FONT_Li
== n
->norm
->Bf
.font
)
1484 * We want this to be inline-formatted, but needs to be div to
1485 * accept block children.
1488 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1493 mdoc_ms_pre(MDOC_ARGS
)
1497 if ((id
= cond_id(n
)) != NULL
)
1498 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1499 print_otag(h
, TAG_B
, "cTi", "Ms", id
);
1505 mdoc_igndelim_pre(MDOC_ARGS
)
1508 h
->flags
|= HTML_IGNDELIM
;
1513 mdoc_pf_post(MDOC_ARGS
)
1516 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1517 h
->flags
|= HTML_NOSPACE
;
1521 mdoc_rs_pre(MDOC_ARGS
)
1523 if (n
->type
!= ROFFT_BLOCK
)
1526 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1529 print_otag(h
, TAG_CITE
, "cT", "Rs");
1534 mdoc_no_pre(MDOC_ARGS
)
1538 if ((id
= cond_id(n
)) != NULL
)
1539 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1540 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1546 mdoc_li_pre(MDOC_ARGS
)
1550 if ((id
= cond_id(n
)) != NULL
)
1551 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1552 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1558 mdoc_sy_pre(MDOC_ARGS
)
1560 print_otag(h
, TAG_B
, "cT", "Sy");
1565 mdoc_lb_pre(MDOC_ARGS
)
1567 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1568 print_otag(h
, TAG_BR
, "");
1570 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1575 mdoc__x_pre(MDOC_ARGS
)
1585 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1586 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1587 print_text(h
, "and");
1626 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1635 print_otag(h
, t
, "c", cattr
);
1640 mdoc__x_post(MDOC_ARGS
)
1643 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1644 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1645 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1650 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1653 h
->flags
|= HTML_NOSPACE
;
1654 print_text(h
, n
->next
? "," : ".");
1658 mdoc_bk_pre(MDOC_ARGS
)
1667 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1668 h
->flags
|= HTML_PREKEEP
;
1678 mdoc_bk_post(MDOC_ARGS
)
1681 if (n
->type
== ROFFT_BODY
)
1682 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1686 mdoc_quote_pre(MDOC_ARGS
)
1688 if (n
->type
!= ROFFT_BODY
)
1694 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1695 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1699 print_text(h
, "\\(lC");
1703 print_text(h
, "\\(lB");
1707 print_text(h
, "\\(lB");
1708 h
->flags
|= HTML_NOSPACE
;
1709 print_otag(h
, TAG_SPAN
, "c", "Op");
1712 if (NULL
== n
->norm
->Es
||
1713 NULL
== n
->norm
->Es
->child
)
1715 print_text(h
, n
->norm
->Es
->child
->string
);
1721 print_text(h
, "\\(lq");
1728 print_text(h
, "\\(oq");
1729 h
->flags
|= HTML_NOSPACE
;
1730 print_otag(h
, TAG_CODE
, "c", "Li");
1734 print_text(h
, "\\(oq");
1740 h
->flags
|= HTML_NOSPACE
;
1745 mdoc_quote_post(MDOC_ARGS
)
1748 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1751 h
->flags
|= HTML_NOSPACE
;
1756 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1757 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1761 print_text(h
, "\\(rC");
1767 print_text(h
, "\\(rB");
1770 if (n
->norm
->Es
== NULL
||
1771 n
->norm
->Es
->child
== NULL
||
1772 n
->norm
->Es
->child
->next
== NULL
)
1773 h
->flags
&= ~HTML_NOSPACE
;
1775 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1781 print_text(h
, "\\(rq");
1790 print_text(h
, "\\(cq");
1798 mdoc_eo_pre(MDOC_ARGS
)
1801 if (n
->type
!= ROFFT_BODY
)
1804 if (n
->end
== ENDBODY_NOT
&&
1805 n
->parent
->head
->child
== NULL
&&
1807 n
->child
->end
!= ENDBODY_NOT
)
1808 print_text(h
, "\\&");
1809 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1810 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1811 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1812 h
->flags
|= HTML_NOSPACE
;
1817 mdoc_eo_post(MDOC_ARGS
)
1821 if (n
->type
!= ROFFT_BODY
)
1824 if (n
->end
!= ENDBODY_NOT
) {
1825 h
->flags
&= ~HTML_NOSPACE
;
1829 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1830 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1833 h
->flags
|= HTML_NOSPACE
;
1835 h
->flags
&= ~HTML_NOSPACE
;