]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.67 2010/05/24 12:17:09 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 int mdoc_fd_pre(MDOC_ARGS
);
88 static int mdoc_fl_pre(MDOC_ARGS
);
89 static int mdoc_fn_pre(MDOC_ARGS
);
90 static int mdoc_ft_pre(MDOC_ARGS
);
91 static int mdoc_em_pre(MDOC_ARGS
);
92 static int mdoc_er_pre(MDOC_ARGS
);
93 static int mdoc_ev_pre(MDOC_ARGS
);
94 static int mdoc_ex_pre(MDOC_ARGS
);
95 static void mdoc_fo_post(MDOC_ARGS
);
96 static int mdoc_fo_pre(MDOC_ARGS
);
97 static int mdoc_ic_pre(MDOC_ARGS
);
98 static int mdoc_in_pre(MDOC_ARGS
);
99 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
100 int, struct roffsu
*, struct roffsu
*);
101 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
103 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
);
104 static int mdoc_it_pre(MDOC_ARGS
);
105 static int mdoc_lb_pre(MDOC_ARGS
);
106 static int mdoc_li_pre(MDOC_ARGS
);
107 static int mdoc_lk_pre(MDOC_ARGS
);
108 static int mdoc_mt_pre(MDOC_ARGS
);
109 static int mdoc_ms_pre(MDOC_ARGS
);
110 static int mdoc_nd_pre(MDOC_ARGS
);
111 static int mdoc_nm_pre(MDOC_ARGS
);
112 static int mdoc_ns_pre(MDOC_ARGS
);
113 static void mdoc_op_post(MDOC_ARGS
);
114 static int mdoc_op_pre(MDOC_ARGS
);
115 static int mdoc_pa_pre(MDOC_ARGS
);
116 static void mdoc_pf_post(MDOC_ARGS
);
117 static int mdoc_pf_pre(MDOC_ARGS
);
118 static void mdoc_pq_post(MDOC_ARGS
);
119 static int mdoc_pq_pre(MDOC_ARGS
);
120 static int mdoc_rs_pre(MDOC_ARGS
);
121 static int mdoc_rv_pre(MDOC_ARGS
);
122 static int mdoc_sh_pre(MDOC_ARGS
);
123 static int mdoc_sp_pre(MDOC_ARGS
);
124 static void mdoc_sq_post(MDOC_ARGS
);
125 static int mdoc_sq_pre(MDOC_ARGS
);
126 static int mdoc_ss_pre(MDOC_ARGS
);
127 static int mdoc_sx_pre(MDOC_ARGS
);
128 static int mdoc_sy_pre(MDOC_ARGS
);
129 static int mdoc_ud_pre(MDOC_ARGS
);
130 static int mdoc_va_pre(MDOC_ARGS
);
131 static int mdoc_vt_pre(MDOC_ARGS
);
132 static int mdoc_xr_pre(MDOC_ARGS
);
133 static int mdoc_xx_pre(MDOC_ARGS
);
135 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
136 {mdoc_ap_pre
, NULL
}, /* Ap */
137 {NULL
, NULL
}, /* Dd */
138 {NULL
, NULL
}, /* Dt */
139 {NULL
, NULL
}, /* Os */
140 {mdoc_sh_pre
, NULL
}, /* Sh */
141 {mdoc_ss_pre
, NULL
}, /* Ss */
142 {mdoc_sp_pre
, NULL
}, /* Pp */
143 {mdoc_d1_pre
, NULL
}, /* D1 */
144 {mdoc_d1_pre
, NULL
}, /* Dl */
145 {mdoc_bd_pre
, NULL
}, /* Bd */
146 {NULL
, NULL
}, /* Ed */
147 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
148 {NULL
, NULL
}, /* El */
149 {mdoc_it_pre
, NULL
}, /* It */
150 {mdoc_ad_pre
, NULL
}, /* Ad */
151 {mdoc_an_pre
, NULL
}, /* An */
152 {mdoc_ar_pre
, NULL
}, /* Ar */
153 {mdoc_cd_pre
, NULL
}, /* Cd */
154 {mdoc_fl_pre
, NULL
}, /* Cm */
155 {mdoc_dv_pre
, NULL
}, /* Dv */
156 {mdoc_er_pre
, NULL
}, /* Er */
157 {mdoc_ev_pre
, NULL
}, /* Ev */
158 {mdoc_ex_pre
, NULL
}, /* Ex */
159 {mdoc_fa_pre
, NULL
}, /* Fa */
160 {mdoc_fd_pre
, NULL
}, /* Fd */
161 {mdoc_fl_pre
, NULL
}, /* Fl */
162 {mdoc_fn_pre
, NULL
}, /* Fn */
163 {mdoc_ft_pre
, NULL
}, /* Ft */
164 {mdoc_ic_pre
, NULL
}, /* Ic */
165 {mdoc_in_pre
, NULL
}, /* In */
166 {mdoc_li_pre
, NULL
}, /* Li */
167 {mdoc_nd_pre
, NULL
}, /* Nd */
168 {mdoc_nm_pre
, NULL
}, /* Nm */
169 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
170 {NULL
, NULL
}, /* Ot */
171 {mdoc_pa_pre
, NULL
}, /* Pa */
172 {mdoc_rv_pre
, NULL
}, /* Rv */
173 {NULL
, NULL
}, /* St */
174 {mdoc_va_pre
, NULL
}, /* Va */
175 {mdoc_vt_pre
, NULL
}, /* Vt */
176 {mdoc_xr_pre
, NULL
}, /* Xr */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
188 {NULL
, NULL
}, /* Ac */
189 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
190 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
191 {NULL
, NULL
}, /* At */
192 {NULL
, NULL
}, /* Bc */
193 {mdoc_bf_pre
, NULL
}, /* Bf */
194 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
195 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
196 {mdoc_xx_pre
, NULL
}, /* Bsx */
197 {mdoc_bx_pre
, NULL
}, /* Bx */
198 {NULL
, NULL
}, /* Db */
199 {NULL
, NULL
}, /* Dc */
200 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
201 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
202 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
203 {NULL
, NULL
}, /* Ef */
204 {mdoc_em_pre
, NULL
}, /* Em */
205 {NULL
, NULL
}, /* Eo */
206 {mdoc_xx_pre
, NULL
}, /* Fx */
207 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
208 {NULL
, NULL
}, /* No */
209 {mdoc_ns_pre
, NULL
}, /* Ns */
210 {mdoc_xx_pre
, NULL
}, /* Nx */
211 {mdoc_xx_pre
, NULL
}, /* Ox */
212 {NULL
, NULL
}, /* Pc */
213 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
214 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
215 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
216 {NULL
, NULL
}, /* Qc */
217 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
218 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
219 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
220 {NULL
, NULL
}, /* Re */
221 {mdoc_rs_pre
, NULL
}, /* Rs */
222 {NULL
, NULL
}, /* Sc */
223 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
224 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
225 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
226 {mdoc_sx_pre
, NULL
}, /* Sx */
227 {mdoc_sy_pre
, NULL
}, /* Sy */
228 {NULL
, NULL
}, /* Tn */
229 {mdoc_xx_pre
, NULL
}, /* Ux */
230 {NULL
, NULL
}, /* Xc */
231 {NULL
, NULL
}, /* Xo */
232 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
233 {NULL
, NULL
}, /* Fc */
234 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
235 {NULL
, NULL
}, /* Oc */
236 {NULL
, NULL
}, /* Bk */
237 {NULL
, NULL
}, /* Ek */
238 {mdoc_bt_pre
, NULL
}, /* Bt */
239 {NULL
, NULL
}, /* Hf */
240 {NULL
, NULL
}, /* Fr */
241 {mdoc_ud_pre
, NULL
}, /* Ud */
242 {mdoc_lb_pre
, NULL
}, /* Lb */
243 {mdoc_sp_pre
, NULL
}, /* Lp */
244 {mdoc_lk_pre
, NULL
}, /* Lk */
245 {mdoc_mt_pre
, NULL
}, /* Mt */
246 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
247 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
248 {NULL
, NULL
}, /* Brc */
249 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
250 {NULL
, NULL
}, /* Es */ /* TODO */
251 {NULL
, NULL
}, /* En */ /* TODO */
252 {mdoc_xx_pre
, NULL
}, /* Dx */
253 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
254 {mdoc_sp_pre
, NULL
}, /* br */
255 {mdoc_sp_pre
, NULL
}, /* sp */
256 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
261 html_mdoc(void *arg
, const struct mdoc
*m
)
266 h
= (struct html
*)arg
;
269 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
270 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
278 * Calculate the scaling unit passed in a `-width' argument. This uses
279 * either a native scaling unit (e.g., 1i, 2m) or the string length of
283 a2width(const char *p
, struct roffsu
*su
)
286 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
288 su
->scale
= (int)strlen(p
);
294 * Calculate the scaling unit passed in an `-offset' argument. This
295 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
296 * predefined strings (indent, etc.), or the string length of the value.
299 a2offs(const char *p
, struct roffsu
*su
)
302 /* FIXME: "right"? */
304 if (0 == strcmp(p
, "left"))
305 SCALE_HS_INIT(su
, 0);
306 else if (0 == strcmp(p
, "indent"))
307 SCALE_HS_INIT(su
, INDENT
);
308 else if (0 == strcmp(p
, "indent-two"))
309 SCALE_HS_INIT(su
, INDENT
* 2);
310 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
312 su
->scale
= (int)strlen(p
);
318 print_mdoc(MDOC_ARGS
)
323 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
324 print_mdoc_head(m
, n
, h
);
327 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
329 tag
.key
= ATTR_CLASS
;
331 print_otag(h
, TAG_DIV
, 1, &tag
);
333 print_mdoc_nodelist(m
, n
, h
);
340 print_mdoc_head(MDOC_ARGS
)
345 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
353 print_otag(h
, TAG_TITLE
, 0, NULL
);
354 print_text(h
, h
->buf
);
359 print_mdoc_nodelist(MDOC_ARGS
)
362 print_mdoc_node(m
, n
, h
);
364 print_mdoc_nodelist(m
, n
->next
, h
);
369 print_mdoc_node(MDOC_ARGS
)
380 child
= mdoc_root_pre(m
, n
, h
);
383 print_text(h
, n
->string
);
386 if (mdocs
[n
->tok
].pre
)
387 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
391 if (child
&& n
->child
)
392 print_mdoc_nodelist(m
, n
->child
, h
);
399 mdoc_root_post(m
, n
, h
);
402 if (mdocs
[n
->tok
].post
)
403 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
411 mdoc_root_post(MDOC_ARGS
)
413 struct htmlpair tag
[3];
417 time2a(m
->date
, b
, DATESIZ
);
420 * XXX: this should use divs, but in Firefox, divs with nested
421 * divs for some reason puke when trying to put a border line
422 * below. So I use tables, instead.
425 PAIR_CLASS_INIT(&tag
[0], "footer");
426 bufcat_style(h
, "width", "100%");
427 PAIR_STYLE_INIT(&tag
[1], h
);
428 PAIR_SUMMARY_INIT(&tag
[2], "footer");
430 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
431 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
434 bufcat_style(h
, "width", "50%");
435 PAIR_STYLE_INIT(&tag
[0], h
);
436 print_otag(h
, TAG_TD
, 1, tag
);
441 bufcat_style(h
, "width", "50%");
442 bufcat_style(h
, "text-align", "right");
443 PAIR_STYLE_INIT(&tag
[0], h
);
444 print_otag(h
, TAG_TD
, 1, tag
);
445 print_text(h
, m
->os
);
452 mdoc_root_pre(MDOC_ARGS
)
454 struct htmlpair tag
[3];
456 char b
[BUFSIZ
], title
[BUFSIZ
];
458 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
461 (void)strlcat(b
, " (", BUFSIZ
);
462 (void)strlcat(b
, m
->arch
, BUFSIZ
);
463 (void)strlcat(b
, ")", BUFSIZ
);
466 (void)snprintf(title
, BUFSIZ
- 1,
467 "%s(%s)", m
->title
, m
->msec
);
469 /* XXX: see note in mdoc_root_post() about divs. */
471 PAIR_CLASS_INIT(&tag
[0], "header");
472 bufcat_style(h
, "width", "100%");
473 PAIR_STYLE_INIT(&tag
[1], h
);
474 PAIR_SUMMARY_INIT(&tag
[2], "header");
476 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
478 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
481 bufcat_style(h
, "width", "10%");
482 PAIR_STYLE_INIT(&tag
[0], h
);
483 print_otag(h
, TAG_TD
, 1, tag
);
484 print_text(h
, title
);
488 bufcat_style(h
, "text-align", "center");
489 bufcat_style(h
, "white-space", "nowrap");
490 bufcat_style(h
, "width", "80%");
491 PAIR_STYLE_INIT(&tag
[0], h
);
492 print_otag(h
, TAG_TD
, 1, tag
);
497 bufcat_style(h
, "text-align", "right");
498 bufcat_style(h
, "width", "10%");
499 PAIR_STYLE_INIT(&tag
[0], h
);
500 print_otag(h
, TAG_TD
, 1, tag
);
501 print_text(h
, title
);
509 mdoc_sh_pre(MDOC_ARGS
)
511 struct htmlpair tag
[2];
512 const struct mdoc_node
*nn
;
516 if (MDOC_BODY
== n
->type
) {
517 SCALE_HS_INIT(&su
, INDENT
);
518 bufcat_su(h
, "margin-left", &su
);
519 PAIR_CLASS_INIT(&tag
[0], "sec-body");
520 PAIR_STYLE_INIT(&tag
[1], h
);
521 print_otag(h
, TAG_DIV
, 2, tag
);
523 } else if (MDOC_BLOCK
== n
->type
) {
524 PAIR_CLASS_INIT(&tag
[0], "sec-block");
525 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
526 print_otag(h
, TAG_DIV
, 1, tag
);
530 SCALE_VS_INIT(&su
, 1);
531 bufcat_su(h
, "margin-top", &su
);
533 bufcat_su(h
, "margin-bottom", &su
);
535 PAIR_STYLE_INIT(&tag
[1], h
);
536 print_otag(h
, TAG_DIV
, 2, tag
);
541 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
542 html_idcat(buf
, nn
->string
, BUFSIZ
);
544 html_idcat(buf
, " ", BUFSIZ
);
547 PAIR_CLASS_INIT(&tag
[0], "sec-head");
548 PAIR_ID_INIT(&tag
[1], buf
);
550 print_otag(h
, TAG_DIV
, 2, tag
);
557 mdoc_ss_pre(MDOC_ARGS
)
559 struct htmlpair tag
[3];
560 const struct mdoc_node
*nn
;
564 SCALE_VS_INIT(&su
, 1);
566 if (MDOC_BODY
== n
->type
) {
567 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
568 if (n
->parent
->next
&& n
->child
) {
569 bufcat_su(h
, "margin-bottom", &su
);
570 PAIR_STYLE_INIT(&tag
[1], h
);
571 print_otag(h
, TAG_DIV
, 2, tag
);
573 print_otag(h
, TAG_DIV
, 1, tag
);
575 } else if (MDOC_BLOCK
== n
->type
) {
576 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
578 bufcat_su(h
, "margin-top", &su
);
579 PAIR_STYLE_INIT(&tag
[1], h
);
580 print_otag(h
, TAG_DIV
, 2, tag
);
582 print_otag(h
, TAG_DIV
, 1, tag
);
586 /* TODO: see note in mdoc_sh_pre() about duplicates. */
589 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
590 html_idcat(buf
, nn
->string
, BUFSIZ
);
592 html_idcat(buf
, " ", BUFSIZ
);
595 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
596 su
.scale
= -su
.scale
;
597 bufcat_su(h
, "margin-left", &su
);
599 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
600 PAIR_STYLE_INIT(&tag
[1], h
);
601 PAIR_ID_INIT(&tag
[2], buf
);
603 print_otag(h
, TAG_DIV
, 3, tag
);
610 mdoc_fl_pre(MDOC_ARGS
)
614 PAIR_CLASS_INIT(&tag
, "flag");
615 print_otag(h
, TAG_SPAN
, 1, &tag
);
617 /* `Cm' has no leading hyphen. */
619 if (MDOC_Cm
== n
->tok
)
622 print_text(h
, "\\-");
625 h
->flags
|= HTML_NOSPACE
;
626 else if (n
->next
&& n
->next
->line
== n
->line
)
627 h
->flags
|= HTML_NOSPACE
;
635 mdoc_nd_pre(MDOC_ARGS
)
639 if (MDOC_BODY
!= n
->type
)
642 /* XXX: this tag in theory can contain block elements. */
644 print_text(h
, "\\(em");
645 PAIR_CLASS_INIT(&tag
, "desc-body");
646 print_otag(h
, TAG_SPAN
, 1, &tag
);
653 mdoc_op_pre(MDOC_ARGS
)
657 if (MDOC_BODY
!= n
->type
)
660 /* XXX: this tag in theory can contain block elements. */
662 print_text(h
, "\\(lB");
663 h
->flags
|= HTML_NOSPACE
;
664 PAIR_CLASS_INIT(&tag
, "opt");
665 print_otag(h
, TAG_SPAN
, 1, &tag
);
672 mdoc_op_post(MDOC_ARGS
)
675 if (MDOC_BODY
!= n
->type
)
677 h
->flags
|= HTML_NOSPACE
;
678 print_text(h
, "\\(rB");
683 mdoc_nm_pre(MDOC_ARGS
)
687 if (NULL
== n
->child
&& NULL
== m
->name
)
690 if (SEC_SYNOPSIS
== n
->sec
&&
691 n
->prev
&& MDOC_LINE
& n
->flags
) {
692 bufcat_style(h
, "clear", "both");
693 PAIR_STYLE_INIT(&tag
, h
);
694 print_otag(h
, TAG_BR
, 1, &tag
);
697 PAIR_CLASS_INIT(&tag
, "name");
698 print_otag(h
, TAG_SPAN
, 1, &tag
);
699 if (NULL
== n
->child
)
700 print_text(h
, m
->name
);
708 mdoc_xr_pre(MDOC_ARGS
)
710 struct htmlpair tag
[2];
711 const struct mdoc_node
*nn
;
713 if (NULL
== n
->child
)
716 PAIR_CLASS_INIT(&tag
[0], "link-man");
719 buffmt_man(h
, n
->child
->string
,
721 n
->child
->next
->string
: NULL
);
722 PAIR_HREF_INIT(&tag
[1], h
->buf
);
723 print_otag(h
, TAG_A
, 2, tag
);
725 print_otag(h
, TAG_A
, 1, tag
);
728 print_text(h
, nn
->string
);
730 if (NULL
== (nn
= nn
->next
))
733 h
->flags
|= HTML_NOSPACE
;
735 h
->flags
|= HTML_NOSPACE
;
736 print_text(h
, nn
->string
);
737 h
->flags
|= HTML_NOSPACE
;
745 mdoc_ns_pre(MDOC_ARGS
)
748 h
->flags
|= HTML_NOSPACE
;
755 mdoc_ar_pre(MDOC_ARGS
)
759 PAIR_CLASS_INIT(&tag
, "arg");
760 print_otag(h
, TAG_SPAN
, 1, &tag
);
767 mdoc_xx_pre(MDOC_ARGS
)
795 PAIR_CLASS_INIT(&tag
, "unix");
796 print_otag(h
, TAG_SPAN
, 1, &tag
);
804 mdoc_bx_pre(MDOC_ARGS
)
806 const struct mdoc_node
*nn
;
809 PAIR_CLASS_INIT(&tag
, "unix");
810 print_otag(h
, TAG_SPAN
, 1, &tag
);
812 for (nn
= n
->child
; nn
; nn
= nn
->next
)
813 print_mdoc_node(m
, nn
, h
);
816 h
->flags
|= HTML_NOSPACE
;
818 print_text(h
, "BSD");
825 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
826 struct roffsu
*offs
, struct roffsu
*width
)
829 const struct mdoc_node
*nn
;
832 nn
= n
->parent
->parent
;
835 /* XXX: see notes in mdoc_it_pre(). */
837 if (LIST_column
== type
) {
838 /* Don't width-pad on the left. */
839 SCALE_HS_INIT(width
, 0);
840 /* Also disallow non-compact. */
843 if (LIST_diag
== type
)
844 /* Mandate non-compact with empty prior. */
845 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
848 bufcat_style(h
, "clear", "both");
850 bufcat_su(h
, "margin-left", offs
);
851 if (width
->scale
> 0)
852 bufcat_su(h
, "padding-left", width
);
854 PAIR_STYLE_INIT(&tag
, h
);
856 /* Mandate compact following `Ss' and `Sh' starts. */
858 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
859 if (MDOC_BLOCK
!= nn
->type
)
861 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
868 SCALE_VS_INIT(&su
, 1);
869 bufcat_su(h
, "padding-top", &su
);
872 PAIR_STYLE_INIT(&tag
, h
);
873 print_otag(h
, TAG_DIV
, 1, &tag
);
880 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
)
894 * XXX: this tricks CSS into aligning the bodies with
895 * the right-padding in the head.
897 SCALE_HS_INIT(&su
, 2);
898 bufcat_su(h
, "margin-left", &su
);
899 PAIR_STYLE_INIT(&tag
, h
);
900 print_otag(h
, TAG_DIV
, 1, &tag
);
910 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
920 print_otag(h
, TAG_DIV
, 0, &tag
);
923 bufcat_su(h
, "min-width", width
);
924 bufcat_style(h
, "clear", "none");
925 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
926 bufcat_style(h
, "float", "left");
927 PAIR_STYLE_INIT(&tag
, h
);
928 print_otag(h
, TAG_DIV
, 1, &tag
);
931 bufcat_su(h
, "min-width", width
);
933 bufcat_su(h
, "margin-left", width
);
934 if (n
->next
&& n
->next
->child
)
935 bufcat_style(h
, "float", "left");
937 /* XXX: buffer if we run into body. */
938 SCALE_HS_INIT(width
, 1);
939 bufcat_su(h
, "margin-right", width
);
940 PAIR_STYLE_INIT(&tag
, h
);
941 print_otag(h
, TAG_DIV
, 1, &tag
);
947 PAIR_CLASS_INIT(&tag
, "diag");
948 print_otag(h
, TAG_SPAN
, 1, &tag
);
953 nbuf
[BUFSIZ
- 1] = 0;
954 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
958 print_text(h
, "\\(en");
961 print_text(h
, "\\(hy");
964 print_text(h
, "\\(bu");
975 mdoc_it_pre(MDOC_ARGS
)
978 const struct mdoc_node
*bl
, *nn
;
979 struct roffsu width
, offs
;
983 * XXX: be very careful in changing anything, here. Lists in
984 * mandoc have many peculiarities; furthermore, they don't
985 * translate well into HTML and require a bit of mangling.
988 bl
= n
->parent
->parent
;
989 if (MDOC_BLOCK
!= n
->type
)
992 type
= bl
->data
.list
;
994 /* Set default width and offset. */
996 SCALE_HS_INIT(&offs
, 0);
1006 SCALE_HS_INIT(&width
, 2);
1009 SCALE_HS_INIT(&width
, INDENT
);
1013 /* Get width, offset, and compact arguments. */
1015 for (wp
= -1, comp
= i
= 0; i
< (int)bl
->args
->argc
; i
++)
1016 switch (bl
->args
->argv
[i
].arg
) {
1018 wp
= i
; /* Save for later. */
1021 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1024 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1026 case (MDOC_Compact
):
1033 /* Override width in some cases. */
1043 SCALE_HS_INIT(&width
, 0);
1046 if (0 == width
.scale
)
1047 SCALE_HS_INIT(&width
, INDENT
);
1051 /* Flip to body/block processing. */
1053 if (MDOC_BODY
== n
->type
)
1054 return(mdoc_it_body_pre(m
, n
, h
, type
));
1055 if (MDOC_BLOCK
== n
->type
)
1056 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1059 /* Override column widths. */
1061 if (LIST_column
== type
) {
1062 nn
= n
->parent
->child
;
1063 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1065 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1066 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1069 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1075 mdoc_bl_pre(MDOC_ARGS
)
1079 if (MDOC_HEAD
== n
->type
)
1081 if (MDOC_BLOCK
!= n
->type
)
1083 if (LIST_enum
!= n
->data
.list
)
1086 ord
= malloc(sizeof(struct ord
));
1093 ord
->next
= h
->ords
.head
;
1101 mdoc_bl_post(MDOC_ARGS
)
1105 if (MDOC_BLOCK
!= n
->type
)
1107 if (LIST_enum
!= n
->data
.list
)
1112 h
->ords
.head
= ord
->next
;
1119 mdoc_ex_pre(MDOC_ARGS
)
1121 const struct mdoc_node
*nn
;
1123 struct htmlpair tag
;
1125 PAIR_CLASS_INIT(&tag
, "utility");
1127 print_text(h
, "The");
1128 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1129 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1130 print_text(h
, nn
->string
);
1133 h
->flags
|= HTML_NOSPACE
;
1135 if (nn
->next
&& NULL
== nn
->next
->next
)
1136 print_text(h
, ", and");
1140 h
->flags
&= ~HTML_NOSPACE
;
1143 if (n
->child
&& n
->child
->next
)
1144 print_text(h
, "utilities exit");
1146 print_text(h
, "utility exits");
1148 print_text(h
, "0 on success, and >0 if an error occurs.");
1155 mdoc_dq_pre(MDOC_ARGS
)
1158 if (MDOC_BODY
!= n
->type
)
1160 print_text(h
, "\\(lq");
1161 h
->flags
|= HTML_NOSPACE
;
1168 mdoc_dq_post(MDOC_ARGS
)
1171 if (MDOC_BODY
!= n
->type
)
1173 h
->flags
|= HTML_NOSPACE
;
1174 print_text(h
, "\\(rq");
1180 mdoc_pq_pre(MDOC_ARGS
)
1183 if (MDOC_BODY
!= n
->type
)
1185 print_text(h
, "\\&(");
1186 h
->flags
|= HTML_NOSPACE
;
1193 mdoc_pq_post(MDOC_ARGS
)
1196 if (MDOC_BODY
!= n
->type
)
1204 mdoc_sq_pre(MDOC_ARGS
)
1207 if (MDOC_BODY
!= n
->type
)
1209 print_text(h
, "\\(oq");
1210 h
->flags
|= HTML_NOSPACE
;
1217 mdoc_sq_post(MDOC_ARGS
)
1220 if (MDOC_BODY
!= n
->type
)
1222 h
->flags
|= HTML_NOSPACE
;
1223 print_text(h
, "\\(aq");
1229 mdoc_em_pre(MDOC_ARGS
)
1231 struct htmlpair tag
;
1233 PAIR_CLASS_INIT(&tag
, "emph");
1234 print_otag(h
, TAG_SPAN
, 1, &tag
);
1241 mdoc_d1_pre(MDOC_ARGS
)
1243 struct htmlpair tag
[2];
1246 if (MDOC_BLOCK
!= n
->type
)
1249 /* FIXME: D1 shouldn't be literal. */
1251 SCALE_VS_INIT(&su
, INDENT
- 1);
1252 bufcat_su(h
, "margin-left", &su
);
1253 PAIR_CLASS_INIT(&tag
[0], "lit");
1254 PAIR_STYLE_INIT(&tag
[1], h
);
1255 print_otag(h
, TAG_DIV
, 2, tag
);
1262 mdoc_sx_pre(MDOC_ARGS
)
1264 struct htmlpair tag
[2];
1265 const struct mdoc_node
*nn
;
1268 strlcpy(buf
, "#", BUFSIZ
);
1269 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1270 html_idcat(buf
, nn
->string
, BUFSIZ
);
1272 html_idcat(buf
, " ", BUFSIZ
);
1275 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1276 PAIR_HREF_INIT(&tag
[1], buf
);
1278 print_otag(h
, TAG_A
, 2, tag
);
1285 mdoc_aq_pre(MDOC_ARGS
)
1288 if (MDOC_BODY
!= n
->type
)
1290 print_text(h
, "\\(la");
1291 h
->flags
|= HTML_NOSPACE
;
1298 mdoc_aq_post(MDOC_ARGS
)
1301 if (MDOC_BODY
!= n
->type
)
1303 h
->flags
|= HTML_NOSPACE
;
1304 print_text(h
, "\\(ra");
1310 mdoc_bd_pre(MDOC_ARGS
)
1312 struct htmlpair tag
[2];
1314 const struct mdoc_node
*bl
, *nn
;
1317 if (MDOC_BLOCK
== n
->type
)
1319 else if (MDOC_HEAD
== n
->type
)
1324 SCALE_VS_INIT(&su
, 0);
1327 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1328 switch (bl
->args
->argv
[i
].arg
) {
1330 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1332 case (MDOC_Compact
):
1335 case (MDOC_Centred
):
1341 case (MDOC_Unfilled
):
1343 case (MDOC_Literal
):
1344 type
= bl
->args
->argv
[i
].arg
;
1350 /* FIXME: -centered, etc. formatting. */
1351 /* FIXME: does not respect -offset ??? */
1353 if (MDOC_BLOCK
== n
->type
) {
1354 bufcat_su(h
, "margin-left", &su
);
1355 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1356 if (MDOC_BLOCK
!= nn
->type
)
1358 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1364 PAIR_STYLE_INIT(&tag
[0], h
);
1365 print_otag(h
, TAG_DIV
, 1, tag
);
1368 SCALE_VS_INIT(&su
, 1);
1369 bufcat_su(h
, "margin-top", &su
);
1370 PAIR_STYLE_INIT(&tag
[0], h
);
1371 print_otag(h
, TAG_DIV
, 1, tag
);
1375 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1378 PAIR_CLASS_INIT(&tag
[0], "lit");
1379 bufcat_style(h
, "white-space", "pre");
1380 PAIR_STYLE_INIT(&tag
[1], h
);
1381 print_otag(h
, TAG_DIV
, 2, tag
);
1383 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1384 h
->flags
|= HTML_NOSPACE
;
1385 print_mdoc_node(m
, nn
, h
);
1386 if (NULL
== nn
->next
)
1388 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1389 print_text(h
, "\n");
1390 else if (NULL
== nn
->prev
)
1391 print_text(h
, "\n");
1400 mdoc_pa_pre(MDOC_ARGS
)
1402 struct htmlpair tag
;
1404 PAIR_CLASS_INIT(&tag
, "file");
1405 print_otag(h
, TAG_SPAN
, 1, &tag
);
1412 mdoc_ad_pre(MDOC_ARGS
)
1414 struct htmlpair tag
;
1416 PAIR_CLASS_INIT(&tag
, "addr");
1417 print_otag(h
, TAG_SPAN
, 1, &tag
);
1424 mdoc_an_pre(MDOC_ARGS
)
1426 struct htmlpair tag
;
1428 /* TODO: -split and -nosplit (see termp_an_pre()). */
1430 PAIR_CLASS_INIT(&tag
, "author");
1431 print_otag(h
, TAG_SPAN
, 1, &tag
);
1438 mdoc_cd_pre(MDOC_ARGS
)
1440 struct htmlpair tag
;
1442 print_otag(h
, TAG_DIV
, 0, NULL
);
1443 PAIR_CLASS_INIT(&tag
, "config");
1444 print_otag(h
, TAG_SPAN
, 1, &tag
);
1451 mdoc_dv_pre(MDOC_ARGS
)
1453 struct htmlpair tag
;
1455 PAIR_CLASS_INIT(&tag
, "define");
1456 print_otag(h
, TAG_SPAN
, 1, &tag
);
1463 mdoc_ev_pre(MDOC_ARGS
)
1465 struct htmlpair tag
;
1467 PAIR_CLASS_INIT(&tag
, "env");
1468 print_otag(h
, TAG_SPAN
, 1, &tag
);
1475 mdoc_er_pre(MDOC_ARGS
)
1477 struct htmlpair tag
;
1479 PAIR_CLASS_INIT(&tag
, "errno");
1480 print_otag(h
, TAG_SPAN
, 1, &tag
);
1487 mdoc_fa_pre(MDOC_ARGS
)
1489 const struct mdoc_node
*nn
;
1490 struct htmlpair tag
;
1493 PAIR_CLASS_INIT(&tag
, "farg");
1494 if (n
->parent
->tok
!= MDOC_Fo
) {
1495 print_otag(h
, TAG_SPAN
, 1, &tag
);
1499 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1500 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1501 print_text(h
, nn
->string
);
1507 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1516 mdoc_fd_pre(MDOC_ARGS
)
1518 struct htmlpair tag
;
1521 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1522 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1523 SCALE_VS_INIT(&su
, 1);
1524 bufcat_su(h
, "margin-bottom", &su
);
1525 PAIR_STYLE_INIT(&tag
, h
);
1526 print_otag(h
, TAG_DIV
, 1, &tag
);
1528 print_otag(h
, TAG_DIV
, 0, NULL
);
1531 PAIR_CLASS_INIT(&tag
, "macro");
1532 print_otag(h
, TAG_SPAN
, 1, &tag
);
1539 mdoc_vt_pre(MDOC_ARGS
)
1541 struct htmlpair tag
;
1544 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_BLOCK
== n
->type
) {
1545 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1546 SCALE_VS_INIT(&su
, 1);
1547 bufcat_su(h
, "margin-bottom", &su
);
1548 PAIR_STYLE_INIT(&tag
, h
);
1549 print_otag(h
, TAG_DIV
, 1, &tag
);
1551 print_otag(h
, TAG_DIV
, 0, NULL
);
1554 } else if (MDOC_HEAD
== n
->type
)
1557 PAIR_CLASS_INIT(&tag
, "type");
1558 print_otag(h
, TAG_SPAN
, 1, &tag
);
1565 mdoc_ft_pre(MDOC_ARGS
)
1567 struct htmlpair tag
;
1569 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1570 print_otag(h
, TAG_DIV
, 0, NULL
);
1572 PAIR_CLASS_INIT(&tag
, "ftype");
1573 print_otag(h
, TAG_SPAN
, 1, &tag
);
1580 mdoc_fn_pre(MDOC_ARGS
)
1583 struct htmlpair tag
[2];
1584 const struct mdoc_node
*nn
;
1586 const char *sp
, *ep
;
1590 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1591 SCALE_HS_INIT(&su
, INDENT
);
1592 bufcat_su(h
, "margin-left", &su
);
1593 su
.scale
= -su
.scale
;
1594 bufcat_su(h
, "text-indent", &su
);
1596 SCALE_VS_INIT(&su
, 1);
1597 bufcat_su(h
, "margin-bottom", &su
);
1599 PAIR_STYLE_INIT(&tag
[0], h
);
1600 print_otag(h
, TAG_DIV
, 1, tag
);
1603 /* Split apart into type and name. */
1604 assert(n
->child
->string
);
1605 sp
= n
->child
->string
;
1607 ep
= strchr(sp
, ' ');
1609 PAIR_CLASS_INIT(&tag
[0], "ftype");
1610 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1613 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1614 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1616 print_text(h
, nbuf
);
1618 ep
= strchr(sp
, ' ');
1623 PAIR_CLASS_INIT(&tag
[0], "fname");
1626 * FIXME: only refer to IDs that we know exist.
1630 if (SEC_SYNOPSIS
== n
->sec
) {
1632 html_idcat(nbuf
, sp
, BUFSIZ
);
1633 PAIR_ID_INIT(&tag
[1], nbuf
);
1635 strlcpy(nbuf
, "#", BUFSIZ
);
1636 html_idcat(nbuf
, sp
, BUFSIZ
);
1637 PAIR_HREF_INIT(&tag
[1], nbuf
);
1641 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1644 strlcpy(nbuf
, sp
, BUFSIZ
);
1645 print_text(h
, nbuf
);
1650 h
->flags
|= HTML_NOSPACE
;
1654 PAIR_CLASS_INIT(&tag
[0], "farg");
1655 bufcat_style(h
, "white-space", "nowrap");
1656 PAIR_STYLE_INIT(&tag
[1], h
);
1658 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1660 if (SEC_SYNOPSIS
== n
->sec
)
1662 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1663 print_text(h
, nn
->string
);
1670 if (SEC_SYNOPSIS
== n
->sec
)
1679 mdoc_sp_pre(MDOC_ARGS
)
1682 struct htmlpair tag
;
1687 /* FIXME: can this have a scaling indicator? */
1688 len
= n
->child
? atoi(n
->child
->string
) : 1;
1698 SCALE_VS_INIT(&su
, len
);
1699 bufcat_su(h
, "height", &su
);
1700 PAIR_STYLE_INIT(&tag
, h
);
1701 print_otag(h
, TAG_DIV
, 1, &tag
);
1702 /* So the div isn't empty: */
1703 print_text(h
, "\\~");
1712 mdoc_brq_pre(MDOC_ARGS
)
1715 if (MDOC_BODY
!= n
->type
)
1717 print_text(h
, "\\(lC");
1718 h
->flags
|= HTML_NOSPACE
;
1725 mdoc_brq_post(MDOC_ARGS
)
1728 if (MDOC_BODY
!= n
->type
)
1730 h
->flags
|= HTML_NOSPACE
;
1731 print_text(h
, "\\(rC");
1737 mdoc_lk_pre(MDOC_ARGS
)
1739 const struct mdoc_node
*nn
;
1740 struct htmlpair tag
[2];
1744 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1745 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1746 print_otag(h
, TAG_A
, 2, tag
);
1748 if (NULL
== nn
->next
)
1751 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1752 print_text(h
, nn
->string
);
1760 mdoc_mt_pre(MDOC_ARGS
)
1762 struct htmlpair tag
[2];
1764 const struct mdoc_node
*nn
;
1766 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1768 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1770 bufcat(h
, "mailto:");
1771 bufcat(h
, nn
->string
);
1772 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1773 t
= print_otag(h
, TAG_A
, 2, tag
);
1774 print_text(h
, nn
->string
);
1784 mdoc_fo_pre(MDOC_ARGS
)
1786 struct htmlpair tag
;
1789 if (MDOC_BODY
== n
->type
) {
1790 h
->flags
|= HTML_NOSPACE
;
1792 h
->flags
|= HTML_NOSPACE
;
1794 } else if (MDOC_BLOCK
== n
->type
&& n
->next
) {
1795 SCALE_VS_INIT(&su
, 1);
1796 bufcat_su(h
, "margin-bottom", &su
);
1797 PAIR_STYLE_INIT(&tag
, h
);
1798 print_otag(h
, TAG_DIV
, 1, &tag
);
1802 PAIR_CLASS_INIT(&tag
, "fname");
1803 print_otag(h
, TAG_SPAN
, 1, &tag
);
1810 mdoc_fo_post(MDOC_ARGS
)
1812 if (MDOC_BODY
!= n
->type
)
1814 h
->flags
|= HTML_NOSPACE
;
1816 h
->flags
|= HTML_NOSPACE
;
1823 mdoc_in_pre(MDOC_ARGS
)
1825 const struct mdoc_node
*nn
;
1827 struct htmlpair tag
[2];
1831 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1832 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1833 SCALE_VS_INIT(&su
, 1);
1834 bufcat_su(h
, "margin-bottom", &su
);
1835 PAIR_STYLE_INIT(&tag
[0], h
);
1836 print_otag(h
, TAG_DIV
, 1, tag
);
1838 print_otag(h
, TAG_DIV
, 0, NULL
);
1841 /* FIXME: there's a buffer bug in here somewhere. */
1843 PAIR_CLASS_INIT(&tag
[0], "includes");
1844 print_otag(h
, TAG_SPAN
, 1, tag
);
1846 if (SEC_SYNOPSIS
== n
->sec
)
1847 print_text(h
, "#include");
1850 h
->flags
|= HTML_NOSPACE
;
1852 /* XXX -- see warning in termp_in_post(). */
1854 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1855 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1858 if (h
->base_includes
) {
1859 buffmt_includes(h
, nn
->string
);
1860 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1863 t
= print_otag(h
, TAG_A
, i
, tag
);
1864 print_mdoc_node(m
, nn
, h
);
1868 h
->flags
|= HTML_NOSPACE
;
1877 mdoc_ic_pre(MDOC_ARGS
)
1879 struct htmlpair tag
;
1881 PAIR_CLASS_INIT(&tag
, "cmd");
1882 print_otag(h
, TAG_SPAN
, 1, &tag
);
1889 mdoc_rv_pre(MDOC_ARGS
)
1891 const struct mdoc_node
*nn
;
1892 struct htmlpair tag
;
1895 print_otag(h
, TAG_DIV
, 0, NULL
);
1896 print_text(h
, "The");
1898 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1899 PAIR_CLASS_INIT(&tag
, "fname");
1900 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1901 print_text(h
, nn
->string
);
1904 h
->flags
|= HTML_NOSPACE
;
1905 if (nn
->next
&& NULL
== nn
->next
->next
)
1906 print_text(h
, "(), and");
1908 print_text(h
, "(),");
1910 print_text(h
, "()");
1913 if (n
->child
&& n
->child
->next
)
1914 print_text(h
, "functions return");
1916 print_text(h
, "function returns");
1918 print_text(h
, "the value 0 if successful; otherwise the value "
1919 "-1 is returned and the global variable");
1921 PAIR_CLASS_INIT(&tag
, "var");
1922 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1923 print_text(h
, "errno");
1925 print_text(h
, "is set to indicate the error.");
1932 mdoc_va_pre(MDOC_ARGS
)
1934 struct htmlpair tag
;
1936 PAIR_CLASS_INIT(&tag
, "var");
1937 print_otag(h
, TAG_SPAN
, 1, &tag
);
1944 mdoc_bq_pre(MDOC_ARGS
)
1947 if (MDOC_BODY
!= n
->type
)
1949 print_text(h
, "\\(lB");
1950 h
->flags
|= HTML_NOSPACE
;
1957 mdoc_bq_post(MDOC_ARGS
)
1960 if (MDOC_BODY
!= n
->type
)
1962 h
->flags
|= HTML_NOSPACE
;
1963 print_text(h
, "\\(rB");
1969 mdoc_ap_pre(MDOC_ARGS
)
1972 h
->flags
|= HTML_NOSPACE
;
1973 print_text(h
, "\\(aq");
1974 h
->flags
|= HTML_NOSPACE
;
1981 mdoc_bf_pre(MDOC_ARGS
)
1984 struct htmlpair tag
[2];
1987 if (MDOC_HEAD
== n
->type
)
1989 else if (MDOC_BLOCK
!= n
->type
)
1992 PAIR_CLASS_INIT(&tag
[0], "lit");
1994 if (n
->head
->child
) {
1995 if ( ! strcmp("Em", n
->head
->child
->string
))
1996 PAIR_CLASS_INIT(&tag
[0], "emph");
1997 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1998 PAIR_CLASS_INIT(&tag
[0], "symb");
1999 else if ( ! strcmp("Li", n
->head
->child
->string
))
2000 PAIR_CLASS_INIT(&tag
[0], "lit");
2003 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2004 switch (n
->args
->argv
[i
].arg
) {
2005 case (MDOC_Symbolic
):
2006 PAIR_CLASS_INIT(&tag
[0], "symb");
2008 case (MDOC_Literal
):
2009 PAIR_CLASS_INIT(&tag
[0], "lit");
2011 case (MDOC_Emphasis
):
2012 PAIR_CLASS_INIT(&tag
[0], "emph");
2019 /* FIXME: div's have spaces stripped--we want them. */
2021 bufcat_style(h
, "display", "inline");
2022 SCALE_HS_INIT(&su
, 1);
2023 bufcat_su(h
, "margin-right", &su
);
2024 PAIR_STYLE_INIT(&tag
[1], h
);
2025 print_otag(h
, TAG_DIV
, 2, tag
);
2032 mdoc_ms_pre(MDOC_ARGS
)
2034 struct htmlpair tag
;
2036 PAIR_CLASS_INIT(&tag
, "symb");
2037 print_otag(h
, TAG_SPAN
, 1, &tag
);
2044 mdoc_pf_pre(MDOC_ARGS
)
2047 h
->flags
|= HTML_IGNDELIM
;
2054 mdoc_pf_post(MDOC_ARGS
)
2057 h
->flags
&= ~HTML_IGNDELIM
;
2058 h
->flags
|= HTML_NOSPACE
;
2064 mdoc_rs_pre(MDOC_ARGS
)
2066 struct htmlpair tag
;
2069 if (MDOC_BLOCK
!= n
->type
)
2072 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2073 SCALE_VS_INIT(&su
, 1);
2074 bufcat_su(h
, "margin-top", &su
);
2075 PAIR_STYLE_INIT(&tag
, h
);
2076 print_otag(h
, TAG_DIV
, 1, &tag
);
2079 PAIR_CLASS_INIT(&tag
, "ref");
2080 print_otag(h
, TAG_SPAN
, 1, &tag
);
2088 mdoc_li_pre(MDOC_ARGS
)
2090 struct htmlpair tag
;
2092 PAIR_CLASS_INIT(&tag
, "lit");
2093 print_otag(h
, TAG_SPAN
, 1, &tag
);
2100 mdoc_sy_pre(MDOC_ARGS
)
2102 struct htmlpair tag
;
2104 PAIR_CLASS_INIT(&tag
, "symb");
2105 print_otag(h
, TAG_SPAN
, 1, &tag
);
2112 mdoc_bt_pre(MDOC_ARGS
)
2115 print_text(h
, "is currently in beta test.");
2122 mdoc_ud_pre(MDOC_ARGS
)
2125 print_text(h
, "currently under development.");
2132 mdoc_lb_pre(MDOC_ARGS
)
2134 struct htmlpair tag
;
2136 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2137 print_otag(h
, TAG_DIV
, 0, NULL
);
2138 PAIR_CLASS_INIT(&tag
, "lib");
2139 print_otag(h
, TAG_SPAN
, 1, &tag
);
2146 mdoc__x_pre(MDOC_ARGS
)
2148 struct htmlpair tag
[2];
2152 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2155 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2158 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2161 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2164 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2167 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2170 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2173 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2176 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2179 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2182 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2185 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2188 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2191 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2198 if (MDOC__U
!= n
->tok
) {
2199 print_otag(h
, TAG_SPAN
, 1, tag
);
2203 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2204 print_otag(h
, TAG_A
, 2, tag
);
2211 mdoc__x_post(MDOC_ARGS
)
2216 h
->flags
|= HTML_NOSPACE
;
2217 print_text(h
, n
->next
? "," : ".");