]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.76 2010/06/04 22:26:13 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
39 #define MDOC_ARGS const struct mdoc_meta *m, \
40 const struct mdoc_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static void print_mdoc(MDOC_ARGS
);
53 static void print_mdoc_head(MDOC_ARGS
);
54 static void print_mdoc_node(MDOC_ARGS
);
55 static void print_mdoc_nodelist(MDOC_ARGS
);
57 static void a2width(const char *, struct roffsu
*);
58 static void a2offs(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 void mdoc_aq_post(MDOC_ARGS
);
69 static int mdoc_aq_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bl_post(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static void mdoc_bq_post(MDOC_ARGS
);
76 static int mdoc_bq_pre(MDOC_ARGS
);
77 static void mdoc_brq_post(MDOC_ARGS
);
78 static int mdoc_brq_pre(MDOC_ARGS
);
79 static int mdoc_bt_pre(MDOC_ARGS
);
80 static int mdoc_bx_pre(MDOC_ARGS
);
81 static int mdoc_cd_pre(MDOC_ARGS
);
82 static int mdoc_d1_pre(MDOC_ARGS
);
83 static void mdoc_dq_post(MDOC_ARGS
);
84 static int mdoc_dq_pre(MDOC_ARGS
);
85 static int mdoc_dv_pre(MDOC_ARGS
);
86 static int mdoc_fa_pre(MDOC_ARGS
);
87 static void mdoc_fd_post(MDOC_ARGS
);
88 static int mdoc_fd_pre(MDOC_ARGS
);
89 static int mdoc_fl_pre(MDOC_ARGS
);
90 static int mdoc_fn_pre(MDOC_ARGS
);
91 static int mdoc_ft_pre(MDOC_ARGS
);
92 static int mdoc_em_pre(MDOC_ARGS
);
93 static int mdoc_er_pre(MDOC_ARGS
);
94 static int mdoc_ev_pre(MDOC_ARGS
);
95 static int mdoc_ex_pre(MDOC_ARGS
);
96 static void mdoc_fo_post(MDOC_ARGS
);
97 static int mdoc_fo_pre(MDOC_ARGS
);
98 static int mdoc_ic_pre(MDOC_ARGS
);
99 static int mdoc_in_pre(MDOC_ARGS
);
100 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
101 int, struct roffsu
*, struct roffsu
*);
102 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
104 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
,
106 static int mdoc_it_pre(MDOC_ARGS
);
107 static int mdoc_lb_pre(MDOC_ARGS
);
108 static int mdoc_li_pre(MDOC_ARGS
);
109 static int mdoc_lk_pre(MDOC_ARGS
);
110 static int mdoc_mt_pre(MDOC_ARGS
);
111 static int mdoc_ms_pre(MDOC_ARGS
);
112 static int mdoc_nd_pre(MDOC_ARGS
);
113 static int mdoc_nm_pre(MDOC_ARGS
);
114 static int mdoc_ns_pre(MDOC_ARGS
);
115 static void mdoc_op_post(MDOC_ARGS
);
116 static int mdoc_op_pre(MDOC_ARGS
);
117 static int mdoc_pa_pre(MDOC_ARGS
);
118 static void mdoc_pf_post(MDOC_ARGS
);
119 static int mdoc_pf_pre(MDOC_ARGS
);
120 static void mdoc_pq_post(MDOC_ARGS
);
121 static int mdoc_pq_pre(MDOC_ARGS
);
122 static int mdoc_rs_pre(MDOC_ARGS
);
123 static int mdoc_rv_pre(MDOC_ARGS
);
124 static int mdoc_sh_pre(MDOC_ARGS
);
125 static int mdoc_sp_pre(MDOC_ARGS
);
126 static void mdoc_sq_post(MDOC_ARGS
);
127 static int mdoc_sq_pre(MDOC_ARGS
);
128 static int mdoc_ss_pre(MDOC_ARGS
);
129 static int mdoc_sx_pre(MDOC_ARGS
);
130 static int mdoc_sy_pre(MDOC_ARGS
);
131 static int mdoc_ud_pre(MDOC_ARGS
);
132 static int mdoc_va_pre(MDOC_ARGS
);
133 static int mdoc_vt_pre(MDOC_ARGS
);
134 static int mdoc_xr_pre(MDOC_ARGS
);
135 static int mdoc_xx_pre(MDOC_ARGS
);
137 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
138 {mdoc_ap_pre
, NULL
}, /* Ap */
139 {NULL
, NULL
}, /* Dd */
140 {NULL
, NULL
}, /* Dt */
141 {NULL
, NULL
}, /* Os */
142 {mdoc_sh_pre
, NULL
}, /* Sh */
143 {mdoc_ss_pre
, NULL
}, /* Ss */
144 {mdoc_sp_pre
, NULL
}, /* Pp */
145 {mdoc_d1_pre
, NULL
}, /* D1 */
146 {mdoc_d1_pre
, NULL
}, /* Dl */
147 {mdoc_bd_pre
, NULL
}, /* Bd */
148 {NULL
, NULL
}, /* Ed */
149 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
150 {NULL
, NULL
}, /* El */
151 {mdoc_it_pre
, NULL
}, /* It */
152 {mdoc_ad_pre
, NULL
}, /* Ad */
153 {mdoc_an_pre
, NULL
}, /* An */
154 {mdoc_ar_pre
, NULL
}, /* Ar */
155 {mdoc_cd_pre
, NULL
}, /* Cd */
156 {mdoc_fl_pre
, NULL
}, /* Cm */
157 {mdoc_dv_pre
, NULL
}, /* Dv */
158 {mdoc_er_pre
, NULL
}, /* Er */
159 {mdoc_ev_pre
, NULL
}, /* Ev */
160 {mdoc_ex_pre
, NULL
}, /* Ex */
161 {mdoc_fa_pre
, NULL
}, /* Fa */
162 {mdoc_fd_pre
, mdoc_fd_post
}, /* Fd */
163 {mdoc_fl_pre
, NULL
}, /* Fl */
164 {mdoc_fn_pre
, NULL
}, /* Fn */
165 {mdoc_ft_pre
, NULL
}, /* Ft */
166 {mdoc_ic_pre
, NULL
}, /* Ic */
167 {mdoc_in_pre
, NULL
}, /* In */
168 {mdoc_li_pre
, NULL
}, /* Li */
169 {mdoc_nd_pre
, NULL
}, /* Nd */
170 {mdoc_nm_pre
, NULL
}, /* Nm */
171 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
172 {NULL
, NULL
}, /* Ot */
173 {mdoc_pa_pre
, NULL
}, /* Pa */
174 {mdoc_rv_pre
, NULL
}, /* Rv */
175 {NULL
, NULL
}, /* St */
176 {mdoc_va_pre
, NULL
}, /* Va */
177 {mdoc_vt_pre
, NULL
}, /* Vt */
178 {mdoc_xr_pre
, NULL
}, /* Xr */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
189 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
190 {NULL
, NULL
}, /* Ac */
191 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
192 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
193 {NULL
, NULL
}, /* At */
194 {NULL
, NULL
}, /* Bc */
195 {mdoc_bf_pre
, NULL
}, /* Bf */
196 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
197 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
198 {mdoc_xx_pre
, NULL
}, /* Bsx */
199 {mdoc_bx_pre
, NULL
}, /* Bx */
200 {NULL
, NULL
}, /* Db */
201 {NULL
, NULL
}, /* Dc */
202 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
203 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
204 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
205 {NULL
, NULL
}, /* Ef */
206 {mdoc_em_pre
, NULL
}, /* Em */
207 {NULL
, NULL
}, /* Eo */
208 {mdoc_xx_pre
, NULL
}, /* Fx */
209 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
210 {NULL
, NULL
}, /* No */
211 {mdoc_ns_pre
, NULL
}, /* Ns */
212 {mdoc_xx_pre
, NULL
}, /* Nx */
213 {mdoc_xx_pre
, NULL
}, /* Ox */
214 {NULL
, NULL
}, /* Pc */
215 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
216 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
217 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
218 {NULL
, NULL
}, /* Qc */
219 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
220 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
221 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
222 {NULL
, NULL
}, /* Re */
223 {mdoc_rs_pre
, NULL
}, /* Rs */
224 {NULL
, NULL
}, /* Sc */
225 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
226 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
227 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
228 {mdoc_sx_pre
, NULL
}, /* Sx */
229 {mdoc_sy_pre
, NULL
}, /* Sy */
230 {NULL
, NULL
}, /* Tn */
231 {mdoc_xx_pre
, NULL
}, /* Ux */
232 {NULL
, NULL
}, /* Xc */
233 {NULL
, NULL
}, /* Xo */
234 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
235 {NULL
, NULL
}, /* Fc */
236 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
237 {NULL
, NULL
}, /* Oc */
238 {NULL
, NULL
}, /* Bk */
239 {NULL
, NULL
}, /* Ek */
240 {mdoc_bt_pre
, NULL
}, /* Bt */
241 {NULL
, NULL
}, /* Hf */
242 {NULL
, NULL
}, /* Fr */
243 {mdoc_ud_pre
, NULL
}, /* Ud */
244 {mdoc_lb_pre
, NULL
}, /* Lb */
245 {mdoc_sp_pre
, NULL
}, /* Lp */
246 {mdoc_lk_pre
, NULL
}, /* Lk */
247 {mdoc_mt_pre
, NULL
}, /* Mt */
248 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
249 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
250 {NULL
, NULL
}, /* Brc */
251 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
252 {NULL
, NULL
}, /* Es */ /* TODO */
253 {NULL
, NULL
}, /* En */ /* TODO */
254 {mdoc_xx_pre
, NULL
}, /* Dx */
255 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
256 {mdoc_sp_pre
, NULL
}, /* br */
257 {mdoc_sp_pre
, NULL
}, /* sp */
258 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
259 {NULL
, NULL
}, /* Ta */
264 html_mdoc(void *arg
, const struct mdoc
*m
)
269 h
= (struct html
*)arg
;
272 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
273 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
281 * Calculate the scaling unit passed in a `-width' argument. This uses
282 * either a native scaling unit (e.g., 1i, 2m) or the string length of
286 a2width(const char *p
, struct roffsu
*su
)
289 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
291 su
->scale
= (int)strlen(p
);
297 * Calculate the scaling unit passed in an `-offset' argument. This
298 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
299 * predefined strings (indent, etc.), or the string length of the value.
302 a2offs(const char *p
, struct roffsu
*su
)
305 /* FIXME: "right"? */
307 if (0 == strcmp(p
, "left"))
308 SCALE_HS_INIT(su
, 0);
309 else if (0 == strcmp(p
, "indent"))
310 SCALE_HS_INIT(su
, INDENT
);
311 else if (0 == strcmp(p
, "indent-two"))
312 SCALE_HS_INIT(su
, INDENT
* 2);
313 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
315 su
->scale
= (int)strlen(p
);
321 print_mdoc(MDOC_ARGS
)
326 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
327 print_mdoc_head(m
, n
, h
);
330 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
332 tag
.key
= ATTR_CLASS
;
334 print_otag(h
, TAG_DIV
, 1, &tag
);
336 print_mdoc_nodelist(m
, n
, h
);
343 print_mdoc_head(MDOC_ARGS
)
348 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
356 print_otag(h
, TAG_TITLE
, 0, NULL
);
357 print_text(h
, h
->buf
);
362 print_mdoc_nodelist(MDOC_ARGS
)
365 print_mdoc_node(m
, n
, h
);
367 print_mdoc_nodelist(m
, n
->next
, h
);
372 print_mdoc_node(MDOC_ARGS
)
383 child
= mdoc_root_pre(m
, n
, h
);
386 print_text(h
, n
->string
);
389 if (mdocs
[n
->tok
].pre
)
390 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
394 if (child
&& n
->child
)
395 print_mdoc_nodelist(m
, n
->child
, h
);
402 mdoc_root_post(m
, n
, h
);
405 if (mdocs
[n
->tok
].post
)
406 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
414 mdoc_root_post(MDOC_ARGS
)
416 struct htmlpair tag
[3];
420 time2a(m
->date
, b
, DATESIZ
);
423 * XXX: this should use divs, but in Firefox, divs with nested
424 * divs for some reason puke when trying to put a border line
425 * below. So I use tables, instead.
428 PAIR_CLASS_INIT(&tag
[0], "footer");
429 bufcat_style(h
, "width", "100%");
430 PAIR_STYLE_INIT(&tag
[1], h
);
431 PAIR_SUMMARY_INIT(&tag
[2], "footer");
433 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
434 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
437 bufcat_style(h
, "width", "50%");
438 PAIR_STYLE_INIT(&tag
[0], h
);
439 print_otag(h
, TAG_TD
, 1, tag
);
444 bufcat_style(h
, "width", "50%");
445 bufcat_style(h
, "text-align", "right");
446 PAIR_STYLE_INIT(&tag
[0], h
);
447 print_otag(h
, TAG_TD
, 1, tag
);
448 print_text(h
, m
->os
);
455 mdoc_root_pre(MDOC_ARGS
)
457 struct htmlpair tag
[3];
459 char b
[BUFSIZ
], title
[BUFSIZ
];
461 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
464 (void)strlcat(b
, " (", BUFSIZ
);
465 (void)strlcat(b
, m
->arch
, BUFSIZ
);
466 (void)strlcat(b
, ")", BUFSIZ
);
469 (void)snprintf(title
, BUFSIZ
- 1,
470 "%s(%s)", m
->title
, m
->msec
);
472 /* XXX: see note in mdoc_root_post() about divs. */
474 PAIR_CLASS_INIT(&tag
[0], "header");
475 bufcat_style(h
, "width", "100%");
476 PAIR_STYLE_INIT(&tag
[1], h
);
477 PAIR_SUMMARY_INIT(&tag
[2], "header");
479 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
481 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
484 bufcat_style(h
, "width", "10%");
485 PAIR_STYLE_INIT(&tag
[0], h
);
486 print_otag(h
, TAG_TD
, 1, tag
);
487 print_text(h
, title
);
491 bufcat_style(h
, "text-align", "center");
492 bufcat_style(h
, "white-space", "nowrap");
493 bufcat_style(h
, "width", "80%");
494 PAIR_STYLE_INIT(&tag
[0], h
);
495 print_otag(h
, TAG_TD
, 1, tag
);
500 bufcat_style(h
, "text-align", "right");
501 bufcat_style(h
, "width", "10%");
502 PAIR_STYLE_INIT(&tag
[0], h
);
503 print_otag(h
, TAG_TD
, 1, tag
);
504 print_text(h
, title
);
512 mdoc_sh_pre(MDOC_ARGS
)
514 struct htmlpair tag
[2];
515 const struct mdoc_node
*nn
;
519 if (MDOC_BODY
== n
->type
) {
520 SCALE_HS_INIT(&su
, INDENT
);
521 bufcat_su(h
, "margin-left", &su
);
522 PAIR_CLASS_INIT(&tag
[0], "sec-body");
523 PAIR_STYLE_INIT(&tag
[1], h
);
524 print_otag(h
, TAG_DIV
, 2, tag
);
526 } else if (MDOC_BLOCK
== n
->type
) {
527 PAIR_CLASS_INIT(&tag
[0], "sec-block");
528 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
529 print_otag(h
, TAG_DIV
, 1, tag
);
533 SCALE_VS_INIT(&su
, 1);
534 bufcat_su(h
, "margin-top", &su
);
536 bufcat_su(h
, "margin-bottom", &su
);
538 PAIR_STYLE_INIT(&tag
[1], h
);
539 print_otag(h
, TAG_DIV
, 2, tag
);
544 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
545 html_idcat(buf
, nn
->string
, BUFSIZ
);
547 html_idcat(buf
, " ", BUFSIZ
);
550 PAIR_CLASS_INIT(&tag
[0], "sec-head");
551 PAIR_ID_INIT(&tag
[1], buf
);
553 print_otag(h
, TAG_DIV
, 2, tag
);
560 mdoc_ss_pre(MDOC_ARGS
)
562 struct htmlpair tag
[3];
563 const struct mdoc_node
*nn
;
567 SCALE_VS_INIT(&su
, 1);
569 if (MDOC_BODY
== n
->type
) {
570 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
571 if (n
->parent
->next
&& n
->child
) {
572 bufcat_su(h
, "margin-bottom", &su
);
573 PAIR_STYLE_INIT(&tag
[1], h
);
574 print_otag(h
, TAG_DIV
, 2, tag
);
576 print_otag(h
, TAG_DIV
, 1, tag
);
578 } else if (MDOC_BLOCK
== n
->type
) {
579 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
581 bufcat_su(h
, "margin-top", &su
);
582 PAIR_STYLE_INIT(&tag
[1], h
);
583 print_otag(h
, TAG_DIV
, 2, tag
);
585 print_otag(h
, TAG_DIV
, 1, tag
);
589 /* TODO: see note in mdoc_sh_pre() about duplicates. */
592 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
593 html_idcat(buf
, nn
->string
, BUFSIZ
);
595 html_idcat(buf
, " ", BUFSIZ
);
598 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
599 su
.scale
= -su
.scale
;
600 bufcat_su(h
, "margin-left", &su
);
602 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
603 PAIR_STYLE_INIT(&tag
[1], h
);
604 PAIR_ID_INIT(&tag
[2], buf
);
606 print_otag(h
, TAG_DIV
, 3, tag
);
613 mdoc_fl_pre(MDOC_ARGS
)
617 PAIR_CLASS_INIT(&tag
, "flag");
618 print_otag(h
, TAG_SPAN
, 1, &tag
);
620 /* `Cm' has no leading hyphen. */
622 if (MDOC_Cm
== n
->tok
)
625 print_text(h
, "\\-");
628 h
->flags
|= HTML_NOSPACE
;
629 else if (n
->next
&& n
->next
->line
== n
->line
)
630 h
->flags
|= HTML_NOSPACE
;
638 mdoc_nd_pre(MDOC_ARGS
)
642 if (MDOC_BODY
!= n
->type
)
645 /* XXX: this tag in theory can contain block elements. */
647 print_text(h
, "\\(em");
648 PAIR_CLASS_INIT(&tag
, "desc-body");
649 print_otag(h
, TAG_SPAN
, 1, &tag
);
656 mdoc_op_pre(MDOC_ARGS
)
660 if (MDOC_BODY
!= n
->type
)
663 /* XXX: this tag in theory can contain block elements. */
665 print_text(h
, "\\(lB");
666 h
->flags
|= HTML_NOSPACE
;
667 PAIR_CLASS_INIT(&tag
, "opt");
668 print_otag(h
, TAG_SPAN
, 1, &tag
);
675 mdoc_op_post(MDOC_ARGS
)
678 if (MDOC_BODY
!= n
->type
)
680 h
->flags
|= HTML_NOSPACE
;
681 print_text(h
, "\\(rB");
686 mdoc_nm_pre(MDOC_ARGS
)
690 if (NULL
== n
->child
&& NULL
== m
->name
)
693 if (SEC_SYNOPSIS
== n
->sec
&&
694 n
->prev
&& MDOC_LINE
& n
->flags
) {
695 bufcat_style(h
, "clear", "both");
696 PAIR_STYLE_INIT(&tag
, h
);
697 print_otag(h
, TAG_BR
, 1, &tag
);
700 PAIR_CLASS_INIT(&tag
, "name");
701 print_otag(h
, TAG_SPAN
, 1, &tag
);
702 if (NULL
== n
->child
)
703 print_text(h
, m
->name
);
711 mdoc_xr_pre(MDOC_ARGS
)
713 struct htmlpair tag
[2];
714 const struct mdoc_node
*nn
;
716 if (NULL
== n
->child
)
719 PAIR_CLASS_INIT(&tag
[0], "link-man");
722 buffmt_man(h
, n
->child
->string
,
724 n
->child
->next
->string
: NULL
);
725 PAIR_HREF_INIT(&tag
[1], h
->buf
);
726 print_otag(h
, TAG_A
, 2, tag
);
728 print_otag(h
, TAG_A
, 1, tag
);
731 print_text(h
, nn
->string
);
733 if (NULL
== (nn
= nn
->next
))
736 h
->flags
|= HTML_NOSPACE
;
738 h
->flags
|= HTML_NOSPACE
;
739 print_text(h
, nn
->string
);
740 h
->flags
|= HTML_NOSPACE
;
748 mdoc_ns_pre(MDOC_ARGS
)
751 h
->flags
|= HTML_NOSPACE
;
758 mdoc_ar_pre(MDOC_ARGS
)
762 PAIR_CLASS_INIT(&tag
, "arg");
763 print_otag(h
, TAG_SPAN
, 1, &tag
);
770 mdoc_xx_pre(MDOC_ARGS
)
798 PAIR_CLASS_INIT(&tag
, "unix");
799 print_otag(h
, TAG_SPAN
, 1, &tag
);
807 mdoc_bx_pre(MDOC_ARGS
)
809 const struct mdoc_node
*nn
;
812 PAIR_CLASS_INIT(&tag
, "unix");
813 print_otag(h
, TAG_SPAN
, 1, &tag
);
815 for (nn
= n
->child
; nn
; nn
= nn
->next
)
816 print_mdoc_node(m
, nn
, h
);
819 h
->flags
|= HTML_NOSPACE
;
821 print_text(h
, "BSD");
828 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
829 struct roffsu
*offs
, struct roffsu
*width
)
832 const struct mdoc_node
*nn
;
835 nn
= n
->parent
->parent
;
837 /* XXX: see notes in mdoc_it_pre(). */
839 if (LIST_column
== type
) {
840 /* Don't width-pad on the left. */
841 SCALE_HS_INIT(width
, 0);
842 /* Also disallow non-compact. */
845 if (LIST_diag
== type
)
846 /* Mandate non-compact with empty prior. */
847 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
850 bufcat_style(h
, "clear", "both");
852 bufcat_su(h
, "margin-left", offs
);
853 if (width
->scale
> 0)
854 bufcat_su(h
, "padding-left", width
);
856 PAIR_STYLE_INIT(&tag
, h
);
858 /* Mandate compact following `Ss' and `Sh' starts. */
860 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
861 if (MDOC_BLOCK
!= nn
->type
)
863 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
870 SCALE_VS_INIT(&su
, 1);
871 bufcat_su(h
, "padding-top", &su
);
874 PAIR_STYLE_INIT(&tag
, h
);
875 print_otag(h
, TAG_DIV
, 1, &tag
);
882 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
893 bufcat_su(h
, "min-width", width
);
894 bufcat_style(h
, "clear", "none");
896 bufcat_style(h
, "float", "left");
897 PAIR_STYLE_INIT(&tag
, h
);
898 print_otag(h
, TAG_DIV
, 1, &tag
);
902 * XXX: this tricks CSS into aligning the bodies with
903 * the right-padding in the head.
905 SCALE_HS_INIT(&su
, 2);
906 bufcat_su(h
, "margin-left", &su
);
907 PAIR_STYLE_INIT(&tag
, h
);
908 print_otag(h
, TAG_DIV
, 1, &tag
);
918 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
928 print_otag(h
, TAG_DIV
, 0, &tag
);
933 bufcat_su(h
, "min-width", width
);
935 bufcat_su(h
, "margin-left", width
);
936 if (n
->next
&& n
->next
->child
)
937 bufcat_style(h
, "float", "left");
939 /* XXX: buffer if we run into body. */
940 SCALE_HS_INIT(width
, 1);
941 bufcat_su(h
, "margin-right", width
);
942 PAIR_STYLE_INIT(&tag
, h
);
943 print_otag(h
, TAG_DIV
, 1, &tag
);
949 PAIR_CLASS_INIT(&tag
, "diag");
950 print_otag(h
, TAG_SPAN
, 1, &tag
);
955 nbuf
[BUFSIZ
- 1] = 0;
956 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
960 print_text(h
, "\\(en");
963 print_text(h
, "\\(hy");
966 print_text(h
, "\\(bu");
977 mdoc_it_pre(MDOC_ARGS
)
980 const struct mdoc_node
*bl
, *nn
;
981 struct roffsu width
, offs
;
985 * XXX: be very careful in changing anything, here. Lists in
986 * mandoc have many peculiarities; furthermore, they don't
987 * translate well into HTML and require a bit of mangling.
990 bl
= n
->parent
->parent
;
991 if (MDOC_BLOCK
!= n
->type
)
994 type
= bl
->data
.list
;
996 /* Set default width and offset. */
998 SCALE_HS_INIT(&offs
, 0);
1008 SCALE_HS_INIT(&width
, 2);
1011 SCALE_HS_INIT(&width
, INDENT
);
1015 /* Get width, offset, and compact arguments. */
1018 for (comp
= i
= 0; bl
->args
&& i
< (int)bl
->args
->argc
; i
++)
1019 switch (bl
->args
->argv
[i
].arg
) {
1021 wp
= i
; /* Save for later. */
1024 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1027 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1029 case (MDOC_Compact
):
1036 /* Override width in some cases. */
1046 SCALE_HS_INIT(&width
, 0);
1049 if (0 == width
.scale
)
1050 SCALE_HS_INIT(&width
, INDENT
);
1054 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1055 nn
= n
->parent
->child
;
1056 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1057 if (MDOC_BODY
== nn
->type
)
1059 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1060 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1063 if (MDOC_HEAD
== n
->type
)
1064 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1065 else if (MDOC_BODY
== n
->type
)
1066 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1068 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1074 mdoc_bl_pre(MDOC_ARGS
)
1078 if (MDOC_HEAD
== n
->type
)
1080 if (MDOC_BLOCK
!= n
->type
)
1082 if (LIST_enum
!= n
->data
.list
)
1085 ord
= malloc(sizeof(struct ord
));
1092 ord
->next
= h
->ords
.head
;
1100 mdoc_bl_post(MDOC_ARGS
)
1104 if (MDOC_BLOCK
!= n
->type
)
1106 if (LIST_enum
!= n
->data
.list
)
1111 h
->ords
.head
= ord
->next
;
1118 mdoc_ex_pre(MDOC_ARGS
)
1120 const struct mdoc_node
*nn
;
1122 struct htmlpair tag
;
1124 PAIR_CLASS_INIT(&tag
, "utility");
1126 print_text(h
, "The");
1127 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1128 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1129 print_text(h
, nn
->string
);
1132 h
->flags
|= HTML_NOSPACE
;
1134 if (nn
->next
&& NULL
== nn
->next
->next
)
1135 print_text(h
, ", and");
1139 h
->flags
&= ~HTML_NOSPACE
;
1142 if (n
->child
&& n
->child
->next
)
1143 print_text(h
, "utilities exit");
1145 print_text(h
, "utility exits");
1147 print_text(h
, "0 on success, and >0 if an error occurs.");
1154 mdoc_dq_pre(MDOC_ARGS
)
1157 if (MDOC_BODY
!= n
->type
)
1159 print_text(h
, "\\(lq");
1160 h
->flags
|= HTML_NOSPACE
;
1167 mdoc_dq_post(MDOC_ARGS
)
1170 if (MDOC_BODY
!= n
->type
)
1172 h
->flags
|= HTML_NOSPACE
;
1173 print_text(h
, "\\(rq");
1179 mdoc_pq_pre(MDOC_ARGS
)
1182 if (MDOC_BODY
!= n
->type
)
1184 print_text(h
, "\\&(");
1185 h
->flags
|= HTML_NOSPACE
;
1192 mdoc_pq_post(MDOC_ARGS
)
1195 if (MDOC_BODY
!= n
->type
)
1203 mdoc_sq_pre(MDOC_ARGS
)
1206 if (MDOC_BODY
!= n
->type
)
1208 print_text(h
, "\\(oq");
1209 h
->flags
|= HTML_NOSPACE
;
1216 mdoc_sq_post(MDOC_ARGS
)
1219 if (MDOC_BODY
!= n
->type
)
1221 h
->flags
|= HTML_NOSPACE
;
1222 print_text(h
, "\\(aq");
1228 mdoc_em_pre(MDOC_ARGS
)
1230 struct htmlpair tag
;
1232 PAIR_CLASS_INIT(&tag
, "emph");
1233 print_otag(h
, TAG_SPAN
, 1, &tag
);
1240 mdoc_d1_pre(MDOC_ARGS
)
1242 struct htmlpair tag
[2];
1245 if (MDOC_BLOCK
!= n
->type
)
1248 /* FIXME: D1 shouldn't be literal. */
1250 SCALE_VS_INIT(&su
, INDENT
- 1);
1251 bufcat_su(h
, "margin-left", &su
);
1252 PAIR_CLASS_INIT(&tag
[0], "lit");
1253 PAIR_STYLE_INIT(&tag
[1], h
);
1254 print_otag(h
, TAG_DIV
, 2, tag
);
1261 mdoc_sx_pre(MDOC_ARGS
)
1263 struct htmlpair tag
[2];
1264 const struct mdoc_node
*nn
;
1267 strlcpy(buf
, "#", BUFSIZ
);
1268 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1269 html_idcat(buf
, nn
->string
, BUFSIZ
);
1271 html_idcat(buf
, " ", BUFSIZ
);
1274 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1275 PAIR_HREF_INIT(&tag
[1], buf
);
1277 print_otag(h
, TAG_A
, 2, tag
);
1284 mdoc_aq_pre(MDOC_ARGS
)
1287 if (MDOC_BODY
!= n
->type
)
1289 print_text(h
, "\\(la");
1290 h
->flags
|= HTML_NOSPACE
;
1297 mdoc_aq_post(MDOC_ARGS
)
1300 if (MDOC_BODY
!= n
->type
)
1302 h
->flags
|= HTML_NOSPACE
;
1303 print_text(h
, "\\(ra");
1309 mdoc_bd_pre(MDOC_ARGS
)
1311 struct htmlpair tag
[2];
1313 const struct mdoc_node
*bl
, *nn
;
1316 if (MDOC_BLOCK
== n
->type
)
1318 else if (MDOC_HEAD
== n
->type
)
1323 SCALE_VS_INIT(&su
, 0);
1326 for (i
= 0; bl
->args
&& i
< (int)bl
->args
->argc
; i
++)
1327 switch (bl
->args
->argv
[i
].arg
) {
1329 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1331 case (MDOC_Compact
):
1334 case (MDOC_Centred
):
1340 case (MDOC_Unfilled
):
1342 case (MDOC_Literal
):
1343 type
= bl
->args
->argv
[i
].arg
;
1349 /* FIXME: -centered, etc. formatting. */
1350 /* FIXME: does not respect -offset ??? */
1352 if (MDOC_BLOCK
== n
->type
) {
1353 bufcat_su(h
, "margin-left", &su
);
1354 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1355 if (MDOC_BLOCK
!= nn
->type
)
1357 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1363 PAIR_STYLE_INIT(&tag
[0], h
);
1364 print_otag(h
, TAG_DIV
, 1, tag
);
1367 SCALE_VS_INIT(&su
, 1);
1368 bufcat_su(h
, "margin-top", &su
);
1369 PAIR_STYLE_INIT(&tag
[0], h
);
1370 print_otag(h
, TAG_DIV
, 1, tag
);
1374 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1377 PAIR_CLASS_INIT(&tag
[0], "lit");
1378 bufcat_style(h
, "white-space", "pre");
1379 PAIR_STYLE_INIT(&tag
[1], h
);
1380 print_otag(h
, TAG_DIV
, 2, tag
);
1382 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1383 h
->flags
|= HTML_NOSPACE
;
1384 print_mdoc_node(m
, nn
, h
);
1385 if (NULL
== nn
->next
)
1387 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1388 print_text(h
, "\n");
1389 else if (NULL
== nn
->prev
)
1390 print_text(h
, "\n");
1399 mdoc_pa_pre(MDOC_ARGS
)
1401 struct htmlpair tag
;
1403 PAIR_CLASS_INIT(&tag
, "file");
1404 print_otag(h
, TAG_SPAN
, 1, &tag
);
1411 mdoc_ad_pre(MDOC_ARGS
)
1413 struct htmlpair tag
;
1415 PAIR_CLASS_INIT(&tag
, "addr");
1416 print_otag(h
, TAG_SPAN
, 1, &tag
);
1423 mdoc_an_pre(MDOC_ARGS
)
1425 struct htmlpair tag
;
1427 /* TODO: -split and -nosplit (see termp_an_pre()). */
1429 PAIR_CLASS_INIT(&tag
, "author");
1430 print_otag(h
, TAG_SPAN
, 1, &tag
);
1437 mdoc_cd_pre(MDOC_ARGS
)
1439 struct htmlpair tag
;
1441 print_otag(h
, TAG_DIV
, 0, NULL
);
1442 PAIR_CLASS_INIT(&tag
, "config");
1443 print_otag(h
, TAG_SPAN
, 1, &tag
);
1450 mdoc_dv_pre(MDOC_ARGS
)
1452 struct htmlpair tag
;
1454 PAIR_CLASS_INIT(&tag
, "define");
1455 print_otag(h
, TAG_SPAN
, 1, &tag
);
1462 mdoc_ev_pre(MDOC_ARGS
)
1464 struct htmlpair tag
;
1466 PAIR_CLASS_INIT(&tag
, "env");
1467 print_otag(h
, TAG_SPAN
, 1, &tag
);
1474 mdoc_er_pre(MDOC_ARGS
)
1476 struct htmlpair tag
;
1478 PAIR_CLASS_INIT(&tag
, "errno");
1479 print_otag(h
, TAG_SPAN
, 1, &tag
);
1486 mdoc_fa_pre(MDOC_ARGS
)
1488 const struct mdoc_node
*nn
;
1489 struct htmlpair tag
;
1492 PAIR_CLASS_INIT(&tag
, "farg");
1493 if (n
->parent
->tok
!= MDOC_Fo
) {
1494 print_otag(h
, TAG_SPAN
, 1, &tag
);
1498 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1499 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1500 print_text(h
, nn
->string
);
1506 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1515 mdoc_fd_post(MDOC_ARGS
)
1518 print_otag(h
, TAG_BR
, 0, NULL
);
1524 mdoc_fd_pre(MDOC_ARGS
)
1526 struct htmlpair tag
;
1528 PAIR_CLASS_INIT(&tag
, "macro");
1529 print_otag(h
, TAG_SPAN
, 1, &tag
);
1536 mdoc_vt_pre(MDOC_ARGS
)
1538 struct htmlpair tag
;
1541 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_BLOCK
== n
->type
) {
1542 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1543 SCALE_VS_INIT(&su
, 1);
1544 bufcat_su(h
, "margin-bottom", &su
);
1545 PAIR_STYLE_INIT(&tag
, h
);
1546 print_otag(h
, TAG_DIV
, 1, &tag
);
1548 print_otag(h
, TAG_DIV
, 0, NULL
);
1551 } else if (MDOC_HEAD
== n
->type
)
1554 PAIR_CLASS_INIT(&tag
, "type");
1555 print_otag(h
, TAG_SPAN
, 1, &tag
);
1562 mdoc_ft_pre(MDOC_ARGS
)
1564 struct htmlpair tag
;
1566 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1567 print_otag(h
, TAG_DIV
, 0, NULL
);
1569 PAIR_CLASS_INIT(&tag
, "ftype");
1570 print_otag(h
, TAG_SPAN
, 1, &tag
);
1577 mdoc_fn_pre(MDOC_ARGS
)
1580 struct htmlpair tag
[2];
1581 const struct mdoc_node
*nn
;
1583 const char *sp
, *ep
;
1587 /* NB: MDOC_LINE has no effect on this macro! */
1588 if (SEC_SYNOPSIS
== n
->sec
) {
1589 SCALE_HS_INIT(&su
, INDENT
);
1590 bufcat_su(h
, "margin-left", &su
);
1591 su
.scale
= -su
.scale
;
1592 bufcat_su(h
, "text-indent", &su
);
1593 if (n
->prev
&& MDOC_Ft
!= n
->prev
->tok
) {
1594 SCALE_VS_INIT(&su
, 1);
1595 bufcat_su(h
, "margin-top", &su
);
1598 SCALE_VS_INIT(&su
, 1);
1599 bufcat_su(h
, "margin-bottom", &su
);
1601 PAIR_STYLE_INIT(&tag
[0], h
);
1602 print_otag(h
, TAG_DIV
, 1, tag
);
1605 /* Split apart into type and name. */
1606 assert(n
->child
->string
);
1607 sp
= n
->child
->string
;
1609 ep
= strchr(sp
, ' ');
1611 PAIR_CLASS_INIT(&tag
[0], "ftype");
1612 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1615 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1616 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1618 print_text(h
, nbuf
);
1620 ep
= strchr(sp
, ' ');
1625 PAIR_CLASS_INIT(&tag
[0], "fname");
1628 * FIXME: only refer to IDs that we know exist.
1632 if (SEC_SYNOPSIS
== n
->sec
) {
1634 html_idcat(nbuf
, sp
, BUFSIZ
);
1635 PAIR_ID_INIT(&tag
[1], nbuf
);
1637 strlcpy(nbuf
, "#", BUFSIZ
);
1638 html_idcat(nbuf
, sp
, BUFSIZ
);
1639 PAIR_HREF_INIT(&tag
[1], nbuf
);
1643 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1646 strlcpy(nbuf
, sp
, BUFSIZ
);
1647 print_text(h
, nbuf
);
1652 h
->flags
|= HTML_NOSPACE
;
1656 PAIR_CLASS_INIT(&tag
[0], "farg");
1657 bufcat_style(h
, "white-space", "nowrap");
1658 PAIR_STYLE_INIT(&tag
[1], h
);
1660 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1662 if (SEC_SYNOPSIS
== n
->sec
)
1664 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1665 print_text(h
, nn
->string
);
1672 if (SEC_SYNOPSIS
== n
->sec
)
1681 mdoc_sp_pre(MDOC_ARGS
)
1684 struct htmlpair tag
;
1689 /* FIXME: can this have a scaling indicator? */
1690 len
= n
->child
? atoi(n
->child
->string
) : 1;
1700 SCALE_VS_INIT(&su
, len
);
1701 bufcat_su(h
, "height", &su
);
1702 PAIR_STYLE_INIT(&tag
, h
);
1703 print_otag(h
, TAG_DIV
, 1, &tag
);
1704 /* So the div isn't empty: */
1705 print_text(h
, "\\~");
1714 mdoc_brq_pre(MDOC_ARGS
)
1717 if (MDOC_BODY
!= n
->type
)
1719 print_text(h
, "\\(lC");
1720 h
->flags
|= HTML_NOSPACE
;
1727 mdoc_brq_post(MDOC_ARGS
)
1730 if (MDOC_BODY
!= n
->type
)
1732 h
->flags
|= HTML_NOSPACE
;
1733 print_text(h
, "\\(rC");
1739 mdoc_lk_pre(MDOC_ARGS
)
1741 const struct mdoc_node
*nn
;
1742 struct htmlpair tag
[2];
1746 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1747 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1748 print_otag(h
, TAG_A
, 2, tag
);
1750 if (NULL
== nn
->next
)
1753 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1754 print_text(h
, nn
->string
);
1762 mdoc_mt_pre(MDOC_ARGS
)
1764 struct htmlpair tag
[2];
1766 const struct mdoc_node
*nn
;
1768 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1770 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1772 bufcat(h
, "mailto:");
1773 bufcat(h
, nn
->string
);
1774 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1775 t
= print_otag(h
, TAG_A
, 2, tag
);
1776 print_text(h
, nn
->string
);
1786 mdoc_fo_pre(MDOC_ARGS
)
1788 struct htmlpair tag
;
1791 if (MDOC_BODY
== n
->type
) {
1792 h
->flags
|= HTML_NOSPACE
;
1794 h
->flags
|= HTML_NOSPACE
;
1796 } else if (MDOC_BLOCK
== n
->type
&& n
->next
) {
1797 SCALE_VS_INIT(&su
, 1);
1798 bufcat_su(h
, "margin-bottom", &su
);
1799 PAIR_STYLE_INIT(&tag
, h
);
1800 print_otag(h
, TAG_DIV
, 1, &tag
);
1804 PAIR_CLASS_INIT(&tag
, "fname");
1805 print_otag(h
, TAG_SPAN
, 1, &tag
);
1812 mdoc_fo_post(MDOC_ARGS
)
1814 if (MDOC_BODY
!= n
->type
)
1816 h
->flags
|= HTML_NOSPACE
;
1818 h
->flags
|= HTML_NOSPACE
;
1825 mdoc_in_pre(MDOC_ARGS
)
1827 const struct mdoc_node
*nn
;
1829 struct htmlpair tag
[2];
1832 PAIR_CLASS_INIT(&tag
[0], "includes");
1833 print_otag(h
, TAG_SPAN
, 1, tag
);
1835 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1836 print_text(h
, "#include");
1839 h
->flags
|= HTML_NOSPACE
;
1841 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1842 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1845 if (h
->base_includes
) {
1846 buffmt_includes(h
, nn
->string
);
1847 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1850 t
= print_otag(h
, TAG_A
, i
, tag
);
1851 print_mdoc_node(m
, nn
, h
);
1855 h
->flags
|= HTML_NOSPACE
;
1858 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1859 print_otag(h
, TAG_BR
, 0, NULL
);
1867 mdoc_ic_pre(MDOC_ARGS
)
1869 struct htmlpair tag
;
1871 PAIR_CLASS_INIT(&tag
, "cmd");
1872 print_otag(h
, TAG_SPAN
, 1, &tag
);
1879 mdoc_rv_pre(MDOC_ARGS
)
1881 const struct mdoc_node
*nn
;
1882 struct htmlpair tag
;
1885 print_otag(h
, TAG_DIV
, 0, NULL
);
1886 print_text(h
, "The");
1888 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1889 PAIR_CLASS_INIT(&tag
, "fname");
1890 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1891 print_text(h
, nn
->string
);
1894 h
->flags
|= HTML_NOSPACE
;
1895 if (nn
->next
&& NULL
== nn
->next
->next
)
1896 print_text(h
, "(), and");
1898 print_text(h
, "(),");
1900 print_text(h
, "()");
1903 if (n
->child
&& n
->child
->next
)
1904 print_text(h
, "functions return");
1906 print_text(h
, "function returns");
1908 print_text(h
, "the value 0 if successful; otherwise the value "
1909 "-1 is returned and the global variable");
1911 PAIR_CLASS_INIT(&tag
, "var");
1912 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1913 print_text(h
, "errno");
1915 print_text(h
, "is set to indicate the error.");
1922 mdoc_va_pre(MDOC_ARGS
)
1924 struct htmlpair tag
;
1926 PAIR_CLASS_INIT(&tag
, "var");
1927 print_otag(h
, TAG_SPAN
, 1, &tag
);
1934 mdoc_bq_pre(MDOC_ARGS
)
1937 if (MDOC_BODY
!= n
->type
)
1939 print_text(h
, "\\(lB");
1940 h
->flags
|= HTML_NOSPACE
;
1947 mdoc_bq_post(MDOC_ARGS
)
1950 if (MDOC_BODY
!= n
->type
)
1952 h
->flags
|= HTML_NOSPACE
;
1953 print_text(h
, "\\(rB");
1959 mdoc_ap_pre(MDOC_ARGS
)
1962 h
->flags
|= HTML_NOSPACE
;
1963 print_text(h
, "\\(aq");
1964 h
->flags
|= HTML_NOSPACE
;
1971 mdoc_bf_pre(MDOC_ARGS
)
1974 struct htmlpair tag
[2];
1977 if (MDOC_HEAD
== n
->type
)
1979 else if (MDOC_BLOCK
!= n
->type
)
1982 PAIR_CLASS_INIT(&tag
[0], "lit");
1984 if (n
->head
->child
) {
1985 if ( ! strcmp("Em", n
->head
->child
->string
))
1986 PAIR_CLASS_INIT(&tag
[0], "emph");
1987 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1988 PAIR_CLASS_INIT(&tag
[0], "symb");
1989 else if ( ! strcmp("Li", n
->head
->child
->string
))
1990 PAIR_CLASS_INIT(&tag
[0], "lit");
1992 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++)
1993 switch (n
->args
->argv
[i
].arg
) {
1994 case (MDOC_Symbolic
):
1995 PAIR_CLASS_INIT(&tag
[0], "symb");
1997 case (MDOC_Literal
):
1998 PAIR_CLASS_INIT(&tag
[0], "lit");
2000 case (MDOC_Emphasis
):
2001 PAIR_CLASS_INIT(&tag
[0], "emph");
2008 /* FIXME: div's have spaces stripped--we want them. */
2010 bufcat_style(h
, "display", "inline");
2011 SCALE_HS_INIT(&su
, 1);
2012 bufcat_su(h
, "margin-right", &su
);
2013 PAIR_STYLE_INIT(&tag
[1], h
);
2014 print_otag(h
, TAG_DIV
, 2, tag
);
2021 mdoc_ms_pre(MDOC_ARGS
)
2023 struct htmlpair tag
;
2025 PAIR_CLASS_INIT(&tag
, "symb");
2026 print_otag(h
, TAG_SPAN
, 1, &tag
);
2033 mdoc_pf_pre(MDOC_ARGS
)
2036 h
->flags
|= HTML_IGNDELIM
;
2043 mdoc_pf_post(MDOC_ARGS
)
2046 h
->flags
&= ~HTML_IGNDELIM
;
2047 h
->flags
|= HTML_NOSPACE
;
2053 mdoc_rs_pre(MDOC_ARGS
)
2055 struct htmlpair tag
;
2058 if (MDOC_BLOCK
!= n
->type
)
2061 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2062 SCALE_VS_INIT(&su
, 1);
2063 bufcat_su(h
, "margin-top", &su
);
2064 PAIR_STYLE_INIT(&tag
, h
);
2065 print_otag(h
, TAG_DIV
, 1, &tag
);
2068 PAIR_CLASS_INIT(&tag
, "ref");
2069 print_otag(h
, TAG_SPAN
, 1, &tag
);
2077 mdoc_li_pre(MDOC_ARGS
)
2079 struct htmlpair tag
;
2081 PAIR_CLASS_INIT(&tag
, "lit");
2082 print_otag(h
, TAG_SPAN
, 1, &tag
);
2089 mdoc_sy_pre(MDOC_ARGS
)
2091 struct htmlpair tag
;
2093 PAIR_CLASS_INIT(&tag
, "symb");
2094 print_otag(h
, TAG_SPAN
, 1, &tag
);
2101 mdoc_bt_pre(MDOC_ARGS
)
2104 print_text(h
, "is currently in beta test.");
2111 mdoc_ud_pre(MDOC_ARGS
)
2114 print_text(h
, "currently under development.");
2121 mdoc_lb_pre(MDOC_ARGS
)
2123 struct htmlpair tag
;
2125 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2126 print_otag(h
, TAG_DIV
, 0, NULL
);
2127 PAIR_CLASS_INIT(&tag
, "lib");
2128 print_otag(h
, TAG_SPAN
, 1, &tag
);
2135 mdoc__x_pre(MDOC_ARGS
)
2137 struct htmlpair tag
[2];
2141 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2144 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2147 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2150 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2153 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2156 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2159 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2162 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2165 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2168 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2171 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2174 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2177 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2180 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2187 if (MDOC__U
!= n
->tok
) {
2188 print_otag(h
, TAG_SPAN
, 1, tag
);
2192 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2193 print_otag(h
, TAG_A
, 2, tag
);
2200 mdoc__x_post(MDOC_ARGS
)
2205 h
->flags
|= HTML_NOSPACE
;
2206 print_text(h
, n
->next
? "," : ".");