]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
62d7099371d913cb82b69ab6ba0da032cc01cd4d
1 /* $Id: mdoc_html.c,v 1.231 2015/04/18 16:06:40 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015 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(MDOC_ARGS
);
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 a2width(const char *, struct roffsu
*);
60 static void mdoc_root_post(MDOC_ARGS
);
61 static int mdoc_root_pre(MDOC_ARGS
);
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_ad_pre(MDOC_ARGS
);
66 static int mdoc_an_pre(MDOC_ARGS
);
67 static int mdoc_ap_pre(MDOC_ARGS
);
68 static int mdoc_ar_pre(MDOC_ARGS
);
69 static int mdoc_bd_pre(MDOC_ARGS
);
70 static int mdoc_bf_pre(MDOC_ARGS
);
71 static void mdoc_bk_post(MDOC_ARGS
);
72 static int mdoc_bk_pre(MDOC_ARGS
);
73 static int mdoc_bl_pre(MDOC_ARGS
);
74 static int mdoc_bt_pre(MDOC_ARGS
);
75 static int mdoc_bx_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static int mdoc_dv_pre(MDOC_ARGS
);
79 static int mdoc_fa_pre(MDOC_ARGS
);
80 static int mdoc_fd_pre(MDOC_ARGS
);
81 static int mdoc_fl_pre(MDOC_ARGS
);
82 static int mdoc_fn_pre(MDOC_ARGS
);
83 static int mdoc_ft_pre(MDOC_ARGS
);
84 static int mdoc_em_pre(MDOC_ARGS
);
85 static void mdoc_eo_post(MDOC_ARGS
);
86 static int mdoc_eo_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_no_pre(MDOC_ARGS
);
104 static int mdoc_ns_pre(MDOC_ARGS
);
105 static int mdoc_pa_pre(MDOC_ARGS
);
106 static void mdoc_pf_post(MDOC_ARGS
);
107 static int mdoc_pp_pre(MDOC_ARGS
);
108 static void mdoc_quote_post(MDOC_ARGS
);
109 static int mdoc_quote_pre(MDOC_ARGS
);
110 static int mdoc_rs_pre(MDOC_ARGS
);
111 static int mdoc_rv_pre(MDOC_ARGS
);
112 static int mdoc_sh_pre(MDOC_ARGS
);
113 static int mdoc_skip_pre(MDOC_ARGS
);
114 static int mdoc_sm_pre(MDOC_ARGS
);
115 static int mdoc_sp_pre(MDOC_ARGS
);
116 static int mdoc_ss_pre(MDOC_ARGS
);
117 static int mdoc_sx_pre(MDOC_ARGS
);
118 static int mdoc_sy_pre(MDOC_ARGS
);
119 static int mdoc_ud_pre(MDOC_ARGS
);
120 static int mdoc_va_pre(MDOC_ARGS
);
121 static int mdoc_vt_pre(MDOC_ARGS
);
122 static int mdoc_xr_pre(MDOC_ARGS
);
123 static int mdoc_xx_pre(MDOC_ARGS
);
125 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
126 {mdoc_ap_pre
, NULL
}, /* Ap */
127 {NULL
, NULL
}, /* Dd */
128 {NULL
, NULL
}, /* Dt */
129 {NULL
, NULL
}, /* Os */
130 {mdoc_sh_pre
, NULL
}, /* Sh */
131 {mdoc_ss_pre
, NULL
}, /* Ss */
132 {mdoc_pp_pre
, NULL
}, /* Pp */
133 {mdoc_d1_pre
, NULL
}, /* D1 */
134 {mdoc_d1_pre
, NULL
}, /* Dl */
135 {mdoc_bd_pre
, NULL
}, /* Bd */
136 {NULL
, NULL
}, /* Ed */
137 {mdoc_bl_pre
, NULL
}, /* Bl */
138 {NULL
, NULL
}, /* El */
139 {mdoc_it_pre
, NULL
}, /* It */
140 {mdoc_ad_pre
, NULL
}, /* Ad */
141 {mdoc_an_pre
, NULL
}, /* An */
142 {mdoc_ar_pre
, NULL
}, /* Ar */
143 {mdoc_cd_pre
, NULL
}, /* Cd */
144 {mdoc_fl_pre
, NULL
}, /* Cm */
145 {mdoc_dv_pre
, NULL
}, /* Dv */
146 {mdoc_er_pre
, NULL
}, /* Er */
147 {mdoc_ev_pre
, NULL
}, /* Ev */
148 {mdoc_ex_pre
, NULL
}, /* Ex */
149 {mdoc_fa_pre
, NULL
}, /* Fa */
150 {mdoc_fd_pre
, NULL
}, /* Fd */
151 {mdoc_fl_pre
, NULL
}, /* Fl */
152 {mdoc_fn_pre
, NULL
}, /* Fn */
153 {mdoc_ft_pre
, NULL
}, /* Ft */
154 {mdoc_ic_pre
, NULL
}, /* Ic */
155 {mdoc_in_pre
, NULL
}, /* In */
156 {mdoc_li_pre
, NULL
}, /* Li */
157 {mdoc_nd_pre
, NULL
}, /* Nd */
158 {mdoc_nm_pre
, NULL
}, /* Nm */
159 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
160 {mdoc_ft_pre
, NULL
}, /* Ot */
161 {mdoc_pa_pre
, NULL
}, /* Pa */
162 {mdoc_rv_pre
, NULL
}, /* Rv */
163 {NULL
, NULL
}, /* St */
164 {mdoc_va_pre
, NULL
}, /* Va */
165 {mdoc_vt_pre
, NULL
}, /* Vt */
166 {mdoc_xr_pre
, NULL
}, /* Xr */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
178 {NULL
, NULL
}, /* Ac */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
180 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
181 {NULL
, NULL
}, /* At */
182 {NULL
, NULL
}, /* Bc */
183 {mdoc_bf_pre
, NULL
}, /* Bf */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
185 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
186 {mdoc_xx_pre
, NULL
}, /* Bsx */
187 {mdoc_bx_pre
, NULL
}, /* Bx */
188 {mdoc_skip_pre
, NULL
}, /* Db */
189 {NULL
, NULL
}, /* Dc */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
191 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
192 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
193 {NULL
, NULL
}, /* Ef */
194 {mdoc_em_pre
, NULL
}, /* Em */
195 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
196 {mdoc_xx_pre
, NULL
}, /* Fx */
197 {mdoc_ms_pre
, NULL
}, /* Ms */
198 {mdoc_no_pre
, NULL
}, /* No */
199 {mdoc_ns_pre
, NULL
}, /* Ns */
200 {mdoc_xx_pre
, NULL
}, /* Nx */
201 {mdoc_xx_pre
, NULL
}, /* Ox */
202 {NULL
, NULL
}, /* Pc */
203 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
206 {NULL
, NULL
}, /* Qc */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
209 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
210 {NULL
, NULL
}, /* Re */
211 {mdoc_rs_pre
, NULL
}, /* Rs */
212 {NULL
, NULL
}, /* Sc */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
214 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
215 {mdoc_sm_pre
, NULL
}, /* Sm */
216 {mdoc_sx_pre
, NULL
}, /* Sx */
217 {mdoc_sy_pre
, NULL
}, /* Sy */
218 {NULL
, NULL
}, /* Tn */
219 {mdoc_xx_pre
, NULL
}, /* Ux */
220 {NULL
, NULL
}, /* Xc */
221 {NULL
, NULL
}, /* Xo */
222 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
223 {NULL
, NULL
}, /* Fc */
224 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
225 {NULL
, NULL
}, /* Oc */
226 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
227 {NULL
, NULL
}, /* Ek */
228 {mdoc_bt_pre
, NULL
}, /* Bt */
229 {NULL
, NULL
}, /* Hf */
230 {mdoc_em_pre
, NULL
}, /* Fr */
231 {mdoc_ud_pre
, NULL
}, /* Ud */
232 {mdoc_lb_pre
, NULL
}, /* Lb */
233 {mdoc_pp_pre
, NULL
}, /* Lp */
234 {mdoc_lk_pre
, NULL
}, /* Lk */
235 {mdoc_mt_pre
, NULL
}, /* Mt */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
237 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
238 {NULL
, NULL
}, /* Brc */
239 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
240 {mdoc_skip_pre
, NULL
}, /* Es */
241 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
242 {mdoc_xx_pre
, NULL
}, /* Dx */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
244 {mdoc_sp_pre
, NULL
}, /* br */
245 {mdoc_sp_pre
, NULL
}, /* sp */
246 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
247 {NULL
, NULL
}, /* Ta */
248 {mdoc_skip_pre
, NULL
}, /* ll */
251 static const char * const lists
[LIST_MAX
] = {
268 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
271 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
)->child
,
277 * Calculate the scaling unit passed in a `-width' argument. This uses
278 * either a native scaling unit (e.g., 1i, 2m) or the string length of
282 a2width(const char *p
, struct roffsu
*su
)
285 if (a2roffsu(p
, su
, SCALE_MAX
) < 2) {
287 su
->scale
= html_strlen(p
);
288 } else if (su
->scale
< 0.0)
293 * See the same function in mdoc_term.c for documentation.
296 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
299 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
302 if (n
->prev
->tok
== n
->tok
&&
306 print_otag(h
, TAG_BR
, 0, NULL
);
310 switch (n
->prev
->tok
) {
323 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
329 print_otag(h
, TAG_BR
, 0, NULL
);
335 print_mdoc(MDOC_ARGS
)
340 PAIR_CLASS_INIT(&tag
, "mandoc");
342 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
344 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
345 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
346 print_mdoc_head(meta
, n
, h
);
348 print_otag(h
, TAG_BODY
, 0, NULL
);
349 print_otag(h
, TAG_DIV
, 1, &tag
);
351 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
353 mdoc_root_pre(meta
, n
, h
);
354 print_mdoc_nodelist(meta
, n
, h
);
355 mdoc_root_post(meta
, n
, h
);
360 print_mdoc_head(MDOC_ARGS
)
365 bufcat(h
, meta
->title
);
367 bufcat_fmt(h
, "(%s)", meta
->msec
);
369 bufcat_fmt(h
, " (%s)", meta
->arch
);
371 print_otag(h
, TAG_TITLE
, 0, NULL
);
372 print_text(h
, h
->buf
);
376 print_mdoc_nodelist(MDOC_ARGS
)
380 print_mdoc_node(meta
, n
, h
);
386 print_mdoc_node(MDOC_ARGS
)
393 n
->flags
&= ~MDOC_ENDED
;
397 /* No tables in this mode... */
398 assert(NULL
== h
->tblt
);
401 * Make sure that if we're in a literal mode already
402 * (i.e., within a <PRE>) don't print the newline.
404 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
405 if ( ! (HTML_LITERAL
& h
->flags
))
406 print_otag(h
, TAG_BR
, 0, NULL
);
407 if (MDOC_DELIMC
& n
->flags
)
408 h
->flags
|= HTML_NOSPACE
;
409 print_text(h
, n
->string
);
410 if (MDOC_DELIMO
& n
->flags
)
411 h
->flags
|= HTML_NOSPACE
;
414 if (n
->flags
& MDOC_LINE
)
416 print_eqn(h
, n
->eqn
);
420 * This will take care of initialising all of the table
421 * state data for the first table, then tearing it down
424 print_tbl(h
, n
->span
);
428 * Close out the current table, if it's open, and unset
429 * the "meta" table state. This will be reopened on the
430 * next table element.
432 if (h
->tblt
!= NULL
) {
436 assert(h
->tblt
== NULL
);
437 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
438 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
442 if (h
->flags
& HTML_KEEP
&& n
->flags
& MDOC_LINE
) {
443 h
->flags
&= ~HTML_KEEP
;
444 h
->flags
|= HTML_PREKEEP
;
447 if (child
&& n
->child
)
448 print_mdoc_nodelist(meta
, n
->child
, h
);
456 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
458 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
459 if (n
->end
!= ENDBODY_NOT
)
460 n
->body
->flags
|= MDOC_ENDED
;
461 if (n
->end
== ENDBODY_NOSPACE
)
462 h
->flags
|= HTML_NOSPACE
;
468 mdoc_root_post(MDOC_ARGS
)
473 PAIR_CLASS_INIT(&tag
, "foot");
474 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
476 print_otag(h
, TAG_TBODY
, 0, NULL
);
478 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
480 PAIR_CLASS_INIT(&tag
, "foot-date");
481 print_otag(h
, TAG_TD
, 1, &tag
);
482 print_text(h
, meta
->date
);
485 PAIR_CLASS_INIT(&tag
, "foot-os");
486 print_otag(h
, TAG_TD
, 1, &tag
);
487 print_text(h
, meta
->os
);
492 mdoc_root_pre(MDOC_ARGS
)
496 char *volume
, *title
;
498 if (NULL
== meta
->arch
)
499 volume
= mandoc_strdup(meta
->vol
);
501 mandoc_asprintf(&volume
, "%s (%s)",
502 meta
->vol
, meta
->arch
);
504 if (NULL
== meta
->msec
)
505 title
= mandoc_strdup(meta
->title
);
507 mandoc_asprintf(&title
, "%s(%s)",
508 meta
->title
, meta
->msec
);
510 PAIR_CLASS_INIT(&tag
, "head");
511 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
513 print_otag(h
, TAG_TBODY
, 0, NULL
);
515 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
517 PAIR_CLASS_INIT(&tag
, "head-ltitle");
518 print_otag(h
, TAG_TD
, 1, &tag
);
519 print_text(h
, title
);
522 PAIR_CLASS_INIT(&tag
, "head-vol");
523 print_otag(h
, TAG_TD
, 1, &tag
);
524 print_text(h
, volume
);
527 PAIR_CLASS_INIT(&tag
, "head-rtitle");
528 print_otag(h
, TAG_TD
, 1, &tag
);
529 print_text(h
, title
);
538 mdoc_sh_pre(MDOC_ARGS
)
544 PAIR_CLASS_INIT(&tag
, "section");
545 print_otag(h
, TAG_DIV
, 1, &tag
);
548 if (n
->sec
== SEC_AUTHORS
)
549 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
558 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
559 bufcat_id(h
, n
->string
);
560 if (NULL
!= (n
= n
->next
))
565 PAIR_ID_INIT(&tag
, h
->buf
);
566 print_otag(h
, TAG_H1
, 1, &tag
);
568 print_otag(h
, TAG_H1
, 0, NULL
);
574 mdoc_ss_pre(MDOC_ARGS
)
578 if (n
->type
== ROFFT_BLOCK
) {
579 PAIR_CLASS_INIT(&tag
, "subsection");
580 print_otag(h
, TAG_DIV
, 1, &tag
);
582 } else if (n
->type
== ROFFT_BODY
)
588 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
589 bufcat_id(h
, n
->string
);
590 if (NULL
!= (n
= n
->next
))
595 PAIR_ID_INIT(&tag
, h
->buf
);
596 print_otag(h
, TAG_H2
, 1, &tag
);
598 print_otag(h
, TAG_H2
, 0, NULL
);
604 mdoc_fl_pre(MDOC_ARGS
)
608 PAIR_CLASS_INIT(&tag
, "flag");
609 print_otag(h
, TAG_B
, 1, &tag
);
611 /* `Cm' has no leading hyphen. */
613 if (MDOC_Cm
== n
->tok
)
616 print_text(h
, "\\-");
618 if ( ! (n
->nchild
== 0 &&
620 n
->next
->type
== ROFFT_TEXT
||
621 n
->next
->flags
& MDOC_LINE
)))
622 h
->flags
|= HTML_NOSPACE
;
628 mdoc_nd_pre(MDOC_ARGS
)
632 if (n
->type
!= ROFFT_BODY
)
635 /* XXX: this tag in theory can contain block elements. */
637 print_text(h
, "\\(em");
638 PAIR_CLASS_INIT(&tag
, "desc");
639 print_otag(h
, TAG_SPAN
, 1, &tag
);
644 mdoc_nm_pre(MDOC_ARGS
)
653 PAIR_CLASS_INIT(&tag
, "name");
654 print_otag(h
, TAG_B
, 1, &tag
);
655 if (NULL
== n
->child
&& meta
->name
)
656 print_text(h
, meta
->name
);
659 print_otag(h
, TAG_TD
, 0, NULL
);
660 if (NULL
== n
->child
&& meta
->name
)
661 print_text(h
, meta
->name
);
664 print_otag(h
, TAG_TD
, 0, NULL
);
671 PAIR_CLASS_INIT(&tag
, "synopsis");
672 print_otag(h
, TAG_TABLE
, 1, &tag
);
674 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
675 if (n
->type
== ROFFT_TEXT
)
676 len
+= html_strlen(n
->string
);
678 if (0 == len
&& meta
->name
)
679 len
= html_strlen(meta
->name
);
681 SCALE_HS_INIT(&su
, len
);
683 bufcat_su(h
, "width", &su
);
684 PAIR_STYLE_INIT(&tag
, h
);
685 print_otag(h
, TAG_COL
, 1, &tag
);
686 print_otag(h
, TAG_COL
, 0, NULL
);
687 print_otag(h
, TAG_TBODY
, 0, NULL
);
688 print_otag(h
, TAG_TR
, 0, NULL
);
693 mdoc_xr_pre(MDOC_ARGS
)
695 struct htmlpair tag
[2];
697 if (NULL
== n
->child
)
700 PAIR_CLASS_INIT(&tag
[0], "link-man");
703 buffmt_man(h
, n
->child
->string
,
705 n
->child
->next
->string
: NULL
);
706 PAIR_HREF_INIT(&tag
[1], h
->buf
);
707 print_otag(h
, TAG_A
, 2, tag
);
709 print_otag(h
, TAG_A
, 1, tag
);
712 print_text(h
, n
->string
);
714 if (NULL
== (n
= n
->next
))
717 h
->flags
|= HTML_NOSPACE
;
719 h
->flags
|= HTML_NOSPACE
;
720 print_text(h
, n
->string
);
721 h
->flags
|= HTML_NOSPACE
;
727 mdoc_ns_pre(MDOC_ARGS
)
730 if ( ! (MDOC_LINE
& n
->flags
))
731 h
->flags
|= HTML_NOSPACE
;
736 mdoc_ar_pre(MDOC_ARGS
)
740 PAIR_CLASS_INIT(&tag
, "arg");
741 print_otag(h
, TAG_I
, 1, &tag
);
746 mdoc_xx_pre(MDOC_ARGS
)
775 PAIR_CLASS_INIT(&tag
, "unix");
776 print_otag(h
, TAG_SPAN
, 1, &tag
);
781 h
->flags
|= HTML_KEEP
;
782 print_text(h
, n
->child
->string
);
789 mdoc_bx_pre(MDOC_ARGS
)
793 PAIR_CLASS_INIT(&tag
, "unix");
794 print_otag(h
, TAG_SPAN
, 1, &tag
);
796 if (NULL
!= (n
= n
->child
)) {
797 print_text(h
, n
->string
);
798 h
->flags
|= HTML_NOSPACE
;
799 print_text(h
, "BSD");
801 print_text(h
, "BSD");
805 if (NULL
!= (n
= n
->next
)) {
806 h
->flags
|= HTML_NOSPACE
;
808 h
->flags
|= HTML_NOSPACE
;
809 print_text(h
, n
->string
);
816 mdoc_it_pre(MDOC_ARGS
)
820 struct htmlpair tag
[2];
821 const struct roff_node
*bl
;
824 while (bl
&& MDOC_Bl
!= bl
->tok
)
829 type
= bl
->norm
->Bl
.type
;
832 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
836 if (n
->type
== ROFFT_HEAD
) {
857 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
858 bufcat_su(h
, "margin-top", &su
);
859 PAIR_STYLE_INIT(&tag
[1], h
);
860 print_otag(h
, TAG_DT
, 2, tag
);
861 if (LIST_diag
!= type
)
863 PAIR_CLASS_INIT(&tag
[0], "diag");
864 print_otag(h
, TAG_B
, 1, tag
);
871 } else if (n
->type
== ROFFT_BODY
) {
882 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
883 bufcat_su(h
, "margin-top", &su
);
884 PAIR_STYLE_INIT(&tag
[1], h
);
885 print_otag(h
, TAG_LI
, 2, tag
);
896 if (NULL
== bl
->norm
->Bl
.width
) {
897 print_otag(h
, TAG_DD
, 1, tag
);
900 a2width(bl
->norm
->Bl
.width
, &su
);
901 bufcat_su(h
, "margin-left", &su
);
902 PAIR_STYLE_INIT(&tag
[1], h
);
903 print_otag(h
, TAG_DD
, 2, tag
);
906 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
907 bufcat_su(h
, "margin-top", &su
);
908 PAIR_STYLE_INIT(&tag
[1], h
);
909 print_otag(h
, TAG_TD
, 2, tag
);
917 print_otag(h
, TAG_TR
, 1, tag
);
928 mdoc_bl_pre(MDOC_ARGS
)
931 struct htmlpair tag
[3];
935 if (n
->type
== ROFFT_BODY
) {
936 if (LIST_column
== n
->norm
->Bl
.type
)
937 print_otag(h
, TAG_TBODY
, 0, NULL
);
941 if (n
->type
== ROFFT_HEAD
) {
942 if (LIST_column
!= n
->norm
->Bl
.type
)
946 * For each column, print out the <COL> tag with our
947 * suggested width. The last column gets min-width, as
948 * in terminal mode it auto-sizes to the width of the
949 * screen and we want to preserve that behaviour.
952 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
954 a2width(n
->norm
->Bl
.cols
[i
], &su
);
955 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
956 bufcat_su(h
, "width", &su
);
958 bufcat_su(h
, "min-width", &su
);
959 PAIR_STYLE_INIT(&tag
[0], h
);
960 print_otag(h
, TAG_COL
, 1, tag
);
966 SCALE_VS_INIT(&su
, 0);
968 bufcat_su(h
, "margin-top", &su
);
969 bufcat_su(h
, "margin-bottom", &su
);
970 PAIR_STYLE_INIT(&tag
[0], h
);
972 assert(lists
[n
->norm
->Bl
.type
]);
973 (void)strlcpy(buf
, "list ", BUFSIZ
);
974 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
975 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
977 /* Set the block's left-hand margin. */
979 if (n
->norm
->Bl
.offs
) {
980 a2width(n
->norm
->Bl
.offs
, &su
);
981 bufcat_su(h
, "margin-left", &su
);
984 switch (n
->norm
->Bl
.type
) {
992 print_otag(h
, TAG_UL
, 2, tag
);
995 print_otag(h
, TAG_OL
, 2, tag
);
1006 print_otag(h
, TAG_DL
, 2, tag
);
1009 print_otag(h
, TAG_TABLE
, 2, tag
);
1020 mdoc_ex_pre(MDOC_ARGS
)
1023 struct htmlpair tag
;
1027 print_otag(h
, TAG_BR
, 0, NULL
);
1029 PAIR_CLASS_INIT(&tag
, "utility");
1031 print_text(h
, "The");
1034 for (n
= n
->child
; n
; n
= n
->next
) {
1035 assert(n
->type
== ROFFT_TEXT
);
1037 t
= print_otag(h
, TAG_B
, 1, &tag
);
1038 print_text(h
, n
->string
);
1041 if (nchild
> 2 && n
->next
) {
1042 h
->flags
|= HTML_NOSPACE
;
1046 if (n
->next
&& NULL
== n
->next
->next
)
1047 print_text(h
, "and");
1051 print_text(h
, "utilities exit\\~0");
1053 print_text(h
, "utility exits\\~0");
1055 print_text(h
, "on success, and\\~>0 if an error occurs.");
1060 mdoc_em_pre(MDOC_ARGS
)
1062 struct htmlpair tag
;
1064 PAIR_CLASS_INIT(&tag
, "emph");
1065 print_otag(h
, TAG_SPAN
, 1, &tag
);
1070 mdoc_d1_pre(MDOC_ARGS
)
1072 struct htmlpair tag
[2];
1075 if (n
->type
!= ROFFT_BLOCK
)
1078 SCALE_VS_INIT(&su
, 0);
1080 bufcat_su(h
, "margin-top", &su
);
1081 bufcat_su(h
, "margin-bottom", &su
);
1082 PAIR_STYLE_INIT(&tag
[0], h
);
1083 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1085 /* BLOCKQUOTE needs a block body. */
1087 PAIR_CLASS_INIT(&tag
[0], "display");
1088 print_otag(h
, TAG_DIV
, 1, tag
);
1090 if (MDOC_Dl
== n
->tok
) {
1091 PAIR_CLASS_INIT(&tag
[0], "lit");
1092 print_otag(h
, TAG_CODE
, 1, tag
);
1099 mdoc_sx_pre(MDOC_ARGS
)
1101 struct htmlpair tag
[2];
1106 for (n
= n
->child
; n
; ) {
1107 bufcat_id(h
, n
->string
);
1108 if (NULL
!= (n
= n
->next
))
1112 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1113 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1115 print_otag(h
, TAG_I
, 1, tag
);
1116 print_otag(h
, TAG_A
, 2, tag
);
1121 mdoc_bd_pre(MDOC_ARGS
)
1123 struct htmlpair tag
[2];
1125 struct roff_node
*nn
;
1128 if (n
->type
== ROFFT_HEAD
)
1131 if (n
->type
== ROFFT_BLOCK
) {
1132 comp
= n
->norm
->Bd
.comp
;
1133 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1134 if (nn
->type
!= ROFFT_BLOCK
)
1136 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1146 /* Handle the -offset argument. */
1148 if (n
->norm
->Bd
.offs
== NULL
||
1149 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1150 SCALE_HS_INIT(&su
, 0);
1151 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1152 SCALE_HS_INIT(&su
, INDENT
);
1153 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1154 SCALE_HS_INIT(&su
, INDENT
* 2);
1156 a2width(n
->norm
->Bd
.offs
, &su
);
1159 bufcat_su(h
, "margin-left", &su
);
1160 PAIR_STYLE_INIT(&tag
[0], h
);
1162 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1163 DISP_literal
!= n
->norm
->Bd
.type
) {
1164 PAIR_CLASS_INIT(&tag
[1], "display");
1165 print_otag(h
, TAG_DIV
, 2, tag
);
1169 PAIR_CLASS_INIT(&tag
[1], "lit display");
1170 print_otag(h
, TAG_PRE
, 2, tag
);
1172 /* This can be recursive: save & set our literal state. */
1174 sv
= h
->flags
& HTML_LITERAL
;
1175 h
->flags
|= HTML_LITERAL
;
1177 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1178 print_mdoc_node(meta
, nn
, h
);
1180 * If the printed node flushes its own line, then we
1181 * needn't do it here as well. This is hacky, but the
1182 * notion of selective eoln whitespace is pretty dumb
1183 * anyway, so don't sweat it.
1205 if (h
->flags
& HTML_NONEWLINE
||
1206 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1209 print_text(h
, "\n");
1211 h
->flags
|= HTML_NOSPACE
;
1215 h
->flags
&= ~HTML_LITERAL
;
1221 mdoc_pa_pre(MDOC_ARGS
)
1223 struct htmlpair tag
;
1225 PAIR_CLASS_INIT(&tag
, "file");
1226 print_otag(h
, TAG_I
, 1, &tag
);
1231 mdoc_ad_pre(MDOC_ARGS
)
1233 struct htmlpair tag
;
1235 PAIR_CLASS_INIT(&tag
, "addr");
1236 print_otag(h
, TAG_I
, 1, &tag
);
1241 mdoc_an_pre(MDOC_ARGS
)
1243 struct htmlpair tag
;
1245 if (n
->norm
->An
.auth
== AUTH_split
) {
1246 h
->flags
&= ~HTML_NOSPLIT
;
1247 h
->flags
|= HTML_SPLIT
;
1250 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1251 h
->flags
&= ~HTML_SPLIT
;
1252 h
->flags
|= HTML_NOSPLIT
;
1256 if (h
->flags
& HTML_SPLIT
)
1257 print_otag(h
, TAG_BR
, 0, NULL
);
1259 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1260 h
->flags
|= HTML_SPLIT
;
1262 PAIR_CLASS_INIT(&tag
, "author");
1263 print_otag(h
, TAG_SPAN
, 1, &tag
);
1268 mdoc_cd_pre(MDOC_ARGS
)
1270 struct htmlpair tag
;
1273 PAIR_CLASS_INIT(&tag
, "config");
1274 print_otag(h
, TAG_B
, 1, &tag
);
1279 mdoc_dv_pre(MDOC_ARGS
)
1281 struct htmlpair tag
;
1283 PAIR_CLASS_INIT(&tag
, "define");
1284 print_otag(h
, TAG_SPAN
, 1, &tag
);
1289 mdoc_ev_pre(MDOC_ARGS
)
1291 struct htmlpair tag
;
1293 PAIR_CLASS_INIT(&tag
, "env");
1294 print_otag(h
, TAG_SPAN
, 1, &tag
);
1299 mdoc_er_pre(MDOC_ARGS
)
1301 struct htmlpair tag
;
1303 PAIR_CLASS_INIT(&tag
, "errno");
1304 print_otag(h
, TAG_SPAN
, 1, &tag
);
1309 mdoc_fa_pre(MDOC_ARGS
)
1311 const struct roff_node
*nn
;
1312 struct htmlpair tag
;
1315 PAIR_CLASS_INIT(&tag
, "farg");
1316 if (n
->parent
->tok
!= MDOC_Fo
) {
1317 print_otag(h
, TAG_I
, 1, &tag
);
1321 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1322 t
= print_otag(h
, TAG_I
, 1, &tag
);
1323 print_text(h
, nn
->string
);
1326 h
->flags
|= HTML_NOSPACE
;
1331 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1332 h
->flags
|= HTML_NOSPACE
;
1340 mdoc_fd_pre(MDOC_ARGS
)
1342 struct htmlpair tag
[2];
1350 if (NULL
== (n
= n
->child
))
1353 assert(n
->type
== ROFFT_TEXT
);
1355 if (strcmp(n
->string
, "#include")) {
1356 PAIR_CLASS_INIT(&tag
[0], "macro");
1357 print_otag(h
, TAG_B
, 1, tag
);
1361 PAIR_CLASS_INIT(&tag
[0], "includes");
1362 print_otag(h
, TAG_B
, 1, tag
);
1363 print_text(h
, n
->string
);
1365 if (NULL
!= (n
= n
->next
)) {
1366 assert(n
->type
== ROFFT_TEXT
);
1369 * XXX This is broken and not easy to fix.
1370 * When using -Oincludes, truncation may occur.
1371 * Dynamic allocation wouldn't help because
1372 * passing long strings to buffmt_includes()
1373 * does not work either.
1376 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1377 n
->string
+ 1 : n
->string
, BUFSIZ
);
1380 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1383 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1386 if (h
->base_includes
) {
1387 buffmt_includes(h
, buf
);
1388 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1392 t
= print_otag(h
, TAG_A
, i
, tag
);
1393 print_text(h
, n
->string
);
1399 for ( ; n
; n
= n
->next
) {
1400 assert(n
->type
== ROFFT_TEXT
);
1401 print_text(h
, n
->string
);
1408 mdoc_vt_pre(MDOC_ARGS
)
1410 struct htmlpair tag
;
1412 if (n
->type
== ROFFT_BLOCK
) {
1415 } else if (n
->type
== ROFFT_ELEM
) {
1417 } else if (n
->type
== ROFFT_HEAD
)
1420 PAIR_CLASS_INIT(&tag
, "type");
1421 print_otag(h
, TAG_SPAN
, 1, &tag
);
1426 mdoc_ft_pre(MDOC_ARGS
)
1428 struct htmlpair tag
;
1431 PAIR_CLASS_INIT(&tag
, "ftype");
1432 print_otag(h
, TAG_I
, 1, &tag
);
1437 mdoc_fn_pre(MDOC_ARGS
)
1440 struct htmlpair tag
[2];
1442 const char *sp
, *ep
;
1445 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1448 /* Split apart into type and name. */
1449 assert(n
->child
->string
);
1450 sp
= n
->child
->string
;
1452 ep
= strchr(sp
, ' ');
1454 PAIR_CLASS_INIT(&tag
[0], "ftype");
1455 t
= print_otag(h
, TAG_I
, 1, tag
);
1458 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1459 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1461 print_text(h
, nbuf
);
1463 ep
= strchr(sp
, ' ');
1468 PAIR_CLASS_INIT(&tag
[0], "fname");
1471 * FIXME: only refer to IDs that we know exist.
1475 if (MDOC_SYNPRETTY
& n
->flags
) {
1477 html_idcat(nbuf
, sp
, BUFSIZ
);
1478 PAIR_ID_INIT(&tag
[1], nbuf
);
1480 strlcpy(nbuf
, "#", BUFSIZ
);
1481 html_idcat(nbuf
, sp
, BUFSIZ
);
1482 PAIR_HREF_INIT(&tag
[1], nbuf
);
1486 t
= print_otag(h
, TAG_B
, 1, tag
);
1493 h
->flags
|= HTML_NOSPACE
;
1495 h
->flags
|= HTML_NOSPACE
;
1497 PAIR_CLASS_INIT(&tag
[0], "farg");
1499 bufcat_style(h
, "white-space", "nowrap");
1500 PAIR_STYLE_INIT(&tag
[1], h
);
1502 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1504 if (MDOC_SYNPRETTY
& n
->flags
)
1506 t
= print_otag(h
, TAG_I
, i
, tag
);
1507 print_text(h
, n
->string
);
1510 h
->flags
|= HTML_NOSPACE
;
1515 h
->flags
|= HTML_NOSPACE
;
1519 h
->flags
|= HTML_NOSPACE
;
1527 mdoc_sm_pre(MDOC_ARGS
)
1530 if (NULL
== n
->child
)
1531 h
->flags
^= HTML_NONOSPACE
;
1532 else if (0 == strcmp("on", n
->child
->string
))
1533 h
->flags
&= ~HTML_NONOSPACE
;
1535 h
->flags
|= HTML_NONOSPACE
;
1537 if ( ! (HTML_NONOSPACE
& h
->flags
))
1538 h
->flags
&= ~HTML_NOSPACE
;
1544 mdoc_skip_pre(MDOC_ARGS
)
1551 mdoc_pp_pre(MDOC_ARGS
)
1559 mdoc_sp_pre(MDOC_ARGS
)
1562 struct htmlpair tag
;
1564 SCALE_VS_INIT(&su
, 1);
1566 if (MDOC_sp
== n
->tok
) {
1567 if (NULL
!= (n
= n
->child
)) {
1568 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1570 else if (su
.scale
< 0.0)
1577 bufcat_su(h
, "height", &su
);
1578 PAIR_STYLE_INIT(&tag
, h
);
1579 print_otag(h
, TAG_DIV
, 1, &tag
);
1581 /* So the div isn't empty: */
1582 print_text(h
, "\\~");
1589 mdoc_lk_pre(MDOC_ARGS
)
1591 struct htmlpair tag
[2];
1593 if (NULL
== (n
= n
->child
))
1596 assert(n
->type
== ROFFT_TEXT
);
1598 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1599 PAIR_HREF_INIT(&tag
[1], n
->string
);
1601 print_otag(h
, TAG_A
, 2, tag
);
1603 if (NULL
== n
->next
)
1604 print_text(h
, n
->string
);
1606 for (n
= n
->next
; n
; n
= n
->next
)
1607 print_text(h
, n
->string
);
1613 mdoc_mt_pre(MDOC_ARGS
)
1615 struct htmlpair tag
[2];
1618 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1620 for (n
= n
->child
; n
; n
= n
->next
) {
1621 assert(n
->type
== ROFFT_TEXT
);
1624 bufcat(h
, "mailto:");
1625 bufcat(h
, n
->string
);
1627 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1628 t
= print_otag(h
, TAG_A
, 2, tag
);
1629 print_text(h
, n
->string
);
1637 mdoc_fo_pre(MDOC_ARGS
)
1639 struct htmlpair tag
;
1642 if (n
->type
== ROFFT_BODY
) {
1643 h
->flags
|= HTML_NOSPACE
;
1645 h
->flags
|= HTML_NOSPACE
;
1647 } else if (n
->type
== ROFFT_BLOCK
) {
1652 /* XXX: we drop non-initial arguments as per groff. */
1655 assert(n
->child
->string
);
1657 PAIR_CLASS_INIT(&tag
, "fname");
1658 t
= print_otag(h
, TAG_B
, 1, &tag
);
1659 print_text(h
, n
->child
->string
);
1665 mdoc_fo_post(MDOC_ARGS
)
1668 if (n
->type
!= ROFFT_BODY
)
1670 h
->flags
|= HTML_NOSPACE
;
1672 h
->flags
|= HTML_NOSPACE
;
1677 mdoc_in_pre(MDOC_ARGS
)
1680 struct htmlpair tag
[2];
1685 PAIR_CLASS_INIT(&tag
[0], "includes");
1686 print_otag(h
, TAG_B
, 1, tag
);
1689 * The first argument of the `In' gets special treatment as
1690 * being a linked value. Subsequent values are printed
1691 * afterward. groff does similarly. This also handles the case
1695 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1696 print_text(h
, "#include");
1699 h
->flags
|= HTML_NOSPACE
;
1701 if (NULL
!= (n
= n
->child
)) {
1702 assert(n
->type
== ROFFT_TEXT
);
1704 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1707 if (h
->base_includes
) {
1708 buffmt_includes(h
, n
->string
);
1709 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1713 t
= print_otag(h
, TAG_A
, i
, tag
);
1714 print_text(h
, n
->string
);
1720 h
->flags
|= HTML_NOSPACE
;
1723 for ( ; n
; n
= n
->next
) {
1724 assert(n
->type
== ROFFT_TEXT
);
1725 print_text(h
, n
->string
);
1732 mdoc_ic_pre(MDOC_ARGS
)
1734 struct htmlpair tag
;
1736 PAIR_CLASS_INIT(&tag
, "cmd");
1737 print_otag(h
, TAG_B
, 1, &tag
);
1742 mdoc_rv_pre(MDOC_ARGS
)
1744 struct htmlpair tag
;
1749 print_otag(h
, TAG_BR
, 0, NULL
);
1751 PAIR_CLASS_INIT(&tag
, "fname");
1755 print_text(h
, "The");
1757 for (n
= n
->child
; n
; n
= n
->next
) {
1758 t
= print_otag(h
, TAG_B
, 1, &tag
);
1759 print_text(h
, n
->string
);
1762 h
->flags
|= HTML_NOSPACE
;
1763 print_text(h
, "()");
1765 if (n
->next
== NULL
)
1769 h
->flags
|= HTML_NOSPACE
;
1772 if (n
->next
->next
== NULL
)
1773 print_text(h
, "and");
1777 print_text(h
, "functions return");
1779 print_text(h
, "function returns");
1781 print_text(h
, "the value\\~0 if successful;");
1783 print_text(h
, "Upon successful completion,"
1784 " the value\\~0 is returned;");
1786 print_text(h
, "otherwise the value\\~\\-1 is returned"
1787 " and the global variable");
1789 PAIR_CLASS_INIT(&tag
, "var");
1790 t
= print_otag(h
, TAG_B
, 1, &tag
);
1791 print_text(h
, "errno");
1793 print_text(h
, "is set to indicate the error.");
1798 mdoc_va_pre(MDOC_ARGS
)
1800 struct htmlpair tag
;
1802 PAIR_CLASS_INIT(&tag
, "var");
1803 print_otag(h
, TAG_B
, 1, &tag
);
1808 mdoc_ap_pre(MDOC_ARGS
)
1811 h
->flags
|= HTML_NOSPACE
;
1812 print_text(h
, "\\(aq");
1813 h
->flags
|= HTML_NOSPACE
;
1818 mdoc_bf_pre(MDOC_ARGS
)
1820 struct htmlpair tag
[2];
1823 if (n
->type
== ROFFT_HEAD
)
1825 else if (n
->type
!= ROFFT_BODY
)
1828 if (FONT_Em
== n
->norm
->Bf
.font
)
1829 PAIR_CLASS_INIT(&tag
[0], "emph");
1830 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1831 PAIR_CLASS_INIT(&tag
[0], "symb");
1832 else if (FONT_Li
== n
->norm
->Bf
.font
)
1833 PAIR_CLASS_INIT(&tag
[0], "lit");
1835 PAIR_CLASS_INIT(&tag
[0], "none");
1838 * We want this to be inline-formatted, but needs to be div to
1839 * accept block children.
1842 bufcat_style(h
, "display", "inline");
1843 SCALE_HS_INIT(&su
, 1);
1844 /* Needs a left-margin for spacing. */
1845 bufcat_su(h
, "margin-left", &su
);
1846 PAIR_STYLE_INIT(&tag
[1], h
);
1847 print_otag(h
, TAG_DIV
, 2, tag
);
1852 mdoc_ms_pre(MDOC_ARGS
)
1854 struct htmlpair tag
;
1856 PAIR_CLASS_INIT(&tag
, "symb");
1857 print_otag(h
, TAG_SPAN
, 1, &tag
);
1862 mdoc_igndelim_pre(MDOC_ARGS
)
1865 h
->flags
|= HTML_IGNDELIM
;
1870 mdoc_pf_post(MDOC_ARGS
)
1873 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1874 h
->flags
|= HTML_NOSPACE
;
1878 mdoc_rs_pre(MDOC_ARGS
)
1880 struct htmlpair tag
;
1882 if (n
->type
!= ROFFT_BLOCK
)
1885 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1888 PAIR_CLASS_INIT(&tag
, "ref");
1889 print_otag(h
, TAG_SPAN
, 1, &tag
);
1894 mdoc_no_pre(MDOC_ARGS
)
1896 struct htmlpair tag
;
1898 PAIR_CLASS_INIT(&tag
, "none");
1899 print_otag(h
, TAG_CODE
, 1, &tag
);
1904 mdoc_li_pre(MDOC_ARGS
)
1906 struct htmlpair tag
;
1908 PAIR_CLASS_INIT(&tag
, "lit");
1909 print_otag(h
, TAG_CODE
, 1, &tag
);
1914 mdoc_sy_pre(MDOC_ARGS
)
1916 struct htmlpair tag
;
1918 PAIR_CLASS_INIT(&tag
, "symb");
1919 print_otag(h
, TAG_SPAN
, 1, &tag
);
1924 mdoc_bt_pre(MDOC_ARGS
)
1927 print_text(h
, "is currently in beta test.");
1932 mdoc_ud_pre(MDOC_ARGS
)
1935 print_text(h
, "currently under development.");
1940 mdoc_lb_pre(MDOC_ARGS
)
1942 struct htmlpair tag
;
1944 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1945 print_otag(h
, TAG_BR
, 0, NULL
);
1947 PAIR_CLASS_INIT(&tag
, "lib");
1948 print_otag(h
, TAG_SPAN
, 1, &tag
);
1953 mdoc__x_pre(MDOC_ARGS
)
1955 struct htmlpair tag
[2];
1962 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1963 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1964 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1965 print_text(h
, "and");
1968 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1978 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1982 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1986 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1989 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1992 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1995 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1998 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2001 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2004 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2007 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2014 if (MDOC__U
!= n
->tok
) {
2015 print_otag(h
, t
, 1, tag
);
2019 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2020 print_otag(h
, TAG_A
, 2, tag
);
2026 mdoc__x_post(MDOC_ARGS
)
2029 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2030 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2031 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2036 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2039 h
->flags
|= HTML_NOSPACE
;
2040 print_text(h
, n
->next
? "," : ".");
2044 mdoc_bk_pre(MDOC_ARGS
)
2053 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2054 h
->flags
|= HTML_PREKEEP
;
2065 mdoc_bk_post(MDOC_ARGS
)
2068 if (n
->type
== ROFFT_BODY
)
2069 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2073 mdoc_quote_pre(MDOC_ARGS
)
2075 struct htmlpair tag
;
2077 if (n
->type
!= ROFFT_BODY
)
2084 print_text(h
, n
->nchild
== 1 &&
2085 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2090 print_text(h
, "\\(lC");
2095 print_text(h
, "\\(lB");
2100 print_text(h
, "\\(lB");
2101 h
->flags
|= HTML_NOSPACE
;
2102 PAIR_CLASS_INIT(&tag
, "opt");
2103 print_otag(h
, TAG_SPAN
, 1, &tag
);
2106 if (NULL
== n
->norm
->Es
||
2107 NULL
== n
->norm
->Es
->child
)
2109 print_text(h
, n
->norm
->Es
->child
->string
);
2118 print_text(h
, "\\(lq");
2126 print_text(h
, "\\(oq");
2127 h
->flags
|= HTML_NOSPACE
;
2128 PAIR_CLASS_INIT(&tag
, "lit");
2129 print_otag(h
, TAG_CODE
, 1, &tag
);
2134 print_text(h
, "\\(oq");
2141 h
->flags
|= HTML_NOSPACE
;
2146 mdoc_quote_post(MDOC_ARGS
)
2149 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
2152 h
->flags
|= HTML_NOSPACE
;
2158 print_text(h
, n
->nchild
== 1 &&
2159 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2164 print_text(h
, "\\(rC");
2173 print_text(h
, "\\(rB");
2176 if (n
->norm
->Es
== NULL
||
2177 n
->norm
->Es
->child
== NULL
||
2178 n
->norm
->Es
->child
->next
== NULL
)
2179 h
->flags
&= ~HTML_NOSPACE
;
2181 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2190 print_text(h
, "\\(rq");
2202 print_text(h
, "\\(cq");
2211 mdoc_eo_pre(MDOC_ARGS
)
2214 if (n
->type
!= ROFFT_BODY
)
2217 if (n
->end
== ENDBODY_NOT
&&
2218 n
->parent
->head
->child
== NULL
&&
2220 n
->child
->end
!= ENDBODY_NOT
)
2221 print_text(h
, "\\&");
2222 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2223 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2224 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2225 h
->flags
|= HTML_NOSPACE
;
2230 mdoc_eo_post(MDOC_ARGS
)
2234 if (n
->type
!= ROFFT_BODY
)
2237 if (n
->end
!= ENDBODY_NOT
) {
2238 h
->flags
&= ~HTML_NOSPACE
;
2242 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2243 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2246 h
->flags
|= HTML_NOSPACE
;
2248 h
->flags
&= ~HTML_NOSPACE
;