]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.261 2017/01/25 02:14:43 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 *make_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_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
] = {
121 {mdoc_ap_pre
, NULL
}, /* Ap */
122 {NULL
, NULL
}, /* Dd */
123 {NULL
, NULL
}, /* Dt */
124 {NULL
, NULL
}, /* Os */
125 {mdoc_sh_pre
, NULL
}, /* Sh */
126 {mdoc_ss_pre
, NULL
}, /* Ss */
127 {mdoc_pp_pre
, NULL
}, /* Pp */
128 {mdoc_d1_pre
, NULL
}, /* D1 */
129 {mdoc_d1_pre
, NULL
}, /* Dl */
130 {mdoc_bd_pre
, NULL
}, /* Bd */
131 {NULL
, NULL
}, /* Ed */
132 {mdoc_bl_pre
, NULL
}, /* Bl */
133 {NULL
, NULL
}, /* El */
134 {mdoc_it_pre
, NULL
}, /* It */
135 {mdoc_ad_pre
, NULL
}, /* Ad */
136 {mdoc_an_pre
, NULL
}, /* An */
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 {NULL
, 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 {NULL
, 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_sp_pre
, NULL
}, /* br */
240 {mdoc_sp_pre
, NULL
}, /* sp */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
242 {NULL
, NULL
}, /* Ta */
243 {mdoc_skip_pre
, NULL
}, /* ll */
248 * See the same function in mdoc_term.c for documentation.
251 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
254 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
257 if (n
->prev
->tok
== n
->tok
&&
261 print_otag(h
, TAG_BR
, "");
265 switch (n
->prev
->tok
) {
274 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
280 print_otag(h
, TAG_BR
, "");
286 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
291 h
= (struct html
*)arg
;
293 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
295 print_otag(h
, TAG_HTML
, "");
296 t
= print_otag(h
, TAG_HEAD
, "");
297 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
299 print_otag(h
, TAG_BODY
, "");
302 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
303 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
304 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
306 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
311 print_mdoc_head(MDOC_ARGS
)
317 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
318 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
319 meta
->msec
, meta
->arch
);
320 else if (meta
->msec
!= NULL
)
321 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
322 else if (meta
->arch
!= NULL
)
323 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
325 cp
= mandoc_strdup(meta
->title
);
327 print_otag(h
, TAG_TITLE
, "");
333 print_mdoc_nodelist(MDOC_ARGS
)
337 print_mdoc_node(meta
, n
, h
);
343 print_mdoc_node(MDOC_ARGS
)
348 if (n
->flags
& NODE_NOPRT
)
353 n
->flags
&= ~NODE_ENDED
;
357 /* No tables in this mode... */
358 assert(NULL
== h
->tblt
);
361 * Make sure that if we're in a literal mode already
362 * (i.e., within a <PRE>) don't print the newline.
364 if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
365 if ( ! (HTML_LITERAL
& h
->flags
))
366 print_otag(h
, TAG_BR
, "");
367 if (NODE_DELIMC
& n
->flags
)
368 h
->flags
|= HTML_NOSPACE
;
369 print_text(h
, n
->string
);
370 if (NODE_DELIMO
& n
->flags
)
371 h
->flags
|= HTML_NOSPACE
;
374 print_eqn(h
, n
->eqn
);
378 * This will take care of initialising all of the table
379 * state data for the first table, then tearing it down
382 print_tbl(h
, n
->span
);
386 * Close out the current table, if it's open, and unset
387 * the "meta" table state. This will be reopened on the
388 * next table element.
390 if (h
->tblt
!= NULL
) {
394 assert(h
->tblt
== NULL
);
395 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
396 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
400 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
401 h
->flags
&= ~HTML_KEEP
;
402 h
->flags
|= HTML_PREKEEP
;
405 if (child
&& n
->child
)
406 print_mdoc_nodelist(meta
, n
->child
, h
);
414 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& NODE_ENDED
)
416 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
417 if (n
->end
!= ENDBODY_NOT
)
418 n
->body
->flags
|= NODE_ENDED
;
419 if (n
->end
== ENDBODY_NOSPACE
)
420 h
->flags
|= HTML_NOSPACE
;
426 mdoc_root_post(MDOC_ARGS
)
430 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
431 print_otag(h
, TAG_TBODY
, "");
432 tt
= print_otag(h
, TAG_TR
, "");
434 print_otag(h
, TAG_TD
, "c", "foot-date");
435 print_text(h
, meta
->date
);
438 print_otag(h
, TAG_TD
, "c", "foot-os");
439 print_text(h
, meta
->os
);
444 mdoc_root_pre(MDOC_ARGS
)
447 char *volume
, *title
;
449 if (NULL
== meta
->arch
)
450 volume
= mandoc_strdup(meta
->vol
);
452 mandoc_asprintf(&volume
, "%s (%s)",
453 meta
->vol
, meta
->arch
);
455 if (NULL
== meta
->msec
)
456 title
= mandoc_strdup(meta
->title
);
458 mandoc_asprintf(&title
, "%s(%s)",
459 meta
->title
, meta
->msec
);
461 t
= print_otag(h
, TAG_TABLE
, "c", "head");
462 print_otag(h
, TAG_TBODY
, "");
463 tt
= print_otag(h
, TAG_TR
, "");
465 print_otag(h
, TAG_TD
, "c", "head-ltitle");
466 print_text(h
, title
);
469 print_otag(h
, TAG_TD
, "c", "head-vol");
470 print_text(h
, volume
);
473 print_otag(h
, TAG_TD
, "c", "head-rtitle");
474 print_text(h
, title
);
483 make_id(const struct roff_node
*n
)
485 const struct roff_node
*nch
;
488 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
)
489 if (nch
->type
!= ROFFT_TEXT
)
495 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
497 for (cp
= buf
; *cp
!= '\0'; cp
++)
505 mdoc_sh_pre(MDOC_ARGS
)
513 if (n
->sec
== SEC_AUTHORS
)
514 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
520 if ((id
= make_id(n
)) != NULL
) {
521 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
524 print_otag(h
, TAG_H1
, "c", "Sh");
530 mdoc_ss_pre(MDOC_ARGS
)
534 if (n
->type
!= ROFFT_HEAD
)
537 if ((id
= make_id(n
)) != NULL
) {
538 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
541 print_otag(h
, TAG_H2
, "c", "Ss");
547 mdoc_fl_pre(MDOC_ARGS
)
549 print_otag(h
, TAG_B
, "c", "Fl");
550 print_text(h
, "\\-");
552 if (!(n
->child
== NULL
&&
554 n
->next
->type
== ROFFT_TEXT
||
555 n
->next
->flags
& NODE_LINE
)))
556 h
->flags
|= HTML_NOSPACE
;
562 mdoc_cm_pre(MDOC_ARGS
)
564 print_otag(h
, TAG_B
, "c", "Cm");
569 mdoc_nd_pre(MDOC_ARGS
)
571 if (n
->type
!= ROFFT_BODY
)
574 /* XXX: this tag in theory can contain block elements. */
576 print_text(h
, "\\(em");
577 print_otag(h
, TAG_SPAN
, "c", "Nd");
582 mdoc_nm_pre(MDOC_ARGS
)
588 print_otag(h
, TAG_TD
, "");
591 print_otag(h
, TAG_B
, "c", "Nm");
592 if (n
->child
== NULL
&& meta
->name
!= NULL
)
593 print_text(h
, meta
->name
);
596 print_otag(h
, TAG_TD
, "");
603 print_otag(h
, TAG_TABLE
, "c", "Nm");
605 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
606 if (n
->type
== ROFFT_TEXT
)
607 len
+= html_strlen(n
->string
);
609 if (len
== 0 && meta
->name
!= NULL
)
610 len
= html_strlen(meta
->name
);
612 print_otag(h
, TAG_COL
, "shw", len
);
613 print_otag(h
, TAG_COL
, "");
614 print_otag(h
, TAG_TBODY
, "");
615 print_otag(h
, TAG_TR
, "");
620 mdoc_xr_pre(MDOC_ARGS
)
622 if (NULL
== n
->child
)
626 print_otag(h
, TAG_A
, "chM", "Xr",
627 n
->child
->string
, n
->child
->next
== NULL
?
628 NULL
: n
->child
->next
->string
);
630 print_otag(h
, TAG_A
, "c", "Xr");
633 print_text(h
, n
->string
);
635 if (NULL
== (n
= n
->next
))
638 h
->flags
|= HTML_NOSPACE
;
640 h
->flags
|= HTML_NOSPACE
;
641 print_text(h
, n
->string
);
642 h
->flags
|= HTML_NOSPACE
;
648 mdoc_ns_pre(MDOC_ARGS
)
651 if ( ! (NODE_LINE
& n
->flags
))
652 h
->flags
|= HTML_NOSPACE
;
657 mdoc_ar_pre(MDOC_ARGS
)
659 print_otag(h
, TAG_I
, "c", "Ar");
664 mdoc_xx_pre(MDOC_ARGS
)
666 print_otag(h
, TAG_SPAN
, "c", "Ux");
671 mdoc_it_pre(MDOC_ARGS
)
673 const struct roff_node
*bl
;
679 while (bl
!= NULL
&& bl
->tok
!= MDOC_Bl
)
681 type
= bl
->norm
->Bl
.type
;
729 if (bl
->norm
->Bl
.comp
)
730 print_otag(h
, TAG_LI
, "csvt", cattr
, 0);
732 print_otag(h
, TAG_LI
, "c", cattr
);
744 if (bl
->norm
->Bl
.comp
)
745 print_otag(h
, TAG_DT
, "csvt", cattr
, 0);
747 print_otag(h
, TAG_DT
, "c", cattr
);
748 if (type
== LIST_diag
)
749 print_otag(h
, TAG_B
, "c", cattr
);
752 if (bl
->norm
->Bl
.width
== NULL
)
753 print_otag(h
, TAG_DD
, "c", cattr
);
755 print_otag(h
, TAG_DD
, "cswl", cattr
,
765 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
766 (n
->parent
->prev
== NULL
||
767 n
->parent
->prev
->body
->child
!= NULL
)) {
768 if (bl
->norm
->Bl
.width
== NULL
)
769 t
= print_otag(h
, TAG_DT
, "c", cattr
);
771 t
= print_otag(h
, TAG_DT
, "csWl",
772 cattr
, bl
->norm
->Bl
.width
);
773 print_text(h
, "\\ ");
775 t
= print_otag(h
, TAG_DD
, "c", cattr
);
776 print_text(h
, "\\ ");
779 if (bl
->norm
->Bl
.width
== NULL
)
780 print_otag(h
, TAG_DT
, "c", cattr
);
782 print_otag(h
, TAG_DT
, "csWl", cattr
,
786 if (n
->child
== NULL
) {
787 print_otag(h
, TAG_DD
, "css?", cattr
,
789 print_text(h
, "\\ ");
791 print_otag(h
, TAG_DD
, "c", cattr
);
802 if (bl
->norm
->Bl
.comp
)
803 print_otag(h
, TAG_TD
, "csvt", cattr
, 0);
805 print_otag(h
, TAG_TD
, "c", cattr
);
808 print_otag(h
, TAG_TR
, "c", cattr
);
818 mdoc_bl_pre(MDOC_ARGS
)
822 enum htmltag elemtype
;
824 if (n
->type
== ROFFT_BODY
) {
825 if (LIST_column
== n
->norm
->Bl
.type
)
826 print_otag(h
, TAG_TBODY
, "");
830 if (n
->type
== ROFFT_HEAD
) {
831 if (LIST_column
!= n
->norm
->Bl
.type
)
835 * For each column, print out the <COL> tag with our
836 * suggested width. The last column gets min-width, as
837 * in terminal mode it auto-sizes to the width of the
838 * screen and we want to preserve that behaviour.
841 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
- 1; i
++)
842 print_otag(h
, TAG_COL
, "sww", n
->norm
->Bl
.cols
[i
]);
843 print_otag(h
, TAG_COL
, "swW", n
->norm
->Bl
.cols
[i
]);
848 switch (n
->norm
->Bl
.type
) {
884 if (n
->norm
->Bl
.offs
)
885 print_otag(h
, TAG_DIV
, "cswl", cattr
,
887 if (n
->norm
->Bl
.width
== NULL
)
888 print_otag(h
, TAG_DL
, "c", cattr
);
890 print_otag(h
, TAG_DL
, "cswl", cattr
,
894 elemtype
= TAG_TABLE
;
901 if (n
->norm
->Bl
.offs
)
902 print_otag(h
, elemtype
, "cswl", cattr
, n
->norm
->Bl
.offs
);
904 print_otag(h
, elemtype
, "c", cattr
);
910 mdoc_ex_pre(MDOC_ARGS
)
913 print_otag(h
, TAG_BR
, "");
918 mdoc_em_pre(MDOC_ARGS
)
920 print_otag(h
, TAG_I
, "c", "Em");
925 mdoc_d1_pre(MDOC_ARGS
)
927 if (n
->type
!= ROFFT_BLOCK
)
930 print_otag(h
, TAG_DIV
, "c", "D1");
932 if (n
->tok
== MDOC_Dl
)
933 print_otag(h
, TAG_CODE
, "c", "Li");
939 mdoc_sx_pre(MDOC_ARGS
)
943 if ((id
= make_id(n
)) != NULL
) {
944 print_otag(h
, TAG_A
, "chR", "Sx", id
);
947 print_otag(h
, TAG_A
, "c", "Sx");
953 mdoc_bd_pre(MDOC_ARGS
)
956 struct roff_node
*nn
;
958 if (n
->type
== ROFFT_HEAD
)
961 if (n
->type
== ROFFT_BLOCK
) {
962 comp
= n
->norm
->Bd
.comp
;
963 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
964 if (nn
->type
!= ROFFT_BLOCK
)
966 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
976 /* Handle the -offset argument. */
978 if (n
->norm
->Bd
.offs
== NULL
||
979 ! strcmp(n
->norm
->Bd
.offs
, "left"))
981 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
983 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
989 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
991 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
993 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
994 n
->norm
->Bd
.type
!= DISP_literal
)
997 print_otag(h
, TAG_PRE
, "c", "Li");
999 /* This can be recursive: save & set our literal state. */
1001 sv
= h
->flags
& HTML_LITERAL
;
1002 h
->flags
|= HTML_LITERAL
;
1004 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1005 print_mdoc_node(meta
, nn
, h
);
1007 * If the printed node flushes its own line, then we
1008 * needn't do it here as well. This is hacky, but the
1009 * notion of selective eoln whitespace is pretty dumb
1010 * anyway, so don't sweat it.
1025 if (h
->flags
& HTML_NONEWLINE
||
1026 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1029 print_text(h
, "\n");
1031 h
->flags
|= HTML_NOSPACE
;
1035 h
->flags
&= ~HTML_LITERAL
;
1041 mdoc_pa_pre(MDOC_ARGS
)
1043 print_otag(h
, TAG_I
, "c", "Pa");
1048 mdoc_ad_pre(MDOC_ARGS
)
1050 print_otag(h
, TAG_I
, "c", "Ad");
1055 mdoc_an_pre(MDOC_ARGS
)
1057 if (n
->norm
->An
.auth
== AUTH_split
) {
1058 h
->flags
&= ~HTML_NOSPLIT
;
1059 h
->flags
|= HTML_SPLIT
;
1062 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1063 h
->flags
&= ~HTML_SPLIT
;
1064 h
->flags
|= HTML_NOSPLIT
;
1068 if (h
->flags
& HTML_SPLIT
)
1069 print_otag(h
, TAG_BR
, "");
1071 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1072 h
->flags
|= HTML_SPLIT
;
1074 print_otag(h
, TAG_SPAN
, "c", "An");
1079 mdoc_cd_pre(MDOC_ARGS
)
1082 print_otag(h
, TAG_B
, "c", "Cd");
1087 mdoc_dv_pre(MDOC_ARGS
)
1089 print_otag(h
, TAG_CODE
, "c", "Dv");
1094 mdoc_ev_pre(MDOC_ARGS
)
1096 print_otag(h
, TAG_CODE
, "c", "Ev");
1101 mdoc_er_pre(MDOC_ARGS
)
1103 print_otag(h
, TAG_CODE
, "c", "Er");
1108 mdoc_fa_pre(MDOC_ARGS
)
1110 const struct roff_node
*nn
;
1113 if (n
->parent
->tok
!= MDOC_Fo
) {
1114 print_otag(h
, TAG_I
, "c", "Fa");
1118 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1119 t
= print_otag(h
, TAG_I
, "c", "Fa");
1120 print_text(h
, nn
->string
);
1123 h
->flags
|= HTML_NOSPACE
;
1128 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1129 h
->flags
|= HTML_NOSPACE
;
1137 mdoc_fd_pre(MDOC_ARGS
)
1144 if (NULL
== (n
= n
->child
))
1147 assert(n
->type
== ROFFT_TEXT
);
1149 if (strcmp(n
->string
, "#include")) {
1150 print_otag(h
, TAG_B
, "c", "Fd");
1154 print_otag(h
, TAG_B
, "c", "In");
1155 print_text(h
, n
->string
);
1157 if (NULL
!= (n
= n
->next
)) {
1158 assert(n
->type
== ROFFT_TEXT
);
1160 if (h
->base_includes
) {
1162 if (*cp
== '<' || *cp
== '"')
1164 buf
= mandoc_strdup(cp
);
1165 cp
= strchr(buf
, '\0') - 1;
1166 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1168 t
= print_otag(h
, TAG_A
, "chI", "In", buf
);
1171 t
= print_otag(h
, TAG_A
, "c", "In");
1173 print_text(h
, n
->string
);
1179 for ( ; n
; n
= n
->next
) {
1180 assert(n
->type
== ROFFT_TEXT
);
1181 print_text(h
, n
->string
);
1188 mdoc_vt_pre(MDOC_ARGS
)
1190 if (n
->type
== ROFFT_BLOCK
) {
1193 } else if (n
->type
== ROFFT_ELEM
) {
1195 } else if (n
->type
== ROFFT_HEAD
)
1198 print_otag(h
, TAG_I
, "c", "Vt");
1203 mdoc_ft_pre(MDOC_ARGS
)
1206 print_otag(h
, TAG_I
, "c", "Ft");
1211 mdoc_fn_pre(MDOC_ARGS
)
1215 const char *sp
, *ep
;
1218 pretty
= NODE_SYNPRETTY
& n
->flags
;
1221 /* Split apart into type and name. */
1222 assert(n
->child
->string
);
1223 sp
= n
->child
->string
;
1225 ep
= strchr(sp
, ' ');
1227 t
= print_otag(h
, TAG_I
, "c", "Ft");
1230 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1231 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1233 print_text(h
, nbuf
);
1235 ep
= strchr(sp
, ' ');
1240 t
= print_otag(h
, TAG_B
, "c", "Fn");
1247 h
->flags
|= HTML_NOSPACE
;
1249 h
->flags
|= HTML_NOSPACE
;
1251 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1252 if (NODE_SYNPRETTY
& n
->flags
)
1253 t
= print_otag(h
, TAG_I
, "css?", "Fa",
1254 "white-space", "nowrap");
1256 t
= print_otag(h
, TAG_I
, "c", "Fa");
1257 print_text(h
, n
->string
);
1260 h
->flags
|= HTML_NOSPACE
;
1265 h
->flags
|= HTML_NOSPACE
;
1269 h
->flags
|= HTML_NOSPACE
;
1277 mdoc_sm_pre(MDOC_ARGS
)
1280 if (NULL
== n
->child
)
1281 h
->flags
^= HTML_NONOSPACE
;
1282 else if (0 == strcmp("on", n
->child
->string
))
1283 h
->flags
&= ~HTML_NONOSPACE
;
1285 h
->flags
|= HTML_NONOSPACE
;
1287 if ( ! (HTML_NONOSPACE
& h
->flags
))
1288 h
->flags
&= ~HTML_NOSPACE
;
1294 mdoc_skip_pre(MDOC_ARGS
)
1301 mdoc_pp_pre(MDOC_ARGS
)
1309 mdoc_sp_pre(MDOC_ARGS
)
1313 SCALE_VS_INIT(&su
, 1);
1315 if (MDOC_sp
== n
->tok
) {
1316 if (NULL
!= (n
= n
->child
)) {
1317 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1319 else if (su
.scale
< 0.0)
1325 print_otag(h
, TAG_DIV
, "suh", &su
);
1327 /* So the div isn't empty: */
1328 print_text(h
, "\\~");
1335 mdoc_lk_pre(MDOC_ARGS
)
1337 if (NULL
== (n
= n
->child
))
1340 assert(n
->type
== ROFFT_TEXT
);
1342 print_otag(h
, TAG_A
, "ch", "Lk", n
->string
);
1344 if (NULL
== n
->next
)
1345 print_text(h
, n
->string
);
1347 for (n
= n
->next
; n
; n
= n
->next
)
1348 print_text(h
, n
->string
);
1354 mdoc_mt_pre(MDOC_ARGS
)
1359 for (n
= n
->child
; n
; n
= n
->next
) {
1360 assert(n
->type
== ROFFT_TEXT
);
1362 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1363 t
= print_otag(h
, TAG_A
, "ch", "Mt", cp
);
1364 print_text(h
, n
->string
);
1373 mdoc_fo_pre(MDOC_ARGS
)
1377 if (n
->type
== ROFFT_BODY
) {
1378 h
->flags
|= HTML_NOSPACE
;
1380 h
->flags
|= HTML_NOSPACE
;
1382 } else if (n
->type
== ROFFT_BLOCK
) {
1387 if (n
->child
== NULL
)
1390 assert(n
->child
->string
);
1391 t
= print_otag(h
, TAG_B
, "c", "Fn");
1392 print_text(h
, n
->child
->string
);
1398 mdoc_fo_post(MDOC_ARGS
)
1401 if (n
->type
!= ROFFT_BODY
)
1403 h
->flags
|= HTML_NOSPACE
;
1405 h
->flags
|= HTML_NOSPACE
;
1410 mdoc_in_pre(MDOC_ARGS
)
1415 print_otag(h
, TAG_B
, "c", "In");
1418 * The first argument of the `In' gets special treatment as
1419 * being a linked value. Subsequent values are printed
1420 * afterward. groff does similarly. This also handles the case
1424 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1425 print_text(h
, "#include");
1428 h
->flags
|= HTML_NOSPACE
;
1430 if (NULL
!= (n
= n
->child
)) {
1431 assert(n
->type
== ROFFT_TEXT
);
1433 if (h
->base_includes
)
1434 t
= print_otag(h
, TAG_A
, "chI", "In", n
->string
);
1436 t
= print_otag(h
, TAG_A
, "c", "In");
1437 print_text(h
, n
->string
);
1443 h
->flags
|= HTML_NOSPACE
;
1446 for ( ; n
; n
= n
->next
) {
1447 assert(n
->type
== ROFFT_TEXT
);
1448 print_text(h
, n
->string
);
1455 mdoc_ic_pre(MDOC_ARGS
)
1457 print_otag(h
, TAG_B
, "c", "Ic");
1462 mdoc_va_pre(MDOC_ARGS
)
1464 print_otag(h
, TAG_I
, "c", "Va");
1469 mdoc_ap_pre(MDOC_ARGS
)
1472 h
->flags
|= HTML_NOSPACE
;
1473 print_text(h
, "\\(aq");
1474 h
->flags
|= HTML_NOSPACE
;
1479 mdoc_bf_pre(MDOC_ARGS
)
1483 if (n
->type
== ROFFT_HEAD
)
1485 else if (n
->type
!= ROFFT_BODY
)
1488 if (FONT_Em
== n
->norm
->Bf
.font
)
1490 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1492 else if (FONT_Li
== n
->norm
->Bf
.font
)
1498 * We want this to be inline-formatted, but needs to be div to
1499 * accept block children.
1502 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1507 mdoc_ms_pre(MDOC_ARGS
)
1509 print_otag(h
, TAG_B
, "c", "Ms");
1514 mdoc_igndelim_pre(MDOC_ARGS
)
1517 h
->flags
|= HTML_IGNDELIM
;
1522 mdoc_pf_post(MDOC_ARGS
)
1525 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1526 h
->flags
|= HTML_NOSPACE
;
1530 mdoc_rs_pre(MDOC_ARGS
)
1532 if (n
->type
!= ROFFT_BLOCK
)
1535 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1538 print_otag(h
, TAG_SPAN
, "c", "Rs");
1543 mdoc_no_pre(MDOC_ARGS
)
1545 print_otag(h
, TAG_SPAN
, "c", "No");
1550 mdoc_li_pre(MDOC_ARGS
)
1552 print_otag(h
, TAG_CODE
, "c", "Li");
1557 mdoc_sy_pre(MDOC_ARGS
)
1559 print_otag(h
, TAG_B
, "c", "Sy");
1564 mdoc_lb_pre(MDOC_ARGS
)
1566 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1567 print_otag(h
, TAG_BR
, "");
1569 print_otag(h
, TAG_SPAN
, "c", "Lb");
1574 mdoc__x_pre(MDOC_ARGS
)
1584 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1585 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1586 print_text(h
, "and");
1625 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1634 print_otag(h
, t
, "c", cattr
);
1639 mdoc__x_post(MDOC_ARGS
)
1642 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1643 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1644 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1649 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1652 h
->flags
|= HTML_NOSPACE
;
1653 print_text(h
, n
->next
? "," : ".");
1657 mdoc_bk_pre(MDOC_ARGS
)
1666 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1667 h
->flags
|= HTML_PREKEEP
;
1677 mdoc_bk_post(MDOC_ARGS
)
1680 if (n
->type
== ROFFT_BODY
)
1681 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1685 mdoc_quote_pre(MDOC_ARGS
)
1687 if (n
->type
!= ROFFT_BODY
)
1693 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1694 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1698 print_text(h
, "\\(lC");
1702 print_text(h
, "\\(lB");
1706 print_text(h
, "\\(lB");
1707 h
->flags
|= HTML_NOSPACE
;
1708 print_otag(h
, TAG_SPAN
, "c", "Op");
1711 if (NULL
== n
->norm
->Es
||
1712 NULL
== n
->norm
->Es
->child
)
1714 print_text(h
, n
->norm
->Es
->child
->string
);
1720 print_text(h
, "\\(lq");
1727 print_text(h
, "\\(oq");
1728 h
->flags
|= HTML_NOSPACE
;
1729 print_otag(h
, TAG_CODE
, "c", "Li");
1733 print_text(h
, "\\(oq");
1739 h
->flags
|= HTML_NOSPACE
;
1744 mdoc_quote_post(MDOC_ARGS
)
1747 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1750 h
->flags
|= HTML_NOSPACE
;
1755 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1756 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1760 print_text(h
, "\\(rC");
1766 print_text(h
, "\\(rB");
1769 if (n
->norm
->Es
== NULL
||
1770 n
->norm
->Es
->child
== NULL
||
1771 n
->norm
->Es
->child
->next
== NULL
)
1772 h
->flags
&= ~HTML_NOSPACE
;
1774 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1780 print_text(h
, "\\(rq");
1789 print_text(h
, "\\(cq");
1797 mdoc_eo_pre(MDOC_ARGS
)
1800 if (n
->type
!= ROFFT_BODY
)
1803 if (n
->end
== ENDBODY_NOT
&&
1804 n
->parent
->head
->child
== NULL
&&
1806 n
->child
->end
!= ENDBODY_NOT
)
1807 print_text(h
, "\\&");
1808 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1809 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1810 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1811 h
->flags
|= HTML_NOSPACE
;
1816 mdoc_eo_post(MDOC_ARGS
)
1820 if (n
->type
!= ROFFT_BODY
)
1823 if (n
->end
!= ENDBODY_NOT
) {
1824 h
->flags
&= ~HTML_NOSPACE
;
1828 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1829 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1832 h
->flags
|= HTML_NOSPACE
;
1834 h
->flags
&= ~HTML_NOSPACE
;