]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
6d0d89bf50664bfc2c17a0cd5c3d3ed7d8de602e
1 /* $Id: mdoc_html.c,v 1.274 2017/03/13 19:01:38 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_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 make_id(const struct roff_node
*n
)
482 const struct roff_node
*nch
;
485 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
)
486 if (nch
->type
!= ROFFT_TEXT
)
492 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
494 for (cp
= buf
; *cp
!= '\0'; cp
++)
502 mdoc_sh_pre(MDOC_ARGS
)
509 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
513 if (n
->sec
== SEC_AUTHORS
)
514 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
523 mdoc_ss_pre(MDOC_ARGS
)
527 if (n
->type
!= ROFFT_HEAD
)
531 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
537 mdoc_fl_pre(MDOC_ARGS
)
539 print_otag(h
, TAG_B
, "cT", "Fl");
540 print_text(h
, "\\-");
542 if (!(n
->child
== NULL
&&
544 n
->next
->type
== ROFFT_TEXT
||
545 n
->next
->flags
& NODE_LINE
)))
546 h
->flags
|= HTML_NOSPACE
;
552 mdoc_cm_pre(MDOC_ARGS
)
554 print_otag(h
, TAG_B
, "cT", "Cm");
559 mdoc_nd_pre(MDOC_ARGS
)
561 if (n
->type
!= ROFFT_BODY
)
564 /* XXX: this tag in theory can contain block elements. */
566 print_text(h
, "\\(em");
567 print_otag(h
, TAG_SPAN
, "cT", "Nd");
572 mdoc_nm_pre(MDOC_ARGS
)
579 print_otag(h
, TAG_TD
, "");
582 print_otag(h
, TAG_B
, "cT", "Nm");
585 print_otag(h
, TAG_TD
, "");
592 print_otag(h
, TAG_TABLE
, "c", "Nm");
594 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
595 if (n
->type
== ROFFT_TEXT
)
596 len
+= html_strlen(n
->string
);
598 if (len
== 0 && meta
->name
!= NULL
)
599 len
= html_strlen(meta
->name
);
601 t
= print_otag(h
, TAG_COLGROUP
, "");
602 print_otag(h
, TAG_COL
, "shw", len
);
603 print_otag(h
, TAG_COL
, "");
605 print_otag(h
, TAG_TR
, "");
610 mdoc_xr_pre(MDOC_ARGS
)
612 if (NULL
== n
->child
)
616 print_otag(h
, TAG_A
, "cThM", "Xr",
617 n
->child
->string
, n
->child
->next
== NULL
?
618 NULL
: n
->child
->next
->string
);
620 print_otag(h
, TAG_A
, "cT", "Xr");
623 print_text(h
, n
->string
);
625 if (NULL
== (n
= n
->next
))
628 h
->flags
|= HTML_NOSPACE
;
630 h
->flags
|= HTML_NOSPACE
;
631 print_text(h
, n
->string
);
632 h
->flags
|= HTML_NOSPACE
;
638 mdoc_ns_pre(MDOC_ARGS
)
641 if ( ! (NODE_LINE
& n
->flags
))
642 h
->flags
|= HTML_NOSPACE
;
647 mdoc_ar_pre(MDOC_ARGS
)
649 print_otag(h
, TAG_VAR
, "cT", "Ar");
654 mdoc_xx_pre(MDOC_ARGS
)
656 print_otag(h
, TAG_SPAN
, "c", "Ux");
661 mdoc_it_pre(MDOC_ARGS
)
663 const struct roff_node
*bl
;
669 while (bl
->tok
!= MDOC_Bl
)
671 type
= bl
->norm
->Bl
.type
;
719 if (bl
->norm
->Bl
.comp
)
720 print_otag(h
, TAG_LI
, "csvt", cattr
, 0);
722 print_otag(h
, TAG_LI
, "c", cattr
);
734 if (bl
->norm
->Bl
.comp
)
735 print_otag(h
, TAG_DT
, "csvt", cattr
, 0);
737 print_otag(h
, TAG_DT
, "c", cattr
);
738 if (type
== LIST_diag
)
739 print_otag(h
, TAG_B
, "c", cattr
);
742 print_otag(h
, TAG_DD
, "cswl", cattr
,
752 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
753 (n
->parent
->prev
== NULL
||
754 n
->parent
->prev
->body
== NULL
||
755 n
->parent
->prev
->body
->child
!= NULL
)) {
756 t
= print_otag(h
, TAG_DT
, "csWl",
757 cattr
, bl
->norm
->Bl
.width
);
758 print_text(h
, "\\ ");
760 t
= print_otag(h
, TAG_DD
, "c", cattr
);
761 print_text(h
, "\\ ");
764 print_otag(h
, TAG_DT
, "csWl", cattr
,
768 if (n
->child
== NULL
) {
769 print_otag(h
, TAG_DD
, "css?", cattr
,
771 print_text(h
, "\\ ");
773 print_otag(h
, TAG_DD
, "c", cattr
);
784 if (bl
->norm
->Bl
.comp
)
785 print_otag(h
, TAG_TD
, "csvt", cattr
, 0);
787 print_otag(h
, TAG_TD
, "c", cattr
);
790 print_otag(h
, TAG_TR
, "c", cattr
);
800 mdoc_bl_pre(MDOC_ARGS
)
806 enum htmltag elemtype
;
815 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
819 * For each column, print out the <COL> tag with our
820 * suggested width. The last column gets min-width, as
821 * in terminal mode it auto-sizes to the width of the
822 * screen and we want to preserve that behaviour.
825 t
= print_otag(h
, TAG_COLGROUP
, "");
826 for (i
= 0; i
< bl
->ncols
- 1; i
++)
827 print_otag(h
, TAG_COL
, "sww", bl
->cols
[i
]);
828 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
873 print_otag(h
, TAG_DIV
, "cswl", cattr
, bl
->offs
);
874 print_otag(h
, TAG_DL
, "cswl", cattr
, bl
->width
);
877 elemtype
= TAG_TABLE
;
883 print_otag(h
, elemtype
, "cswl", cattr
, bl
->offs
);
888 mdoc_ex_pre(MDOC_ARGS
)
891 print_otag(h
, TAG_BR
, "");
896 mdoc_st_pre(MDOC_ARGS
)
898 print_otag(h
, TAG_SPAN
, "cT", "St");
903 mdoc_em_pre(MDOC_ARGS
)
905 print_otag(h
, TAG_I
, "cT", "Em");
910 mdoc_d1_pre(MDOC_ARGS
)
912 if (n
->type
!= ROFFT_BLOCK
)
915 print_otag(h
, TAG_DIV
, "c", "D1");
917 if (n
->tok
== MDOC_Dl
)
918 print_otag(h
, TAG_CODE
, "c", "Li");
924 mdoc_sx_pre(MDOC_ARGS
)
929 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
935 mdoc_bd_pre(MDOC_ARGS
)
938 struct roff_node
*nn
;
940 if (n
->type
== ROFFT_HEAD
)
943 if (n
->type
== ROFFT_BLOCK
) {
944 comp
= n
->norm
->Bd
.comp
;
945 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
946 if (nn
->type
!= ROFFT_BLOCK
)
948 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
958 /* Handle the -offset argument. */
960 if (n
->norm
->Bd
.offs
== NULL
||
961 ! strcmp(n
->norm
->Bd
.offs
, "left"))
963 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
965 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
971 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
973 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
975 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
976 n
->norm
->Bd
.type
!= DISP_literal
)
979 print_otag(h
, TAG_PRE
, "c", "Li");
981 /* This can be recursive: save & set our literal state. */
983 sv
= h
->flags
& HTML_LITERAL
;
984 h
->flags
|= HTML_LITERAL
;
986 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
987 print_mdoc_node(meta
, nn
, h
);
989 * If the printed node flushes its own line, then we
990 * needn't do it here as well. This is hacky, but the
991 * notion of selective eoln whitespace is pretty dumb
992 * anyway, so don't sweat it.
1007 if (h
->flags
& HTML_NONEWLINE
||
1008 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1011 print_text(h
, "\n");
1013 h
->flags
|= HTML_NOSPACE
;
1017 h
->flags
&= ~HTML_LITERAL
;
1023 mdoc_pa_pre(MDOC_ARGS
)
1025 print_otag(h
, TAG_I
, "cT", "Pa");
1030 mdoc_ad_pre(MDOC_ARGS
)
1032 print_otag(h
, TAG_I
, "c", "Ad");
1037 mdoc_an_pre(MDOC_ARGS
)
1039 if (n
->norm
->An
.auth
== AUTH_split
) {
1040 h
->flags
&= ~HTML_NOSPLIT
;
1041 h
->flags
|= HTML_SPLIT
;
1044 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1045 h
->flags
&= ~HTML_SPLIT
;
1046 h
->flags
|= HTML_NOSPLIT
;
1050 if (h
->flags
& HTML_SPLIT
)
1051 print_otag(h
, TAG_BR
, "");
1053 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1054 h
->flags
|= HTML_SPLIT
;
1056 print_otag(h
, TAG_SPAN
, "cT", "An");
1061 mdoc_cd_pre(MDOC_ARGS
)
1064 print_otag(h
, TAG_B
, "cT", "Cd");
1069 mdoc_dv_pre(MDOC_ARGS
)
1071 print_otag(h
, TAG_CODE
, "cT", "Dv");
1076 mdoc_ev_pre(MDOC_ARGS
)
1078 print_otag(h
, TAG_CODE
, "cT", "Ev");
1083 mdoc_er_pre(MDOC_ARGS
)
1085 print_otag(h
, TAG_CODE
, "cT", "Er");
1090 mdoc_fa_pre(MDOC_ARGS
)
1092 const struct roff_node
*nn
;
1095 if (n
->parent
->tok
!= MDOC_Fo
) {
1096 print_otag(h
, TAG_VAR
, "cT", "Fa");
1100 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1101 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1102 print_text(h
, nn
->string
);
1105 h
->flags
|= HTML_NOSPACE
;
1110 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1111 h
->flags
|= HTML_NOSPACE
;
1119 mdoc_fd_pre(MDOC_ARGS
)
1126 if (NULL
== (n
= n
->child
))
1129 assert(n
->type
== ROFFT_TEXT
);
1131 if (strcmp(n
->string
, "#include")) {
1132 print_otag(h
, TAG_B
, "cT", "Fd");
1136 print_otag(h
, TAG_B
, "cT", "In");
1137 print_text(h
, n
->string
);
1139 if (NULL
!= (n
= n
->next
)) {
1140 assert(n
->type
== ROFFT_TEXT
);
1142 if (h
->base_includes
) {
1144 if (*cp
== '<' || *cp
== '"')
1146 buf
= mandoc_strdup(cp
);
1147 cp
= strchr(buf
, '\0') - 1;
1148 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1150 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1153 t
= print_otag(h
, TAG_A
, "cT", "In");
1155 print_text(h
, n
->string
);
1161 for ( ; n
; n
= n
->next
) {
1162 assert(n
->type
== ROFFT_TEXT
);
1163 print_text(h
, n
->string
);
1170 mdoc_vt_pre(MDOC_ARGS
)
1172 if (n
->type
== ROFFT_BLOCK
) {
1175 } else if (n
->type
== ROFFT_ELEM
) {
1177 } else if (n
->type
== ROFFT_HEAD
)
1180 print_otag(h
, TAG_VAR
, "cT", "Vt");
1185 mdoc_ft_pre(MDOC_ARGS
)
1188 print_otag(h
, TAG_VAR
, "cT", "Ft");
1193 mdoc_fn_pre(MDOC_ARGS
)
1197 const char *sp
, *ep
;
1200 pretty
= NODE_SYNPRETTY
& n
->flags
;
1203 /* Split apart into type and name. */
1204 assert(n
->child
->string
);
1205 sp
= n
->child
->string
;
1207 ep
= strchr(sp
, ' ');
1209 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1212 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1213 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1215 print_text(h
, nbuf
);
1217 ep
= strchr(sp
, ' ');
1222 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1229 h
->flags
|= HTML_NOSPACE
;
1231 h
->flags
|= HTML_NOSPACE
;
1233 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1234 if (NODE_SYNPRETTY
& n
->flags
)
1235 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1236 "white-space", "nowrap");
1238 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1239 print_text(h
, n
->string
);
1242 h
->flags
|= HTML_NOSPACE
;
1247 h
->flags
|= HTML_NOSPACE
;
1251 h
->flags
|= HTML_NOSPACE
;
1259 mdoc_sm_pre(MDOC_ARGS
)
1262 if (NULL
== n
->child
)
1263 h
->flags
^= HTML_NONOSPACE
;
1264 else if (0 == strcmp("on", n
->child
->string
))
1265 h
->flags
&= ~HTML_NONOSPACE
;
1267 h
->flags
|= HTML_NONOSPACE
;
1269 if ( ! (HTML_NONOSPACE
& h
->flags
))
1270 h
->flags
&= ~HTML_NOSPACE
;
1276 mdoc_skip_pre(MDOC_ARGS
)
1283 mdoc_pp_pre(MDOC_ARGS
)
1291 mdoc_sp_pre(MDOC_ARGS
)
1295 SCALE_VS_INIT(&su
, 1);
1297 if (MDOC_sp
== n
->tok
) {
1298 if (NULL
!= (n
= n
->child
)) {
1299 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1301 else if (su
.scale
< 0.0)
1307 print_otag(h
, TAG_DIV
, "suh", &su
);
1309 /* So the div isn't empty: */
1310 print_text(h
, "\\~");
1317 mdoc_lk_pre(MDOC_ARGS
)
1319 if (NULL
== (n
= n
->child
))
1322 assert(n
->type
== ROFFT_TEXT
);
1324 print_otag(h
, TAG_A
, "cTh", "Lk", n
->string
);
1326 if (NULL
== n
->next
)
1327 print_text(h
, n
->string
);
1329 for (n
= n
->next
; n
; n
= n
->next
)
1330 print_text(h
, n
->string
);
1336 mdoc_mt_pre(MDOC_ARGS
)
1341 for (n
= n
->child
; n
; n
= n
->next
) {
1342 assert(n
->type
== ROFFT_TEXT
);
1344 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1345 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1346 print_text(h
, n
->string
);
1355 mdoc_fo_pre(MDOC_ARGS
)
1359 if (n
->type
== ROFFT_BODY
) {
1360 h
->flags
|= HTML_NOSPACE
;
1362 h
->flags
|= HTML_NOSPACE
;
1364 } else if (n
->type
== ROFFT_BLOCK
) {
1369 if (n
->child
== NULL
)
1372 assert(n
->child
->string
);
1373 t
= print_otag(h
, TAG_B
, "cT", "Fn");
1374 print_text(h
, n
->child
->string
);
1380 mdoc_fo_post(MDOC_ARGS
)
1383 if (n
->type
!= ROFFT_BODY
)
1385 h
->flags
|= HTML_NOSPACE
;
1387 h
->flags
|= HTML_NOSPACE
;
1392 mdoc_in_pre(MDOC_ARGS
)
1397 print_otag(h
, TAG_B
, "cT", "In");
1400 * The first argument of the `In' gets special treatment as
1401 * being a linked value. Subsequent values are printed
1402 * afterward. groff does similarly. This also handles the case
1406 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1407 print_text(h
, "#include");
1410 h
->flags
|= HTML_NOSPACE
;
1412 if (NULL
!= (n
= n
->child
)) {
1413 assert(n
->type
== ROFFT_TEXT
);
1415 if (h
->base_includes
)
1416 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1418 t
= print_otag(h
, TAG_A
, "cT", "In");
1419 print_text(h
, n
->string
);
1425 h
->flags
|= HTML_NOSPACE
;
1428 for ( ; n
; n
= n
->next
) {
1429 assert(n
->type
== ROFFT_TEXT
);
1430 print_text(h
, n
->string
);
1437 mdoc_ic_pre(MDOC_ARGS
)
1439 print_otag(h
, TAG_B
, "cT", "Ic");
1444 mdoc_va_pre(MDOC_ARGS
)
1446 print_otag(h
, TAG_VAR
, "cT", "Va");
1451 mdoc_ap_pre(MDOC_ARGS
)
1454 h
->flags
|= HTML_NOSPACE
;
1455 print_text(h
, "\\(aq");
1456 h
->flags
|= HTML_NOSPACE
;
1461 mdoc_bf_pre(MDOC_ARGS
)
1465 if (n
->type
== ROFFT_HEAD
)
1467 else if (n
->type
!= ROFFT_BODY
)
1470 if (FONT_Em
== n
->norm
->Bf
.font
)
1472 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1474 else if (FONT_Li
== n
->norm
->Bf
.font
)
1480 * We want this to be inline-formatted, but needs to be div to
1481 * accept block children.
1484 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1489 mdoc_ms_pre(MDOC_ARGS
)
1491 print_otag(h
, TAG_B
, "cT", "Ms");
1496 mdoc_igndelim_pre(MDOC_ARGS
)
1499 h
->flags
|= HTML_IGNDELIM
;
1504 mdoc_pf_post(MDOC_ARGS
)
1507 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1508 h
->flags
|= HTML_NOSPACE
;
1512 mdoc_rs_pre(MDOC_ARGS
)
1514 if (n
->type
!= ROFFT_BLOCK
)
1517 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1520 print_otag(h
, TAG_CITE
, "cT", "Rs");
1525 mdoc_no_pre(MDOC_ARGS
)
1527 print_otag(h
, TAG_SPAN
, "c", "No");
1532 mdoc_li_pre(MDOC_ARGS
)
1534 print_otag(h
, TAG_CODE
, "c", "Li");
1539 mdoc_sy_pre(MDOC_ARGS
)
1541 print_otag(h
, TAG_B
, "cT", "Sy");
1546 mdoc_lb_pre(MDOC_ARGS
)
1548 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1549 print_otag(h
, TAG_BR
, "");
1551 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1556 mdoc__x_pre(MDOC_ARGS
)
1566 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1567 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1568 print_text(h
, "and");
1607 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1616 print_otag(h
, t
, "c", cattr
);
1621 mdoc__x_post(MDOC_ARGS
)
1624 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1625 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1626 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1631 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1634 h
->flags
|= HTML_NOSPACE
;
1635 print_text(h
, n
->next
? "," : ".");
1639 mdoc_bk_pre(MDOC_ARGS
)
1648 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1649 h
->flags
|= HTML_PREKEEP
;
1659 mdoc_bk_post(MDOC_ARGS
)
1662 if (n
->type
== ROFFT_BODY
)
1663 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1667 mdoc_quote_pre(MDOC_ARGS
)
1669 if (n
->type
!= ROFFT_BODY
)
1675 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1676 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1680 print_text(h
, "\\(lC");
1684 print_text(h
, "\\(lB");
1688 print_text(h
, "\\(lB");
1689 h
->flags
|= HTML_NOSPACE
;
1690 print_otag(h
, TAG_SPAN
, "c", "Op");
1693 if (NULL
== n
->norm
->Es
||
1694 NULL
== n
->norm
->Es
->child
)
1696 print_text(h
, n
->norm
->Es
->child
->string
);
1702 print_text(h
, "\\(lq");
1709 print_text(h
, "\\(oq");
1710 h
->flags
|= HTML_NOSPACE
;
1711 print_otag(h
, TAG_CODE
, "c", "Li");
1715 print_text(h
, "\\(oq");
1721 h
->flags
|= HTML_NOSPACE
;
1726 mdoc_quote_post(MDOC_ARGS
)
1729 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1732 h
->flags
|= HTML_NOSPACE
;
1737 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1738 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1742 print_text(h
, "\\(rC");
1748 print_text(h
, "\\(rB");
1751 if (n
->norm
->Es
== NULL
||
1752 n
->norm
->Es
->child
== NULL
||
1753 n
->norm
->Es
->child
->next
== NULL
)
1754 h
->flags
&= ~HTML_NOSPACE
;
1756 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1762 print_text(h
, "\\(rq");
1771 print_text(h
, "\\(cq");
1779 mdoc_eo_pre(MDOC_ARGS
)
1782 if (n
->type
!= ROFFT_BODY
)
1785 if (n
->end
== ENDBODY_NOT
&&
1786 n
->parent
->head
->child
== NULL
&&
1788 n
->child
->end
!= ENDBODY_NOT
)
1789 print_text(h
, "\\&");
1790 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1791 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1792 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1793 h
->flags
|= HTML_NOSPACE
;
1798 mdoc_eo_post(MDOC_ARGS
)
1802 if (n
->type
!= ROFFT_BODY
)
1805 if (n
->end
!= ENDBODY_NOT
) {
1806 h
->flags
&= ~HTML_NOSPACE
;
1810 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1811 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1814 h
->flags
|= HTML_NOSPACE
;
1816 h
->flags
&= ~HTML_NOSPACE
;