]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.46 2009/10/31 08:34:12 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>
35 #define MDOC_ARGS const struct mdoc_meta *m, \
36 const struct mdoc_node *n, \
40 int (*pre
)(MDOC_ARGS
);
41 void (*post
)(MDOC_ARGS
);
44 static void print_mdoc(MDOC_ARGS
);
45 static void print_mdoc_head(MDOC_ARGS
);
46 static void print_mdoc_node(MDOC_ARGS
);
47 static void print_mdoc_nodelist(MDOC_ARGS
);
49 static void a2width(const char *, struct roffsu
*);
50 static void a2offs(const char *, struct roffsu
*);
52 static int a2list(const struct mdoc_node
*);
54 static void mdoc_root_post(MDOC_ARGS
);
55 static int mdoc_root_pre(MDOC_ARGS
);
57 static void mdoc__x_post(MDOC_ARGS
);
58 static int mdoc__x_pre(MDOC_ARGS
);
59 static int mdoc_ad_pre(MDOC_ARGS
);
60 static int mdoc_an_pre(MDOC_ARGS
);
61 static int mdoc_ap_pre(MDOC_ARGS
);
62 static void mdoc_aq_post(MDOC_ARGS
);
63 static int mdoc_aq_pre(MDOC_ARGS
);
64 static int mdoc_ar_pre(MDOC_ARGS
);
65 static int mdoc_bd_pre(MDOC_ARGS
);
66 static int mdoc_bf_pre(MDOC_ARGS
);
67 static void mdoc_bl_post(MDOC_ARGS
);
68 static int mdoc_bl_pre(MDOC_ARGS
);
69 static void mdoc_bq_post(MDOC_ARGS
);
70 static int mdoc_bq_pre(MDOC_ARGS
);
71 static void mdoc_brq_post(MDOC_ARGS
);
72 static int mdoc_brq_pre(MDOC_ARGS
);
73 static int mdoc_bt_pre(MDOC_ARGS
);
74 static int mdoc_bx_pre(MDOC_ARGS
);
75 static int mdoc_cd_pre(MDOC_ARGS
);
76 static int mdoc_d1_pre(MDOC_ARGS
);
77 static void mdoc_dq_post(MDOC_ARGS
);
78 static int mdoc_dq_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_pre(MDOC_ARGS
);
86 static int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_in_pre(MDOC_ARGS
);
93 static int mdoc_it_block_pre(MDOC_ARGS
, int, int,
94 struct roffsu
*, struct roffsu
*);
95 static int mdoc_it_head_pre(MDOC_ARGS
, int,
97 static int mdoc_it_body_pre(MDOC_ARGS
, int);
98 static int mdoc_it_pre(MDOC_ARGS
);
99 static int mdoc_lb_pre(MDOC_ARGS
);
100 static int mdoc_li_pre(MDOC_ARGS
);
101 static int mdoc_lk_pre(MDOC_ARGS
);
102 static int mdoc_mt_pre(MDOC_ARGS
);
103 static int mdoc_ms_pre(MDOC_ARGS
);
104 static int mdoc_nd_pre(MDOC_ARGS
);
105 static int mdoc_nm_pre(MDOC_ARGS
);
106 static int mdoc_ns_pre(MDOC_ARGS
);
107 static void mdoc_op_post(MDOC_ARGS
);
108 static int mdoc_op_pre(MDOC_ARGS
);
109 static int mdoc_pa_pre(MDOC_ARGS
);
110 static void mdoc_pf_post(MDOC_ARGS
);
111 static int mdoc_pf_pre(MDOC_ARGS
);
112 static void mdoc_pq_post(MDOC_ARGS
);
113 static int mdoc_pq_pre(MDOC_ARGS
);
114 static int mdoc_rs_pre(MDOC_ARGS
);
115 static int mdoc_rv_pre(MDOC_ARGS
);
116 static int mdoc_sh_pre(MDOC_ARGS
);
117 static int mdoc_sp_pre(MDOC_ARGS
);
118 static void mdoc_sq_post(MDOC_ARGS
);
119 static int mdoc_sq_pre(MDOC_ARGS
);
120 static int mdoc_ss_pre(MDOC_ARGS
);
121 static int mdoc_sx_pre(MDOC_ARGS
);
122 static int mdoc_sy_pre(MDOC_ARGS
);
123 static int mdoc_ud_pre(MDOC_ARGS
);
124 static int mdoc_va_pre(MDOC_ARGS
);
125 static int mdoc_vt_pre(MDOC_ARGS
);
126 static int mdoc_xr_pre(MDOC_ARGS
);
127 static int mdoc_xx_pre(MDOC_ARGS
);
130 extern size_t strlcpy(char *, const char *, size_t);
131 extern size_t strlcat(char *, const char *, size_t);
134 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
135 {mdoc_ap_pre
, NULL
}, /* Ap */
136 {NULL
, NULL
}, /* Dd */
137 {NULL
, NULL
}, /* Dt */
138 {NULL
, NULL
}, /* Os */
139 {mdoc_sh_pre
, NULL
}, /* Sh */
140 {mdoc_ss_pre
, NULL
}, /* Ss */
141 {mdoc_sp_pre
, NULL
}, /* Pp */
142 {mdoc_d1_pre
, NULL
}, /* D1 */
143 {mdoc_d1_pre
, NULL
}, /* Dl */
144 {mdoc_bd_pre
, NULL
}, /* Bd */
145 {NULL
, NULL
}, /* Ed */
146 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
147 {NULL
, NULL
}, /* El */
148 {mdoc_it_pre
, NULL
}, /* It */
149 {mdoc_ad_pre
, NULL
}, /* Ad */
150 {mdoc_an_pre
, NULL
}, /* An */
151 {mdoc_ar_pre
, NULL
}, /* Ar */
152 {mdoc_cd_pre
, NULL
}, /* Cd */
153 {mdoc_fl_pre
, NULL
}, /* Cm */
154 {mdoc_dv_pre
, NULL
}, /* Dv */
155 {mdoc_er_pre
, NULL
}, /* Er */
156 {mdoc_ev_pre
, NULL
}, /* Ev */
157 {mdoc_ex_pre
, NULL
}, /* Ex */
158 {mdoc_fa_pre
, NULL
}, /* Fa */
159 {mdoc_fd_pre
, NULL
}, /* Fd */
160 {mdoc_fl_pre
, NULL
}, /* Fl */
161 {mdoc_fn_pre
, NULL
}, /* Fn */
162 {mdoc_ft_pre
, NULL
}, /* Ft */
163 {mdoc_ic_pre
, NULL
}, /* Ic */
164 {mdoc_in_pre
, NULL
}, /* In */
165 {mdoc_li_pre
, NULL
}, /* Li */
166 {mdoc_nd_pre
, NULL
}, /* Nd */
167 {mdoc_nm_pre
, NULL
}, /* Nm */
168 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
169 {NULL
, NULL
}, /* Ot */
170 {mdoc_pa_pre
, NULL
}, /* Pa */
171 {mdoc_rv_pre
, NULL
}, /* Rv */
172 {NULL
, NULL
}, /* St */
173 {mdoc_va_pre
, NULL
}, /* Va */
174 {mdoc_vt_pre
, NULL
}, /* Vt */
175 {mdoc_xr_pre
, NULL
}, /* Xr */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
187 {NULL
, NULL
}, /* Ac */
188 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
189 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
190 {NULL
, NULL
}, /* At */
191 {NULL
, NULL
}, /* Bc */
192 {mdoc_bf_pre
, NULL
}, /* Bf */
193 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
194 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
195 {mdoc_xx_pre
, NULL
}, /* Bsx */
196 {mdoc_bx_pre
, NULL
}, /* Bx */
197 {NULL
, NULL
}, /* Db */
198 {NULL
, NULL
}, /* Dc */
199 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
200 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
201 {NULL
, NULL
}, /* Ec */
202 {NULL
, NULL
}, /* Ef */
203 {mdoc_em_pre
, NULL
}, /* Em */
204 {NULL
, NULL
}, /* Eo */
205 {mdoc_xx_pre
, NULL
}, /* Fx */
206 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
207 {NULL
, NULL
}, /* No */
208 {mdoc_ns_pre
, NULL
}, /* Ns */
209 {mdoc_xx_pre
, NULL
}, /* Nx */
210 {mdoc_xx_pre
, NULL
}, /* Ox */
211 {NULL
, NULL
}, /* Pc */
212 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
213 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
214 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
215 {NULL
, NULL
}, /* Qc */
216 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
217 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
218 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
219 {NULL
, NULL
}, /* Re */
220 {mdoc_rs_pre
, NULL
}, /* Rs */
221 {NULL
, NULL
}, /* Sc */
222 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
223 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
224 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
225 {mdoc_sx_pre
, NULL
}, /* Sx */
226 {mdoc_sy_pre
, NULL
}, /* Sy */
227 {NULL
, NULL
}, /* Tn */
228 {mdoc_xx_pre
, NULL
}, /* Ux */
229 {NULL
, NULL
}, /* Xc */
230 {NULL
, NULL
}, /* Xo */
231 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
232 {NULL
, NULL
}, /* Fc */
233 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
234 {NULL
, NULL
}, /* Oc */
235 {NULL
, NULL
}, /* Bk */
236 {NULL
, NULL
}, /* Ek */
237 {mdoc_bt_pre
, NULL
}, /* Bt */
238 {NULL
, NULL
}, /* Hf */
239 {NULL
, NULL
}, /* Fr */
240 {mdoc_ud_pre
, NULL
}, /* Ud */
241 {mdoc_lb_pre
, NULL
}, /* Lb */
242 {mdoc_sp_pre
, NULL
}, /* Lp */
243 {mdoc_lk_pre
, NULL
}, /* Lk */
244 {mdoc_mt_pre
, NULL
}, /* Mt */
245 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
246 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
247 {NULL
, NULL
}, /* Brc */
248 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
249 {NULL
, NULL
}, /* Es */ /* TODO */
250 {NULL
, NULL
}, /* En */ /* TODO */
251 {mdoc_xx_pre
, NULL
}, /* Dx */
252 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
253 {mdoc_sp_pre
, NULL
}, /* br */
254 {mdoc_sp_pre
, NULL
}, /* sp */
255 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
260 html_mdoc(void *arg
, const struct mdoc
*m
)
265 h
= (struct html
*)arg
;
267 print_gen_doctype(h
);
268 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
269 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
277 * Return the list type for `Bl', e.g., `Bl -column' returns
278 * MDOC_Column. This can ONLY be run for lists; it will abort() if no
279 * list type is found.
282 a2list(const struct mdoc_node
*n
)
287 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
288 switch (n
->args
->argv
[i
].arg
) {
310 return(n
->args
->argv
[i
].arg
);
321 * Calculate the scaling unit passed in a `-width' argument. This uses
322 * either a native scaling unit (e.g., 1i, 2m) or the string length of
326 a2width(const char *p
, struct roffsu
*su
)
329 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
331 su
->scale
= (int)strlen(p
);
337 * Calculate the scaling unit passed in an `-offset' argument. This
338 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
339 * predefined strings (indent, etc.), or the string length of the value.
342 a2offs(const char *p
, struct roffsu
*su
)
345 /* FIXME: "right"? */
347 if (0 == strcmp(p
, "left"))
348 SCALE_HS_INIT(su
, 0);
349 else if (0 == strcmp(p
, "indent"))
350 SCALE_HS_INIT(su
, INDENT
);
351 else if (0 == strcmp(p
, "indent-two"))
352 SCALE_HS_INIT(su
, INDENT
* 2);
353 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
355 su
->scale
= (int)strlen(p
);
361 print_mdoc(MDOC_ARGS
)
366 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
367 print_mdoc_head(m
, n
, h
);
370 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
372 tag
.key
= ATTR_CLASS
;
374 print_otag(h
, TAG_DIV
, 1, &tag
);
376 print_mdoc_nodelist(m
, n
, h
);
383 print_mdoc_head(MDOC_ARGS
)
388 buffmt(h
, "%s(%d)", m
->title
, m
->msec
);
396 print_otag(h
, TAG_TITLE
, 0, NULL
);
397 print_text(h
, h
->buf
);
402 print_mdoc_nodelist(MDOC_ARGS
)
405 print_mdoc_node(m
, n
, h
);
407 print_mdoc_nodelist(m
, n
->next
, h
);
412 print_mdoc_node(MDOC_ARGS
)
423 child
= mdoc_root_pre(m
, n
, h
);
426 print_text(h
, n
->string
);
429 if (mdocs
[n
->tok
].pre
)
430 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
434 if (child
&& n
->child
)
435 print_mdoc_nodelist(m
, n
->child
, h
);
442 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
);
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 html_idcat(buf
, nn
->string
, BUFSIZ
);
642 html_idcat(buf
, " ", 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, &tag
);
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
);
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. */
1078 SCALE_HS_INIT(&width
, 0);
1081 if (0 == width
.scale
)
1082 SCALE_HS_INIT(&width
, INDENT
);
1086 /* Flip to body/block processing. */
1088 if (MDOC_BODY
== n
->type
)
1089 return(mdoc_it_body_pre(m
, n
, h
, type
));
1090 if (MDOC_BLOCK
== n
->type
)
1091 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1094 /* Override column widths. */
1096 if (MDOC_Column
== type
) {
1097 nn
= n
->parent
->child
;
1098 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1100 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1101 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1104 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1110 mdoc_bl_pre(MDOC_ARGS
)
1114 if (MDOC_BLOCK
!= n
->type
)
1116 if (MDOC_Enum
!= a2list(n
))
1119 ord
= malloc(sizeof(struct ord
));
1126 ord
->next
= h
->ords
.head
;
1134 mdoc_bl_post(MDOC_ARGS
)
1138 if (MDOC_BLOCK
!= n
->type
)
1140 if (MDOC_Enum
!= a2list(n
))
1145 h
->ords
.head
= ord
->next
;
1152 mdoc_ex_pre(MDOC_ARGS
)
1154 const struct mdoc_node
*nn
;
1156 struct htmlpair tag
;
1158 PAIR_CLASS_INIT(&tag
, "utility");
1160 print_text(h
, "The");
1161 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1162 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1163 print_text(h
, nn
->string
);
1166 h
->flags
|= HTML_NOSPACE
;
1168 if (nn
->next
&& NULL
== nn
->next
->next
)
1169 print_text(h
, ", and");
1173 h
->flags
&= ~HTML_NOSPACE
;
1177 print_text(h
, "utilities exit");
1179 print_text(h
, "utility exits");
1181 print_text(h
, "0 on success, and >0 if an error occurs.");
1188 mdoc_dq_pre(MDOC_ARGS
)
1191 if (MDOC_BODY
!= n
->type
)
1193 print_text(h
, "\\(lq");
1194 h
->flags
|= HTML_NOSPACE
;
1201 mdoc_dq_post(MDOC_ARGS
)
1204 if (MDOC_BODY
!= n
->type
)
1206 h
->flags
|= HTML_NOSPACE
;
1207 print_text(h
, "\\(rq");
1213 mdoc_pq_pre(MDOC_ARGS
)
1216 if (MDOC_BODY
!= n
->type
)
1218 print_text(h
, "\\&(");
1219 h
->flags
|= HTML_NOSPACE
;
1226 mdoc_pq_post(MDOC_ARGS
)
1229 if (MDOC_BODY
!= n
->type
)
1237 mdoc_sq_pre(MDOC_ARGS
)
1240 if (MDOC_BODY
!= n
->type
)
1242 print_text(h
, "\\(oq");
1243 h
->flags
|= HTML_NOSPACE
;
1250 mdoc_sq_post(MDOC_ARGS
)
1253 if (MDOC_BODY
!= n
->type
)
1255 h
->flags
|= HTML_NOSPACE
;
1256 print_text(h
, "\\(aq");
1262 mdoc_em_pre(MDOC_ARGS
)
1264 struct htmlpair tag
;
1266 PAIR_CLASS_INIT(&tag
, "emph");
1267 print_otag(h
, TAG_SPAN
, 1, &tag
);
1274 mdoc_d1_pre(MDOC_ARGS
)
1276 struct htmlpair tag
[2];
1279 if (MDOC_BLOCK
!= n
->type
)
1282 /* FIXME: D1 shouldn't be literal. */
1284 SCALE_VS_INIT(&su
, INDENT
- 2);
1285 bufcat_su(h
, "margin-left", &su
);
1286 PAIR_CLASS_INIT(&tag
[0], "lit");
1287 PAIR_STYLE_INIT(&tag
[1], h
);
1288 print_otag(h
, TAG_DIV
, 2, tag
);
1295 mdoc_sx_pre(MDOC_ARGS
)
1297 struct htmlpair tag
[2];
1298 const struct mdoc_node
*nn
;
1301 /* FIXME: duplicates? */
1303 strlcpy(buf
, "#", BUFSIZ
);
1304 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1305 html_idcat(buf
, nn
->string
, BUFSIZ
);
1307 html_idcat(buf
, " ", BUFSIZ
);
1310 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1311 tag
[1].key
= ATTR_HREF
;
1314 print_otag(h
, TAG_A
, 2, tag
);
1321 mdoc_aq_pre(MDOC_ARGS
)
1324 if (MDOC_BODY
!= n
->type
)
1326 print_text(h
, "\\(la");
1327 h
->flags
|= HTML_NOSPACE
;
1334 mdoc_aq_post(MDOC_ARGS
)
1337 if (MDOC_BODY
!= n
->type
)
1339 h
->flags
|= HTML_NOSPACE
;
1340 print_text(h
, "\\(ra");
1346 mdoc_bd_pre(MDOC_ARGS
)
1348 struct htmlpair tag
[2];
1350 const struct mdoc_node
*bl
, *nn
;
1353 if (MDOC_BLOCK
== n
->type
)
1355 else if (MDOC_HEAD
== n
->type
)
1360 SCALE_VS_INIT(&su
, 0);
1363 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1364 switch (bl
->args
->argv
[i
].arg
) {
1366 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1368 case (MDOC_Compact
):
1371 case (MDOC_Centred
):
1377 case (MDOC_Unfilled
):
1379 case (MDOC_Literal
):
1380 type
= bl
->args
->argv
[i
].arg
;
1386 /* FIXME: -centered, etc. formatting. */
1388 if (MDOC_BLOCK
== n
->type
) {
1389 bufcat_su(h
, "margin-left", &su
);
1390 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1391 if (MDOC_BLOCK
!= nn
->type
)
1393 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1399 print_otag(h
, TAG_DIV
, 0, tag
);
1402 SCALE_VS_INIT(&su
, 1);
1403 bufcat_su(h
, "margin-top", &su
);
1404 PAIR_STYLE_INIT(&tag
[0], h
);
1405 print_otag(h
, TAG_DIV
, 1, tag
);
1409 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1412 PAIR_CLASS_INIT(&tag
[0], "lit");
1413 bufcat_style(h
, "white-space", "pre");
1414 PAIR_STYLE_INIT(&tag
[1], h
);
1415 print_otag(h
, TAG_DIV
, 2, tag
);
1417 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1418 h
->flags
|= HTML_NOSPACE
;
1419 print_mdoc_node(m
, nn
, h
);
1420 if (NULL
== nn
->next
)
1422 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1423 print_text(h
, "\n");
1424 else if (NULL
== nn
->prev
)
1425 print_text(h
, "\n");
1434 mdoc_pa_pre(MDOC_ARGS
)
1436 struct htmlpair tag
;
1438 PAIR_CLASS_INIT(&tag
, "file");
1439 print_otag(h
, TAG_SPAN
, 1, &tag
);
1446 mdoc_ad_pre(MDOC_ARGS
)
1448 struct htmlpair tag
;
1450 PAIR_CLASS_INIT(&tag
, "addr");
1451 print_otag(h
, TAG_SPAN
, 1, &tag
);
1458 mdoc_an_pre(MDOC_ARGS
)
1460 struct htmlpair tag
;
1462 /* TODO: -split and -nosplit (see termp_an_pre()). */
1464 PAIR_CLASS_INIT(&tag
, "author");
1465 print_otag(h
, TAG_SPAN
, 1, &tag
);
1472 mdoc_cd_pre(MDOC_ARGS
)
1474 struct htmlpair tag
;
1476 print_otag(h
, TAG_DIV
, 0, NULL
);
1477 PAIR_CLASS_INIT(&tag
, "config");
1478 print_otag(h
, TAG_SPAN
, 1, &tag
);
1485 mdoc_dv_pre(MDOC_ARGS
)
1487 struct htmlpair tag
;
1489 PAIR_CLASS_INIT(&tag
, "define");
1490 print_otag(h
, TAG_SPAN
, 1, &tag
);
1497 mdoc_ev_pre(MDOC_ARGS
)
1499 struct htmlpair tag
;
1501 PAIR_CLASS_INIT(&tag
, "env");
1502 print_otag(h
, TAG_SPAN
, 1, &tag
);
1509 mdoc_er_pre(MDOC_ARGS
)
1511 struct htmlpair tag
;
1513 PAIR_CLASS_INIT(&tag
, "errno");
1514 print_otag(h
, TAG_SPAN
, 1, &tag
);
1521 mdoc_fa_pre(MDOC_ARGS
)
1523 const struct mdoc_node
*nn
;
1524 struct htmlpair tag
;
1527 PAIR_CLASS_INIT(&tag
, "farg");
1528 if (n
->parent
->tok
!= MDOC_Fo
) {
1529 print_otag(h
, TAG_SPAN
, 1, &tag
);
1533 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1534 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1535 print_text(h
, nn
->string
);
1541 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1550 mdoc_fd_pre(MDOC_ARGS
)
1552 struct htmlpair tag
;
1555 if (SEC_SYNOPSIS
== n
->sec
) {
1556 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1557 SCALE_VS_INIT(&su
, 1);
1558 bufcat_su(h
, "margin-bottom", &su
);
1559 PAIR_STYLE_INIT(&tag
, h
);
1560 print_otag(h
, TAG_DIV
, 1, &tag
);
1562 print_otag(h
, TAG_DIV
, 0, NULL
);
1565 PAIR_CLASS_INIT(&tag
, "macro");
1566 print_otag(h
, TAG_SPAN
, 1, &tag
);
1573 mdoc_vt_pre(MDOC_ARGS
)
1575 struct htmlpair tag
;
1578 if (SEC_SYNOPSIS
== n
->sec
) {
1579 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1580 SCALE_VS_INIT(&su
, 1);
1581 bufcat_su(h
, "margin-bottom", &su
);
1582 PAIR_STYLE_INIT(&tag
, h
);
1583 print_otag(h
, TAG_DIV
, 1, &tag
);
1585 print_otag(h
, TAG_DIV
, 0, NULL
);
1588 PAIR_CLASS_INIT(&tag
, "type");
1589 print_otag(h
, TAG_SPAN
, 1, &tag
);
1596 mdoc_ft_pre(MDOC_ARGS
)
1598 struct htmlpair tag
;
1601 if (SEC_SYNOPSIS
== n
->sec
) {
1602 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1603 SCALE_VS_INIT(&su
, 1);
1604 bufcat_su(h
, "margin-top", &su
);
1605 PAIR_STYLE_INIT(&tag
, h
);
1606 print_otag(h
, TAG_DIV
, 1, &tag
);
1608 print_otag(h
, TAG_DIV
, 0, NULL
);
1611 PAIR_CLASS_INIT(&tag
, "ftype");
1612 print_otag(h
, TAG_SPAN
, 1, &tag
);
1619 mdoc_fn_pre(MDOC_ARGS
)
1622 struct htmlpair tag
[2];
1623 const struct mdoc_node
*nn
;
1625 const char *sp
, *ep
;
1629 if (SEC_SYNOPSIS
== n
->sec
) {
1630 SCALE_HS_INIT(&su
, INDENT
);
1631 bufcat_su(h
, "margin-left", &su
);
1632 su
.scale
= -su
.scale
;
1633 bufcat_su(h
, "text-indent", &su
);
1635 SCALE_VS_INIT(&su
, 1);
1636 bufcat_su(h
, "margin-bottom", &su
);
1638 PAIR_STYLE_INIT(&tag
[0], h
);
1639 print_otag(h
, TAG_DIV
, 1, tag
);
1642 /* Split apart into type and name. */
1643 assert(n
->child
->string
);
1644 sp
= n
->child
->string
;
1646 ep
= strchr(sp
, ' ');
1648 PAIR_CLASS_INIT(&tag
[0], "ftype");
1649 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1652 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1653 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1655 print_text(h
, nbuf
);
1657 ep
= strchr(sp
, ' ');
1662 PAIR_CLASS_INIT(&tag
[0], "fname");
1663 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1666 (void)strlcpy(nbuf
, sp
, BUFSIZ
);
1667 print_text(h
, nbuf
);
1672 h
->flags
|= HTML_NOSPACE
;
1676 PAIR_CLASS_INIT(&tag
[0], "farg");
1677 bufcat_style(h
, "white-space", "nowrap");
1678 PAIR_STYLE_INIT(&tag
[1], h
);
1680 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1682 if (SEC_SYNOPSIS
== n
->sec
)
1684 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1685 print_text(h
, nn
->string
);
1692 if (SEC_SYNOPSIS
== n
->sec
)
1701 mdoc_sp_pre(MDOC_ARGS
)
1704 struct htmlpair tag
;
1709 /* FIXME: can this have a scaling indicator? */
1710 len
= n
->child
? atoi(n
->child
->string
) : 1;
1720 SCALE_VS_INIT(&su
, len
);
1721 bufcat_su(h
, "height", &su
);
1722 PAIR_STYLE_INIT(&tag
, h
);
1723 print_otag(h
, TAG_DIV
, 1, &tag
);
1724 /* So the div isn't empty: */
1725 print_text(h
, "\\~");
1734 mdoc_brq_pre(MDOC_ARGS
)
1737 if (MDOC_BODY
!= n
->type
)
1739 print_text(h
, "\\(lC");
1740 h
->flags
|= HTML_NOSPACE
;
1747 mdoc_brq_post(MDOC_ARGS
)
1750 if (MDOC_BODY
!= n
->type
)
1752 h
->flags
|= HTML_NOSPACE
;
1753 print_text(h
, "\\(rC");
1759 mdoc_lk_pre(MDOC_ARGS
)
1761 const struct mdoc_node
*nn
;
1762 struct htmlpair tag
[2];
1766 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1767 tag
[1].key
= ATTR_HREF
;
1768 tag
[1].val
= nn
->string
;
1769 print_otag(h
, TAG_A
, 2, tag
);
1771 if (NULL
== nn
->next
)
1774 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1775 print_text(h
, nn
->string
);
1783 mdoc_mt_pre(MDOC_ARGS
)
1785 struct htmlpair tag
[2];
1787 const struct mdoc_node
*nn
;
1789 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1791 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1793 bufcat(h
, "mailto:");
1794 bufcat(h
, nn
->string
);
1795 PAIR_STYLE_INIT(&tag
[1], h
);
1796 t
= print_otag(h
, TAG_A
, 2, tag
);
1797 print_text(h
, nn
->string
);
1807 mdoc_fo_pre(MDOC_ARGS
)
1809 struct htmlpair tag
;
1811 if (MDOC_BODY
== n
->type
) {
1812 h
->flags
|= HTML_NOSPACE
;
1814 h
->flags
|= HTML_NOSPACE
;
1816 } else if (MDOC_BLOCK
== n
->type
)
1819 PAIR_CLASS_INIT(&tag
, "fname");
1820 print_otag(h
, TAG_SPAN
, 1, &tag
);
1827 mdoc_fo_post(MDOC_ARGS
)
1829 if (MDOC_BODY
!= n
->type
)
1831 h
->flags
|= HTML_NOSPACE
;
1833 h
->flags
|= HTML_NOSPACE
;
1840 mdoc_in_pre(MDOC_ARGS
)
1842 const struct mdoc_node
*nn
;
1844 struct htmlpair tag
[2];
1848 if (SEC_SYNOPSIS
== n
->sec
) {
1849 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1850 SCALE_VS_INIT(&su
, 1);
1851 bufcat_su(h
, "margin-bottom", &su
);
1852 PAIR_STYLE_INIT(&tag
[0], h
);
1853 print_otag(h
, TAG_DIV
, 1, tag
);
1855 print_otag(h
, TAG_DIV
, 0, NULL
);
1858 /* FIXME: there's a buffer bug in here somewhere. */
1860 PAIR_CLASS_INIT(&tag
[0], "includes");
1861 print_otag(h
, TAG_SPAN
, 1, tag
);
1863 if (SEC_SYNOPSIS
== n
->sec
)
1864 print_text(h
, "#include");
1867 h
->flags
|= HTML_NOSPACE
;
1869 /* XXX -- see warning in termp_in_post(). */
1871 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1872 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1875 if (h
->base_includes
) {
1876 buffmt_includes(h
, nn
->string
);
1877 tag
[i
].key
= ATTR_HREF
;
1878 tag
[i
++].val
= h
->buf
;
1880 t
= print_otag(h
, TAG_A
, i
, tag
);
1881 print_mdoc_node(m
, nn
, h
);
1885 h
->flags
|= HTML_NOSPACE
;
1894 mdoc_ic_pre(MDOC_ARGS
)
1896 struct htmlpair tag
;
1898 PAIR_CLASS_INIT(&tag
, "cmd");
1899 print_otag(h
, TAG_SPAN
, 1, &tag
);
1906 mdoc_rv_pre(MDOC_ARGS
)
1908 const struct mdoc_node
*nn
;
1909 struct htmlpair tag
;
1912 print_otag(h
, TAG_DIV
, 0, NULL
);
1913 print_text(h
, "The");
1915 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1916 PAIR_CLASS_INIT(&tag
, "fname");
1917 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1918 print_text(h
, nn
->string
);
1921 h
->flags
|= HTML_NOSPACE
;
1922 if (nn
->next
&& NULL
== nn
->next
->next
)
1923 print_text(h
, "(), and");
1925 print_text(h
, "(),");
1927 print_text(h
, "()");
1931 print_text(h
, "functions return");
1933 print_text(h
, "function returns");
1935 print_text(h
, "the value 0 if successful; otherwise the value "
1936 "-1 is returned and the global variable");
1938 PAIR_CLASS_INIT(&tag
, "var");
1939 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1940 print_text(h
, "errno");
1942 print_text(h
, "is set to indicate the error.");
1949 mdoc_va_pre(MDOC_ARGS
)
1951 struct htmlpair tag
;
1953 PAIR_CLASS_INIT(&tag
, "var");
1954 print_otag(h
, TAG_SPAN
, 1, &tag
);
1961 mdoc_bq_pre(MDOC_ARGS
)
1964 if (MDOC_BODY
!= n
->type
)
1966 print_text(h
, "\\(lB");
1967 h
->flags
|= HTML_NOSPACE
;
1974 mdoc_bq_post(MDOC_ARGS
)
1977 if (MDOC_BODY
!= n
->type
)
1979 h
->flags
|= HTML_NOSPACE
;
1980 print_text(h
, "\\(rB");
1986 mdoc_ap_pre(MDOC_ARGS
)
1989 h
->flags
|= HTML_NOSPACE
;
1990 print_text(h
, "\\(aq");
1991 h
->flags
|= HTML_NOSPACE
;
1998 mdoc_bf_pre(MDOC_ARGS
)
2001 struct htmlpair tag
[2];
2004 if (MDOC_HEAD
== n
->type
)
2006 else if (MDOC_BLOCK
!= n
->type
)
2009 PAIR_CLASS_INIT(&tag
[0], "lit");
2011 if (n
->head
->child
) {
2012 if ( ! strcmp("Em", n
->head
->child
->string
))
2013 PAIR_CLASS_INIT(&tag
[0], "emph");
2014 else if ( ! strcmp("Sy", n
->head
->child
->string
))
2015 PAIR_CLASS_INIT(&tag
[0], "symb");
2016 else if ( ! strcmp("Li", n
->head
->child
->string
))
2017 PAIR_CLASS_INIT(&tag
[0], "lit");
2020 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2021 switch (n
->args
->argv
[i
].arg
) {
2022 case (MDOC_Symbolic
):
2023 PAIR_CLASS_INIT(&tag
[0], "symb");
2025 case (MDOC_Literal
):
2026 PAIR_CLASS_INIT(&tag
[0], "lit");
2028 case (MDOC_Emphasis
):
2029 PAIR_CLASS_INIT(&tag
[0], "emph");
2036 /* FIXME: div's have spaces stripped--we want them. */
2038 bufcat_style(h
, "display", "inline");
2039 SCALE_HS_INIT(&su
, 1);
2040 bufcat_su(h
, "margin-right", &su
);
2041 PAIR_STYLE_INIT(&tag
[1], h
);
2042 print_otag(h
, TAG_DIV
, 2, tag
);
2049 mdoc_ms_pre(MDOC_ARGS
)
2051 struct htmlpair tag
;
2053 PAIR_CLASS_INIT(&tag
, "symb");
2054 print_otag(h
, TAG_SPAN
, 1, &tag
);
2061 mdoc_pf_pre(MDOC_ARGS
)
2064 h
->flags
|= HTML_IGNDELIM
;
2071 mdoc_pf_post(MDOC_ARGS
)
2074 h
->flags
&= ~HTML_IGNDELIM
;
2075 h
->flags
|= HTML_NOSPACE
;
2081 mdoc_rs_pre(MDOC_ARGS
)
2083 struct htmlpair tag
;
2086 if (MDOC_BLOCK
!= n
->type
)
2089 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2090 SCALE_VS_INIT(&su
, 1);
2091 bufcat_su(h
, "margin-top", &su
);
2092 PAIR_STYLE_INIT(&tag
, h
);
2093 print_otag(h
, TAG_DIV
, 1, &tag
);
2096 PAIR_CLASS_INIT(&tag
, "ref");
2097 print_otag(h
, TAG_SPAN
, 1, &tag
);
2105 mdoc_li_pre(MDOC_ARGS
)
2107 struct htmlpair tag
;
2109 PAIR_CLASS_INIT(&tag
, "lit");
2110 print_otag(h
, TAG_SPAN
, 1, &tag
);
2117 mdoc_sy_pre(MDOC_ARGS
)
2119 struct htmlpair tag
;
2121 PAIR_CLASS_INIT(&tag
, "symb");
2122 print_otag(h
, TAG_SPAN
, 1, &tag
);
2129 mdoc_bt_pre(MDOC_ARGS
)
2132 print_text(h
, "is currently in beta test.");
2139 mdoc_ud_pre(MDOC_ARGS
)
2142 print_text(h
, "currently under development.");
2149 mdoc_lb_pre(MDOC_ARGS
)
2151 struct htmlpair tag
;
2153 if (SEC_SYNOPSIS
== n
->sec
)
2154 print_otag(h
, TAG_DIV
, 0, NULL
);
2155 PAIR_CLASS_INIT(&tag
, "lib");
2156 print_otag(h
, TAG_SPAN
, 1, &tag
);
2163 mdoc__x_pre(MDOC_ARGS
)
2165 struct htmlpair tag
[2];
2169 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2172 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2175 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2178 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2181 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2184 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2187 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2190 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2193 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2196 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2199 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2202 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2203 print_text(h
, "\\(lq");
2204 h
->flags
|= HTML_NOSPACE
;
2207 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2210 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2217 if (MDOC__U
!= n
->tok
) {
2218 print_otag(h
, TAG_SPAN
, 1, tag
);
2222 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2223 print_otag(h
, TAG_A
, 2, tag
);
2230 mdoc__x_post(MDOC_ARGS
)
2233 h
->flags
|= HTML_NOSPACE
;
2236 print_text(h
, "\\(rq");
2237 h
->flags
|= HTML_NOSPACE
;
2242 print_text(h
, n
->next
? "," : ".");