]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.62 2010/05/13 06:22:11 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>
38 #define MDOC_ARGS const struct mdoc_meta *m, \
39 const struct mdoc_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
);
56 static void a2width(const char *, struct roffsu
*);
57 static void a2offs(const char *, struct roffsu
*);
59 static int a2list(const struct mdoc_node
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static void mdoc_aq_post(MDOC_ARGS
);
70 static int mdoc_aq_pre(MDOC_ARGS
);
71 static int mdoc_ar_pre(MDOC_ARGS
);
72 static int mdoc_bd_pre(MDOC_ARGS
);
73 static int mdoc_bf_pre(MDOC_ARGS
);
74 static void mdoc_bl_post(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static void mdoc_bq_post(MDOC_ARGS
);
77 static int mdoc_bq_pre(MDOC_ARGS
);
78 static void mdoc_brq_post(MDOC_ARGS
);
79 static int mdoc_brq_pre(MDOC_ARGS
);
80 static int mdoc_bt_pre(MDOC_ARGS
);
81 static int mdoc_bx_pre(MDOC_ARGS
);
82 static int mdoc_cd_pre(MDOC_ARGS
);
83 static int mdoc_d1_pre(MDOC_ARGS
);
84 static void mdoc_dq_post(MDOC_ARGS
);
85 static int mdoc_dq_pre(MDOC_ARGS
);
86 static int mdoc_dv_pre(MDOC_ARGS
);
87 static int mdoc_fa_pre(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
, int, int,
101 struct roffsu
*, struct roffsu
*);
102 static int mdoc_it_head_pre(MDOC_ARGS
, int,
104 static int mdoc_it_body_pre(MDOC_ARGS
, int);
105 static int mdoc_it_pre(MDOC_ARGS
);
106 static int mdoc_lb_pre(MDOC_ARGS
);
107 static int mdoc_li_pre(MDOC_ARGS
);
108 static int mdoc_lk_pre(MDOC_ARGS
);
109 static int mdoc_mt_pre(MDOC_ARGS
);
110 static int mdoc_ms_pre(MDOC_ARGS
);
111 static int mdoc_nd_pre(MDOC_ARGS
);
112 static int mdoc_nm_pre(MDOC_ARGS
);
113 static int mdoc_ns_pre(MDOC_ARGS
);
114 static void mdoc_op_post(MDOC_ARGS
);
115 static int mdoc_op_pre(MDOC_ARGS
);
116 static int mdoc_pa_pre(MDOC_ARGS
);
117 static void mdoc_pf_post(MDOC_ARGS
);
118 static int mdoc_pf_pre(MDOC_ARGS
);
119 static void mdoc_pq_post(MDOC_ARGS
);
120 static int mdoc_pq_pre(MDOC_ARGS
);
121 static int mdoc_rs_pre(MDOC_ARGS
);
122 static int mdoc_rv_pre(MDOC_ARGS
);
123 static int mdoc_sh_pre(MDOC_ARGS
);
124 static int mdoc_sp_pre(MDOC_ARGS
);
125 static void mdoc_sq_post(MDOC_ARGS
);
126 static int mdoc_sq_pre(MDOC_ARGS
);
127 static int mdoc_ss_pre(MDOC_ARGS
);
128 static int mdoc_sx_pre(MDOC_ARGS
);
129 static int mdoc_sy_pre(MDOC_ARGS
);
130 static int mdoc_ud_pre(MDOC_ARGS
);
131 static int mdoc_va_pre(MDOC_ARGS
);
132 static int mdoc_vt_pre(MDOC_ARGS
);
133 static int mdoc_xr_pre(MDOC_ARGS
);
134 static int mdoc_xx_pre(MDOC_ARGS
);
136 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
137 {mdoc_ap_pre
, NULL
}, /* Ap */
138 {NULL
, NULL
}, /* Dd */
139 {NULL
, NULL
}, /* Dt */
140 {NULL
, NULL
}, /* Os */
141 {mdoc_sh_pre
, NULL
}, /* Sh */
142 {mdoc_ss_pre
, NULL
}, /* Ss */
143 {mdoc_sp_pre
, NULL
}, /* Pp */
144 {mdoc_d1_pre
, NULL
}, /* D1 */
145 {mdoc_d1_pre
, NULL
}, /* Dl */
146 {mdoc_bd_pre
, NULL
}, /* Bd */
147 {NULL
, NULL
}, /* Ed */
148 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
149 {NULL
, NULL
}, /* El */
150 {mdoc_it_pre
, NULL
}, /* It */
151 {mdoc_ad_pre
, NULL
}, /* Ad */
152 {mdoc_an_pre
, NULL
}, /* An */
153 {mdoc_ar_pre
, NULL
}, /* Ar */
154 {mdoc_cd_pre
, NULL
}, /* Cd */
155 {mdoc_fl_pre
, NULL
}, /* Cm */
156 {mdoc_dv_pre
, NULL
}, /* Dv */
157 {mdoc_er_pre
, NULL
}, /* Er */
158 {mdoc_ev_pre
, NULL
}, /* Ev */
159 {mdoc_ex_pre
, NULL
}, /* Ex */
160 {mdoc_fa_pre
, NULL
}, /* Fa */
161 {mdoc_fd_pre
, NULL
}, /* Fd */
162 {mdoc_fl_pre
, NULL
}, /* Fl */
163 {mdoc_fn_pre
, NULL
}, /* Fn */
164 {mdoc_ft_pre
, NULL
}, /* Ft */
165 {mdoc_ic_pre
, NULL
}, /* Ic */
166 {mdoc_in_pre
, NULL
}, /* In */
167 {mdoc_li_pre
, NULL
}, /* Li */
168 {mdoc_nd_pre
, NULL
}, /* Nd */
169 {mdoc_nm_pre
, NULL
}, /* Nm */
170 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
171 {NULL
, NULL
}, /* Ot */
172 {mdoc_pa_pre
, NULL
}, /* Pa */
173 {mdoc_rv_pre
, NULL
}, /* Rv */
174 {NULL
, NULL
}, /* St */
175 {mdoc_va_pre
, NULL
}, /* Va */
176 {mdoc_vt_pre
, NULL
}, /* Vt */
177 {mdoc_xr_pre
, NULL
}, /* Xr */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
189 {NULL
, NULL
}, /* Ac */
190 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
191 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
192 {NULL
, NULL
}, /* At */
193 {NULL
, NULL
}, /* Bc */
194 {mdoc_bf_pre
, NULL
}, /* Bf */
195 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
196 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
197 {mdoc_xx_pre
, NULL
}, /* Bsx */
198 {mdoc_bx_pre
, NULL
}, /* Bx */
199 {NULL
, NULL
}, /* Db */
200 {NULL
, NULL
}, /* Dc */
201 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
202 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
203 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
204 {NULL
, NULL
}, /* Ef */
205 {mdoc_em_pre
, NULL
}, /* Em */
206 {NULL
, NULL
}, /* Eo */
207 {mdoc_xx_pre
, NULL
}, /* Fx */
208 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
209 {NULL
, NULL
}, /* No */
210 {mdoc_ns_pre
, NULL
}, /* Ns */
211 {mdoc_xx_pre
, NULL
}, /* Nx */
212 {mdoc_xx_pre
, NULL
}, /* Ox */
213 {NULL
, NULL
}, /* Pc */
214 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
215 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
216 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
217 {NULL
, NULL
}, /* Qc */
218 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
219 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
220 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
221 {NULL
, NULL
}, /* Re */
222 {mdoc_rs_pre
, NULL
}, /* Rs */
223 {NULL
, NULL
}, /* Sc */
224 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
225 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
226 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
227 {mdoc_sx_pre
, NULL
}, /* Sx */
228 {mdoc_sy_pre
, NULL
}, /* Sy */
229 {NULL
, NULL
}, /* Tn */
230 {mdoc_xx_pre
, NULL
}, /* Ux */
231 {NULL
, NULL
}, /* Xc */
232 {NULL
, NULL
}, /* Xo */
233 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
234 {NULL
, NULL
}, /* Fc */
235 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
236 {NULL
, NULL
}, /* Oc */
237 {NULL
, NULL
}, /* Bk */
238 {NULL
, NULL
}, /* Ek */
239 {mdoc_bt_pre
, NULL
}, /* Bt */
240 {NULL
, NULL
}, /* Hf */
241 {NULL
, NULL
}, /* Fr */
242 {mdoc_ud_pre
, NULL
}, /* Ud */
243 {mdoc_lb_pre
, NULL
}, /* Lb */
244 {mdoc_sp_pre
, NULL
}, /* Lp */
245 {mdoc_lk_pre
, NULL
}, /* Lk */
246 {mdoc_mt_pre
, NULL
}, /* Mt */
247 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
248 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
249 {NULL
, NULL
}, /* Brc */
250 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
251 {NULL
, NULL
}, /* Es */ /* TODO */
252 {NULL
, NULL
}, /* En */ /* TODO */
253 {mdoc_xx_pre
, NULL
}, /* Dx */
254 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
255 {mdoc_sp_pre
, NULL
}, /* br */
256 {mdoc_sp_pre
, NULL
}, /* sp */
257 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
262 html_mdoc(void *arg
, const struct mdoc
*m
)
267 h
= (struct html
*)arg
;
270 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
271 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
279 * Return the list type for `Bl', e.g., `Bl -column' returns
280 * MDOC_Column. This can ONLY be run for lists; it will abort() if no
281 * list type is found.
284 a2list(const struct mdoc_node
*n
)
289 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
290 switch (n
->args
->argv
[i
].arg
) {
312 return(n
->args
->argv
[i
].arg
);
323 * Calculate the scaling unit passed in a `-width' argument. This uses
324 * either a native scaling unit (e.g., 1i, 2m) or the string length of
328 a2width(const char *p
, struct roffsu
*su
)
331 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
333 su
->scale
= (int)strlen(p
);
339 * Calculate the scaling unit passed in an `-offset' argument. This
340 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
341 * predefined strings (indent, etc.), or the string length of the value.
344 a2offs(const char *p
, struct roffsu
*su
)
347 /* FIXME: "right"? */
349 if (0 == strcmp(p
, "left"))
350 SCALE_HS_INIT(su
, 0);
351 else if (0 == strcmp(p
, "indent"))
352 SCALE_HS_INIT(su
, INDENT
);
353 else if (0 == strcmp(p
, "indent-two"))
354 SCALE_HS_INIT(su
, INDENT
* 2);
355 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
357 su
->scale
= (int)strlen(p
);
363 print_mdoc(MDOC_ARGS
)
368 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
369 print_mdoc_head(m
, n
, h
);
372 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
374 tag
.key
= ATTR_CLASS
;
376 print_otag(h
, TAG_DIV
, 1, &tag
);
378 print_mdoc_nodelist(m
, n
, h
);
385 print_mdoc_head(MDOC_ARGS
)
390 buffmt(h
, "%s(%d)", m
->title
, m
->msec
);
398 print_otag(h
, TAG_TITLE
, 0, NULL
);
399 print_text(h
, h
->buf
);
404 print_mdoc_nodelist(MDOC_ARGS
)
407 print_mdoc_node(m
, n
, h
);
409 print_mdoc_nodelist(m
, n
->next
, h
);
414 print_mdoc_node(MDOC_ARGS
)
425 child
= mdoc_root_pre(m
, n
, h
);
428 print_text(h
, n
->string
);
431 if (mdocs
[n
->tok
].pre
)
432 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
436 if (child
&& n
->child
)
437 print_mdoc_nodelist(m
, n
->child
, h
);
444 mdoc_root_post(m
, n
, h
);
447 if (mdocs
[n
->tok
].post
)
448 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
456 mdoc_root_post(MDOC_ARGS
)
458 struct htmlpair tag
[3];
462 time2a(m
->date
, b
, DATESIZ
);
465 * XXX: this should use divs, but in Firefox, divs with nested
466 * divs for some reason puke when trying to put a border line
467 * below. So I use tables, instead.
470 PAIR_CLASS_INIT(&tag
[0], "footer");
471 bufcat_style(h
, "width", "100%");
472 PAIR_STYLE_INIT(&tag
[1], h
);
473 PAIR_SUMMARY_INIT(&tag
[2], "footer");
475 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
476 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
479 bufcat_style(h
, "width", "50%");
480 PAIR_STYLE_INIT(&tag
[0], h
);
481 print_otag(h
, TAG_TD
, 1, tag
);
486 bufcat_style(h
, "width", "50%");
487 bufcat_style(h
, "text-align", "right");
488 PAIR_STYLE_INIT(&tag
[0], h
);
489 print_otag(h
, TAG_TD
, 1, tag
);
490 print_text(h
, m
->os
);
497 mdoc_root_pre(MDOC_ARGS
)
499 struct htmlpair tag
[3];
501 char b
[BUFSIZ
], title
[BUFSIZ
];
503 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
506 (void)strlcat(b
, " (", BUFSIZ
);
507 (void)strlcat(b
, m
->arch
, BUFSIZ
);
508 (void)strlcat(b
, ")", BUFSIZ
);
511 (void)snprintf(title
, BUFSIZ
- 1,
512 "%s(%d)", m
->title
, m
->msec
);
514 /* XXX: see note in mdoc_root_post() about divs. */
516 PAIR_CLASS_INIT(&tag
[0], "header");
517 bufcat_style(h
, "width", "100%");
518 PAIR_STYLE_INIT(&tag
[1], h
);
519 PAIR_SUMMARY_INIT(&tag
[2], "header");
521 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
523 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
526 bufcat_style(h
, "width", "10%");
527 PAIR_STYLE_INIT(&tag
[0], h
);
528 print_otag(h
, TAG_TD
, 1, tag
);
529 print_text(h
, title
);
533 bufcat_style(h
, "text-align", "center");
534 bufcat_style(h
, "white-space", "nowrap");
535 bufcat_style(h
, "width", "80%");
536 PAIR_STYLE_INIT(&tag
[0], h
);
537 print_otag(h
, TAG_TD
, 1, tag
);
542 bufcat_style(h
, "text-align", "right");
543 bufcat_style(h
, "width", "10%");
544 PAIR_STYLE_INIT(&tag
[0], h
);
545 print_otag(h
, TAG_TD
, 1, tag
);
546 print_text(h
, title
);
554 mdoc_sh_pre(MDOC_ARGS
)
556 struct htmlpair tag
[2];
557 const struct mdoc_node
*nn
;
561 if (MDOC_BODY
== n
->type
) {
562 SCALE_HS_INIT(&su
, INDENT
);
563 bufcat_su(h
, "margin-left", &su
);
564 PAIR_CLASS_INIT(&tag
[0], "sec-body");
565 PAIR_STYLE_INIT(&tag
[1], h
);
566 print_otag(h
, TAG_DIV
, 2, tag
);
568 } else if (MDOC_BLOCK
== n
->type
) {
569 PAIR_CLASS_INIT(&tag
[0], "sec-block");
570 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
571 print_otag(h
, TAG_DIV
, 1, tag
);
575 SCALE_VS_INIT(&su
, 1);
576 bufcat_su(h
, "margin-top", &su
);
578 bufcat_su(h
, "margin-bottom", &su
);
580 PAIR_STYLE_INIT(&tag
[1], h
);
581 print_otag(h
, TAG_DIV
, 2, tag
);
586 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
587 html_idcat(buf
, nn
->string
, BUFSIZ
);
589 html_idcat(buf
, " ", BUFSIZ
);
592 PAIR_CLASS_INIT(&tag
[0], "sec-head");
593 PAIR_ID_INIT(&tag
[1], buf
);
595 print_otag(h
, TAG_DIV
, 2, tag
);
602 mdoc_ss_pre(MDOC_ARGS
)
604 struct htmlpair tag
[3];
605 const struct mdoc_node
*nn
;
609 SCALE_VS_INIT(&su
, 1);
611 if (MDOC_BODY
== n
->type
) {
612 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
613 if (n
->parent
->next
&& n
->child
) {
614 bufcat_su(h
, "margin-bottom", &su
);
615 PAIR_STYLE_INIT(&tag
[1], h
);
616 print_otag(h
, TAG_DIV
, 2, tag
);
618 print_otag(h
, TAG_DIV
, 1, tag
);
620 } else if (MDOC_BLOCK
== n
->type
) {
621 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
623 bufcat_su(h
, "margin-top", &su
);
624 PAIR_STYLE_INIT(&tag
[1], h
);
625 print_otag(h
, TAG_DIV
, 2, tag
);
627 print_otag(h
, TAG_DIV
, 1, tag
);
631 /* TODO: see note in mdoc_sh_pre() about duplicates. */
634 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
635 html_idcat(buf
, nn
->string
, BUFSIZ
);
637 html_idcat(buf
, " ", BUFSIZ
);
640 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
641 su
.scale
= -su
.scale
;
642 bufcat_su(h
, "margin-left", &su
);
644 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
645 PAIR_STYLE_INIT(&tag
[1], h
);
646 PAIR_ID_INIT(&tag
[2], buf
);
648 print_otag(h
, TAG_DIV
, 3, tag
);
655 mdoc_fl_pre(MDOC_ARGS
)
659 PAIR_CLASS_INIT(&tag
, "flag");
660 print_otag(h
, TAG_SPAN
, 1, &tag
);
662 /* `Cm' has no leading hyphen. */
664 if (MDOC_Cm
== n
->tok
)
667 print_text(h
, "\\-");
670 h
->flags
|= HTML_NOSPACE
;
671 else if (n
->next
&& n
->next
->line
== n
->line
)
672 h
->flags
|= HTML_NOSPACE
;
680 mdoc_nd_pre(MDOC_ARGS
)
684 if (MDOC_BODY
!= n
->type
)
687 /* XXX: this tag in theory can contain block elements. */
689 print_text(h
, "\\(em");
690 PAIR_CLASS_INIT(&tag
, "desc-body");
691 print_otag(h
, TAG_SPAN
, 1, &tag
);
698 mdoc_op_pre(MDOC_ARGS
)
702 if (MDOC_BODY
!= n
->type
)
705 /* XXX: this tag in theory can contain block elements. */
707 print_text(h
, "\\(lB");
708 h
->flags
|= HTML_NOSPACE
;
709 PAIR_CLASS_INIT(&tag
, "opt");
710 print_otag(h
, TAG_SPAN
, 1, &tag
);
717 mdoc_op_post(MDOC_ARGS
)
720 if (MDOC_BODY
!= n
->type
)
722 h
->flags
|= HTML_NOSPACE
;
723 print_text(h
, "\\(rB");
728 mdoc_nm_pre(MDOC_ARGS
)
732 if (SEC_SYNOPSIS
== n
->sec
&&
733 n
->prev
&& MDOC_LINE
& n
->flags
) {
734 bufcat_style(h
, "clear", "both");
735 PAIR_STYLE_INIT(&tag
, h
);
736 print_otag(h
, TAG_BR
, 1, &tag
);
739 PAIR_CLASS_INIT(&tag
, "name");
740 print_otag(h
, TAG_SPAN
, 1, &tag
);
741 if (NULL
== n
->child
)
742 print_text(h
, m
->name
);
750 mdoc_xr_pre(MDOC_ARGS
)
752 struct htmlpair tag
[2];
753 const struct mdoc_node
*nn
;
755 if (NULL
== n
->child
)
758 PAIR_CLASS_INIT(&tag
[0], "link-man");
761 buffmt_man(h
, n
->child
->string
,
763 n
->child
->next
->string
: NULL
);
764 PAIR_HREF_INIT(&tag
[1], h
->buf
);
765 print_otag(h
, TAG_A
, 2, tag
);
767 print_otag(h
, TAG_A
, 1, tag
);
770 print_text(h
, nn
->string
);
772 if (NULL
== (nn
= nn
->next
))
775 h
->flags
|= HTML_NOSPACE
;
777 h
->flags
|= HTML_NOSPACE
;
778 print_text(h
, nn
->string
);
779 h
->flags
|= HTML_NOSPACE
;
787 mdoc_ns_pre(MDOC_ARGS
)
790 h
->flags
|= HTML_NOSPACE
;
797 mdoc_ar_pre(MDOC_ARGS
)
801 PAIR_CLASS_INIT(&tag
, "arg");
802 print_otag(h
, TAG_SPAN
, 1, &tag
);
809 mdoc_xx_pre(MDOC_ARGS
)
837 PAIR_CLASS_INIT(&tag
, "unix");
838 print_otag(h
, TAG_SPAN
, 1, &tag
);
846 mdoc_bx_pre(MDOC_ARGS
)
848 const struct mdoc_node
*nn
;
851 PAIR_CLASS_INIT(&tag
, "unix");
852 print_otag(h
, TAG_SPAN
, 1, &tag
);
854 for (nn
= n
->child
; nn
; nn
= nn
->next
)
855 print_mdoc_node(m
, nn
, h
);
858 h
->flags
|= HTML_NOSPACE
;
860 print_text(h
, "BSD");
867 mdoc_it_block_pre(MDOC_ARGS
, int type
, int comp
,
868 struct roffsu
*offs
, struct roffsu
*width
)
871 const struct mdoc_node
*nn
;
874 nn
= n
->parent
->parent
;
877 /* XXX: see notes in mdoc_it_pre(). */
879 if (MDOC_Column
== type
) {
880 /* Don't width-pad on the left. */
881 SCALE_HS_INIT(width
, 0);
882 /* Also disallow non-compact. */
885 if (MDOC_Diag
== type
)
886 /* Mandate non-compact with empty prior. */
887 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
890 bufcat_style(h
, "clear", "both");
892 bufcat_su(h
, "margin-left", offs
);
893 if (width
->scale
> 0)
894 bufcat_su(h
, "padding-left", width
);
896 PAIR_STYLE_INIT(&tag
, h
);
898 /* Mandate compact following `Ss' and `Sh' starts. */
900 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
901 if (MDOC_BLOCK
!= nn
->type
)
903 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
910 SCALE_VS_INIT(&su
, 1);
911 bufcat_su(h
, "padding-top", &su
);
914 PAIR_STYLE_INIT(&tag
, h
);
915 print_otag(h
, TAG_DIV
, 1, &tag
);
922 mdoc_it_body_pre(MDOC_ARGS
, int type
)
936 * XXX: this tricks CSS into aligning the bodies with
937 * the right-padding in the head.
939 SCALE_HS_INIT(&su
, 2);
940 bufcat_su(h
, "margin-left", &su
);
941 PAIR_STYLE_INIT(&tag
, h
);
942 print_otag(h
, TAG_DIV
, 1, &tag
);
952 mdoc_it_head_pre(MDOC_ARGS
, int type
, struct roffsu
*width
)
962 print_otag(h
, TAG_DIV
, 0, &tag
);
965 bufcat_su(h
, "min-width", width
);
966 bufcat_style(h
, "clear", "none");
967 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
968 bufcat_style(h
, "float", "left");
969 PAIR_STYLE_INIT(&tag
, h
);
970 print_otag(h
, TAG_DIV
, 1, &tag
);
973 bufcat_su(h
, "min-width", width
);
975 bufcat_su(h
, "margin-left", width
);
976 if (n
->next
&& n
->next
->child
)
977 bufcat_style(h
, "float", "left");
979 /* XXX: buffer if we run into body. */
980 SCALE_HS_INIT(width
, 1);
981 bufcat_su(h
, "margin-right", width
);
982 PAIR_STYLE_INIT(&tag
, h
);
983 print_otag(h
, TAG_DIV
, 1, &tag
);
989 PAIR_CLASS_INIT(&tag
, "diag");
990 print_otag(h
, TAG_SPAN
, 1, &tag
);
995 nbuf
[BUFSIZ
- 1] = 0;
996 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1000 print_text(h
, "\\(en");
1003 print_text(h
, "\\(hy");
1006 print_text(h
, "\\(bu");
1017 mdoc_it_pre(MDOC_ARGS
)
1019 int i
, type
, wp
, comp
;
1020 const struct mdoc_node
*bl
, *nn
;
1021 struct roffsu width
, offs
;
1024 * XXX: be very careful in changing anything, here. Lists in
1025 * mandoc have many peculiarities; furthermore, they don't
1026 * translate well into HTML and require a bit of mangling.
1029 bl
= n
->parent
->parent
;
1030 if (MDOC_BLOCK
!= n
->type
)
1035 /* Set default width and offset. */
1037 SCALE_HS_INIT(&offs
, 0);
1047 SCALE_HS_INIT(&width
, 2);
1050 SCALE_HS_INIT(&width
, INDENT
);
1054 /* Get width, offset, and compact arguments. */
1056 for (wp
= -1, comp
= i
= 0; i
< (int)bl
->args
->argc
; i
++)
1057 switch (bl
->args
->argv
[i
].arg
) {
1059 wp
= i
; /* Save for later. */
1062 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1065 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1067 case (MDOC_Compact
):
1074 /* Override width in some cases. */
1084 SCALE_HS_INIT(&width
, 0);
1087 if (0 == width
.scale
)
1088 SCALE_HS_INIT(&width
, INDENT
);
1092 /* Flip to body/block processing. */
1094 if (MDOC_BODY
== n
->type
)
1095 return(mdoc_it_body_pre(m
, n
, h
, type
));
1096 if (MDOC_BLOCK
== n
->type
)
1097 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1100 /* Override column widths. */
1102 if (MDOC_Column
== type
) {
1103 nn
= n
->parent
->child
;
1104 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1106 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1107 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1110 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1116 mdoc_bl_pre(MDOC_ARGS
)
1120 if (MDOC_HEAD
== n
->type
)
1122 if (MDOC_BLOCK
!= n
->type
)
1124 if (MDOC_Enum
!= a2list(n
))
1127 ord
= malloc(sizeof(struct ord
));
1134 ord
->next
= h
->ords
.head
;
1142 mdoc_bl_post(MDOC_ARGS
)
1146 if (MDOC_BLOCK
!= n
->type
)
1148 if (MDOC_Enum
!= a2list(n
))
1153 h
->ords
.head
= ord
->next
;
1160 mdoc_ex_pre(MDOC_ARGS
)
1162 const struct mdoc_node
*nn
;
1164 struct htmlpair tag
;
1166 PAIR_CLASS_INIT(&tag
, "utility");
1168 print_text(h
, "The");
1169 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1170 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1171 print_text(h
, nn
->string
);
1174 h
->flags
|= HTML_NOSPACE
;
1176 if (nn
->next
&& NULL
== nn
->next
->next
)
1177 print_text(h
, ", and");
1181 h
->flags
&= ~HTML_NOSPACE
;
1185 print_text(h
, "utilities exit");
1187 print_text(h
, "utility exits");
1189 print_text(h
, "0 on success, and >0 if an error occurs.");
1196 mdoc_dq_pre(MDOC_ARGS
)
1199 if (MDOC_BODY
!= n
->type
)
1201 print_text(h
, "\\(lq");
1202 h
->flags
|= HTML_NOSPACE
;
1209 mdoc_dq_post(MDOC_ARGS
)
1212 if (MDOC_BODY
!= n
->type
)
1214 h
->flags
|= HTML_NOSPACE
;
1215 print_text(h
, "\\(rq");
1221 mdoc_pq_pre(MDOC_ARGS
)
1224 if (MDOC_BODY
!= n
->type
)
1226 print_text(h
, "\\&(");
1227 h
->flags
|= HTML_NOSPACE
;
1234 mdoc_pq_post(MDOC_ARGS
)
1237 if (MDOC_BODY
!= n
->type
)
1245 mdoc_sq_pre(MDOC_ARGS
)
1248 if (MDOC_BODY
!= n
->type
)
1250 print_text(h
, "\\(oq");
1251 h
->flags
|= HTML_NOSPACE
;
1258 mdoc_sq_post(MDOC_ARGS
)
1261 if (MDOC_BODY
!= n
->type
)
1263 h
->flags
|= HTML_NOSPACE
;
1264 print_text(h
, "\\(aq");
1270 mdoc_em_pre(MDOC_ARGS
)
1272 struct htmlpair tag
;
1274 PAIR_CLASS_INIT(&tag
, "emph");
1275 print_otag(h
, TAG_SPAN
, 1, &tag
);
1282 mdoc_d1_pre(MDOC_ARGS
)
1284 struct htmlpair tag
[2];
1287 if (MDOC_BLOCK
!= n
->type
)
1290 /* FIXME: D1 shouldn't be literal. */
1292 SCALE_VS_INIT(&su
, INDENT
- 2);
1293 bufcat_su(h
, "margin-left", &su
);
1294 PAIR_CLASS_INIT(&tag
[0], "lit");
1295 PAIR_STYLE_INIT(&tag
[1], h
);
1296 print_otag(h
, TAG_DIV
, 2, tag
);
1303 mdoc_sx_pre(MDOC_ARGS
)
1305 struct htmlpair tag
[2];
1306 const struct mdoc_node
*nn
;
1309 strlcpy(buf
, "#", BUFSIZ
);
1310 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1311 html_idcat(buf
, nn
->string
, BUFSIZ
);
1313 html_idcat(buf
, " ", BUFSIZ
);
1316 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1317 PAIR_HREF_INIT(&tag
[1], buf
);
1319 print_otag(h
, TAG_A
, 2, tag
);
1326 mdoc_aq_pre(MDOC_ARGS
)
1329 if (MDOC_BODY
!= n
->type
)
1331 print_text(h
, "\\(la");
1332 h
->flags
|= HTML_NOSPACE
;
1339 mdoc_aq_post(MDOC_ARGS
)
1342 if (MDOC_BODY
!= n
->type
)
1344 h
->flags
|= HTML_NOSPACE
;
1345 print_text(h
, "\\(ra");
1351 mdoc_bd_pre(MDOC_ARGS
)
1353 struct htmlpair tag
[2];
1355 const struct mdoc_node
*bl
, *nn
;
1358 if (MDOC_BLOCK
== n
->type
)
1360 else if (MDOC_HEAD
== n
->type
)
1365 SCALE_VS_INIT(&su
, 0);
1368 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1369 switch (bl
->args
->argv
[i
].arg
) {
1371 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1373 case (MDOC_Compact
):
1376 case (MDOC_Centred
):
1382 case (MDOC_Unfilled
):
1384 case (MDOC_Literal
):
1385 type
= bl
->args
->argv
[i
].arg
;
1391 /* FIXME: -centered, etc. formatting. */
1392 /* FIXME: does not respect -offset ??? */
1394 if (MDOC_BLOCK
== n
->type
) {
1395 bufcat_su(h
, "margin-left", &su
);
1396 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1397 if (MDOC_BLOCK
!= nn
->type
)
1399 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1405 print_otag(h
, TAG_DIV
, 0, tag
);
1408 SCALE_VS_INIT(&su
, 1);
1409 bufcat_su(h
, "margin-top", &su
);
1410 PAIR_STYLE_INIT(&tag
[0], h
);
1411 print_otag(h
, TAG_DIV
, 1, tag
);
1415 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1418 PAIR_CLASS_INIT(&tag
[0], "lit");
1419 bufcat_style(h
, "white-space", "pre");
1420 PAIR_STYLE_INIT(&tag
[1], h
);
1421 print_otag(h
, TAG_DIV
, 2, tag
);
1423 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1424 h
->flags
|= HTML_NOSPACE
;
1425 print_mdoc_node(m
, nn
, h
);
1426 if (NULL
== nn
->next
)
1428 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1429 print_text(h
, "\n");
1430 else if (NULL
== nn
->prev
)
1431 print_text(h
, "\n");
1440 mdoc_pa_pre(MDOC_ARGS
)
1442 struct htmlpair tag
;
1444 PAIR_CLASS_INIT(&tag
, "file");
1445 print_otag(h
, TAG_SPAN
, 1, &tag
);
1452 mdoc_ad_pre(MDOC_ARGS
)
1454 struct htmlpair tag
;
1456 PAIR_CLASS_INIT(&tag
, "addr");
1457 print_otag(h
, TAG_SPAN
, 1, &tag
);
1464 mdoc_an_pre(MDOC_ARGS
)
1466 struct htmlpair tag
;
1468 /* TODO: -split and -nosplit (see termp_an_pre()). */
1470 PAIR_CLASS_INIT(&tag
, "author");
1471 print_otag(h
, TAG_SPAN
, 1, &tag
);
1478 mdoc_cd_pre(MDOC_ARGS
)
1480 struct htmlpair tag
;
1482 print_otag(h
, TAG_DIV
, 0, NULL
);
1483 PAIR_CLASS_INIT(&tag
, "config");
1484 print_otag(h
, TAG_SPAN
, 1, &tag
);
1491 mdoc_dv_pre(MDOC_ARGS
)
1493 struct htmlpair tag
;
1495 PAIR_CLASS_INIT(&tag
, "define");
1496 print_otag(h
, TAG_SPAN
, 1, &tag
);
1503 mdoc_ev_pre(MDOC_ARGS
)
1505 struct htmlpair tag
;
1507 PAIR_CLASS_INIT(&tag
, "env");
1508 print_otag(h
, TAG_SPAN
, 1, &tag
);
1515 mdoc_er_pre(MDOC_ARGS
)
1517 struct htmlpair tag
;
1519 PAIR_CLASS_INIT(&tag
, "errno");
1520 print_otag(h
, TAG_SPAN
, 1, &tag
);
1527 mdoc_fa_pre(MDOC_ARGS
)
1529 const struct mdoc_node
*nn
;
1530 struct htmlpair tag
;
1533 PAIR_CLASS_INIT(&tag
, "farg");
1534 if (n
->parent
->tok
!= MDOC_Fo
) {
1535 print_otag(h
, TAG_SPAN
, 1, &tag
);
1539 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1540 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1541 print_text(h
, nn
->string
);
1547 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1556 mdoc_fd_pre(MDOC_ARGS
)
1558 struct htmlpair tag
;
1561 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1562 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1563 SCALE_VS_INIT(&su
, 1);
1564 bufcat_su(h
, "margin-bottom", &su
);
1565 PAIR_STYLE_INIT(&tag
, h
);
1566 print_otag(h
, TAG_DIV
, 1, &tag
);
1568 print_otag(h
, TAG_DIV
, 0, NULL
);
1571 PAIR_CLASS_INIT(&tag
, "macro");
1572 print_otag(h
, TAG_SPAN
, 1, &tag
);
1579 mdoc_vt_pre(MDOC_ARGS
)
1581 struct htmlpair tag
;
1584 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_BLOCK
== n
->type
) {
1585 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1586 SCALE_VS_INIT(&su
, 1);
1587 bufcat_su(h
, "margin-bottom", &su
);
1588 PAIR_STYLE_INIT(&tag
, h
);
1589 print_otag(h
, TAG_DIV
, 1, &tag
);
1591 print_otag(h
, TAG_DIV
, 0, NULL
);
1594 } else if (MDOC_HEAD
== n
->type
)
1597 PAIR_CLASS_INIT(&tag
, "type");
1598 print_otag(h
, TAG_SPAN
, 1, &tag
);
1605 mdoc_ft_pre(MDOC_ARGS
)
1607 struct htmlpair tag
;
1609 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1610 print_otag(h
, TAG_DIV
, 0, NULL
);
1612 PAIR_CLASS_INIT(&tag
, "ftype");
1613 print_otag(h
, TAG_SPAN
, 1, &tag
);
1620 mdoc_fn_pre(MDOC_ARGS
)
1623 struct htmlpair tag
[2];
1624 const struct mdoc_node
*nn
;
1626 const char *sp
, *ep
;
1630 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1631 SCALE_HS_INIT(&su
, INDENT
);
1632 bufcat_su(h
, "margin-left", &su
);
1633 su
.scale
= -su
.scale
;
1634 bufcat_su(h
, "text-indent", &su
);
1636 SCALE_VS_INIT(&su
, 1);
1637 bufcat_su(h
, "margin-bottom", &su
);
1639 PAIR_STYLE_INIT(&tag
[0], h
);
1640 print_otag(h
, TAG_DIV
, 1, tag
);
1643 /* Split apart into type and name. */
1644 assert(n
->child
->string
);
1645 sp
= n
->child
->string
;
1647 ep
= strchr(sp
, ' ');
1649 PAIR_CLASS_INIT(&tag
[0], "ftype");
1650 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1653 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1654 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1656 print_text(h
, nbuf
);
1658 ep
= strchr(sp
, ' ');
1663 PAIR_CLASS_INIT(&tag
[0], "fname");
1666 * FIXME: only refer to IDs that we know exist.
1670 if (SEC_SYNOPSIS
== n
->sec
) {
1672 html_idcat(nbuf
, sp
, BUFSIZ
);
1673 PAIR_ID_INIT(&tag
[1], nbuf
);
1675 strlcpy(nbuf
, "#", BUFSIZ
);
1676 html_idcat(nbuf
, sp
, BUFSIZ
);
1677 PAIR_HREF_INIT(&tag
[1], nbuf
);
1681 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1684 strlcpy(nbuf
, sp
, BUFSIZ
);
1685 print_text(h
, nbuf
);
1690 h
->flags
|= HTML_NOSPACE
;
1694 PAIR_CLASS_INIT(&tag
[0], "farg");
1695 bufcat_style(h
, "white-space", "nowrap");
1696 PAIR_STYLE_INIT(&tag
[1], h
);
1698 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1700 if (SEC_SYNOPSIS
== n
->sec
)
1702 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1703 print_text(h
, nn
->string
);
1710 if (SEC_SYNOPSIS
== n
->sec
)
1719 mdoc_sp_pre(MDOC_ARGS
)
1722 struct htmlpair tag
;
1727 /* FIXME: can this have a scaling indicator? */
1728 len
= n
->child
? atoi(n
->child
->string
) : 1;
1738 SCALE_VS_INIT(&su
, len
);
1739 bufcat_su(h
, "height", &su
);
1740 PAIR_STYLE_INIT(&tag
, h
);
1741 print_otag(h
, TAG_DIV
, 1, &tag
);
1742 /* So the div isn't empty: */
1743 print_text(h
, "\\~");
1752 mdoc_brq_pre(MDOC_ARGS
)
1755 if (MDOC_BODY
!= n
->type
)
1757 print_text(h
, "\\(lC");
1758 h
->flags
|= HTML_NOSPACE
;
1765 mdoc_brq_post(MDOC_ARGS
)
1768 if (MDOC_BODY
!= n
->type
)
1770 h
->flags
|= HTML_NOSPACE
;
1771 print_text(h
, "\\(rC");
1777 mdoc_lk_pre(MDOC_ARGS
)
1779 const struct mdoc_node
*nn
;
1780 struct htmlpair tag
[2];
1784 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1785 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1786 print_otag(h
, TAG_A
, 2, tag
);
1788 if (NULL
== nn
->next
)
1791 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1792 print_text(h
, nn
->string
);
1800 mdoc_mt_pre(MDOC_ARGS
)
1802 struct htmlpair tag
[2];
1804 const struct mdoc_node
*nn
;
1806 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1808 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1810 bufcat(h
, "mailto:");
1811 bufcat(h
, nn
->string
);
1812 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1813 t
= print_otag(h
, TAG_A
, 2, tag
);
1814 print_text(h
, nn
->string
);
1824 mdoc_fo_pre(MDOC_ARGS
)
1826 struct htmlpair tag
;
1829 if (MDOC_BODY
== n
->type
) {
1830 h
->flags
|= HTML_NOSPACE
;
1832 h
->flags
|= HTML_NOSPACE
;
1834 } else if (MDOC_BLOCK
== n
->type
&& n
->next
) {
1835 SCALE_VS_INIT(&su
, 1);
1836 bufcat_su(h
, "margin-bottom", &su
);
1837 PAIR_STYLE_INIT(&tag
, h
);
1838 print_otag(h
, TAG_DIV
, 1, &tag
);
1842 PAIR_CLASS_INIT(&tag
, "fname");
1843 print_otag(h
, TAG_SPAN
, 1, &tag
);
1850 mdoc_fo_post(MDOC_ARGS
)
1852 if (MDOC_BODY
!= n
->type
)
1854 h
->flags
|= HTML_NOSPACE
;
1856 h
->flags
|= HTML_NOSPACE
;
1863 mdoc_in_pre(MDOC_ARGS
)
1865 const struct mdoc_node
*nn
;
1867 struct htmlpair tag
[2];
1871 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
) {
1872 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1873 SCALE_VS_INIT(&su
, 1);
1874 bufcat_su(h
, "margin-bottom", &su
);
1875 PAIR_STYLE_INIT(&tag
[0], h
);
1876 print_otag(h
, TAG_DIV
, 1, tag
);
1878 print_otag(h
, TAG_DIV
, 0, NULL
);
1881 /* FIXME: there's a buffer bug in here somewhere. */
1883 PAIR_CLASS_INIT(&tag
[0], "includes");
1884 print_otag(h
, TAG_SPAN
, 1, tag
);
1886 if (SEC_SYNOPSIS
== n
->sec
)
1887 print_text(h
, "#include");
1890 h
->flags
|= HTML_NOSPACE
;
1892 /* XXX -- see warning in termp_in_post(). */
1894 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1895 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1898 if (h
->base_includes
) {
1899 buffmt_includes(h
, nn
->string
);
1900 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1903 t
= print_otag(h
, TAG_A
, i
, tag
);
1904 print_mdoc_node(m
, nn
, h
);
1908 h
->flags
|= HTML_NOSPACE
;
1917 mdoc_ic_pre(MDOC_ARGS
)
1919 struct htmlpair tag
;
1921 PAIR_CLASS_INIT(&tag
, "cmd");
1922 print_otag(h
, TAG_SPAN
, 1, &tag
);
1929 mdoc_rv_pre(MDOC_ARGS
)
1931 const struct mdoc_node
*nn
;
1932 struct htmlpair tag
;
1935 print_otag(h
, TAG_DIV
, 0, NULL
);
1936 print_text(h
, "The");
1938 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1939 PAIR_CLASS_INIT(&tag
, "fname");
1940 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1941 print_text(h
, nn
->string
);
1944 h
->flags
|= HTML_NOSPACE
;
1945 if (nn
->next
&& NULL
== nn
->next
->next
)
1946 print_text(h
, "(), and");
1948 print_text(h
, "(),");
1950 print_text(h
, "()");
1954 print_text(h
, "functions return");
1956 print_text(h
, "function returns");
1958 print_text(h
, "the value 0 if successful; otherwise the value "
1959 "-1 is returned and the global variable");
1961 PAIR_CLASS_INIT(&tag
, "var");
1962 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1963 print_text(h
, "errno");
1965 print_text(h
, "is set to indicate the error.");
1972 mdoc_va_pre(MDOC_ARGS
)
1974 struct htmlpair tag
;
1976 PAIR_CLASS_INIT(&tag
, "var");
1977 print_otag(h
, TAG_SPAN
, 1, &tag
);
1984 mdoc_bq_pre(MDOC_ARGS
)
1987 if (MDOC_BODY
!= n
->type
)
1989 print_text(h
, "\\(lB");
1990 h
->flags
|= HTML_NOSPACE
;
1997 mdoc_bq_post(MDOC_ARGS
)
2000 if (MDOC_BODY
!= n
->type
)
2002 h
->flags
|= HTML_NOSPACE
;
2003 print_text(h
, "\\(rB");
2009 mdoc_ap_pre(MDOC_ARGS
)
2012 h
->flags
|= HTML_NOSPACE
;
2013 print_text(h
, "\\(aq");
2014 h
->flags
|= HTML_NOSPACE
;
2021 mdoc_bf_pre(MDOC_ARGS
)
2024 struct htmlpair tag
[2];
2027 if (MDOC_HEAD
== n
->type
)
2029 else if (MDOC_BLOCK
!= n
->type
)
2032 PAIR_CLASS_INIT(&tag
[0], "lit");
2034 if (n
->head
->child
) {
2035 if ( ! strcmp("Em", n
->head
->child
->string
))
2036 PAIR_CLASS_INIT(&tag
[0], "emph");
2037 else if ( ! strcmp("Sy", n
->head
->child
->string
))
2038 PAIR_CLASS_INIT(&tag
[0], "symb");
2039 else if ( ! strcmp("Li", n
->head
->child
->string
))
2040 PAIR_CLASS_INIT(&tag
[0], "lit");
2043 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2044 switch (n
->args
->argv
[i
].arg
) {
2045 case (MDOC_Symbolic
):
2046 PAIR_CLASS_INIT(&tag
[0], "symb");
2048 case (MDOC_Literal
):
2049 PAIR_CLASS_INIT(&tag
[0], "lit");
2051 case (MDOC_Emphasis
):
2052 PAIR_CLASS_INIT(&tag
[0], "emph");
2059 /* FIXME: div's have spaces stripped--we want them. */
2061 bufcat_style(h
, "display", "inline");
2062 SCALE_HS_INIT(&su
, 1);
2063 bufcat_su(h
, "margin-right", &su
);
2064 PAIR_STYLE_INIT(&tag
[1], h
);
2065 print_otag(h
, TAG_DIV
, 2, tag
);
2072 mdoc_ms_pre(MDOC_ARGS
)
2074 struct htmlpair tag
;
2076 PAIR_CLASS_INIT(&tag
, "symb");
2077 print_otag(h
, TAG_SPAN
, 1, &tag
);
2084 mdoc_pf_pre(MDOC_ARGS
)
2087 h
->flags
|= HTML_IGNDELIM
;
2094 mdoc_pf_post(MDOC_ARGS
)
2097 h
->flags
&= ~HTML_IGNDELIM
;
2098 h
->flags
|= HTML_NOSPACE
;
2104 mdoc_rs_pre(MDOC_ARGS
)
2106 struct htmlpair tag
;
2109 if (MDOC_BLOCK
!= n
->type
)
2112 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2113 SCALE_VS_INIT(&su
, 1);
2114 bufcat_su(h
, "margin-top", &su
);
2115 PAIR_STYLE_INIT(&tag
, h
);
2116 print_otag(h
, TAG_DIV
, 1, &tag
);
2119 PAIR_CLASS_INIT(&tag
, "ref");
2120 print_otag(h
, TAG_SPAN
, 1, &tag
);
2128 mdoc_li_pre(MDOC_ARGS
)
2130 struct htmlpair tag
;
2132 PAIR_CLASS_INIT(&tag
, "lit");
2133 print_otag(h
, TAG_SPAN
, 1, &tag
);
2140 mdoc_sy_pre(MDOC_ARGS
)
2142 struct htmlpair tag
;
2144 PAIR_CLASS_INIT(&tag
, "symb");
2145 print_otag(h
, TAG_SPAN
, 1, &tag
);
2152 mdoc_bt_pre(MDOC_ARGS
)
2155 print_text(h
, "is currently in beta test.");
2162 mdoc_ud_pre(MDOC_ARGS
)
2165 print_text(h
, "currently under development.");
2172 mdoc_lb_pre(MDOC_ARGS
)
2174 struct htmlpair tag
;
2176 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2177 print_otag(h
, TAG_DIV
, 0, NULL
);
2178 PAIR_CLASS_INIT(&tag
, "lib");
2179 print_otag(h
, TAG_SPAN
, 1, &tag
);
2186 mdoc__x_pre(MDOC_ARGS
)
2188 struct htmlpair tag
[2];
2192 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2195 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2198 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2201 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2204 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2207 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2210 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2213 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2216 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2219 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2222 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2225 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2228 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2231 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2238 if (MDOC__U
!= n
->tok
) {
2239 print_otag(h
, TAG_SPAN
, 1, tag
);
2243 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2244 print_otag(h
, TAG_A
, 2, tag
);
2251 mdoc__x_post(MDOC_ARGS
)
2256 h
->flags
|= HTML_NOSPACE
;
2257 print_text(h
, n
->next
? "," : ".");