]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.32 2009/10/18 19:03:37 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.
17 #include <sys/types.h>
18 #include <sys/param.h>
19 #include <sys/queue.h>
37 #define MDOC_ARGS const struct mdoc_meta *m, \
38 const struct mdoc_node *n, \
42 int (*pre
)(MDOC_ARGS
);
43 void (*post
)(MDOC_ARGS
);
46 static void print_mdoc(MDOC_ARGS
);
47 static void print_mdoc_head(MDOC_ARGS
);
48 static void print_mdoc_node(MDOC_ARGS
);
49 static void print_mdoc_nodelist(MDOC_ARGS
);
51 static void a2width(const char *, struct roffsu
*);
52 static void a2offs(const char *, struct roffsu
*);
54 static int a2list(const struct mdoc_node
*);
56 static void mdoc_root_post(MDOC_ARGS
);
57 static int mdoc_root_pre(MDOC_ARGS
);
59 static void mdoc__x_post(MDOC_ARGS
);
60 static int mdoc__x_pre(MDOC_ARGS
);
61 static int mdoc_ad_pre(MDOC_ARGS
);
62 static int mdoc_an_pre(MDOC_ARGS
);
63 static int mdoc_ap_pre(MDOC_ARGS
);
64 static void mdoc_aq_post(MDOC_ARGS
);
65 static int mdoc_aq_pre(MDOC_ARGS
);
66 static int mdoc_ar_pre(MDOC_ARGS
);
67 static int mdoc_bd_pre(MDOC_ARGS
);
68 static int mdoc_bf_pre(MDOC_ARGS
);
69 static void mdoc_bl_post(MDOC_ARGS
);
70 static int mdoc_bl_pre(MDOC_ARGS
);
71 static void mdoc_bq_post(MDOC_ARGS
);
72 static int mdoc_bq_pre(MDOC_ARGS
);
73 static void mdoc_brq_post(MDOC_ARGS
);
74 static int mdoc_brq_pre(MDOC_ARGS
);
75 static int mdoc_bt_pre(MDOC_ARGS
);
76 static int mdoc_bx_pre(MDOC_ARGS
);
77 static int mdoc_cd_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static void mdoc_dq_post(MDOC_ARGS
);
80 static int mdoc_dq_pre(MDOC_ARGS
);
81 static int mdoc_dv_pre(MDOC_ARGS
);
82 static int mdoc_fa_pre(MDOC_ARGS
);
83 static int mdoc_fd_pre(MDOC_ARGS
);
84 static int mdoc_fl_pre(MDOC_ARGS
);
85 static int mdoc_fn_pre(MDOC_ARGS
);
86 static int mdoc_ft_pre(MDOC_ARGS
);
87 static int mdoc_em_pre(MDOC_ARGS
);
88 static int mdoc_er_pre(MDOC_ARGS
);
89 static int mdoc_ev_pre(MDOC_ARGS
);
90 static int mdoc_ex_pre(MDOC_ARGS
);
91 static void mdoc_fo_post(MDOC_ARGS
);
92 static int mdoc_fo_pre(MDOC_ARGS
);
93 static int mdoc_ic_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_block_pre(MDOC_ARGS
, int, int,
96 struct roffsu
*, struct roffsu
*);
97 static int mdoc_it_head_pre(MDOC_ARGS
, int,
99 static int mdoc_it_body_pre(MDOC_ARGS
, int);
100 static int mdoc_it_pre(MDOC_ARGS
);
101 static int mdoc_lb_pre(MDOC_ARGS
);
102 static int mdoc_li_pre(MDOC_ARGS
);
103 static int mdoc_lk_pre(MDOC_ARGS
);
104 static int mdoc_mt_pre(MDOC_ARGS
);
105 static int mdoc_ms_pre(MDOC_ARGS
);
106 static int mdoc_nd_pre(MDOC_ARGS
);
107 static int mdoc_nm_pre(MDOC_ARGS
);
108 static int mdoc_ns_pre(MDOC_ARGS
);
109 static void mdoc_op_post(MDOC_ARGS
);
110 static int mdoc_op_pre(MDOC_ARGS
);
111 static int mdoc_pa_pre(MDOC_ARGS
);
112 static void mdoc_pf_post(MDOC_ARGS
);
113 static int mdoc_pf_pre(MDOC_ARGS
);
114 static void mdoc_pq_post(MDOC_ARGS
);
115 static int mdoc_pq_pre(MDOC_ARGS
);
116 static int mdoc_rs_pre(MDOC_ARGS
);
117 static int mdoc_rv_pre(MDOC_ARGS
);
118 static int mdoc_sh_pre(MDOC_ARGS
);
119 static int mdoc_sp_pre(MDOC_ARGS
);
120 static void mdoc_sq_post(MDOC_ARGS
);
121 static int mdoc_sq_pre(MDOC_ARGS
);
122 static int mdoc_ss_pre(MDOC_ARGS
);
123 static int mdoc_sx_pre(MDOC_ARGS
);
124 static int mdoc_sy_pre(MDOC_ARGS
);
125 static int mdoc_ud_pre(MDOC_ARGS
);
126 static int mdoc_va_pre(MDOC_ARGS
);
127 static int mdoc_vt_pre(MDOC_ARGS
);
128 static int mdoc_xr_pre(MDOC_ARGS
);
129 static int mdoc_xx_pre(MDOC_ARGS
);
132 extern size_t strlcpy(char *, const char *, size_t);
133 extern size_t strlcat(char *, const char *, size_t);
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 */
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 */
261 html_mdoc(void *arg
, const struct mdoc
*m
)
266 h
= (struct html
*)arg
;
268 print_gen_doctype(h
);
269 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
270 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
278 * Return the list type for `Bl', e.g., `Bl -column' returns
279 * MDOC_Column. This can ONLY be run for lists; it will abort() if no
280 * list type is found.
283 a2list(const struct mdoc_node
*n
)
288 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
289 switch (n
->args
->argv
[i
].arg
) {
311 return(n
->args
->argv
[i
].arg
);
322 * Calculate the scaling unit passed in a `-width' argument. This uses
323 * either a native scaling unit (e.g., 1i, 2m) or the string length of
327 a2width(const char *p
, struct roffsu
*su
)
330 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
332 su
->scale
= (int)strlen(p
);
338 * Calculate the scaling unit passed in an `-offset' argument. This
339 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
340 * predefined strings (indent, etc.), or the string length of the value.
343 a2offs(const char *p
, struct roffsu
*su
)
346 /* FIXME: "right"? */
348 if (0 == strcmp(p
, "left"))
349 SCALE_HS_INIT(su
, 0);
350 else if (0 == strcmp(p
, "indent"))
351 SCALE_HS_INIT(su
, INDENT
);
352 else if (0 == strcmp(p
, "indent-two"))
353 SCALE_HS_INIT(su
, INDENT
* 2);
354 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
356 su
->scale
= (int)strlen(p
);
362 print_mdoc(MDOC_ARGS
)
367 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
368 print_mdoc_head(m
, n
, h
);
371 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
373 tag
.key
= ATTR_CLASS
;
375 print_otag(h
, TAG_DIV
, 1, &tag
);
377 print_mdoc_nodelist(m
, n
, h
);
384 print_mdoc_head(MDOC_ARGS
)
389 buffmt(h
, "%s(%d)", m
->title
, m
->msec
);
397 print_otag(h
, TAG_TITLE
, 0, NULL
);
398 print_text(h
, h
->buf
);
403 print_mdoc_nodelist(MDOC_ARGS
)
406 print_mdoc_node(m
, n
, h
);
408 print_mdoc_nodelist(m
, n
->next
, h
);
413 print_mdoc_node(MDOC_ARGS
)
419 t
= SLIST_FIRST(&h
->tags
);
424 child
= mdoc_root_pre(m
, n
, h
);
427 print_text(h
, n
->string
);
430 if (mdocs
[n
->tok
].pre
)
431 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
435 if (child
&& n
->child
)
436 print_mdoc_nodelist(m
, n
->child
, h
);
443 mdoc_root_post(m
, n
, h
);
448 if (mdocs
[n
->tok
].post
)
449 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
457 mdoc_root_post(MDOC_ARGS
)
460 struct htmlpair tag
[2];
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 (void)localtime_r(&m
->date
, &tm
);
472 if (0 == strftime(b
, BUFSIZ
- 1, "%B %e, %Y", &tm
))
473 err(EXIT_FAILURE
, "strftime");
475 PAIR_CLASS_INIT(&tag
[0], "footer");
476 bufcat_style(h
, "width", "100%");
477 PAIR_STYLE_INIT(&tag
[1], h
);
478 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
479 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
482 bufcat_style(h
, "width", "50%");
483 PAIR_STYLE_INIT(&tag
[0], h
);
484 print_otag(h
, TAG_TD
, 1, tag
);
489 bufcat_style(h
, "width", "50%");
490 bufcat_style(h
, "text-align", "right");
491 PAIR_STYLE_INIT(&tag
[0], h
);
492 print_otag(h
, TAG_TD
, 1, tag
);
493 print_text(h
, m
->os
);
500 mdoc_root_pre(MDOC_ARGS
)
502 struct htmlpair tag
[2];
504 char b
[BUFSIZ
], title
[BUFSIZ
];
506 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
509 (void)strlcat(b
, " (", BUFSIZ
);
510 (void)strlcat(b
, m
->arch
, BUFSIZ
);
511 (void)strlcat(b
, ")", BUFSIZ
);
514 (void)snprintf(title
, BUFSIZ
- 1,
515 "%s(%d)", m
->title
, m
->msec
);
517 /* XXX: see note in mdoc_root_post() about divs. */
519 PAIR_CLASS_INIT(&tag
[0], "header");
520 bufcat_style(h
, "width", "100%");
521 PAIR_STYLE_INIT(&tag
[1], h
);
522 t
= print_otag(h
, TAG_TABLE
, 2, 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 (void)strlcat(lbuf
, nn
->string
, BUFSIZ
);
589 (void)strlcat(lbuf
, "_", BUFSIZ
);
593 * TODO: make sure there are no duplicates, as HTML does not
594 * allow for multiple `id' tags of the same name.
597 PAIR_CLASS_INIT(&tag
[0], "sec-head");
598 tag
[1].key
= ATTR_ID
;
600 print_otag(h
, TAG_DIV
, 2, tag
);
607 mdoc_ss_pre(MDOC_ARGS
)
609 struct htmlpair tag
[3];
610 const struct mdoc_node
*nn
;
614 SCALE_VS_INIT(&su
, 1);
616 if (MDOC_BODY
== n
->type
) {
617 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
618 if (n
->parent
->next
&& n
->child
) {
619 bufcat_su(h
, "margin-bottom", &su
);
620 PAIR_STYLE_INIT(&tag
[1], h
);
621 print_otag(h
, TAG_DIV
, 2, tag
);
623 print_otag(h
, TAG_DIV
, 1, tag
);
625 } else if (MDOC_BLOCK
== n
->type
) {
626 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
628 bufcat_su(h
, "margin-top", &su
);
629 PAIR_STYLE_INIT(&tag
[1], h
);
630 print_otag(h
, TAG_DIV
, 2, tag
);
632 print_otag(h
, TAG_DIV
, 1, tag
);
636 /* TODO: see note in mdoc_sh_pre() about duplicates. */
639 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
640 (void)strlcat(lbuf
, nn
->string
, BUFSIZ
);
642 (void)strlcat(lbuf
, "_", BUFSIZ
);
645 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
646 su
.scale
= -su
.scale
;
647 bufcat_su(h
, "margin-left", &su
);
649 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
650 PAIR_STYLE_INIT(&tag
[1], h
);
651 tag
[2].key
= ATTR_ID
;
653 print_otag(h
, TAG_DIV
, 3, tag
);
660 mdoc_fl_pre(MDOC_ARGS
)
664 PAIR_CLASS_INIT(&tag
, "flag");
665 print_otag(h
, TAG_SPAN
, 1, &tag
);
666 if (MDOC_Fl
== n
->tok
) {
667 print_text(h
, "\\-");
668 h
->flags
|= HTML_NOSPACE
;
676 mdoc_nd_pre(MDOC_ARGS
)
680 if (MDOC_BODY
!= n
->type
)
683 /* XXX: this tag in theory can contain block elements. */
685 print_text(h
, "\\(em");
686 PAIR_CLASS_INIT(&tag
, "desc-body");
687 print_otag(h
, TAG_SPAN
, 1, &tag
);
694 mdoc_op_pre(MDOC_ARGS
)
698 if (MDOC_BODY
!= n
->type
)
701 /* XXX: this tag in theory can contain block elements. */
703 print_text(h
, "\\(lB");
704 h
->flags
|= HTML_NOSPACE
;
705 PAIR_CLASS_INIT(&tag
, "opt");
706 print_otag(h
, TAG_SPAN
, 1, &tag
);
713 mdoc_op_post(MDOC_ARGS
)
716 if (MDOC_BODY
!= n
->type
)
718 h
->flags
|= HTML_NOSPACE
;
719 print_text(h
, "\\(rB");
724 mdoc_nm_pre(MDOC_ARGS
)
728 if ( ! (HTML_NEWLINE
& h
->flags
))
729 if (SEC_SYNOPSIS
== n
->sec
) {
730 bufcat_style(h
, "clear", "both");
731 PAIR_STYLE_INIT(&tag
, h
);
732 print_otag(h
, TAG_BR
, 1, &tag
);
735 PAIR_CLASS_INIT(&tag
, "name");
736 print_otag(h
, TAG_SPAN
, 1, &tag
);
737 if (NULL
== n
->child
)
738 print_text(h
, m
->name
);
746 mdoc_xr_pre(MDOC_ARGS
)
748 struct htmlpair tag
[2];
749 const struct mdoc_node
*nn
;
751 PAIR_CLASS_INIT(&tag
[0], "link-man");
754 buffmt_man(h
, n
->child
->string
,
756 n
->child
->next
->string
: NULL
);
757 tag
[1].key
= ATTR_HREF
;
759 print_otag(h
, TAG_A
, 2, tag
);
761 print_otag(h
, TAG_A
, 1, tag
);
764 print_text(h
, nn
->string
);
766 if (NULL
== (nn
= nn
->next
))
769 h
->flags
|= HTML_NOSPACE
;
771 h
->flags
|= HTML_NOSPACE
;
772 print_text(h
, nn
->string
);
773 h
->flags
|= HTML_NOSPACE
;
781 mdoc_ns_pre(MDOC_ARGS
)
784 h
->flags
|= HTML_NOSPACE
;
791 mdoc_ar_pre(MDOC_ARGS
)
795 PAIR_CLASS_INIT(&tag
, "arg");
796 print_otag(h
, TAG_SPAN
, 1, &tag
);
803 mdoc_xx_pre(MDOC_ARGS
)
831 PAIR_CLASS_INIT(&tag
, "unix");
832 print_otag(h
, TAG_SPAN
, 1, &tag
);
840 mdoc_bx_pre(MDOC_ARGS
)
842 const struct mdoc_node
*nn
;
845 PAIR_CLASS_INIT(&tag
, "unix");
846 print_otag(h
, TAG_SPAN
, 1, &tag
);
848 for (nn
= n
->child
; nn
; nn
= nn
->next
)
849 print_mdoc_node(m
, nn
, h
);
852 h
->flags
|= HTML_NOSPACE
;
854 print_text(h
, "BSD");
861 mdoc_it_block_pre(MDOC_ARGS
, int type
, int comp
,
862 struct roffsu
*offs
, struct roffsu
*width
)
865 const struct mdoc_node
*nn
;
868 nn
= n
->parent
->parent
;
871 /* XXX: see notes in mdoc_it_pre(). */
873 if (MDOC_Column
== type
) {
874 /* Don't width-pad on the left. */
875 SCALE_HS_INIT(width
, 0);
876 /* Also disallow non-compact. */
879 if (MDOC_Diag
== type
)
880 /* Mandate non-compact with empty prior. */
881 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
884 bufcat_style(h
, "clear", "both");
886 bufcat_su(h
, "margin-left", offs
);
887 if (width
->scale
> 0)
888 bufcat_su(h
, "padding-left", width
);
890 PAIR_STYLE_INIT(&tag
, h
);
892 /* Mandate compact following `Ss' and `Sh' starts. */
894 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
895 if (MDOC_BLOCK
!= nn
->type
)
897 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
904 SCALE_VS_INIT(&su
, 1);
905 bufcat_su(h
, "padding-top", &su
);
908 PAIR_STYLE_INIT(&tag
, h
);
909 print_otag(h
, TAG_DIV
, 1, &tag
);
916 mdoc_it_body_pre(MDOC_ARGS
, int type
)
930 * XXX: this tricks CSS into aligning the bodies with
931 * the right-padding in the head.
933 SCALE_HS_INIT(&su
, 2);
934 bufcat_su(h
, "margin-left", &su
);
935 PAIR_STYLE_INIT(&tag
, h
);
936 print_otag(h
, TAG_DIV
, 1, &tag
);
946 mdoc_it_head_pre(MDOC_ARGS
, int type
, struct roffsu
*width
)
956 print_otag(h
, TAG_DIV
, 0, NULL
);
959 bufcat_su(h
, "min-width", width
);
960 bufcat_style(h
, "clear", "none");
961 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
962 bufcat_style(h
, "float", "left");
963 PAIR_STYLE_INIT(&tag
, h
);
964 print_otag(h
, TAG_DIV
, 1, &tag
);
967 bufcat_su(h
, "min-width", width
);
969 bufcat_su(h
, "margin-left", width
);
970 if (n
->next
&& n
->next
->child
)
971 bufcat_style(h
, "float", "left");
973 /* XXX: buffer if we run into body. */
974 SCALE_HS_INIT(width
, 1);
975 bufcat_su(h
, "margin-right", width
);
976 PAIR_STYLE_INIT(&tag
, h
);
977 print_otag(h
, TAG_DIV
, 1, &tag
);
983 PAIR_CLASS_INIT(&tag
, "diag");
984 print_otag(h
, TAG_SPAN
, 1, &tag
);
987 ord
= SLIST_FIRST(&h
->ords
);
989 nbuf
[BUFSIZ
- 1] = 0;
990 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
994 print_text(h
, "\\(en");
997 print_text(h
, "\\(hy");
1000 print_text(h
, "\\(bu");
1011 mdoc_it_pre(MDOC_ARGS
)
1013 int i
, type
, wp
, comp
;
1014 const struct mdoc_node
*bl
, *nn
;
1015 struct roffsu width
, offs
;
1018 * XXX: be very careful in changing anything, here. Lists in
1019 * mandoc have many peculiarities; furthermore, they don't
1020 * translate well into HTML and require a bit of mangling.
1023 bl
= n
->parent
->parent
;
1024 if (MDOC_BLOCK
!= n
->type
)
1029 /* Set default width and offset. */
1031 SCALE_HS_INIT(&offs
, 0);
1041 SCALE_HS_INIT(&width
, 2);
1044 SCALE_HS_INIT(&width
, INDENT
);
1048 /* Get width, offset, and compact arguments. */
1050 for (wp
= -1, comp
= i
= 0; i
< (int)bl
->args
->argc
; i
++)
1051 switch (bl
->args
->argv
[i
].arg
) {
1053 wp
= i
; /* Save for later. */
1056 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1059 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1061 case (MDOC_Compact
):
1068 /* Override width in some cases. */
1074 SCALE_HS_INIT(&width
, 0);
1077 if (0 == width
.scale
)
1078 SCALE_HS_INIT(&width
, INDENT
);
1082 /* Flip to body/block processing. */
1084 if (MDOC_BODY
== n
->type
)
1085 return(mdoc_it_body_pre(m
, n
, h
, type
));
1086 if (MDOC_BLOCK
== n
->type
)
1087 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1090 /* Override column widths. */
1092 if (MDOC_Column
== type
) {
1093 nn
= n
->parent
->child
;
1094 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1096 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1097 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1100 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1106 mdoc_bl_pre(MDOC_ARGS
)
1110 if (MDOC_BLOCK
!= n
->type
)
1112 if (MDOC_Enum
!= a2list(n
))
1115 ord
= malloc(sizeof(struct ord
));
1117 err(EXIT_FAILURE
, "malloc");
1120 SLIST_INSERT_HEAD(&h
->ords
, ord
, entry
);
1127 mdoc_bl_post(MDOC_ARGS
)
1131 if (MDOC_BLOCK
!= n
->type
)
1133 if (MDOC_Enum
!= a2list(n
))
1136 ord
= SLIST_FIRST(&h
->ords
);
1138 SLIST_REMOVE_HEAD(&h
->ords
, entry
);
1145 mdoc_ex_pre(MDOC_ARGS
)
1147 const struct mdoc_node
*nn
;
1149 struct htmlpair tag
;
1151 PAIR_CLASS_INIT(&tag
, "utility");
1153 print_text(h
, "The");
1154 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1155 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1156 print_text(h
, nn
->string
);
1159 h
->flags
|= HTML_NOSPACE
;
1161 if (nn
->next
&& NULL
== nn
->next
->next
)
1162 print_text(h
, ", and");
1166 h
->flags
&= ~HTML_NOSPACE
;
1170 print_text(h
, "utilities exit");
1172 print_text(h
, "utility exits");
1174 print_text(h
, "0 on success, and >0 if an error occurs.");
1181 mdoc_dq_pre(MDOC_ARGS
)
1184 if (MDOC_BODY
!= n
->type
)
1186 print_text(h
, "\\(lq");
1187 h
->flags
|= HTML_NOSPACE
;
1194 mdoc_dq_post(MDOC_ARGS
)
1197 if (MDOC_BODY
!= n
->type
)
1199 h
->flags
|= HTML_NOSPACE
;
1200 print_text(h
, "\\(rq");
1206 mdoc_pq_pre(MDOC_ARGS
)
1209 if (MDOC_BODY
!= n
->type
)
1211 print_text(h
, "\\&(");
1212 h
->flags
|= HTML_NOSPACE
;
1219 mdoc_pq_post(MDOC_ARGS
)
1222 if (MDOC_BODY
!= n
->type
)
1230 mdoc_sq_pre(MDOC_ARGS
)
1233 if (MDOC_BODY
!= n
->type
)
1235 print_text(h
, "\\(oq");
1236 h
->flags
|= HTML_NOSPACE
;
1243 mdoc_sq_post(MDOC_ARGS
)
1246 if (MDOC_BODY
!= n
->type
)
1248 h
->flags
|= HTML_NOSPACE
;
1249 print_text(h
, "\\(aq");
1255 mdoc_em_pre(MDOC_ARGS
)
1257 struct htmlpair tag
;
1259 PAIR_CLASS_INIT(&tag
, "emph");
1260 print_otag(h
, TAG_SPAN
, 1, &tag
);
1267 mdoc_d1_pre(MDOC_ARGS
)
1269 struct htmlpair tag
[2];
1272 if (MDOC_BLOCK
!= n
->type
)
1275 SCALE_VS_INIT(&su
, INDENT
- 2);
1276 bufcat_su(h
, "margin-left", &su
);
1277 PAIR_CLASS_INIT(&tag
[0], "lit");
1278 PAIR_STYLE_INIT(&tag
[1], h
);
1279 print_otag(h
, TAG_DIV
, 2, tag
);
1286 mdoc_sx_pre(MDOC_ARGS
)
1288 struct htmlpair tag
[2];
1289 const struct mdoc_node
*nn
;
1292 /* FIXME: duplicates? */
1294 (void)strlcpy(lbuf
, "#", BUFSIZ
);
1295 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1296 (void)strlcat(lbuf
, nn
->string
, BUFSIZ
);
1298 (void)strlcat(lbuf
, "_", BUFSIZ
);
1301 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1302 tag
[1].key
= ATTR_HREF
;
1305 print_otag(h
, TAG_A
, 2, tag
);
1312 mdoc_aq_pre(MDOC_ARGS
)
1315 if (MDOC_BODY
!= n
->type
)
1317 print_text(h
, "\\(la");
1318 h
->flags
|= HTML_NOSPACE
;
1325 mdoc_aq_post(MDOC_ARGS
)
1328 if (MDOC_BODY
!= n
->type
)
1330 h
->flags
|= HTML_NOSPACE
;
1331 print_text(h
, "\\(ra");
1337 mdoc_bd_pre(MDOC_ARGS
)
1339 struct htmlpair tag
[2];
1341 const struct mdoc_node
*bl
, *nn
;
1344 if (MDOC_BLOCK
== n
->type
)
1346 else if (MDOC_HEAD
== n
->type
)
1351 SCALE_VS_INIT(&su
, 0);
1354 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1355 switch (bl
->args
->argv
[i
].arg
) {
1357 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1359 case (MDOC_Compact
):
1362 case (MDOC_Centred
):
1368 case (MDOC_Unfilled
):
1370 case (MDOC_Literal
):
1371 type
= bl
->args
->argv
[i
].arg
;
1377 /* FIXME: -centered, etc. formatting. */
1379 if (MDOC_BLOCK
== n
->type
) {
1380 bufcat_su(h
, "margin-left", &su
);
1381 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1382 if (MDOC_BLOCK
!= nn
->type
)
1384 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1390 print_otag(h
, TAG_DIV
, 0, tag
);
1393 SCALE_VS_INIT(&su
, 1);
1394 bufcat_su(h
, "margin-top", &su
);
1395 PAIR_STYLE_INIT(&tag
[0], h
);
1396 print_otag(h
, TAG_DIV
, 1, tag
);
1400 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1403 PAIR_CLASS_INIT(&tag
[0], "lit");
1404 bufcat_style(h
, "white-space", "pre");
1405 PAIR_STYLE_INIT(&tag
[1], h
);
1406 print_otag(h
, TAG_DIV
, 2, tag
);
1408 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1409 h
->flags
|= HTML_NOSPACE
;
1410 print_mdoc_node(m
, nn
, h
);
1411 if (NULL
== nn
->next
)
1413 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1414 print_text(h
, "\n");
1415 else if (NULL
== nn
->prev
)
1416 print_text(h
, "\n");
1425 mdoc_pa_pre(MDOC_ARGS
)
1427 struct htmlpair tag
;
1429 PAIR_CLASS_INIT(&tag
, "file");
1430 print_otag(h
, TAG_SPAN
, 1, &tag
);
1437 mdoc_ad_pre(MDOC_ARGS
)
1439 struct htmlpair tag
;
1441 PAIR_CLASS_INIT(&tag
, "addr");
1442 print_otag(h
, TAG_SPAN
, 1, &tag
);
1449 mdoc_an_pre(MDOC_ARGS
)
1451 struct htmlpair tag
;
1453 /* TODO: -split and -nosplit (see termp_an_pre()). */
1455 PAIR_CLASS_INIT(&tag
, "author");
1456 print_otag(h
, TAG_SPAN
, 1, &tag
);
1463 mdoc_cd_pre(MDOC_ARGS
)
1465 struct htmlpair tag
;
1467 print_otag(h
, TAG_DIV
, 0, NULL
);
1468 PAIR_CLASS_INIT(&tag
, "config");
1469 print_otag(h
, TAG_SPAN
, 1, &tag
);
1476 mdoc_dv_pre(MDOC_ARGS
)
1478 struct htmlpair tag
;
1480 PAIR_CLASS_INIT(&tag
, "define");
1481 print_otag(h
, TAG_SPAN
, 1, &tag
);
1488 mdoc_ev_pre(MDOC_ARGS
)
1490 struct htmlpair tag
;
1492 PAIR_CLASS_INIT(&tag
, "env");
1493 print_otag(h
, TAG_SPAN
, 1, &tag
);
1500 mdoc_er_pre(MDOC_ARGS
)
1502 struct htmlpair tag
;
1504 PAIR_CLASS_INIT(&tag
, "errno");
1505 print_otag(h
, TAG_SPAN
, 1, &tag
);
1512 mdoc_fa_pre(MDOC_ARGS
)
1514 const struct mdoc_node
*nn
;
1515 struct htmlpair tag
;
1518 PAIR_CLASS_INIT(&tag
, "farg");
1519 if (n
->parent
->tok
!= MDOC_Fo
) {
1520 print_otag(h
, TAG_SPAN
, 1, &tag
);
1524 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1525 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1526 print_text(h
, nn
->string
);
1532 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1541 mdoc_fd_pre(MDOC_ARGS
)
1543 struct htmlpair tag
;
1546 if (SEC_SYNOPSIS
== n
->sec
) {
1547 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1548 SCALE_VS_INIT(&su
, 1);
1549 bufcat_su(h
, "margin-bottom", &su
);
1550 PAIR_STYLE_INIT(&tag
, h
);
1551 print_otag(h
, TAG_DIV
, 1, &tag
);
1553 print_otag(h
, TAG_DIV
, 0, NULL
);
1556 PAIR_CLASS_INIT(&tag
, "macro");
1557 print_otag(h
, TAG_SPAN
, 1, &tag
);
1564 mdoc_vt_pre(MDOC_ARGS
)
1566 struct htmlpair tag
;
1569 if (SEC_SYNOPSIS
== n
->sec
) {
1570 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1571 SCALE_VS_INIT(&su
, 1);
1572 bufcat_su(h
, "margin-bottom", &su
);
1573 PAIR_STYLE_INIT(&tag
, h
);
1574 print_otag(h
, TAG_DIV
, 1, &tag
);
1576 print_otag(h
, TAG_DIV
, 0, NULL
);
1579 PAIR_CLASS_INIT(&tag
, "type");
1580 print_otag(h
, TAG_SPAN
, 1, &tag
);
1587 mdoc_ft_pre(MDOC_ARGS
)
1589 struct htmlpair tag
;
1592 if (SEC_SYNOPSIS
== n
->sec
) {
1593 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1594 SCALE_VS_INIT(&su
, 1);
1595 bufcat_su(h
, "margin-top", &su
);
1596 PAIR_STYLE_INIT(&tag
, h
);
1597 print_otag(h
, TAG_DIV
, 1, &tag
);
1599 print_otag(h
, TAG_DIV
, 0, NULL
);
1602 PAIR_CLASS_INIT(&tag
, "ftype");
1603 print_otag(h
, TAG_SPAN
, 1, &tag
);
1610 mdoc_fn_pre(MDOC_ARGS
)
1613 struct htmlpair tag
[2];
1614 const struct mdoc_node
*nn
;
1616 const char *sp
, *ep
;
1620 if (SEC_SYNOPSIS
== n
->sec
) {
1621 SCALE_HS_INIT(&su
, INDENT
);
1622 bufcat_su(h
, "margin-left", &su
);
1623 su
.scale
= -su
.scale
;
1624 bufcat_su(h
, "text-indent", &su
);
1626 SCALE_VS_INIT(&su
, 1);
1627 bufcat_su(h
, "margin-bottom", &su
);
1629 PAIR_STYLE_INIT(&tag
[0], h
);
1630 print_otag(h
, TAG_DIV
, 1, tag
);
1633 /* Split apart into type and name. */
1634 assert(n
->child
->string
);
1635 sp
= n
->child
->string
;
1637 ep
= strchr(sp
, ' ');
1639 PAIR_CLASS_INIT(&tag
[0], "ftype");
1640 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1643 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1644 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1646 print_text(h
, nbuf
);
1648 ep
= strchr(sp
, ' ');
1653 PAIR_CLASS_INIT(&tag
[0], "fname");
1654 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1657 (void)strlcpy(nbuf
, sp
, BUFSIZ
);
1658 print_text(h
, nbuf
);
1663 h
->flags
|= HTML_NOSPACE
;
1667 PAIR_CLASS_INIT(&tag
[0], "farg");
1668 bufcat_style(h
, "white-space", "nowrap");
1669 PAIR_STYLE_INIT(&tag
[1], h
);
1671 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1673 if (SEC_SYNOPSIS
== n
->sec
)
1675 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1676 print_text(h
, nn
->string
);
1683 if (SEC_SYNOPSIS
== n
->sec
)
1692 mdoc_sp_pre(MDOC_ARGS
)
1695 struct htmlpair tag
;
1700 /* FIXME: can this have a scaling indicator? */
1701 len
= n
->child
? atoi(n
->child
->string
) : 1;
1711 SCALE_VS_INIT(&su
, len
);
1712 bufcat_su(h
, "height", &su
);
1713 PAIR_STYLE_INIT(&tag
, h
);
1714 print_otag(h
, TAG_DIV
, 1, &tag
);
1722 mdoc_brq_pre(MDOC_ARGS
)
1725 if (MDOC_BODY
!= n
->type
)
1727 print_text(h
, "\\(lC");
1728 h
->flags
|= HTML_NOSPACE
;
1735 mdoc_brq_post(MDOC_ARGS
)
1738 if (MDOC_BODY
!= n
->type
)
1740 h
->flags
|= HTML_NOSPACE
;
1741 print_text(h
, "\\(rC");
1747 mdoc_lk_pre(MDOC_ARGS
)
1749 const struct mdoc_node
*nn
;
1750 struct htmlpair tag
[2];
1754 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1755 tag
[1].key
= ATTR_HREF
;
1756 tag
[1].val
= nn
->string
;
1757 print_otag(h
, TAG_A
, 2, tag
);
1759 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1760 print_text(h
, nn
->string
);
1768 mdoc_mt_pre(MDOC_ARGS
)
1770 struct htmlpair tag
[2];
1772 const struct mdoc_node
*nn
;
1774 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1776 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1778 bufcat(h
, "mailto:");
1779 bufcat(h
, nn
->string
);
1780 PAIR_STYLE_INIT(&tag
[1], h
);
1781 t
= print_otag(h
, TAG_A
, 2, tag
);
1782 print_text(h
, nn
->string
);
1792 mdoc_fo_pre(MDOC_ARGS
)
1794 struct htmlpair tag
;
1796 if (MDOC_BODY
== n
->type
) {
1797 h
->flags
|= HTML_NOSPACE
;
1799 h
->flags
|= HTML_NOSPACE
;
1801 } else if (MDOC_BLOCK
== n
->type
)
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];
1833 if (SEC_SYNOPSIS
== n
->sec
) {
1834 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1835 SCALE_VS_INIT(&su
, 1);
1836 bufcat_su(h
, "margin-bottom", &su
);
1837 PAIR_STYLE_INIT(&tag
[0], h
);
1838 print_otag(h
, TAG_DIV
, 1, tag
);
1840 print_otag(h
, TAG_DIV
, 0, NULL
);
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");
1857 if (h
->base_includes
) {
1858 buffmt_includes(h
, nn
->string
);
1859 tag
[i
].key
= ATTR_HREF
;
1860 tag
[i
++].val
= h
->buf
;
1862 t
= print_otag(h
, TAG_A
, i
, tag
);
1863 print_mdoc_node(m
, nn
, h
);
1867 h
->flags
|= HTML_NOSPACE
;
1876 mdoc_ic_pre(MDOC_ARGS
)
1878 struct htmlpair tag
;
1880 PAIR_CLASS_INIT(&tag
, "cmd");
1881 print_otag(h
, TAG_SPAN
, 1, &tag
);
1888 mdoc_rv_pre(MDOC_ARGS
)
1890 const struct mdoc_node
*nn
;
1891 struct htmlpair tag
;
1894 print_otag(h
, TAG_DIV
, 0, NULL
);
1895 print_text(h
, "The");
1897 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1898 PAIR_CLASS_INIT(&tag
, "fname");
1899 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1900 print_text(h
, nn
->string
);
1903 h
->flags
|= HTML_NOSPACE
;
1904 if (nn
->next
&& NULL
== nn
->next
->next
)
1905 print_text(h
, "(), and");
1907 print_text(h
, "(),");
1909 print_text(h
, "()");
1913 print_text(h
, "functions return");
1915 print_text(h
, "function returns");
1917 print_text(h
, "the value 0 if successful; otherwise the value "
1918 "-1 is returned and the global variable");
1920 PAIR_CLASS_INIT(&tag
, "var");
1921 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1922 print_text(h
, "errno");
1924 print_text(h
, "is set to indicate the error.");
1931 mdoc_va_pre(MDOC_ARGS
)
1933 struct htmlpair tag
;
1935 PAIR_CLASS_INIT(&tag
, "var");
1936 print_otag(h
, TAG_SPAN
, 1, &tag
);
1943 mdoc_bq_pre(MDOC_ARGS
)
1946 if (MDOC_BODY
!= n
->type
)
1948 print_text(h
, "\\(lB");
1949 h
->flags
|= HTML_NOSPACE
;
1956 mdoc_bq_post(MDOC_ARGS
)
1959 if (MDOC_BODY
!= n
->type
)
1961 h
->flags
|= HTML_NOSPACE
;
1962 print_text(h
, "\\(rB");
1968 mdoc_ap_pre(MDOC_ARGS
)
1971 h
->flags
|= HTML_NOSPACE
;
1972 print_text(h
, "\\(aq");
1973 h
->flags
|= HTML_NOSPACE
;
1980 mdoc_bf_pre(MDOC_ARGS
)
1983 struct htmlpair tag
[2];
1986 if (MDOC_HEAD
== n
->type
)
1988 else if (MDOC_BLOCK
!= n
->type
)
1991 PAIR_CLASS_INIT(&tag
[0], "lit");
1993 if (n
->head
->child
) {
1994 if ( ! strcmp("Em", n
->head
->child
->string
))
1995 PAIR_CLASS_INIT(&tag
[0], "emph");
1996 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1997 PAIR_CLASS_INIT(&tag
[0], "symb");
1998 else if ( ! strcmp("Li", n
->head
->child
->string
))
1999 PAIR_CLASS_INIT(&tag
[0], "lit");
2002 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2003 switch (n
->args
->argv
[i
].arg
) {
2004 case (MDOC_Symbolic
):
2005 PAIR_CLASS_INIT(&tag
[0], "symb");
2007 case (MDOC_Literal
):
2008 PAIR_CLASS_INIT(&tag
[0], "lit");
2010 case (MDOC_Emphasis
):
2011 PAIR_CLASS_INIT(&tag
[0], "emph");
2018 /* FIXME: div's have spaces stripped--we want them. */
2020 bufcat_style(h
, "display", "inline");
2021 SCALE_HS_INIT(&su
, 1);
2022 bufcat_su(h
, "margin-right", &su
);
2023 PAIR_STYLE_INIT(&tag
[1], h
);
2024 print_otag(h
, TAG_DIV
, 2, tag
);
2031 mdoc_ms_pre(MDOC_ARGS
)
2033 struct htmlpair tag
;
2035 PAIR_CLASS_INIT(&tag
, "symb");
2036 print_otag(h
, TAG_SPAN
, 1, &tag
);
2043 mdoc_pf_pre(MDOC_ARGS
)
2046 h
->flags
|= HTML_IGNDELIM
;
2053 mdoc_pf_post(MDOC_ARGS
)
2056 h
->flags
&= ~HTML_IGNDELIM
;
2057 h
->flags
|= HTML_NOSPACE
;
2063 mdoc_rs_pre(MDOC_ARGS
)
2065 struct htmlpair tag
;
2068 if (MDOC_BLOCK
!= n
->type
)
2071 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2072 SCALE_VS_INIT(&su
, 1);
2073 bufcat_su(h
, "margin-top", &su
);
2074 PAIR_STYLE_INIT(&tag
, h
);
2075 print_otag(h
, TAG_DIV
, 1, &tag
);
2078 PAIR_CLASS_INIT(&tag
, "ref");
2079 print_otag(h
, TAG_SPAN
, 1, &tag
);
2087 mdoc_li_pre(MDOC_ARGS
)
2089 struct htmlpair tag
;
2091 PAIR_CLASS_INIT(&tag
, "lit");
2092 print_otag(h
, TAG_SPAN
, 1, &tag
);
2099 mdoc_sy_pre(MDOC_ARGS
)
2101 struct htmlpair tag
;
2103 PAIR_CLASS_INIT(&tag
, "symb");
2104 print_otag(h
, TAG_SPAN
, 1, &tag
);
2111 mdoc_bt_pre(MDOC_ARGS
)
2114 print_text(h
, "is currently in beta test.");
2121 mdoc_ud_pre(MDOC_ARGS
)
2124 print_text(h
, "currently under development.");
2131 mdoc_lb_pre(MDOC_ARGS
)
2133 struct htmlpair tag
;
2135 if (SEC_SYNOPSIS
== n
->sec
)
2136 print_otag(h
, TAG_DIV
, 0, NULL
);
2137 PAIR_CLASS_INIT(&tag
, "lib");
2138 print_otag(h
, TAG_SPAN
, 1, &tag
);
2145 mdoc__x_pre(MDOC_ARGS
)
2147 struct htmlpair tag
;
2151 PAIR_CLASS_INIT(&tag
, "ref-auth");
2154 PAIR_CLASS_INIT(&tag
, "ref-book");
2157 PAIR_CLASS_INIT(&tag
, "ref-city");
2160 PAIR_CLASS_INIT(&tag
, "ref-date");
2163 PAIR_CLASS_INIT(&tag
, "ref-issue");
2166 PAIR_CLASS_INIT(&tag
, "ref-jrnl");
2169 PAIR_CLASS_INIT(&tag
, "ref-num");
2172 PAIR_CLASS_INIT(&tag
, "ref-opt");
2175 PAIR_CLASS_INIT(&tag
, "ref-page");
2178 PAIR_CLASS_INIT(&tag
, "ref-corp");
2181 PAIR_CLASS_INIT(&tag
, "ref-rep");
2184 PAIR_CLASS_INIT(&tag
, "ref-title");
2185 print_text(h
, "\\(lq");
2186 h
->flags
|= HTML_NOSPACE
;
2189 PAIR_CLASS_INIT(&tag
, "ref-vol");
2196 print_otag(h
, TAG_SPAN
, 1, &tag
);
2203 mdoc__x_post(MDOC_ARGS
)
2206 h
->flags
|= HTML_NOSPACE
;
2209 print_text(h
, "\\(rq");
2210 h
->flags
|= HTML_NOSPACE
;
2215 print_text(h
, n
->next
? "," : ".");