1 /* $Id: mdoc_html.c,v 1.240 2016/01/08 17:48:09 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2016 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 void print_mdoc_head(MDOC_ARGS
);
52 static void print_mdoc_node(MDOC_ARGS
);
53 static void print_mdoc_nodelist(MDOC_ARGS
);
54 static void synopsis_pre(struct html
*,
55 const struct roff_node
*);
57 static void a2width(const char *, struct roffsu
*);
59 static void mdoc_root_post(MDOC_ARGS
);
60 static int mdoc_root_pre(MDOC_ARGS
);
62 static void mdoc__x_post(MDOC_ARGS
);
63 static int mdoc__x_pre(MDOC_ARGS
);
64 static int mdoc_ad_pre(MDOC_ARGS
);
65 static int mdoc_an_pre(MDOC_ARGS
);
66 static int mdoc_ap_pre(MDOC_ARGS
);
67 static int mdoc_ar_pre(MDOC_ARGS
);
68 static int mdoc_bd_pre(MDOC_ARGS
);
69 static int mdoc_bf_pre(MDOC_ARGS
);
70 static void mdoc_bk_post(MDOC_ARGS
);
71 static int mdoc_bk_pre(MDOC_ARGS
);
72 static int mdoc_bl_pre(MDOC_ARGS
);
73 static int mdoc_bt_pre(MDOC_ARGS
);
74 static int mdoc_bx_pre(MDOC_ARGS
);
75 static int mdoc_cd_pre(MDOC_ARGS
);
76 static int mdoc_d1_pre(MDOC_ARGS
);
77 static int mdoc_dv_pre(MDOC_ARGS
);
78 static int mdoc_fa_pre(MDOC_ARGS
);
79 static int mdoc_fd_pre(MDOC_ARGS
);
80 static int mdoc_fl_pre(MDOC_ARGS
);
81 static int mdoc_fn_pre(MDOC_ARGS
);
82 static int mdoc_ft_pre(MDOC_ARGS
);
83 static int mdoc_em_pre(MDOC_ARGS
);
84 static void mdoc_eo_post(MDOC_ARGS
);
85 static int mdoc_eo_pre(MDOC_ARGS
);
86 static int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_igndelim_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_pre(MDOC_ARGS
);
95 static int mdoc_lb_pre(MDOC_ARGS
);
96 static int mdoc_li_pre(MDOC_ARGS
);
97 static int mdoc_lk_pre(MDOC_ARGS
);
98 static int mdoc_mt_pre(MDOC_ARGS
);
99 static int mdoc_ms_pre(MDOC_ARGS
);
100 static int mdoc_nd_pre(MDOC_ARGS
);
101 static int mdoc_nm_pre(MDOC_ARGS
);
102 static int mdoc_no_pre(MDOC_ARGS
);
103 static int mdoc_ns_pre(MDOC_ARGS
);
104 static int mdoc_pa_pre(MDOC_ARGS
);
105 static void mdoc_pf_post(MDOC_ARGS
);
106 static int mdoc_pp_pre(MDOC_ARGS
);
107 static void mdoc_quote_post(MDOC_ARGS
);
108 static int mdoc_quote_pre(MDOC_ARGS
);
109 static int mdoc_rs_pre(MDOC_ARGS
);
110 static int mdoc_rv_pre(MDOC_ARGS
);
111 static int mdoc_sh_pre(MDOC_ARGS
);
112 static int mdoc_skip_pre(MDOC_ARGS
);
113 static int mdoc_sm_pre(MDOC_ARGS
);
114 static int mdoc_sp_pre(MDOC_ARGS
);
115 static int mdoc_ss_pre(MDOC_ARGS
);
116 static int mdoc_sx_pre(MDOC_ARGS
);
117 static int mdoc_sy_pre(MDOC_ARGS
);
118 static int mdoc_ud_pre(MDOC_ARGS
);
119 static int mdoc_va_pre(MDOC_ARGS
);
120 static int mdoc_vt_pre(MDOC_ARGS
);
121 static int mdoc_xr_pre(MDOC_ARGS
);
122 static int mdoc_xx_pre(MDOC_ARGS
);
124 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
125 {mdoc_ap_pre
, NULL
}, /* Ap */
126 {NULL
, NULL
}, /* Dd */
127 {NULL
, NULL
}, /* Dt */
128 {NULL
, NULL
}, /* Os */
129 {mdoc_sh_pre
, NULL
}, /* Sh */
130 {mdoc_ss_pre
, NULL
}, /* Ss */
131 {mdoc_pp_pre
, NULL
}, /* Pp */
132 {mdoc_d1_pre
, NULL
}, /* D1 */
133 {mdoc_d1_pre
, NULL
}, /* Dl */
134 {mdoc_bd_pre
, NULL
}, /* Bd */
135 {NULL
, NULL
}, /* Ed */
136 {mdoc_bl_pre
, NULL
}, /* Bl */
137 {NULL
, NULL
}, /* El */
138 {mdoc_it_pre
, NULL
}, /* It */
139 {mdoc_ad_pre
, NULL
}, /* Ad */
140 {mdoc_an_pre
, NULL
}, /* An */
141 {mdoc_ar_pre
, NULL
}, /* Ar */
142 {mdoc_cd_pre
, NULL
}, /* Cd */
143 {mdoc_fl_pre
, NULL
}, /* Cm */
144 {mdoc_dv_pre
, NULL
}, /* Dv */
145 {mdoc_er_pre
, NULL
}, /* Er */
146 {mdoc_ev_pre
, NULL
}, /* Ev */
147 {mdoc_ex_pre
, NULL
}, /* Ex */
148 {mdoc_fa_pre
, NULL
}, /* Fa */
149 {mdoc_fd_pre
, NULL
}, /* Fd */
150 {mdoc_fl_pre
, NULL
}, /* Fl */
151 {mdoc_fn_pre
, NULL
}, /* Fn */
152 {mdoc_ft_pre
, NULL
}, /* Ft */
153 {mdoc_ic_pre
, NULL
}, /* Ic */
154 {mdoc_in_pre
, NULL
}, /* In */
155 {mdoc_li_pre
, NULL
}, /* Li */
156 {mdoc_nd_pre
, NULL
}, /* Nd */
157 {mdoc_nm_pre
, NULL
}, /* Nm */
158 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
159 {mdoc_ft_pre
, NULL
}, /* Ot */
160 {mdoc_pa_pre
, NULL
}, /* Pa */
161 {mdoc_rv_pre
, NULL
}, /* Rv */
162 {NULL
, NULL
}, /* St */
163 {mdoc_va_pre
, NULL
}, /* Va */
164 {mdoc_vt_pre
, NULL
}, /* Vt */
165 {mdoc_xr_pre
, NULL
}, /* Xr */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
177 {NULL
, NULL
}, /* Ac */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
180 {NULL
, NULL
}, /* At */
181 {NULL
, NULL
}, /* Bc */
182 {mdoc_bf_pre
, NULL
}, /* Bf */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
185 {mdoc_xx_pre
, NULL
}, /* Bsx */
186 {mdoc_bx_pre
, NULL
}, /* Bx */
187 {mdoc_skip_pre
, NULL
}, /* Db */
188 {NULL
, NULL
}, /* Dc */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
191 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
192 {NULL
, NULL
}, /* Ef */
193 {mdoc_em_pre
, NULL
}, /* Em */
194 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
195 {mdoc_xx_pre
, NULL
}, /* Fx */
196 {mdoc_ms_pre
, NULL
}, /* Ms */
197 {mdoc_no_pre
, NULL
}, /* No */
198 {mdoc_ns_pre
, NULL
}, /* Ns */
199 {mdoc_xx_pre
, NULL
}, /* Nx */
200 {mdoc_xx_pre
, NULL
}, /* Ox */
201 {NULL
, NULL
}, /* Pc */
202 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
205 {NULL
, NULL
}, /* Qc */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
209 {NULL
, NULL
}, /* Re */
210 {mdoc_rs_pre
, NULL
}, /* Rs */
211 {NULL
, NULL
}, /* Sc */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
214 {mdoc_sm_pre
, NULL
}, /* Sm */
215 {mdoc_sx_pre
, NULL
}, /* Sx */
216 {mdoc_sy_pre
, NULL
}, /* Sy */
217 {NULL
, NULL
}, /* Tn */
218 {mdoc_xx_pre
, NULL
}, /* Ux */
219 {NULL
, NULL
}, /* Xc */
220 {NULL
, NULL
}, /* Xo */
221 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
222 {NULL
, NULL
}, /* Fc */
223 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
224 {NULL
, NULL
}, /* Oc */
225 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
226 {NULL
, NULL
}, /* Ek */
227 {mdoc_bt_pre
, NULL
}, /* Bt */
228 {NULL
, NULL
}, /* Hf */
229 {mdoc_em_pre
, NULL
}, /* Fr */
230 {mdoc_ud_pre
, NULL
}, /* Ud */
231 {mdoc_lb_pre
, NULL
}, /* Lb */
232 {mdoc_pp_pre
, NULL
}, /* Lp */
233 {mdoc_lk_pre
, NULL
}, /* Lk */
234 {mdoc_mt_pre
, NULL
}, /* Mt */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
237 {NULL
, NULL
}, /* Brc */
238 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
239 {mdoc_skip_pre
, NULL
}, /* Es */
240 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
241 {mdoc_xx_pre
, NULL
}, /* Dx */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
243 {mdoc_sp_pre
, NULL
}, /* br */
244 {mdoc_sp_pre
, NULL
}, /* sp */
245 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
246 {NULL
, NULL
}, /* Ta */
247 {mdoc_skip_pre
, NULL
}, /* ll */
250 static const char * const lists
[LIST_MAX
] = {
267 * Calculate the scaling unit passed in a `-width' argument. This uses
268 * either a native scaling unit (e.g., 1i, 2m) or the string length of
272 a2width(const char *p
, struct roffsu
*su
)
275 if (a2roffsu(p
, su
, SCALE_MAX
) < 2) {
277 su
->scale
= html_strlen(p
);
278 } else if (su
->scale
< 0.0)
283 * See the same function in mdoc_term.c for documentation.
286 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
289 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
292 if (n
->prev
->tok
== n
->tok
&&
296 print_otag(h
, TAG_BR
, 0, NULL
);
300 switch (n
->prev
->tok
) {
309 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
315 print_otag(h
, TAG_BR
, 0, NULL
);
321 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
327 PAIR_CLASS_INIT(&tag
, "mandoc");
328 h
= (struct html
*)arg
;
330 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
332 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
333 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
334 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
336 print_otag(h
, TAG_BODY
, 0, NULL
);
337 print_otag(h
, TAG_DIV
, 1, &tag
);
339 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
341 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
342 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
343 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
349 print_mdoc_head(MDOC_ARGS
)
354 bufcat(h
, meta
->title
);
356 bufcat_fmt(h
, "(%s)", meta
->msec
);
358 bufcat_fmt(h
, " (%s)", meta
->arch
);
360 print_otag(h
, TAG_TITLE
, 0, NULL
);
361 print_text(h
, h
->buf
);
365 print_mdoc_nodelist(MDOC_ARGS
)
369 print_mdoc_node(meta
, n
, h
);
375 print_mdoc_node(MDOC_ARGS
)
382 n
->flags
&= ~MDOC_ENDED
;
386 /* No tables in this mode... */
387 assert(NULL
== h
->tblt
);
390 * Make sure that if we're in a literal mode already
391 * (i.e., within a <PRE>) don't print the newline.
393 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
394 if ( ! (HTML_LITERAL
& h
->flags
))
395 print_otag(h
, TAG_BR
, 0, NULL
);
396 if (MDOC_DELIMC
& n
->flags
)
397 h
->flags
|= HTML_NOSPACE
;
398 print_text(h
, n
->string
);
399 if (MDOC_DELIMO
& n
->flags
)
400 h
->flags
|= HTML_NOSPACE
;
403 if (n
->flags
& MDOC_LINE
)
405 print_eqn(h
, n
->eqn
);
409 * This will take care of initialising all of the table
410 * state data for the first table, then tearing it down
413 print_tbl(h
, n
->span
);
417 * Close out the current table, if it's open, and unset
418 * the "meta" table state. This will be reopened on the
419 * next table element.
421 if (h
->tblt
!= NULL
) {
425 assert(h
->tblt
== NULL
);
426 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
427 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
431 if (h
->flags
& HTML_KEEP
&& n
->flags
& MDOC_LINE
) {
432 h
->flags
&= ~HTML_KEEP
;
433 h
->flags
|= HTML_PREKEEP
;
436 if (child
&& n
->child
)
437 print_mdoc_nodelist(meta
, n
->child
, h
);
445 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
447 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
448 if (n
->end
!= ENDBODY_NOT
)
449 n
->body
->flags
|= MDOC_ENDED
;
450 if (n
->end
== ENDBODY_NOSPACE
)
451 h
->flags
|= HTML_NOSPACE
;
457 mdoc_root_post(MDOC_ARGS
)
462 PAIR_CLASS_INIT(&tag
, "foot");
463 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
465 print_otag(h
, TAG_TBODY
, 0, NULL
);
467 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
469 PAIR_CLASS_INIT(&tag
, "foot-date");
470 print_otag(h
, TAG_TD
, 1, &tag
);
471 print_text(h
, meta
->date
);
474 PAIR_CLASS_INIT(&tag
, "foot-os");
475 print_otag(h
, TAG_TD
, 1, &tag
);
476 print_text(h
, meta
->os
);
481 mdoc_root_pre(MDOC_ARGS
)
485 char *volume
, *title
;
487 if (NULL
== meta
->arch
)
488 volume
= mandoc_strdup(meta
->vol
);
490 mandoc_asprintf(&volume
, "%s (%s)",
491 meta
->vol
, meta
->arch
);
493 if (NULL
== meta
->msec
)
494 title
= mandoc_strdup(meta
->title
);
496 mandoc_asprintf(&title
, "%s(%s)",
497 meta
->title
, meta
->msec
);
499 PAIR_CLASS_INIT(&tag
, "head");
500 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
502 print_otag(h
, TAG_TBODY
, 0, NULL
);
504 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
506 PAIR_CLASS_INIT(&tag
, "head-ltitle");
507 print_otag(h
, TAG_TD
, 1, &tag
);
508 print_text(h
, title
);
511 PAIR_CLASS_INIT(&tag
, "head-vol");
512 print_otag(h
, TAG_TD
, 1, &tag
);
513 print_text(h
, volume
);
516 PAIR_CLASS_INIT(&tag
, "head-rtitle");
517 print_otag(h
, TAG_TD
, 1, &tag
);
518 print_text(h
, title
);
527 mdoc_sh_pre(MDOC_ARGS
)
533 PAIR_CLASS_INIT(&tag
, "section");
534 print_otag(h
, TAG_DIV
, 1, &tag
);
537 if (n
->sec
== SEC_AUTHORS
)
538 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
546 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
547 bufcat_id(h
, n
->string
);
548 if (NULL
!= (n
= n
->next
))
553 PAIR_ID_INIT(&tag
, h
->buf
);
554 print_otag(h
, TAG_H1
, 1, &tag
);
556 print_otag(h
, TAG_H1
, 0, NULL
);
562 mdoc_ss_pre(MDOC_ARGS
)
566 if (n
->type
== ROFFT_BLOCK
) {
567 PAIR_CLASS_INIT(&tag
, "subsection");
568 print_otag(h
, TAG_DIV
, 1, &tag
);
570 } else if (n
->type
== ROFFT_BODY
)
575 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
576 bufcat_id(h
, n
->string
);
577 if (NULL
!= (n
= n
->next
))
582 PAIR_ID_INIT(&tag
, h
->buf
);
583 print_otag(h
, TAG_H2
, 1, &tag
);
585 print_otag(h
, TAG_H2
, 0, NULL
);
591 mdoc_fl_pre(MDOC_ARGS
)
595 PAIR_CLASS_INIT(&tag
, "flag");
596 print_otag(h
, TAG_B
, 1, &tag
);
598 /* `Cm' has no leading hyphen. */
600 if (MDOC_Cm
== n
->tok
)
603 print_text(h
, "\\-");
605 if (!(n
->child
== NULL
&&
607 n
->next
->type
== ROFFT_TEXT
||
608 n
->next
->flags
& MDOC_LINE
)))
609 h
->flags
|= HTML_NOSPACE
;
615 mdoc_nd_pre(MDOC_ARGS
)
619 if (n
->type
!= ROFFT_BODY
)
622 /* XXX: this tag in theory can contain block elements. */
624 print_text(h
, "\\(em");
625 PAIR_CLASS_INIT(&tag
, "desc");
626 print_otag(h
, TAG_SPAN
, 1, &tag
);
631 mdoc_nm_pre(MDOC_ARGS
)
639 print_otag(h
, TAG_TD
, 0, NULL
);
642 PAIR_CLASS_INIT(&tag
, "name");
643 print_otag(h
, TAG_B
, 1, &tag
);
644 if (n
->child
== NULL
&& meta
->name
!= NULL
)
645 print_text(h
, meta
->name
);
648 print_otag(h
, TAG_TD
, 0, NULL
);
655 PAIR_CLASS_INIT(&tag
, "synopsis");
656 print_otag(h
, TAG_TABLE
, 1, &tag
);
658 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
659 if (n
->type
== ROFFT_TEXT
)
660 len
+= html_strlen(n
->string
);
662 if (len
== 0 && meta
->name
!= NULL
)
663 len
= html_strlen(meta
->name
);
665 SCALE_HS_INIT(&su
, len
);
667 bufcat_su(h
, "width", &su
);
668 PAIR_STYLE_INIT(&tag
, h
);
669 print_otag(h
, TAG_COL
, 1, &tag
);
670 print_otag(h
, TAG_COL
, 0, NULL
);
671 print_otag(h
, TAG_TBODY
, 0, NULL
);
672 print_otag(h
, TAG_TR
, 0, NULL
);
677 mdoc_xr_pre(MDOC_ARGS
)
679 struct htmlpair tag
[2];
681 if (NULL
== n
->child
)
684 PAIR_CLASS_INIT(&tag
[0], "link-man");
687 buffmt_man(h
, n
->child
->string
,
689 n
->child
->next
->string
: NULL
);
690 PAIR_HREF_INIT(&tag
[1], h
->buf
);
691 print_otag(h
, TAG_A
, 2, tag
);
693 print_otag(h
, TAG_A
, 1, tag
);
696 print_text(h
, n
->string
);
698 if (NULL
== (n
= n
->next
))
701 h
->flags
|= HTML_NOSPACE
;
703 h
->flags
|= HTML_NOSPACE
;
704 print_text(h
, n
->string
);
705 h
->flags
|= HTML_NOSPACE
;
711 mdoc_ns_pre(MDOC_ARGS
)
714 if ( ! (MDOC_LINE
& n
->flags
))
715 h
->flags
|= HTML_NOSPACE
;
720 mdoc_ar_pre(MDOC_ARGS
)
724 PAIR_CLASS_INIT(&tag
, "arg");
725 print_otag(h
, TAG_I
, 1, &tag
);
730 mdoc_xx_pre(MDOC_ARGS
)
759 PAIR_CLASS_INIT(&tag
, "unix");
760 print_otag(h
, TAG_SPAN
, 1, &tag
);
765 h
->flags
|= HTML_KEEP
;
766 print_text(h
, n
->child
->string
);
773 mdoc_bx_pre(MDOC_ARGS
)
777 PAIR_CLASS_INIT(&tag
, "unix");
778 print_otag(h
, TAG_SPAN
, 1, &tag
);
780 if (NULL
!= (n
= n
->child
)) {
781 print_text(h
, n
->string
);
782 h
->flags
|= HTML_NOSPACE
;
783 print_text(h
, "BSD");
785 print_text(h
, "BSD");
789 if (NULL
!= (n
= n
->next
)) {
790 h
->flags
|= HTML_NOSPACE
;
792 h
->flags
|= HTML_NOSPACE
;
793 print_text(h
, n
->string
);
800 mdoc_it_pre(MDOC_ARGS
)
804 struct htmlpair tag
[2];
805 const struct roff_node
*bl
;
808 while (bl
&& MDOC_Bl
!= bl
->tok
)
813 type
= bl
->norm
->Bl
.type
;
816 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
820 if (n
->type
== ROFFT_HEAD
) {
833 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
834 bufcat_su(h
, "margin-top", &su
);
835 PAIR_STYLE_INIT(&tag
[1], h
);
836 print_otag(h
, TAG_DT
, 2, tag
);
837 if (LIST_diag
!= type
)
839 PAIR_CLASS_INIT(&tag
[0], "diag");
840 print_otag(h
, TAG_B
, 1, tag
);
847 } else if (n
->type
== ROFFT_BODY
) {
854 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
855 bufcat_su(h
, "margin-top", &su
);
856 PAIR_STYLE_INIT(&tag
[1], h
);
857 print_otag(h
, TAG_LI
, 2, tag
);
864 if (NULL
== bl
->norm
->Bl
.width
) {
865 print_otag(h
, TAG_DD
, 1, tag
);
868 a2width(bl
->norm
->Bl
.width
, &su
);
869 bufcat_su(h
, "margin-left", &su
);
870 PAIR_STYLE_INIT(&tag
[1], h
);
871 print_otag(h
, TAG_DD
, 2, tag
);
874 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
875 bufcat_su(h
, "margin-top", &su
);
876 PAIR_STYLE_INIT(&tag
[1], h
);
877 print_otag(h
, TAG_TD
, 2, tag
);
885 print_otag(h
, TAG_TR
, 1, tag
);
896 mdoc_bl_pre(MDOC_ARGS
)
899 struct htmlpair tag
[3];
903 if (n
->type
== ROFFT_BODY
) {
904 if (LIST_column
== n
->norm
->Bl
.type
)
905 print_otag(h
, TAG_TBODY
, 0, NULL
);
909 if (n
->type
== ROFFT_HEAD
) {
910 if (LIST_column
!= n
->norm
->Bl
.type
)
914 * For each column, print out the <COL> tag with our
915 * suggested width. The last column gets min-width, as
916 * in terminal mode it auto-sizes to the width of the
917 * screen and we want to preserve that behaviour.
920 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
922 a2width(n
->norm
->Bl
.cols
[i
], &su
);
923 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
924 bufcat_su(h
, "width", &su
);
926 bufcat_su(h
, "min-width", &su
);
927 PAIR_STYLE_INIT(&tag
[0], h
);
928 print_otag(h
, TAG_COL
, 1, tag
);
934 SCALE_VS_INIT(&su
, 0);
936 bufcat_su(h
, "margin-top", &su
);
937 bufcat_su(h
, "margin-bottom", &su
);
938 PAIR_STYLE_INIT(&tag
[0], h
);
940 assert(lists
[n
->norm
->Bl
.type
]);
941 (void)strlcpy(buf
, "list ", BUFSIZ
);
942 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
943 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
945 /* Set the block's left-hand margin. */
947 if (n
->norm
->Bl
.offs
) {
948 a2width(n
->norm
->Bl
.offs
, &su
);
949 bufcat_su(h
, "margin-left", &su
);
952 switch (n
->norm
->Bl
.type
) {
957 print_otag(h
, TAG_UL
, 2, tag
);
960 print_otag(h
, TAG_OL
, 2, tag
);
967 print_otag(h
, TAG_DL
, 2, tag
);
970 print_otag(h
, TAG_TABLE
, 2, tag
);
980 mdoc_ex_pre(MDOC_ARGS
)
984 struct roff_node
*nch
;
987 print_otag(h
, TAG_BR
, 0, NULL
);
989 PAIR_CLASS_INIT(&tag
, "utility");
991 print_text(h
, "The");
993 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
) {
994 assert(nch
->type
== ROFFT_TEXT
);
996 t
= print_otag(h
, TAG_B
, 1, &tag
);
997 print_text(h
, nch
->string
);
1000 if (nch
->next
== NULL
)
1003 if (nch
->prev
!= NULL
|| nch
->next
->next
!= NULL
) {
1004 h
->flags
|= HTML_NOSPACE
;
1008 if (nch
->next
->next
== NULL
)
1009 print_text(h
, "and");
1012 if (n
->child
!= NULL
&& n
->child
->next
!= NULL
)
1013 print_text(h
, "utilities exit\\~0");
1015 print_text(h
, "utility exits\\~0");
1017 print_text(h
, "on success, and\\~>0 if an error occurs.");
1022 mdoc_em_pre(MDOC_ARGS
)
1024 struct htmlpair tag
;
1026 PAIR_CLASS_INIT(&tag
, "emph");
1027 print_otag(h
, TAG_SPAN
, 1, &tag
);
1032 mdoc_d1_pre(MDOC_ARGS
)
1034 struct htmlpair tag
[2];
1037 if (n
->type
!= ROFFT_BLOCK
)
1040 SCALE_VS_INIT(&su
, 0);
1042 bufcat_su(h
, "margin-top", &su
);
1043 bufcat_su(h
, "margin-bottom", &su
);
1044 PAIR_STYLE_INIT(&tag
[0], h
);
1045 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1047 /* BLOCKQUOTE needs a block body. */
1049 PAIR_CLASS_INIT(&tag
[0], "display");
1050 print_otag(h
, TAG_DIV
, 1, tag
);
1052 if (MDOC_Dl
== n
->tok
) {
1053 PAIR_CLASS_INIT(&tag
[0], "lit");
1054 print_otag(h
, TAG_CODE
, 1, tag
);
1061 mdoc_sx_pre(MDOC_ARGS
)
1063 struct htmlpair tag
[2];
1068 for (n
= n
->child
; n
; ) {
1069 bufcat_id(h
, n
->string
);
1070 if (NULL
!= (n
= n
->next
))
1074 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1075 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1077 print_otag(h
, TAG_I
, 1, tag
);
1078 print_otag(h
, TAG_A
, 2, tag
);
1083 mdoc_bd_pre(MDOC_ARGS
)
1085 struct htmlpair tag
[2];
1087 struct roff_node
*nn
;
1090 if (n
->type
== ROFFT_HEAD
)
1093 if (n
->type
== ROFFT_BLOCK
) {
1094 comp
= n
->norm
->Bd
.comp
;
1095 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1096 if (nn
->type
!= ROFFT_BLOCK
)
1098 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1108 /* Handle the -offset argument. */
1110 if (n
->norm
->Bd
.offs
== NULL
||
1111 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1112 SCALE_HS_INIT(&su
, 0);
1113 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1114 SCALE_HS_INIT(&su
, INDENT
);
1115 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1116 SCALE_HS_INIT(&su
, INDENT
* 2);
1118 a2width(n
->norm
->Bd
.offs
, &su
);
1121 bufcat_su(h
, "margin-left", &su
);
1122 PAIR_STYLE_INIT(&tag
[0], h
);
1124 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1125 DISP_literal
!= n
->norm
->Bd
.type
) {
1126 PAIR_CLASS_INIT(&tag
[1], "display");
1127 print_otag(h
, TAG_DIV
, 2, tag
);
1131 PAIR_CLASS_INIT(&tag
[1], "lit display");
1132 print_otag(h
, TAG_PRE
, 2, tag
);
1134 /* This can be recursive: save & set our literal state. */
1136 sv
= h
->flags
& HTML_LITERAL
;
1137 h
->flags
|= HTML_LITERAL
;
1139 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1140 print_mdoc_node(meta
, nn
, h
);
1142 * If the printed node flushes its own line, then we
1143 * needn't do it here as well. This is hacky, but the
1144 * notion of selective eoln whitespace is pretty dumb
1145 * anyway, so don't sweat it.
1160 if (h
->flags
& HTML_NONEWLINE
||
1161 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1164 print_text(h
, "\n");
1166 h
->flags
|= HTML_NOSPACE
;
1170 h
->flags
&= ~HTML_LITERAL
;
1176 mdoc_pa_pre(MDOC_ARGS
)
1178 struct htmlpair tag
;
1180 PAIR_CLASS_INIT(&tag
, "file");
1181 print_otag(h
, TAG_I
, 1, &tag
);
1186 mdoc_ad_pre(MDOC_ARGS
)
1188 struct htmlpair tag
;
1190 PAIR_CLASS_INIT(&tag
, "addr");
1191 print_otag(h
, TAG_I
, 1, &tag
);
1196 mdoc_an_pre(MDOC_ARGS
)
1198 struct htmlpair tag
;
1200 if (n
->norm
->An
.auth
== AUTH_split
) {
1201 h
->flags
&= ~HTML_NOSPLIT
;
1202 h
->flags
|= HTML_SPLIT
;
1205 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1206 h
->flags
&= ~HTML_SPLIT
;
1207 h
->flags
|= HTML_NOSPLIT
;
1211 if (h
->flags
& HTML_SPLIT
)
1212 print_otag(h
, TAG_BR
, 0, NULL
);
1214 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1215 h
->flags
|= HTML_SPLIT
;
1217 PAIR_CLASS_INIT(&tag
, "author");
1218 print_otag(h
, TAG_SPAN
, 1, &tag
);
1223 mdoc_cd_pre(MDOC_ARGS
)
1225 struct htmlpair tag
;
1228 PAIR_CLASS_INIT(&tag
, "config");
1229 print_otag(h
, TAG_B
, 1, &tag
);
1234 mdoc_dv_pre(MDOC_ARGS
)
1236 struct htmlpair tag
;
1238 PAIR_CLASS_INIT(&tag
, "define");
1239 print_otag(h
, TAG_SPAN
, 1, &tag
);
1244 mdoc_ev_pre(MDOC_ARGS
)
1246 struct htmlpair tag
;
1248 PAIR_CLASS_INIT(&tag
, "env");
1249 print_otag(h
, TAG_SPAN
, 1, &tag
);
1254 mdoc_er_pre(MDOC_ARGS
)
1256 struct htmlpair tag
;
1258 PAIR_CLASS_INIT(&tag
, "errno");
1259 print_otag(h
, TAG_SPAN
, 1, &tag
);
1264 mdoc_fa_pre(MDOC_ARGS
)
1266 const struct roff_node
*nn
;
1267 struct htmlpair tag
;
1270 PAIR_CLASS_INIT(&tag
, "farg");
1271 if (n
->parent
->tok
!= MDOC_Fo
) {
1272 print_otag(h
, TAG_I
, 1, &tag
);
1276 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1277 t
= print_otag(h
, TAG_I
, 1, &tag
);
1278 print_text(h
, nn
->string
);
1281 h
->flags
|= HTML_NOSPACE
;
1286 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1287 h
->flags
|= HTML_NOSPACE
;
1295 mdoc_fd_pre(MDOC_ARGS
)
1297 struct htmlpair tag
[2];
1305 if (NULL
== (n
= n
->child
))
1308 assert(n
->type
== ROFFT_TEXT
);
1310 if (strcmp(n
->string
, "#include")) {
1311 PAIR_CLASS_INIT(&tag
[0], "macro");
1312 print_otag(h
, TAG_B
, 1, tag
);
1316 PAIR_CLASS_INIT(&tag
[0], "includes");
1317 print_otag(h
, TAG_B
, 1, tag
);
1318 print_text(h
, n
->string
);
1320 if (NULL
!= (n
= n
->next
)) {
1321 assert(n
->type
== ROFFT_TEXT
);
1324 * XXX This is broken and not easy to fix.
1325 * When using -Oincludes, truncation may occur.
1326 * Dynamic allocation wouldn't help because
1327 * passing long strings to buffmt_includes()
1328 * does not work either.
1331 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1332 n
->string
+ 1 : n
->string
, BUFSIZ
);
1335 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1338 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1341 if (h
->base_includes
) {
1342 buffmt_includes(h
, buf
);
1343 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1347 t
= print_otag(h
, TAG_A
, i
, tag
);
1348 print_text(h
, n
->string
);
1354 for ( ; n
; n
= n
->next
) {
1355 assert(n
->type
== ROFFT_TEXT
);
1356 print_text(h
, n
->string
);
1363 mdoc_vt_pre(MDOC_ARGS
)
1365 struct htmlpair tag
;
1367 if (n
->type
== ROFFT_BLOCK
) {
1370 } else if (n
->type
== ROFFT_ELEM
) {
1372 } else if (n
->type
== ROFFT_HEAD
)
1375 PAIR_CLASS_INIT(&tag
, "type");
1376 print_otag(h
, TAG_SPAN
, 1, &tag
);
1381 mdoc_ft_pre(MDOC_ARGS
)
1383 struct htmlpair tag
;
1386 PAIR_CLASS_INIT(&tag
, "ftype");
1387 print_otag(h
, TAG_I
, 1, &tag
);
1392 mdoc_fn_pre(MDOC_ARGS
)
1395 struct htmlpair tag
[2];
1397 const char *sp
, *ep
;
1400 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1403 /* Split apart into type and name. */
1404 assert(n
->child
->string
);
1405 sp
= n
->child
->string
;
1407 ep
= strchr(sp
, ' ');
1409 PAIR_CLASS_INIT(&tag
[0], "ftype");
1410 t
= print_otag(h
, TAG_I
, 1, tag
);
1413 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1414 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1416 print_text(h
, nbuf
);
1418 ep
= strchr(sp
, ' ');
1423 PAIR_CLASS_INIT(&tag
[0], "fname");
1426 * FIXME: only refer to IDs that we know exist.
1430 if (MDOC_SYNPRETTY
& n
->flags
) {
1432 html_idcat(nbuf
, sp
, BUFSIZ
);
1433 PAIR_ID_INIT(&tag
[1], nbuf
);
1435 strlcpy(nbuf
, "#", BUFSIZ
);
1436 html_idcat(nbuf
, sp
, BUFSIZ
);
1437 PAIR_HREF_INIT(&tag
[1], nbuf
);
1441 t
= print_otag(h
, TAG_B
, 1, tag
);
1448 h
->flags
|= HTML_NOSPACE
;
1450 h
->flags
|= HTML_NOSPACE
;
1452 PAIR_CLASS_INIT(&tag
[0], "farg");
1454 bufcat_style(h
, "white-space", "nowrap");
1455 PAIR_STYLE_INIT(&tag
[1], h
);
1457 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1459 if (MDOC_SYNPRETTY
& n
->flags
)
1461 t
= print_otag(h
, TAG_I
, i
, tag
);
1462 print_text(h
, n
->string
);
1465 h
->flags
|= HTML_NOSPACE
;
1470 h
->flags
|= HTML_NOSPACE
;
1474 h
->flags
|= HTML_NOSPACE
;
1482 mdoc_sm_pre(MDOC_ARGS
)
1485 if (NULL
== n
->child
)
1486 h
->flags
^= HTML_NONOSPACE
;
1487 else if (0 == strcmp("on", n
->child
->string
))
1488 h
->flags
&= ~HTML_NONOSPACE
;
1490 h
->flags
|= HTML_NONOSPACE
;
1492 if ( ! (HTML_NONOSPACE
& h
->flags
))
1493 h
->flags
&= ~HTML_NOSPACE
;
1499 mdoc_skip_pre(MDOC_ARGS
)
1506 mdoc_pp_pre(MDOC_ARGS
)
1514 mdoc_sp_pre(MDOC_ARGS
)
1517 struct htmlpair tag
;
1519 SCALE_VS_INIT(&su
, 1);
1521 if (MDOC_sp
== n
->tok
) {
1522 if (NULL
!= (n
= n
->child
)) {
1523 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1525 else if (su
.scale
< 0.0)
1532 bufcat_su(h
, "height", &su
);
1533 PAIR_STYLE_INIT(&tag
, h
);
1534 print_otag(h
, TAG_DIV
, 1, &tag
);
1536 /* So the div isn't empty: */
1537 print_text(h
, "\\~");
1544 mdoc_lk_pre(MDOC_ARGS
)
1546 struct htmlpair tag
[2];
1548 if (NULL
== (n
= n
->child
))
1551 assert(n
->type
== ROFFT_TEXT
);
1553 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1554 PAIR_HREF_INIT(&tag
[1], n
->string
);
1556 print_otag(h
, TAG_A
, 2, tag
);
1558 if (NULL
== n
->next
)
1559 print_text(h
, n
->string
);
1561 for (n
= n
->next
; n
; n
= n
->next
)
1562 print_text(h
, n
->string
);
1568 mdoc_mt_pre(MDOC_ARGS
)
1570 struct htmlpair tag
[2];
1573 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1575 for (n
= n
->child
; n
; n
= n
->next
) {
1576 assert(n
->type
== ROFFT_TEXT
);
1579 bufcat(h
, "mailto:");
1580 bufcat(h
, n
->string
);
1582 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1583 t
= print_otag(h
, TAG_A
, 2, tag
);
1584 print_text(h
, n
->string
);
1592 mdoc_fo_pre(MDOC_ARGS
)
1594 struct htmlpair tag
;
1597 if (n
->type
== ROFFT_BODY
) {
1598 h
->flags
|= HTML_NOSPACE
;
1600 h
->flags
|= HTML_NOSPACE
;
1602 } else if (n
->type
== ROFFT_BLOCK
) {
1607 if (n
->child
== NULL
)
1610 assert(n
->child
->string
);
1611 PAIR_CLASS_INIT(&tag
, "fname");
1612 t
= print_otag(h
, TAG_B
, 1, &tag
);
1613 print_text(h
, n
->child
->string
);
1619 mdoc_fo_post(MDOC_ARGS
)
1622 if (n
->type
!= ROFFT_BODY
)
1624 h
->flags
|= HTML_NOSPACE
;
1626 h
->flags
|= HTML_NOSPACE
;
1631 mdoc_in_pre(MDOC_ARGS
)
1634 struct htmlpair tag
[2];
1639 PAIR_CLASS_INIT(&tag
[0], "includes");
1640 print_otag(h
, TAG_B
, 1, tag
);
1643 * The first argument of the `In' gets special treatment as
1644 * being a linked value. Subsequent values are printed
1645 * afterward. groff does similarly. This also handles the case
1649 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1650 print_text(h
, "#include");
1653 h
->flags
|= HTML_NOSPACE
;
1655 if (NULL
!= (n
= n
->child
)) {
1656 assert(n
->type
== ROFFT_TEXT
);
1658 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1661 if (h
->base_includes
) {
1662 buffmt_includes(h
, n
->string
);
1663 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1667 t
= print_otag(h
, TAG_A
, i
, tag
);
1668 print_text(h
, n
->string
);
1674 h
->flags
|= HTML_NOSPACE
;
1677 for ( ; n
; n
= n
->next
) {
1678 assert(n
->type
== ROFFT_TEXT
);
1679 print_text(h
, n
->string
);
1686 mdoc_ic_pre(MDOC_ARGS
)
1688 struct htmlpair tag
;
1690 PAIR_CLASS_INIT(&tag
, "cmd");
1691 print_otag(h
, TAG_B
, 1, &tag
);
1696 mdoc_rv_pre(MDOC_ARGS
)
1698 struct htmlpair tag
;
1700 struct roff_node
*nch
;
1703 print_otag(h
, TAG_BR
, 0, NULL
);
1705 PAIR_CLASS_INIT(&tag
, "fname");
1707 if (n
->child
!= NULL
) {
1708 print_text(h
, "The");
1710 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
) {
1711 t
= print_otag(h
, TAG_B
, 1, &tag
);
1712 print_text(h
, nch
->string
);
1715 h
->flags
|= HTML_NOSPACE
;
1716 print_text(h
, "()");
1718 if (nch
->next
== NULL
)
1721 if (nch
->prev
!= NULL
|| nch
->next
->next
!= NULL
) {
1722 h
->flags
|= HTML_NOSPACE
;
1725 if (nch
->next
->next
== NULL
)
1726 print_text(h
, "and");
1729 if (n
->child
!= NULL
&& n
->child
->next
!= NULL
)
1730 print_text(h
, "functions return");
1732 print_text(h
, "function returns");
1734 print_text(h
, "the value\\~0 if successful;");
1736 print_text(h
, "Upon successful completion,"
1737 " the value\\~0 is returned;");
1739 print_text(h
, "otherwise the value\\~\\-1 is returned"
1740 " and the global variable");
1742 PAIR_CLASS_INIT(&tag
, "var");
1743 t
= print_otag(h
, TAG_B
, 1, &tag
);
1744 print_text(h
, "errno");
1746 print_text(h
, "is set to indicate the error.");
1751 mdoc_va_pre(MDOC_ARGS
)
1753 struct htmlpair tag
;
1755 PAIR_CLASS_INIT(&tag
, "var");
1756 print_otag(h
, TAG_B
, 1, &tag
);
1761 mdoc_ap_pre(MDOC_ARGS
)
1764 h
->flags
|= HTML_NOSPACE
;
1765 print_text(h
, "\\(aq");
1766 h
->flags
|= HTML_NOSPACE
;
1771 mdoc_bf_pre(MDOC_ARGS
)
1773 struct htmlpair tag
[2];
1776 if (n
->type
== ROFFT_HEAD
)
1778 else if (n
->type
!= ROFFT_BODY
)
1781 if (FONT_Em
== n
->norm
->Bf
.font
)
1782 PAIR_CLASS_INIT(&tag
[0], "emph");
1783 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1784 PAIR_CLASS_INIT(&tag
[0], "symb");
1785 else if (FONT_Li
== n
->norm
->Bf
.font
)
1786 PAIR_CLASS_INIT(&tag
[0], "lit");
1788 PAIR_CLASS_INIT(&tag
[0], "none");
1791 * We want this to be inline-formatted, but needs to be div to
1792 * accept block children.
1795 bufcat_style(h
, "display", "inline");
1796 SCALE_HS_INIT(&su
, 1);
1797 /* Needs a left-margin for spacing. */
1798 bufcat_su(h
, "margin-left", &su
);
1799 PAIR_STYLE_INIT(&tag
[1], h
);
1800 print_otag(h
, TAG_DIV
, 2, tag
);
1805 mdoc_ms_pre(MDOC_ARGS
)
1807 struct htmlpair tag
;
1809 PAIR_CLASS_INIT(&tag
, "symb");
1810 print_otag(h
, TAG_SPAN
, 1, &tag
);
1815 mdoc_igndelim_pre(MDOC_ARGS
)
1818 h
->flags
|= HTML_IGNDELIM
;
1823 mdoc_pf_post(MDOC_ARGS
)
1826 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1827 h
->flags
|= HTML_NOSPACE
;
1831 mdoc_rs_pre(MDOC_ARGS
)
1833 struct htmlpair tag
;
1835 if (n
->type
!= ROFFT_BLOCK
)
1838 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1841 PAIR_CLASS_INIT(&tag
, "ref");
1842 print_otag(h
, TAG_SPAN
, 1, &tag
);
1847 mdoc_no_pre(MDOC_ARGS
)
1849 struct htmlpair tag
;
1851 PAIR_CLASS_INIT(&tag
, "none");
1852 print_otag(h
, TAG_CODE
, 1, &tag
);
1857 mdoc_li_pre(MDOC_ARGS
)
1859 struct htmlpair tag
;
1861 PAIR_CLASS_INIT(&tag
, "lit");
1862 print_otag(h
, TAG_CODE
, 1, &tag
);
1867 mdoc_sy_pre(MDOC_ARGS
)
1869 struct htmlpair tag
;
1871 PAIR_CLASS_INIT(&tag
, "symb");
1872 print_otag(h
, TAG_SPAN
, 1, &tag
);
1877 mdoc_bt_pre(MDOC_ARGS
)
1880 print_text(h
, "is currently in beta test.");
1885 mdoc_ud_pre(MDOC_ARGS
)
1888 print_text(h
, "currently under development.");
1893 mdoc_lb_pre(MDOC_ARGS
)
1895 struct htmlpair tag
;
1897 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1898 print_otag(h
, TAG_BR
, 0, NULL
);
1900 PAIR_CLASS_INIT(&tag
, "lib");
1901 print_otag(h
, TAG_SPAN
, 1, &tag
);
1906 mdoc__x_pre(MDOC_ARGS
)
1908 struct htmlpair tag
[2];
1915 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1916 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1917 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1918 print_text(h
, "and");
1921 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1925 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1928 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1931 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1935 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1939 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1942 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1945 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1948 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1951 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1954 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1957 PAIR_CLASS_INIT(&tag
[0], "link-ref");
1960 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
1966 if (MDOC__U
!= n
->tok
) {
1967 print_otag(h
, t
, 1, tag
);
1971 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
1972 print_otag(h
, TAG_A
, 2, tag
);
1978 mdoc__x_post(MDOC_ARGS
)
1981 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1982 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1983 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1988 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1991 h
->flags
|= HTML_NOSPACE
;
1992 print_text(h
, n
->next
? "," : ".");
1996 mdoc_bk_pre(MDOC_ARGS
)
2005 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
2006 h
->flags
|= HTML_PREKEEP
;
2016 mdoc_bk_post(MDOC_ARGS
)
2019 if (n
->type
== ROFFT_BODY
)
2020 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2024 mdoc_quote_pre(MDOC_ARGS
)
2026 struct htmlpair tag
;
2028 if (n
->type
!= ROFFT_BODY
)
2034 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
2035 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2039 print_text(h
, "\\(lC");
2043 print_text(h
, "\\(lB");
2047 print_text(h
, "\\(lB");
2048 h
->flags
|= HTML_NOSPACE
;
2049 PAIR_CLASS_INIT(&tag
, "opt");
2050 print_otag(h
, TAG_SPAN
, 1, &tag
);
2053 if (NULL
== n
->norm
->Es
||
2054 NULL
== n
->norm
->Es
->child
)
2056 print_text(h
, n
->norm
->Es
->child
->string
);
2062 print_text(h
, "\\(lq");
2069 print_text(h
, "\\(oq");
2070 h
->flags
|= HTML_NOSPACE
;
2071 PAIR_CLASS_INIT(&tag
, "lit");
2072 print_otag(h
, TAG_CODE
, 1, &tag
);
2076 print_text(h
, "\\(oq");
2082 h
->flags
|= HTML_NOSPACE
;
2087 mdoc_quote_post(MDOC_ARGS
)
2090 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
2093 h
->flags
|= HTML_NOSPACE
;
2098 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
2099 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2103 print_text(h
, "\\(rC");
2109 print_text(h
, "\\(rB");
2112 if (n
->norm
->Es
== NULL
||
2113 n
->norm
->Es
->child
== NULL
||
2114 n
->norm
->Es
->child
->next
== NULL
)
2115 h
->flags
&= ~HTML_NOSPACE
;
2117 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2123 print_text(h
, "\\(rq");
2132 print_text(h
, "\\(cq");
2140 mdoc_eo_pre(MDOC_ARGS
)
2143 if (n
->type
!= ROFFT_BODY
)
2146 if (n
->end
== ENDBODY_NOT
&&
2147 n
->parent
->head
->child
== NULL
&&
2149 n
->child
->end
!= ENDBODY_NOT
)
2150 print_text(h
, "\\&");
2151 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2152 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2153 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2154 h
->flags
|= HTML_NOSPACE
;
2159 mdoc_eo_post(MDOC_ARGS
)
2163 if (n
->type
!= ROFFT_BODY
)
2166 if (n
->end
!= ENDBODY_NOT
) {
2167 h
->flags
&= ~HTML_NOSPACE
;
2171 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2172 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2175 h
->flags
|= HTML_NOSPACE
;
2177 h
->flags
&= ~HTML_NOSPACE
;