]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.277 2017/03/15 11:29:53 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
);
504 print_otag(h
, TAG_A
, "chR", "selflink", id
);
508 if (n
->sec
== SEC_AUTHORS
)
509 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
518 mdoc_ss_pre(MDOC_ARGS
)
522 if (n
->type
!= ROFFT_HEAD
)
525 id
= html_make_id(n
);
526 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
527 print_otag(h
, TAG_A
, "chR", "selflink", id
);
533 mdoc_fl_pre(MDOC_ARGS
)
537 if ((id
= cond_id(n
)) != NULL
)
538 print_otag(h
, TAG_A
, "chR", "selflink", id
);
539 print_otag(h
, TAG_B
, "cTi", "Fl", id
);
542 print_text(h
, "\\-");
543 if (!(n
->child
== NULL
&&
545 n
->next
->type
== ROFFT_TEXT
||
546 n
->next
->flags
& NODE_LINE
)))
547 h
->flags
|= HTML_NOSPACE
;
553 mdoc_cm_pre(MDOC_ARGS
)
557 if ((id
= cond_id(n
)) != NULL
)
558 print_otag(h
, TAG_A
, "chR", "selflink", id
);
559 print_otag(h
, TAG_B
, "cTi", "Cm", id
);
565 mdoc_nd_pre(MDOC_ARGS
)
567 if (n
->type
!= ROFFT_BODY
)
570 /* XXX: this tag in theory can contain block elements. */
572 print_text(h
, "\\(em");
573 print_otag(h
, TAG_SPAN
, "cT", "Nd");
578 mdoc_nm_pre(MDOC_ARGS
)
585 print_otag(h
, TAG_TD
, "");
588 print_otag(h
, TAG_B
, "cT", "Nm");
591 print_otag(h
, TAG_TD
, "");
598 print_otag(h
, TAG_TABLE
, "c", "Nm");
600 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
601 if (n
->type
== ROFFT_TEXT
)
602 len
+= html_strlen(n
->string
);
604 if (len
== 0 && meta
->name
!= NULL
)
605 len
= html_strlen(meta
->name
);
607 t
= print_otag(h
, TAG_COLGROUP
, "");
608 /* Increase width to make even bold text fit. */
609 print_otag(h
, TAG_COL
, "shw", len
+ 2);
610 print_otag(h
, TAG_COL
, "");
612 print_otag(h
, TAG_TR
, "");
617 mdoc_xr_pre(MDOC_ARGS
)
619 if (NULL
== n
->child
)
623 print_otag(h
, TAG_A
, "cThM", "Xr",
624 n
->child
->string
, n
->child
->next
== NULL
?
625 NULL
: n
->child
->next
->string
);
627 print_otag(h
, TAG_A
, "cT", "Xr");
630 print_text(h
, n
->string
);
632 if (NULL
== (n
= n
->next
))
635 h
->flags
|= HTML_NOSPACE
;
637 h
->flags
|= HTML_NOSPACE
;
638 print_text(h
, n
->string
);
639 h
->flags
|= HTML_NOSPACE
;
645 mdoc_ns_pre(MDOC_ARGS
)
648 if ( ! (NODE_LINE
& n
->flags
))
649 h
->flags
|= HTML_NOSPACE
;
654 mdoc_ar_pre(MDOC_ARGS
)
656 print_otag(h
, TAG_VAR
, "cT", "Ar");
661 mdoc_xx_pre(MDOC_ARGS
)
663 print_otag(h
, TAG_SPAN
, "c", "Ux");
668 mdoc_it_pre(MDOC_ARGS
)
670 const struct roff_node
*bl
;
676 while (bl
->tok
!= MDOC_Bl
)
678 type
= bl
->norm
->Bl
.type
;
726 if (bl
->norm
->Bl
.comp
)
727 print_otag(h
, TAG_LI
, "csvt", cattr
, 0);
729 print_otag(h
, TAG_LI
, "c", cattr
);
741 if (bl
->norm
->Bl
.comp
)
742 print_otag(h
, TAG_DT
, "csvt", cattr
, 0);
744 print_otag(h
, TAG_DT
, "c", cattr
);
745 if (type
== LIST_diag
)
746 print_otag(h
, TAG_B
, "c", cattr
);
749 print_otag(h
, TAG_DD
, "cswl", cattr
,
759 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
760 (n
->parent
->prev
== NULL
||
761 n
->parent
->prev
->body
== NULL
||
762 n
->parent
->prev
->body
->child
!= NULL
)) {
763 t
= print_otag(h
, TAG_DT
, "csWl",
764 cattr
, bl
->norm
->Bl
.width
);
765 print_text(h
, "\\ ");
767 t
= print_otag(h
, TAG_DD
, "c", cattr
);
768 print_text(h
, "\\ ");
771 print_otag(h
, TAG_DT
, "csWl", cattr
,
775 if (n
->child
== NULL
) {
776 print_otag(h
, TAG_DD
, "css?", cattr
,
778 print_text(h
, "\\ ");
780 print_otag(h
, TAG_DD
, "c", cattr
);
791 if (bl
->norm
->Bl
.comp
)
792 print_otag(h
, TAG_TD
, "csvt", cattr
, 0);
794 print_otag(h
, TAG_TD
, "c", cattr
);
797 print_otag(h
, TAG_TR
, "c", cattr
);
807 mdoc_bl_pre(MDOC_ARGS
)
813 enum htmltag elemtype
;
822 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
826 * For each column, print out the <COL> tag with our
827 * suggested width. The last column gets min-width, as
828 * in terminal mode it auto-sizes to the width of the
829 * screen and we want to preserve that behaviour.
832 t
= print_otag(h
, TAG_COLGROUP
, "");
833 for (i
= 0; i
< bl
->ncols
- 1; i
++)
834 print_otag(h
, TAG_COL
, "sww", bl
->cols
[i
]);
835 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
880 print_otag(h
, TAG_DIV
, "cswl", cattr
, bl
->offs
);
881 print_otag(h
, TAG_DL
, "cswl", cattr
, bl
->width
);
884 elemtype
= TAG_TABLE
;
890 print_otag(h
, elemtype
, "cswl", cattr
, bl
->offs
);
895 mdoc_ex_pre(MDOC_ARGS
)
898 print_otag(h
, TAG_BR
, "");
903 mdoc_st_pre(MDOC_ARGS
)
905 print_otag(h
, TAG_SPAN
, "cT", "St");
910 mdoc_em_pre(MDOC_ARGS
)
912 print_otag(h
, TAG_I
, "cT", "Em");
917 mdoc_d1_pre(MDOC_ARGS
)
919 if (n
->type
!= ROFFT_BLOCK
)
922 print_otag(h
, TAG_DIV
, "c", "D1");
924 if (n
->tok
== MDOC_Dl
)
925 print_otag(h
, TAG_CODE
, "c", "Li");
931 mdoc_sx_pre(MDOC_ARGS
)
935 id
= html_make_id(n
);
936 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
942 mdoc_bd_pre(MDOC_ARGS
)
945 struct roff_node
*nn
;
947 if (n
->type
== ROFFT_HEAD
)
950 if (n
->type
== ROFFT_BLOCK
) {
951 comp
= n
->norm
->Bd
.comp
;
952 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
953 if (nn
->type
!= ROFFT_BLOCK
)
955 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
965 /* Handle the -offset argument. */
967 if (n
->norm
->Bd
.offs
== NULL
||
968 ! strcmp(n
->norm
->Bd
.offs
, "left"))
970 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
972 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
978 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
980 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
982 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
983 n
->norm
->Bd
.type
!= DISP_literal
)
986 print_otag(h
, TAG_PRE
, "c", "Li");
988 /* This can be recursive: save & set our literal state. */
990 sv
= h
->flags
& HTML_LITERAL
;
991 h
->flags
|= HTML_LITERAL
;
993 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
994 print_mdoc_node(meta
, nn
, h
);
996 * If the printed node flushes its own line, then we
997 * needn't do it here as well. This is hacky, but the
998 * notion of selective eoln whitespace is pretty dumb
999 * anyway, so don't sweat it.
1014 if (h
->flags
& HTML_NONEWLINE
||
1015 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1018 print_text(h
, "\n");
1020 h
->flags
|= HTML_NOSPACE
;
1024 h
->flags
&= ~HTML_LITERAL
;
1030 mdoc_pa_pre(MDOC_ARGS
)
1032 print_otag(h
, TAG_I
, "cT", "Pa");
1037 mdoc_ad_pre(MDOC_ARGS
)
1039 print_otag(h
, TAG_I
, "c", "Ad");
1044 mdoc_an_pre(MDOC_ARGS
)
1046 if (n
->norm
->An
.auth
== AUTH_split
) {
1047 h
->flags
&= ~HTML_NOSPLIT
;
1048 h
->flags
|= HTML_SPLIT
;
1051 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1052 h
->flags
&= ~HTML_SPLIT
;
1053 h
->flags
|= HTML_NOSPLIT
;
1057 if (h
->flags
& HTML_SPLIT
)
1058 print_otag(h
, TAG_BR
, "");
1060 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1061 h
->flags
|= HTML_SPLIT
;
1063 print_otag(h
, TAG_SPAN
, "cT", "An");
1068 mdoc_cd_pre(MDOC_ARGS
)
1071 print_otag(h
, TAG_B
, "cT", "Cd");
1076 mdoc_dv_pre(MDOC_ARGS
)
1080 if ((id
= cond_id(n
)) != NULL
)
1081 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1082 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1088 mdoc_ev_pre(MDOC_ARGS
)
1092 if ((id
= cond_id(n
)) != NULL
)
1093 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1094 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1100 mdoc_er_pre(MDOC_ARGS
)
1104 id
= n
->sec
== SEC_ERRORS
&&
1105 (n
->parent
->tok
== MDOC_It
||
1106 (n
->parent
->tok
== MDOC_Bq
&&
1107 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1108 html_make_id(n
) : NULL
;
1111 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1112 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1118 mdoc_fa_pre(MDOC_ARGS
)
1120 const struct roff_node
*nn
;
1123 if (n
->parent
->tok
!= MDOC_Fo
) {
1124 print_otag(h
, TAG_VAR
, "cT", "Fa");
1128 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1129 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1130 print_text(h
, nn
->string
);
1133 h
->flags
|= HTML_NOSPACE
;
1138 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1139 h
->flags
|= HTML_NOSPACE
;
1147 mdoc_fd_pre(MDOC_ARGS
)
1154 if (NULL
== (n
= n
->child
))
1157 assert(n
->type
== ROFFT_TEXT
);
1159 if (strcmp(n
->string
, "#include")) {
1160 print_otag(h
, TAG_B
, "cT", "Fd");
1164 print_otag(h
, TAG_B
, "cT", "In");
1165 print_text(h
, n
->string
);
1167 if (NULL
!= (n
= n
->next
)) {
1168 assert(n
->type
== ROFFT_TEXT
);
1170 if (h
->base_includes
) {
1172 if (*cp
== '<' || *cp
== '"')
1174 buf
= mandoc_strdup(cp
);
1175 cp
= strchr(buf
, '\0') - 1;
1176 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1178 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1181 t
= print_otag(h
, TAG_A
, "cT", "In");
1183 print_text(h
, n
->string
);
1189 for ( ; n
; n
= n
->next
) {
1190 assert(n
->type
== ROFFT_TEXT
);
1191 print_text(h
, n
->string
);
1198 mdoc_vt_pre(MDOC_ARGS
)
1200 if (n
->type
== ROFFT_BLOCK
) {
1203 } else if (n
->type
== ROFFT_ELEM
) {
1205 } else if (n
->type
== ROFFT_HEAD
)
1208 print_otag(h
, TAG_VAR
, "cT", "Vt");
1213 mdoc_ft_pre(MDOC_ARGS
)
1216 print_otag(h
, TAG_VAR
, "cT", "Ft");
1221 mdoc_fn_pre(MDOC_ARGS
)
1225 const char *sp
, *ep
;
1228 pretty
= NODE_SYNPRETTY
& n
->flags
;
1231 /* Split apart into type and name. */
1232 assert(n
->child
->string
);
1233 sp
= n
->child
->string
;
1235 ep
= strchr(sp
, ' ');
1237 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1240 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1241 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1243 print_text(h
, nbuf
);
1245 ep
= strchr(sp
, ' ');
1250 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1257 h
->flags
|= HTML_NOSPACE
;
1259 h
->flags
|= HTML_NOSPACE
;
1261 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1262 if (NODE_SYNPRETTY
& n
->flags
)
1263 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1264 "white-space", "nowrap");
1266 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1267 print_text(h
, n
->string
);
1270 h
->flags
|= HTML_NOSPACE
;
1275 h
->flags
|= HTML_NOSPACE
;
1279 h
->flags
|= HTML_NOSPACE
;
1287 mdoc_sm_pre(MDOC_ARGS
)
1290 if (NULL
== n
->child
)
1291 h
->flags
^= HTML_NONOSPACE
;
1292 else if (0 == strcmp("on", n
->child
->string
))
1293 h
->flags
&= ~HTML_NONOSPACE
;
1295 h
->flags
|= HTML_NONOSPACE
;
1297 if ( ! (HTML_NONOSPACE
& h
->flags
))
1298 h
->flags
&= ~HTML_NOSPACE
;
1304 mdoc_skip_pre(MDOC_ARGS
)
1311 mdoc_pp_pre(MDOC_ARGS
)
1319 mdoc_sp_pre(MDOC_ARGS
)
1323 SCALE_VS_INIT(&su
, 1);
1325 if (MDOC_sp
== n
->tok
) {
1326 if (NULL
!= (n
= n
->child
)) {
1327 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1329 else if (su
.scale
< 0.0)
1335 print_otag(h
, TAG_DIV
, "suh", &su
);
1337 /* So the div isn't empty: */
1338 print_text(h
, "\\~");
1345 mdoc_lk_pre(MDOC_ARGS
)
1347 if (NULL
== (n
= n
->child
))
1350 assert(n
->type
== ROFFT_TEXT
);
1352 print_otag(h
, TAG_A
, "cTh", "Lk", n
->string
);
1354 if (NULL
== n
->next
)
1355 print_text(h
, n
->string
);
1357 for (n
= n
->next
; n
; n
= n
->next
)
1358 print_text(h
, n
->string
);
1364 mdoc_mt_pre(MDOC_ARGS
)
1369 for (n
= n
->child
; n
; n
= n
->next
) {
1370 assert(n
->type
== ROFFT_TEXT
);
1372 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1373 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1374 print_text(h
, n
->string
);
1383 mdoc_fo_pre(MDOC_ARGS
)
1387 if (n
->type
== ROFFT_BODY
) {
1388 h
->flags
|= HTML_NOSPACE
;
1390 h
->flags
|= HTML_NOSPACE
;
1392 } else if (n
->type
== ROFFT_BLOCK
) {
1397 if (n
->child
== NULL
)
1400 assert(n
->child
->string
);
1401 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1402 print_text(h
, n
->child
->string
);
1408 mdoc_fo_post(MDOC_ARGS
)
1411 if (n
->type
!= ROFFT_BODY
)
1413 h
->flags
|= HTML_NOSPACE
;
1415 h
->flags
|= HTML_NOSPACE
;
1420 mdoc_in_pre(MDOC_ARGS
)
1425 print_otag(h
, TAG_B
, "cT", "In");
1428 * The first argument of the `In' gets special treatment as
1429 * being a linked value. Subsequent values are printed
1430 * afterward. groff does similarly. This also handles the case
1434 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1435 print_text(h
, "#include");
1438 h
->flags
|= HTML_NOSPACE
;
1440 if (NULL
!= (n
= n
->child
)) {
1441 assert(n
->type
== ROFFT_TEXT
);
1443 if (h
->base_includes
)
1444 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1446 t
= print_otag(h
, TAG_A
, "cT", "In");
1447 print_text(h
, n
->string
);
1453 h
->flags
|= HTML_NOSPACE
;
1456 for ( ; n
; n
= n
->next
) {
1457 assert(n
->type
== ROFFT_TEXT
);
1458 print_text(h
, n
->string
);
1465 mdoc_ic_pre(MDOC_ARGS
)
1469 if ((id
= cond_id(n
)) != NULL
)
1470 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1471 print_otag(h
, TAG_B
, "cTi", "Ic", id
);
1477 mdoc_va_pre(MDOC_ARGS
)
1479 print_otag(h
, TAG_VAR
, "cT", "Va");
1484 mdoc_ap_pre(MDOC_ARGS
)
1487 h
->flags
|= HTML_NOSPACE
;
1488 print_text(h
, "\\(aq");
1489 h
->flags
|= HTML_NOSPACE
;
1494 mdoc_bf_pre(MDOC_ARGS
)
1498 if (n
->type
== ROFFT_HEAD
)
1500 else if (n
->type
!= ROFFT_BODY
)
1503 if (FONT_Em
== n
->norm
->Bf
.font
)
1505 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1507 else if (FONT_Li
== n
->norm
->Bf
.font
)
1513 * We want this to be inline-formatted, but needs to be div to
1514 * accept block children.
1517 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1522 mdoc_ms_pre(MDOC_ARGS
)
1526 if ((id
= cond_id(n
)) != NULL
)
1527 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1528 print_otag(h
, TAG_B
, "cTi", "Ms", id
);
1534 mdoc_igndelim_pre(MDOC_ARGS
)
1537 h
->flags
|= HTML_IGNDELIM
;
1542 mdoc_pf_post(MDOC_ARGS
)
1545 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1546 h
->flags
|= HTML_NOSPACE
;
1550 mdoc_rs_pre(MDOC_ARGS
)
1552 if (n
->type
!= ROFFT_BLOCK
)
1555 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1558 print_otag(h
, TAG_CITE
, "cT", "Rs");
1563 mdoc_no_pre(MDOC_ARGS
)
1567 if ((id
= cond_id(n
)) != NULL
)
1568 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1569 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1575 mdoc_li_pre(MDOC_ARGS
)
1579 if ((id
= cond_id(n
)) != NULL
)
1580 print_otag(h
, TAG_A
, "chR", "selflink", id
);
1581 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1587 mdoc_sy_pre(MDOC_ARGS
)
1589 print_otag(h
, TAG_B
, "cT", "Sy");
1594 mdoc_lb_pre(MDOC_ARGS
)
1596 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1597 print_otag(h
, TAG_BR
, "");
1599 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1604 mdoc__x_pre(MDOC_ARGS
)
1614 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1615 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1616 print_text(h
, "and");
1655 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1664 print_otag(h
, t
, "c", cattr
);
1669 mdoc__x_post(MDOC_ARGS
)
1672 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1673 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1674 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1679 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1682 h
->flags
|= HTML_NOSPACE
;
1683 print_text(h
, n
->next
? "," : ".");
1687 mdoc_bk_pre(MDOC_ARGS
)
1696 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1697 h
->flags
|= HTML_PREKEEP
;
1707 mdoc_bk_post(MDOC_ARGS
)
1710 if (n
->type
== ROFFT_BODY
)
1711 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1715 mdoc_quote_pre(MDOC_ARGS
)
1717 if (n
->type
!= ROFFT_BODY
)
1723 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1724 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1728 print_text(h
, "\\(lC");
1732 print_text(h
, "\\(lB");
1736 print_text(h
, "\\(lB");
1737 h
->flags
|= HTML_NOSPACE
;
1738 print_otag(h
, TAG_SPAN
, "c", "Op");
1741 if (NULL
== n
->norm
->Es
||
1742 NULL
== n
->norm
->Es
->child
)
1744 print_text(h
, n
->norm
->Es
->child
->string
);
1750 print_text(h
, "\\(lq");
1757 print_text(h
, "\\(oq");
1758 h
->flags
|= HTML_NOSPACE
;
1759 print_otag(h
, TAG_CODE
, "c", "Li");
1763 print_text(h
, "\\(oq");
1769 h
->flags
|= HTML_NOSPACE
;
1774 mdoc_quote_post(MDOC_ARGS
)
1777 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1780 h
->flags
|= HTML_NOSPACE
;
1785 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1786 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1790 print_text(h
, "\\(rC");
1796 print_text(h
, "\\(rB");
1799 if (n
->norm
->Es
== NULL
||
1800 n
->norm
->Es
->child
== NULL
||
1801 n
->norm
->Es
->child
->next
== NULL
)
1802 h
->flags
&= ~HTML_NOSPACE
;
1804 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1810 print_text(h
, "\\(rq");
1819 print_text(h
, "\\(cq");
1827 mdoc_eo_pre(MDOC_ARGS
)
1830 if (n
->type
!= ROFFT_BODY
)
1833 if (n
->end
== ENDBODY_NOT
&&
1834 n
->parent
->head
->child
== NULL
&&
1836 n
->child
->end
!= ENDBODY_NOT
)
1837 print_text(h
, "\\&");
1838 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1839 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1840 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1841 h
->flags
|= HTML_NOSPACE
;
1846 mdoc_eo_post(MDOC_ARGS
)
1850 if (n
->type
!= ROFFT_BODY
)
1853 if (n
->end
!= ENDBODY_NOT
) {
1854 h
->flags
&= ~HTML_NOSPACE
;
1858 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1859 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1862 h
->flags
|= HTML_NOSPACE
;
1864 h
->flags
&= ~HTML_NOSPACE
;