]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.278 2017/03/17 12:10:16 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_sp_pre(MDOC_ARGS
);
112 static int mdoc_ss_pre(MDOC_ARGS
);
113 static int mdoc_st_pre(MDOC_ARGS
);
114 static int mdoc_sx_pre(MDOC_ARGS
);
115 static int mdoc_sy_pre(MDOC_ARGS
);
116 static int mdoc_va_pre(MDOC_ARGS
);
117 static int mdoc_vt_pre(MDOC_ARGS
);
118 static int mdoc_xr_pre(MDOC_ARGS
);
119 static int mdoc_xx_pre(MDOC_ARGS
);
121 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
122 {mdoc_ap_pre
, NULL
}, /* Ap */
123 {NULL
, NULL
}, /* Dd */
124 {NULL
, NULL
}, /* Dt */
125 {NULL
, NULL
}, /* Os */
126 {mdoc_sh_pre
, NULL
}, /* Sh */
127 {mdoc_ss_pre
, NULL
}, /* Ss */
128 {mdoc_pp_pre
, NULL
}, /* Pp */
129 {mdoc_d1_pre
, NULL
}, /* D1 */
130 {mdoc_d1_pre
, NULL
}, /* Dl */
131 {mdoc_bd_pre
, NULL
}, /* Bd */
132 {NULL
, NULL
}, /* Ed */
133 {mdoc_bl_pre
, NULL
}, /* Bl */
134 {NULL
, NULL
}, /* El */
135 {mdoc_it_pre
, NULL
}, /* It */
136 {mdoc_ad_pre
, NULL
}, /* Ad */
137 {mdoc_an_pre
, NULL
}, /* An */
138 {mdoc_ar_pre
, NULL
}, /* Ar */
139 {mdoc_cd_pre
, NULL
}, /* Cd */
140 {mdoc_cm_pre
, NULL
}, /* Cm */
141 {mdoc_dv_pre
, NULL
}, /* Dv */
142 {mdoc_er_pre
, NULL
}, /* Er */
143 {mdoc_ev_pre
, NULL
}, /* Ev */
144 {mdoc_ex_pre
, NULL
}, /* Ex */
145 {mdoc_fa_pre
, NULL
}, /* Fa */
146 {mdoc_fd_pre
, NULL
}, /* Fd */
147 {mdoc_fl_pre
, NULL
}, /* Fl */
148 {mdoc_fn_pre
, NULL
}, /* Fn */
149 {mdoc_ft_pre
, NULL
}, /* Ft */
150 {mdoc_ic_pre
, NULL
}, /* Ic */
151 {mdoc_in_pre
, NULL
}, /* In */
152 {mdoc_li_pre
, NULL
}, /* Li */
153 {mdoc_nd_pre
, NULL
}, /* Nd */
154 {mdoc_nm_pre
, NULL
}, /* Nm */
155 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
156 {mdoc_ft_pre
, NULL
}, /* Ot */
157 {mdoc_pa_pre
, NULL
}, /* Pa */
158 {mdoc_ex_pre
, NULL
}, /* Rv */
159 {mdoc_st_pre
, NULL
}, /* St */
160 {mdoc_va_pre
, NULL
}, /* Va */
161 {mdoc_vt_pre
, NULL
}, /* Vt */
162 {mdoc_xr_pre
, NULL
}, /* Xr */
163 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
174 {NULL
, NULL
}, /* Ac */
175 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
177 {mdoc_xx_pre
, NULL
}, /* At */
178 {NULL
, NULL
}, /* Bc */
179 {mdoc_bf_pre
, NULL
}, /* Bf */
180 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
182 {mdoc_xx_pre
, NULL
}, /* Bsx */
183 {mdoc_xx_pre
, NULL
}, /* Bx */
184 {mdoc_skip_pre
, NULL
}, /* Db */
185 {NULL
, NULL
}, /* Dc */
186 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
188 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
189 {NULL
, NULL
}, /* Ef */
190 {mdoc_em_pre
, NULL
}, /* Em */
191 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
192 {mdoc_xx_pre
, NULL
}, /* Fx */
193 {mdoc_ms_pre
, NULL
}, /* Ms */
194 {mdoc_no_pre
, NULL
}, /* No */
195 {mdoc_ns_pre
, NULL
}, /* Ns */
196 {mdoc_xx_pre
, NULL
}, /* Nx */
197 {mdoc_xx_pre
, NULL
}, /* Ox */
198 {NULL
, NULL
}, /* Pc */
199 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
200 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
202 {NULL
, NULL
}, /* Qc */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
206 {NULL
, NULL
}, /* Re */
207 {mdoc_rs_pre
, NULL
}, /* Rs */
208 {NULL
, NULL
}, /* Sc */
209 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
211 {mdoc_sm_pre
, NULL
}, /* Sm */
212 {mdoc_sx_pre
, NULL
}, /* Sx */
213 {mdoc_sy_pre
, NULL
}, /* Sy */
214 {NULL
, NULL
}, /* Tn */
215 {mdoc_xx_pre
, NULL
}, /* Ux */
216 {NULL
, NULL
}, /* Xc */
217 {NULL
, NULL
}, /* Xo */
218 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
219 {NULL
, NULL
}, /* Fc */
220 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
221 {NULL
, NULL
}, /* Oc */
222 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
223 {NULL
, NULL
}, /* Ek */
224 {NULL
, NULL
}, /* Bt */
225 {NULL
, NULL
}, /* Hf */
226 {mdoc_em_pre
, NULL
}, /* Fr */
227 {NULL
, NULL
}, /* Ud */
228 {mdoc_lb_pre
, NULL
}, /* Lb */
229 {mdoc_pp_pre
, NULL
}, /* Lp */
230 {mdoc_lk_pre
, NULL
}, /* Lk */
231 {mdoc_mt_pre
, NULL
}, /* Mt */
232 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
234 {NULL
, NULL
}, /* Brc */
235 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
236 {mdoc_skip_pre
, NULL
}, /* Es */
237 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
238 {mdoc_xx_pre
, NULL
}, /* Dx */
239 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
240 {mdoc_sp_pre
, NULL
}, /* br */
241 {mdoc_sp_pre
, NULL
}, /* sp */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
243 {NULL
, NULL
}, /* Ta */
244 {mdoc_skip_pre
, NULL
}, /* ll */
249 * See the same function in mdoc_term.c for documentation.
252 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
255 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
258 if (n
->prev
->tok
== n
->tok
&&
262 print_otag(h
, TAG_BR
, "");
266 switch (n
->prev
->tok
) {
275 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
281 print_otag(h
, TAG_BR
, "");
287 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
292 h
= (struct html
*)arg
;
294 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
296 print_otag(h
, TAG_HTML
, "");
297 t
= print_otag(h
, TAG_HEAD
, "");
298 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
300 print_otag(h
, TAG_BODY
, "");
303 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
304 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
305 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
307 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
312 print_mdoc_head(MDOC_ARGS
)
318 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
319 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
320 meta
->msec
, meta
->arch
);
321 else if (meta
->msec
!= NULL
)
322 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
323 else if (meta
->arch
!= NULL
)
324 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
326 cp
= mandoc_strdup(meta
->title
);
328 print_otag(h
, TAG_TITLE
, "");
334 print_mdoc_nodelist(MDOC_ARGS
)
338 print_mdoc_node(meta
, n
, h
);
344 print_mdoc_node(MDOC_ARGS
)
349 if (n
->flags
& NODE_NOPRT
)
354 n
->flags
&= ~NODE_ENDED
;
358 /* No tables in this mode... */
359 assert(NULL
== h
->tblt
);
362 * Make sure that if we're in a literal mode already
363 * (i.e., within a <PRE>) don't print the newline.
365 if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
366 if ( ! (HTML_LITERAL
& h
->flags
))
367 print_otag(h
, TAG_BR
, "");
368 if (NODE_DELIMC
& n
->flags
)
369 h
->flags
|= HTML_NOSPACE
;
370 print_text(h
, n
->string
);
371 if (NODE_DELIMO
& n
->flags
)
372 h
->flags
|= HTML_NOSPACE
;
375 print_eqn(h
, n
->eqn
);
379 * This will take care of initialising all of the table
380 * state data for the first table, then tearing it down
383 print_tbl(h
, n
->span
);
387 * Close out the current table, if it's open, and unset
388 * the "meta" table state. This will be reopened on the
389 * next table element.
391 if (h
->tblt
!= NULL
) {
395 assert(h
->tblt
== NULL
);
396 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
397 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
401 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
402 h
->flags
&= ~HTML_KEEP
;
403 h
->flags
|= HTML_PREKEEP
;
406 if (child
&& n
->child
)
407 print_mdoc_nodelist(meta
, n
->child
, h
);
415 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& NODE_ENDED
)
417 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
418 if (n
->end
!= ENDBODY_NOT
)
419 n
->body
->flags
|= NODE_ENDED
;
425 mdoc_root_post(MDOC_ARGS
)
429 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
430 tt
= print_otag(h
, TAG_TR
, "");
432 print_otag(h
, TAG_TD
, "c", "foot-date");
433 print_text(h
, meta
->date
);
436 print_otag(h
, TAG_TD
, "c", "foot-os");
437 print_text(h
, meta
->os
);
442 mdoc_root_pre(MDOC_ARGS
)
445 char *volume
, *title
;
447 if (NULL
== meta
->arch
)
448 volume
= mandoc_strdup(meta
->vol
);
450 mandoc_asprintf(&volume
, "%s (%s)",
451 meta
->vol
, meta
->arch
);
453 if (NULL
== meta
->msec
)
454 title
= mandoc_strdup(meta
->title
);
456 mandoc_asprintf(&title
, "%s(%s)",
457 meta
->title
, meta
->msec
);
459 t
= print_otag(h
, TAG_TABLE
, "c", "head");
460 tt
= print_otag(h
, TAG_TR
, "");
462 print_otag(h
, TAG_TD
, "c", "head-ltitle");
463 print_text(h
, title
);
466 print_otag(h
, TAG_TD
, "c", "head-vol");
467 print_text(h
, volume
);
470 print_otag(h
, TAG_TD
, "c", "head-rtitle");
471 print_text(h
, title
);
480 cond_id(const struct roff_node
*n
)
482 if (n
->child
!= NULL
&&
483 n
->child
->type
== ROFFT_TEXT
&&
485 (n
->prev
->type
== ROFFT_TEXT
&&
486 strcmp(n
->prev
->string
, "|") == 0)) &&
487 (n
->parent
->tok
== MDOC_It
||
488 (n
->parent
->tok
== MDOC_Xo
&&
489 n
->parent
->parent
->prev
== NULL
&&
490 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
491 return html_make_id(n
);
496 mdoc_sh_pre(MDOC_ARGS
)
502 id
= html_make_id(n
);
503 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
505 print_otag(h
, TAG_A
, "chR", "selflink", id
);
509 if (n
->sec
== SEC_AUTHORS
)
510 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
519 mdoc_ss_pre(MDOC_ARGS
)
523 if (n
->type
!= ROFFT_HEAD
)
526 id
= html_make_id(n
);
527 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
529 print_otag(h
, TAG_A
, "chR", "selflink", id
);
535 mdoc_fl_pre(MDOC_ARGS
)
539 if ((id
= cond_id(n
)) != NULL
)
540 print_otag(h
, TAG_A
, "chR", "selflink", id
);
541 print_otag(h
, TAG_B
, "cTi", "Fl", id
);
544 print_text(h
, "\\-");
545 if (!(n
->child
== NULL
&&
547 n
->next
->type
== ROFFT_TEXT
||
548 n
->next
->flags
& NODE_LINE
)))
549 h
->flags
|= HTML_NOSPACE
;
555 mdoc_cm_pre(MDOC_ARGS
)
559 if ((id
= cond_id(n
)) != NULL
)
560 print_otag(h
, TAG_A
, "chR", "selflink", id
);
561 print_otag(h
, TAG_B
, "cTi", "Cm", id
);
567 mdoc_nd_pre(MDOC_ARGS
)
569 if (n
->type
!= ROFFT_BODY
)
572 /* XXX: this tag in theory can contain block elements. */
574 print_text(h
, "\\(em");
575 print_otag(h
, TAG_SPAN
, "cT", "Nd");
580 mdoc_nm_pre(MDOC_ARGS
)
587 print_otag(h
, TAG_TD
, "");
590 print_otag(h
, TAG_B
, "cT", "Nm");
593 print_otag(h
, TAG_TD
, "");
600 print_otag(h
, TAG_TABLE
, "c", "Nm");
602 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
603 if (n
->type
== ROFFT_TEXT
)
604 len
+= html_strlen(n
->string
);
606 if (len
== 0 && meta
->name
!= NULL
)
607 len
= html_strlen(meta
->name
);
609 t
= print_otag(h
, TAG_COLGROUP
, "");
610 /* Increase width to make even bold text fit. */
611 print_otag(h
, TAG_COL
, "shw", len
+ 2);
612 print_otag(h
, TAG_COL
, "");
614 print_otag(h
, TAG_TR
, "");
619 mdoc_xr_pre(MDOC_ARGS
)
621 if (NULL
== n
->child
)
625 print_otag(h
, TAG_A
, "cThM", "Xr",
626 n
->child
->string
, n
->child
->next
== NULL
?
627 NULL
: n
->child
->next
->string
);
629 print_otag(h
, TAG_A
, "cT", "Xr");
632 print_text(h
, n
->string
);
634 if (NULL
== (n
= n
->next
))
637 h
->flags
|= HTML_NOSPACE
;
639 h
->flags
|= HTML_NOSPACE
;
640 print_text(h
, n
->string
);
641 h
->flags
|= HTML_NOSPACE
;
647 mdoc_ns_pre(MDOC_ARGS
)
650 if ( ! (NODE_LINE
& n
->flags
))
651 h
->flags
|= HTML_NOSPACE
;
656 mdoc_ar_pre(MDOC_ARGS
)
658 print_otag(h
, TAG_VAR
, "cT", "Ar");
663 mdoc_xx_pre(MDOC_ARGS
)
665 print_otag(h
, TAG_SPAN
, "c", "Ux");
670 mdoc_it_pre(MDOC_ARGS
)
672 const struct roff_node
*bl
;
678 while (bl
->tok
!= MDOC_Bl
)
680 type
= bl
->norm
->Bl
.type
;
728 if (bl
->norm
->Bl
.comp
)
729 print_otag(h
, TAG_LI
, "csvt", cattr
, 0);
731 print_otag(h
, TAG_LI
, "c", cattr
);
743 if (bl
->norm
->Bl
.comp
)
744 print_otag(h
, TAG_DT
, "csvt", cattr
, 0);
746 print_otag(h
, TAG_DT
, "c", cattr
);
747 if (type
== LIST_diag
)
748 print_otag(h
, TAG_B
, "c", cattr
);
751 print_otag(h
, TAG_DD
, "cswl", cattr
,
761 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
762 (n
->parent
->prev
== NULL
||
763 n
->parent
->prev
->body
== NULL
||
764 n
->parent
->prev
->body
->child
!= NULL
)) {
765 t
= print_otag(h
, TAG_DT
, "csWl",
766 cattr
, bl
->norm
->Bl
.width
);
767 print_text(h
, "\\ ");
769 t
= print_otag(h
, TAG_DD
, "c", cattr
);
770 print_text(h
, "\\ ");
773 print_otag(h
, TAG_DT
, "csWl", cattr
,
777 if (n
->child
== NULL
) {
778 print_otag(h
, TAG_DD
, "css?", cattr
,
780 print_text(h
, "\\ ");
782 print_otag(h
, TAG_DD
, "c", cattr
);
793 if (bl
->norm
->Bl
.comp
)
794 print_otag(h
, TAG_TD
, "csvt", cattr
, 0);
796 print_otag(h
, TAG_TD
, "c", cattr
);
799 print_otag(h
, TAG_TR
, "c", cattr
);
809 mdoc_bl_pre(MDOC_ARGS
)
815 enum htmltag elemtype
;
824 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
828 * For each column, print out the <COL> tag with our
829 * suggested width. The last column gets min-width, as
830 * in terminal mode it auto-sizes to the width of the
831 * screen and we want to preserve that behaviour.
834 t
= print_otag(h
, TAG_COLGROUP
, "");
835 for (i
= 0; i
< bl
->ncols
- 1; i
++)
836 print_otag(h
, TAG_COL
, "sww", bl
->cols
[i
]);
837 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
882 print_otag(h
, TAG_DIV
, "cswl", cattr
, bl
->offs
);
883 print_otag(h
, TAG_DL
, "cswl", cattr
, bl
->width
);
886 elemtype
= TAG_TABLE
;
892 print_otag(h
, elemtype
, "cswl", cattr
, bl
->offs
);
897 mdoc_ex_pre(MDOC_ARGS
)
900 print_otag(h
, TAG_BR
, "");
905 mdoc_st_pre(MDOC_ARGS
)
907 print_otag(h
, TAG_SPAN
, "cT", "St");
912 mdoc_em_pre(MDOC_ARGS
)
914 print_otag(h
, TAG_I
, "cT", "Em");
919 mdoc_d1_pre(MDOC_ARGS
)
921 if (n
->type
!= ROFFT_BLOCK
)
924 print_otag(h
, TAG_DIV
, "c", "D1");
926 if (n
->tok
== MDOC_Dl
)
927 print_otag(h
, TAG_CODE
, "c", "Li");
933 mdoc_sx_pre(MDOC_ARGS
)
937 id
= html_make_id(n
);
938 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
944 mdoc_bd_pre(MDOC_ARGS
)
947 struct roff_node
*nn
;
949 if (n
->type
== ROFFT_HEAD
)
952 if (n
->type
== ROFFT_BLOCK
) {
953 comp
= n
->norm
->Bd
.comp
;
954 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
955 if (nn
->type
!= ROFFT_BLOCK
)
957 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
967 /* Handle the -offset argument. */
969 if (n
->norm
->Bd
.offs
== NULL
||
970 ! strcmp(n
->norm
->Bd
.offs
, "left"))
972 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
974 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
980 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
982 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
984 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
985 n
->norm
->Bd
.type
!= DISP_literal
)
988 print_otag(h
, TAG_PRE
, "c", "Li");
990 /* This can be recursive: save & set our literal state. */
992 sv
= h
->flags
& HTML_LITERAL
;
993 h
->flags
|= HTML_LITERAL
;
995 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
996 print_mdoc_node(meta
, nn
, h
);
998 * If the printed node flushes its own line, then we
999 * needn't do it here as well. This is hacky, but the
1000 * notion of selective eoln whitespace is pretty dumb
1001 * anyway, so don't sweat it.
1016 if (h
->flags
& HTML_NONEWLINE
||
1017 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1020 print_text(h
, "\n");
1022 h
->flags
|= HTML_NOSPACE
;
1026 h
->flags
&= ~HTML_LITERAL
;
1032 mdoc_pa_pre(MDOC_ARGS
)
1034 print_otag(h
, TAG_I
, "cT", "Pa");
1039 mdoc_ad_pre(MDOC_ARGS
)
1041 print_otag(h
, TAG_I
, "c", "Ad");
1046 mdoc_an_pre(MDOC_ARGS
)
1048 if (n
->norm
->An
.auth
== AUTH_split
) {
1049 h
->flags
&= ~HTML_NOSPLIT
;
1050 h
->flags
|= HTML_SPLIT
;
1053 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1054 h
->flags
&= ~HTML_SPLIT
;
1055 h
->flags
|= HTML_NOSPLIT
;
1059 if (h
->flags
& HTML_SPLIT
)
1060 print_otag(h
, TAG_BR
, "");
1062 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1063 h
->flags
|= HTML_SPLIT
;
1065 print_otag(h
, TAG_SPAN
, "cT", "An");
1070 mdoc_cd_pre(MDOC_ARGS
)
1073 print_otag(h
, TAG_B
, "cT", "Cd");
1078 mdoc_dv_pre(MDOC_ARGS
)
1082 if ((id
= cond_id(n
)) != NULL
)
1083 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1084 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1090 mdoc_ev_pre(MDOC_ARGS
)
1094 if ((id
= cond_id(n
)) != NULL
)
1095 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1096 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1102 mdoc_er_pre(MDOC_ARGS
)
1106 id
= n
->sec
== SEC_ERRORS
&&
1107 (n
->parent
->tok
== MDOC_It
||
1108 (n
->parent
->tok
== MDOC_Bq
&&
1109 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1110 html_make_id(n
) : NULL
;
1113 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1114 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1120 mdoc_fa_pre(MDOC_ARGS
)
1122 const struct roff_node
*nn
;
1125 if (n
->parent
->tok
!= MDOC_Fo
) {
1126 print_otag(h
, TAG_VAR
, "cT", "Fa");
1130 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1131 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1132 print_text(h
, nn
->string
);
1135 h
->flags
|= HTML_NOSPACE
;
1140 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1141 h
->flags
|= HTML_NOSPACE
;
1149 mdoc_fd_pre(MDOC_ARGS
)
1156 if (NULL
== (n
= n
->child
))
1159 assert(n
->type
== ROFFT_TEXT
);
1161 if (strcmp(n
->string
, "#include")) {
1162 print_otag(h
, TAG_B
, "cT", "Fd");
1166 print_otag(h
, TAG_B
, "cT", "In");
1167 print_text(h
, n
->string
);
1169 if (NULL
!= (n
= n
->next
)) {
1170 assert(n
->type
== ROFFT_TEXT
);
1172 if (h
->base_includes
) {
1174 if (*cp
== '<' || *cp
== '"')
1176 buf
= mandoc_strdup(cp
);
1177 cp
= strchr(buf
, '\0') - 1;
1178 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1180 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1183 t
= print_otag(h
, TAG_A
, "cT", "In");
1185 print_text(h
, n
->string
);
1191 for ( ; n
; n
= n
->next
) {
1192 assert(n
->type
== ROFFT_TEXT
);
1193 print_text(h
, n
->string
);
1200 mdoc_vt_pre(MDOC_ARGS
)
1202 if (n
->type
== ROFFT_BLOCK
) {
1205 } else if (n
->type
== ROFFT_ELEM
) {
1207 } else if (n
->type
== ROFFT_HEAD
)
1210 print_otag(h
, TAG_VAR
, "cT", "Vt");
1215 mdoc_ft_pre(MDOC_ARGS
)
1218 print_otag(h
, TAG_VAR
, "cT", "Ft");
1223 mdoc_fn_pre(MDOC_ARGS
)
1227 const char *sp
, *ep
;
1230 pretty
= NODE_SYNPRETTY
& n
->flags
;
1233 /* Split apart into type and name. */
1234 assert(n
->child
->string
);
1235 sp
= n
->child
->string
;
1237 ep
= strchr(sp
, ' ');
1239 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1242 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1243 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1245 print_text(h
, nbuf
);
1247 ep
= strchr(sp
, ' ');
1252 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1259 h
->flags
|= HTML_NOSPACE
;
1261 h
->flags
|= HTML_NOSPACE
;
1263 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1264 if (NODE_SYNPRETTY
& n
->flags
)
1265 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1266 "white-space", "nowrap");
1268 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1269 print_text(h
, n
->string
);
1272 h
->flags
|= HTML_NOSPACE
;
1277 h
->flags
|= HTML_NOSPACE
;
1281 h
->flags
|= HTML_NOSPACE
;
1289 mdoc_sm_pre(MDOC_ARGS
)
1292 if (NULL
== n
->child
)
1293 h
->flags
^= HTML_NONOSPACE
;
1294 else if (0 == strcmp("on", n
->child
->string
))
1295 h
->flags
&= ~HTML_NONOSPACE
;
1297 h
->flags
|= HTML_NONOSPACE
;
1299 if ( ! (HTML_NONOSPACE
& h
->flags
))
1300 h
->flags
&= ~HTML_NOSPACE
;
1306 mdoc_skip_pre(MDOC_ARGS
)
1313 mdoc_pp_pre(MDOC_ARGS
)
1321 mdoc_sp_pre(MDOC_ARGS
)
1325 SCALE_VS_INIT(&su
, 1);
1327 if (MDOC_sp
== n
->tok
) {
1328 if (NULL
!= (n
= n
->child
)) {
1329 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1331 else if (su
.scale
< 0.0)
1337 print_otag(h
, TAG_DIV
, "suh", &su
);
1339 /* So the div isn't empty: */
1340 print_text(h
, "\\~");
1347 mdoc_lk_pre(MDOC_ARGS
)
1349 if (NULL
== (n
= n
->child
))
1352 assert(n
->type
== ROFFT_TEXT
);
1354 print_otag(h
, TAG_A
, "cTh", "Lk", n
->string
);
1356 if (NULL
== n
->next
)
1357 print_text(h
, n
->string
);
1359 for (n
= n
->next
; n
; n
= n
->next
)
1360 print_text(h
, n
->string
);
1366 mdoc_mt_pre(MDOC_ARGS
)
1371 for (n
= n
->child
; n
; n
= n
->next
) {
1372 assert(n
->type
== ROFFT_TEXT
);
1374 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1375 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1376 print_text(h
, n
->string
);
1385 mdoc_fo_pre(MDOC_ARGS
)
1389 if (n
->type
== ROFFT_BODY
) {
1390 h
->flags
|= HTML_NOSPACE
;
1392 h
->flags
|= HTML_NOSPACE
;
1394 } else if (n
->type
== ROFFT_BLOCK
) {
1399 if (n
->child
== NULL
)
1402 assert(n
->child
->string
);
1403 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1404 print_text(h
, n
->child
->string
);
1410 mdoc_fo_post(MDOC_ARGS
)
1413 if (n
->type
!= ROFFT_BODY
)
1415 h
->flags
|= HTML_NOSPACE
;
1417 h
->flags
|= HTML_NOSPACE
;
1422 mdoc_in_pre(MDOC_ARGS
)
1427 print_otag(h
, TAG_B
, "cT", "In");
1430 * The first argument of the `In' gets special treatment as
1431 * being a linked value. Subsequent values are printed
1432 * afterward. groff does similarly. This also handles the case
1436 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1437 print_text(h
, "#include");
1440 h
->flags
|= HTML_NOSPACE
;
1442 if (NULL
!= (n
= n
->child
)) {
1443 assert(n
->type
== ROFFT_TEXT
);
1445 if (h
->base_includes
)
1446 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1448 t
= print_otag(h
, TAG_A
, "cT", "In");
1449 print_text(h
, n
->string
);
1455 h
->flags
|= HTML_NOSPACE
;
1458 for ( ; n
; n
= n
->next
) {
1459 assert(n
->type
== ROFFT_TEXT
);
1460 print_text(h
, n
->string
);
1467 mdoc_ic_pre(MDOC_ARGS
)
1471 if ((id
= cond_id(n
)) != NULL
)
1472 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1473 print_otag(h
, TAG_B
, "cTi", "Ic", id
);
1479 mdoc_va_pre(MDOC_ARGS
)
1481 print_otag(h
, TAG_VAR
, "cT", "Va");
1486 mdoc_ap_pre(MDOC_ARGS
)
1489 h
->flags
|= HTML_NOSPACE
;
1490 print_text(h
, "\\(aq");
1491 h
->flags
|= HTML_NOSPACE
;
1496 mdoc_bf_pre(MDOC_ARGS
)
1500 if (n
->type
== ROFFT_HEAD
)
1502 else if (n
->type
!= ROFFT_BODY
)
1505 if (FONT_Em
== n
->norm
->Bf
.font
)
1507 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1509 else if (FONT_Li
== n
->norm
->Bf
.font
)
1515 * We want this to be inline-formatted, but needs to be div to
1516 * accept block children.
1519 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1524 mdoc_ms_pre(MDOC_ARGS
)
1528 if ((id
= cond_id(n
)) != NULL
)
1529 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1530 print_otag(h
, TAG_B
, "cTi", "Ms", id
);
1536 mdoc_igndelim_pre(MDOC_ARGS
)
1539 h
->flags
|= HTML_IGNDELIM
;
1544 mdoc_pf_post(MDOC_ARGS
)
1547 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1548 h
->flags
|= HTML_NOSPACE
;
1552 mdoc_rs_pre(MDOC_ARGS
)
1554 if (n
->type
!= ROFFT_BLOCK
)
1557 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1560 print_otag(h
, TAG_CITE
, "cT", "Rs");
1565 mdoc_no_pre(MDOC_ARGS
)
1569 if ((id
= cond_id(n
)) != NULL
)
1570 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1571 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1577 mdoc_li_pre(MDOC_ARGS
)
1581 if ((id
= cond_id(n
)) != NULL
)
1582 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1583 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1589 mdoc_sy_pre(MDOC_ARGS
)
1591 print_otag(h
, TAG_B
, "cT", "Sy");
1596 mdoc_lb_pre(MDOC_ARGS
)
1598 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1599 print_otag(h
, TAG_BR
, "");
1601 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1606 mdoc__x_pre(MDOC_ARGS
)
1616 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1617 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1618 print_text(h
, "and");
1657 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1666 print_otag(h
, t
, "c", cattr
);
1671 mdoc__x_post(MDOC_ARGS
)
1674 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1675 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1676 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1681 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1684 h
->flags
|= HTML_NOSPACE
;
1685 print_text(h
, n
->next
? "," : ".");
1689 mdoc_bk_pre(MDOC_ARGS
)
1698 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1699 h
->flags
|= HTML_PREKEEP
;
1709 mdoc_bk_post(MDOC_ARGS
)
1712 if (n
->type
== ROFFT_BODY
)
1713 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1717 mdoc_quote_pre(MDOC_ARGS
)
1719 if (n
->type
!= ROFFT_BODY
)
1725 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1726 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1730 print_text(h
, "\\(lC");
1734 print_text(h
, "\\(lB");
1738 print_text(h
, "\\(lB");
1739 h
->flags
|= HTML_NOSPACE
;
1740 print_otag(h
, TAG_SPAN
, "c", "Op");
1743 if (NULL
== n
->norm
->Es
||
1744 NULL
== n
->norm
->Es
->child
)
1746 print_text(h
, n
->norm
->Es
->child
->string
);
1752 print_text(h
, "\\(lq");
1759 print_text(h
, "\\(oq");
1760 h
->flags
|= HTML_NOSPACE
;
1761 print_otag(h
, TAG_CODE
, "c", "Li");
1765 print_text(h
, "\\(oq");
1771 h
->flags
|= HTML_NOSPACE
;
1776 mdoc_quote_post(MDOC_ARGS
)
1779 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1782 h
->flags
|= HTML_NOSPACE
;
1787 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1788 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1792 print_text(h
, "\\(rC");
1798 print_text(h
, "\\(rB");
1801 if (n
->norm
->Es
== NULL
||
1802 n
->norm
->Es
->child
== NULL
||
1803 n
->norm
->Es
->child
->next
== NULL
)
1804 h
->flags
&= ~HTML_NOSPACE
;
1806 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1812 print_text(h
, "\\(rq");
1821 print_text(h
, "\\(cq");
1829 mdoc_eo_pre(MDOC_ARGS
)
1832 if (n
->type
!= ROFFT_BODY
)
1835 if (n
->end
== ENDBODY_NOT
&&
1836 n
->parent
->head
->child
== NULL
&&
1838 n
->child
->end
!= ENDBODY_NOT
)
1839 print_text(h
, "\\&");
1840 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1841 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1842 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1843 h
->flags
|= HTML_NOSPACE
;
1848 mdoc_eo_post(MDOC_ARGS
)
1852 if (n
->type
!= ROFFT_BODY
)
1855 if (n
->end
!= ENDBODY_NOT
) {
1856 h
->flags
&= ~HTML_NOSPACE
;
1860 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1861 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1864 h
->flags
|= HTML_NOSPACE
;
1866 h
->flags
&= ~HTML_NOSPACE
;