]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.42 2009/10/28 08:00:18 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>
36 #define MDOC_ARGS const struct mdoc_meta *m, \
37 const struct mdoc_node *n, \
41 int (*pre
)(MDOC_ARGS
);
42 void (*post
)(MDOC_ARGS
);
45 static void print_mdoc(MDOC_ARGS
);
46 static void print_mdoc_head(MDOC_ARGS
);
47 static void print_mdoc_node(MDOC_ARGS
);
48 static void print_mdoc_nodelist(MDOC_ARGS
);
50 static void a2width(const char *, struct roffsu
*);
51 static void a2offs(const char *, struct roffsu
*);
53 static int a2list(const struct mdoc_node
*);
55 static void mdoc_root_post(MDOC_ARGS
);
56 static int mdoc_root_pre(MDOC_ARGS
);
58 static void mdoc__x_post(MDOC_ARGS
);
59 static int mdoc__x_pre(MDOC_ARGS
);
60 static int mdoc_ad_pre(MDOC_ARGS
);
61 static int mdoc_an_pre(MDOC_ARGS
);
62 static int mdoc_ap_pre(MDOC_ARGS
);
63 static void mdoc_aq_post(MDOC_ARGS
);
64 static int mdoc_aq_pre(MDOC_ARGS
);
65 static int mdoc_ar_pre(MDOC_ARGS
);
66 static int mdoc_bd_pre(MDOC_ARGS
);
67 static int mdoc_bf_pre(MDOC_ARGS
);
68 static void mdoc_bl_post(MDOC_ARGS
);
69 static int mdoc_bl_pre(MDOC_ARGS
);
70 static void mdoc_bq_post(MDOC_ARGS
);
71 static int mdoc_bq_pre(MDOC_ARGS
);
72 static void mdoc_brq_post(MDOC_ARGS
);
73 static int mdoc_brq_pre(MDOC_ARGS
);
74 static int mdoc_bt_pre(MDOC_ARGS
);
75 static int mdoc_bx_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static void mdoc_dq_post(MDOC_ARGS
);
79 static int mdoc_dq_pre(MDOC_ARGS
);
80 static int mdoc_dv_pre(MDOC_ARGS
);
81 static int mdoc_fa_pre(MDOC_ARGS
);
82 static int mdoc_fd_pre(MDOC_ARGS
);
83 static int mdoc_fl_pre(MDOC_ARGS
);
84 static int mdoc_fn_pre(MDOC_ARGS
);
85 static int mdoc_ft_pre(MDOC_ARGS
);
86 static int mdoc_em_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_block_pre(MDOC_ARGS
, int, int,
95 struct roffsu
*, struct roffsu
*);
96 static int mdoc_it_head_pre(MDOC_ARGS
, int,
98 static int mdoc_it_body_pre(MDOC_ARGS
, int);
99 static int mdoc_it_pre(MDOC_ARGS
);
100 static int mdoc_lb_pre(MDOC_ARGS
);
101 static int mdoc_li_pre(MDOC_ARGS
);
102 static int mdoc_lk_pre(MDOC_ARGS
);
103 static int mdoc_mt_pre(MDOC_ARGS
);
104 static int mdoc_ms_pre(MDOC_ARGS
);
105 static int mdoc_nd_pre(MDOC_ARGS
);
106 static int mdoc_nm_pre(MDOC_ARGS
);
107 static int mdoc_ns_pre(MDOC_ARGS
);
108 static void mdoc_op_post(MDOC_ARGS
);
109 static int mdoc_op_pre(MDOC_ARGS
);
110 static int mdoc_pa_pre(MDOC_ARGS
);
111 static void mdoc_pf_post(MDOC_ARGS
);
112 static int mdoc_pf_pre(MDOC_ARGS
);
113 static void mdoc_pq_post(MDOC_ARGS
);
114 static int mdoc_pq_pre(MDOC_ARGS
);
115 static int mdoc_rs_pre(MDOC_ARGS
);
116 static int mdoc_rv_pre(MDOC_ARGS
);
117 static int mdoc_sh_pre(MDOC_ARGS
);
118 static int mdoc_sp_pre(MDOC_ARGS
);
119 static void mdoc_sq_post(MDOC_ARGS
);
120 static int mdoc_sq_pre(MDOC_ARGS
);
121 static int mdoc_ss_pre(MDOC_ARGS
);
122 static int mdoc_sx_pre(MDOC_ARGS
);
123 static int mdoc_sy_pre(MDOC_ARGS
);
124 static int mdoc_ud_pre(MDOC_ARGS
);
125 static int mdoc_va_pre(MDOC_ARGS
);
126 static int mdoc_vt_pre(MDOC_ARGS
);
127 static int mdoc_xr_pre(MDOC_ARGS
);
128 static int mdoc_xx_pre(MDOC_ARGS
);
131 extern size_t strlcpy(char *, const char *, size_t);
132 extern size_t strlcat(char *, const char *, size_t);
135 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
136 {mdoc_ap_pre
, NULL
}, /* Ap */
137 {NULL
, NULL
}, /* Dd */
138 {NULL
, NULL
}, /* Dt */
139 {NULL
, NULL
}, /* Os */
140 {mdoc_sh_pre
, NULL
}, /* Sh */
141 {mdoc_ss_pre
, NULL
}, /* Ss */
142 {mdoc_sp_pre
, NULL
}, /* Pp */
143 {mdoc_d1_pre
, NULL
}, /* D1 */
144 {mdoc_d1_pre
, NULL
}, /* Dl */
145 {mdoc_bd_pre
, NULL
}, /* Bd */
146 {NULL
, NULL
}, /* Ed */
147 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
148 {NULL
, NULL
}, /* El */
149 {mdoc_it_pre
, NULL
}, /* It */
150 {mdoc_ad_pre
, NULL
}, /* Ad */
151 {mdoc_an_pre
, NULL
}, /* An */
152 {mdoc_ar_pre
, NULL
}, /* Ar */
153 {mdoc_cd_pre
, NULL
}, /* Cd */
154 {mdoc_fl_pre
, NULL
}, /* Cm */
155 {mdoc_dv_pre
, NULL
}, /* Dv */
156 {mdoc_er_pre
, NULL
}, /* Er */
157 {mdoc_ev_pre
, NULL
}, /* Ev */
158 {mdoc_ex_pre
, NULL
}, /* Ex */
159 {mdoc_fa_pre
, NULL
}, /* Fa */
160 {mdoc_fd_pre
, NULL
}, /* Fd */
161 {mdoc_fl_pre
, NULL
}, /* Fl */
162 {mdoc_fn_pre
, NULL
}, /* Fn */
163 {mdoc_ft_pre
, NULL
}, /* Ft */
164 {mdoc_ic_pre
, NULL
}, /* Ic */
165 {mdoc_in_pre
, NULL
}, /* In */
166 {mdoc_li_pre
, NULL
}, /* Li */
167 {mdoc_nd_pre
, NULL
}, /* Nd */
168 {mdoc_nm_pre
, NULL
}, /* Nm */
169 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
170 {NULL
, NULL
}, /* Ot */
171 {mdoc_pa_pre
, NULL
}, /* Pa */
172 {mdoc_rv_pre
, NULL
}, /* Rv */
173 {NULL
, NULL
}, /* St */
174 {mdoc_va_pre
, NULL
}, /* Va */
175 {mdoc_vt_pre
, NULL
}, /* Vt */
176 {mdoc_xr_pre
, NULL
}, /* Xr */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
188 {NULL
, NULL
}, /* Ac */
189 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
190 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
191 {NULL
, NULL
}, /* At */
192 {NULL
, NULL
}, /* Bc */
193 {mdoc_bf_pre
, NULL
}, /* Bf */
194 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
195 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
196 {mdoc_xx_pre
, NULL
}, /* Bsx */
197 {mdoc_bx_pre
, NULL
}, /* Bx */
198 {NULL
, NULL
}, /* Db */
199 {NULL
, NULL
}, /* Dc */
200 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
201 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
202 {NULL
, NULL
}, /* Ec */
203 {NULL
, NULL
}, /* Ef */
204 {mdoc_em_pre
, NULL
}, /* Em */
205 {NULL
, NULL
}, /* Eo */
206 {mdoc_xx_pre
, NULL
}, /* Fx */
207 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
208 {NULL
, NULL
}, /* No */
209 {mdoc_ns_pre
, NULL
}, /* Ns */
210 {mdoc_xx_pre
, NULL
}, /* Nx */
211 {mdoc_xx_pre
, NULL
}, /* Ox */
212 {NULL
, NULL
}, /* Pc */
213 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
214 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
215 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
216 {NULL
, NULL
}, /* Qc */
217 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
218 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
219 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
220 {NULL
, NULL
}, /* Re */
221 {mdoc_rs_pre
, NULL
}, /* Rs */
222 {NULL
, NULL
}, /* Sc */
223 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
224 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
225 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
226 {mdoc_sx_pre
, NULL
}, /* Sx */
227 {mdoc_sy_pre
, NULL
}, /* Sy */
228 {NULL
, NULL
}, /* Tn */
229 {mdoc_xx_pre
, NULL
}, /* Ux */
230 {NULL
, NULL
}, /* Xc */
231 {NULL
, NULL
}, /* Xo */
232 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
233 {NULL
, NULL
}, /* Fc */
234 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
235 {NULL
, NULL
}, /* Oc */
236 {NULL
, NULL
}, /* Bk */
237 {NULL
, NULL
}, /* Ek */
238 {mdoc_bt_pre
, NULL
}, /* Bt */
239 {NULL
, NULL
}, /* Hf */
240 {NULL
, NULL
}, /* Fr */
241 {mdoc_ud_pre
, NULL
}, /* Ud */
242 {mdoc_lb_pre
, NULL
}, /* Lb */
243 {mdoc_sp_pre
, NULL
}, /* Lp */
244 {mdoc_lk_pre
, NULL
}, /* Lk */
245 {mdoc_mt_pre
, NULL
}, /* Mt */
246 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
247 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
248 {NULL
, NULL
}, /* Brc */
249 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
250 {NULL
, NULL
}, /* Es */ /* TODO */
251 {NULL
, NULL
}, /* En */ /* TODO */
252 {mdoc_xx_pre
, NULL
}, /* Dx */
253 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
254 {mdoc_sp_pre
, NULL
}, /* br */
255 {mdoc_sp_pre
, NULL
}, /* sp */
256 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
261 html_mdoc(void *arg
, const struct mdoc
*m
)
266 h
= (struct html
*)arg
;
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
)
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
)
459 struct htmlpair tag
[3];
463 time2a(m
->date
, b
, DATESIZ
);
466 * XXX: this should use divs, but in Firefox, divs with nested
467 * divs for some reason puke when trying to put a border line
468 * below. So I use tables, instead.
471 PAIR_CLASS_INIT(&tag
[0], "footer");
472 bufcat_style(h
, "width", "100%");
473 PAIR_STYLE_INIT(&tag
[1], h
);
474 PAIR_SUMMARY_INIT(&tag
[2], "footer");
476 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
477 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
480 bufcat_style(h
, "width", "50%");
481 PAIR_STYLE_INIT(&tag
[0], h
);
482 print_otag(h
, TAG_TD
, 1, tag
);
487 bufcat_style(h
, "width", "50%");
488 bufcat_style(h
, "text-align", "right");
489 PAIR_STYLE_INIT(&tag
[0], h
);
490 print_otag(h
, TAG_TD
, 1, tag
);
491 print_text(h
, m
->os
);
498 mdoc_root_pre(MDOC_ARGS
)
500 struct htmlpair tag
[3];
502 char b
[BUFSIZ
], title
[BUFSIZ
];
504 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
507 (void)strlcat(b
, " (", BUFSIZ
);
508 (void)strlcat(b
, m
->arch
, BUFSIZ
);
509 (void)strlcat(b
, ")", BUFSIZ
);
512 (void)snprintf(title
, BUFSIZ
- 1,
513 "%s(%d)", m
->title
, m
->msec
);
515 /* XXX: see note in mdoc_root_post() about divs. */
517 PAIR_CLASS_INIT(&tag
[0], "header");
518 bufcat_style(h
, "width", "100%");
519 PAIR_STYLE_INIT(&tag
[1], h
);
520 PAIR_SUMMARY_INIT(&tag
[2], "header");
522 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
524 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
527 bufcat_style(h
, "width", "10%");
528 PAIR_STYLE_INIT(&tag
[0], h
);
529 print_otag(h
, TAG_TD
, 1, tag
);
530 print_text(h
, title
);
534 bufcat_style(h
, "text-align", "center");
535 bufcat_style(h
, "white-space", "nowrap");
536 bufcat_style(h
, "width", "80%");
537 PAIR_STYLE_INIT(&tag
[0], h
);
538 print_otag(h
, TAG_TD
, 1, tag
);
543 bufcat_style(h
, "text-align", "right");
544 bufcat_style(h
, "width", "10%");
545 PAIR_STYLE_INIT(&tag
[0], h
);
546 print_otag(h
, TAG_TD
, 1, tag
);
547 print_text(h
, title
);
555 mdoc_sh_pre(MDOC_ARGS
)
557 struct htmlpair tag
[2];
558 const struct mdoc_node
*nn
;
562 if (MDOC_BODY
== n
->type
) {
563 SCALE_HS_INIT(&su
, INDENT
);
564 bufcat_su(h
, "margin-left", &su
);
565 PAIR_CLASS_INIT(&tag
[0], "sec-body");
566 PAIR_STYLE_INIT(&tag
[1], h
);
567 print_otag(h
, TAG_DIV
, 2, tag
);
569 } else if (MDOC_BLOCK
== n
->type
) {
570 PAIR_CLASS_INIT(&tag
[0], "sec-block");
571 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
572 print_otag(h
, TAG_DIV
, 1, tag
);
576 SCALE_VS_INIT(&su
, 1);
577 bufcat_su(h
, "margin-top", &su
);
579 bufcat_su(h
, "margin-bottom", &su
);
581 PAIR_STYLE_INIT(&tag
[1], h
);
582 print_otag(h
, TAG_DIV
, 2, tag
);
587 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
588 html_idcat(buf
, nn
->string
, BUFSIZ
);
590 html_idcat(buf
, " ", BUFSIZ
);
594 * TODO: make sure there are no duplicates, as HTML does not
595 * allow for multiple `id' tags of the same name.
598 PAIR_CLASS_INIT(&tag
[0], "sec-head");
599 tag
[1].key
= ATTR_ID
;
601 print_otag(h
, TAG_DIV
, 2, tag
);
608 mdoc_ss_pre(MDOC_ARGS
)
610 struct htmlpair tag
[3];
611 const struct mdoc_node
*nn
;
615 SCALE_VS_INIT(&su
, 1);
617 if (MDOC_BODY
== n
->type
) {
618 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
619 if (n
->parent
->next
&& n
->child
) {
620 bufcat_su(h
, "margin-bottom", &su
);
621 PAIR_STYLE_INIT(&tag
[1], h
);
622 print_otag(h
, TAG_DIV
, 2, tag
);
624 print_otag(h
, TAG_DIV
, 1, tag
);
626 } else if (MDOC_BLOCK
== n
->type
) {
627 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
629 bufcat_su(h
, "margin-top", &su
);
630 PAIR_STYLE_INIT(&tag
[1], h
);
631 print_otag(h
, TAG_DIV
, 2, tag
);
633 print_otag(h
, TAG_DIV
, 1, tag
);
637 /* TODO: see note in mdoc_sh_pre() about duplicates. */
640 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
641 html_idcat(buf
, nn
->string
, BUFSIZ
);
643 html_idcat(buf
, " ", BUFSIZ
);
646 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
647 su
.scale
= -su
.scale
;
648 bufcat_su(h
, "margin-left", &su
);
650 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
651 PAIR_STYLE_INIT(&tag
[1], h
);
652 tag
[2].key
= ATTR_ID
;
654 print_otag(h
, TAG_DIV
, 3, tag
);
661 mdoc_fl_pre(MDOC_ARGS
)
665 PAIR_CLASS_INIT(&tag
, "flag");
666 print_otag(h
, TAG_SPAN
, 1, &tag
);
667 if (MDOC_Fl
== n
->tok
) {
668 print_text(h
, "\\-");
669 h
->flags
|= HTML_NOSPACE
;
677 mdoc_nd_pre(MDOC_ARGS
)
681 if (MDOC_BODY
!= n
->type
)
684 /* XXX: this tag in theory can contain block elements. */
686 print_text(h
, "\\(em");
687 PAIR_CLASS_INIT(&tag
, "desc-body");
688 print_otag(h
, TAG_SPAN
, 1, &tag
);
695 mdoc_op_pre(MDOC_ARGS
)
699 if (MDOC_BODY
!= n
->type
)
702 /* XXX: this tag in theory can contain block elements. */
704 print_text(h
, "\\(lB");
705 h
->flags
|= HTML_NOSPACE
;
706 PAIR_CLASS_INIT(&tag
, "opt");
707 print_otag(h
, TAG_SPAN
, 1, &tag
);
714 mdoc_op_post(MDOC_ARGS
)
717 if (MDOC_BODY
!= n
->type
)
719 h
->flags
|= HTML_NOSPACE
;
720 print_text(h
, "\\(rB");
725 mdoc_nm_pre(MDOC_ARGS
)
729 if ( ! (HTML_NEWLINE
& h
->flags
))
730 if (SEC_SYNOPSIS
== n
->sec
) {
731 bufcat_style(h
, "clear", "both");
732 PAIR_STYLE_INIT(&tag
, h
);
733 print_otag(h
, TAG_BR
, 1, &tag
);
736 PAIR_CLASS_INIT(&tag
, "name");
737 print_otag(h
, TAG_SPAN
, 1, &tag
);
738 if (NULL
== n
->child
)
739 print_text(h
, m
->name
);
747 mdoc_xr_pre(MDOC_ARGS
)
749 struct htmlpair tag
[2];
750 const struct mdoc_node
*nn
;
752 PAIR_CLASS_INIT(&tag
[0], "link-man");
755 buffmt_man(h
, n
->child
->string
,
757 n
->child
->next
->string
: NULL
);
758 tag
[1].key
= ATTR_HREF
;
760 print_otag(h
, TAG_A
, 2, tag
);
762 print_otag(h
, TAG_A
, 1, tag
);
765 print_text(h
, nn
->string
);
767 if (NULL
== (nn
= nn
->next
))
770 h
->flags
|= HTML_NOSPACE
;
772 h
->flags
|= HTML_NOSPACE
;
773 print_text(h
, nn
->string
);
774 h
->flags
|= HTML_NOSPACE
;
782 mdoc_ns_pre(MDOC_ARGS
)
785 h
->flags
|= HTML_NOSPACE
;
792 mdoc_ar_pre(MDOC_ARGS
)
796 PAIR_CLASS_INIT(&tag
, "arg");
797 print_otag(h
, TAG_SPAN
, 1, &tag
);
804 mdoc_xx_pre(MDOC_ARGS
)
832 PAIR_CLASS_INIT(&tag
, "unix");
833 print_otag(h
, TAG_SPAN
, 1, &tag
);
841 mdoc_bx_pre(MDOC_ARGS
)
843 const struct mdoc_node
*nn
;
846 PAIR_CLASS_INIT(&tag
, "unix");
847 print_otag(h
, TAG_SPAN
, 1, &tag
);
849 for (nn
= n
->child
; nn
; nn
= nn
->next
)
850 print_mdoc_node(m
, nn
, h
);
853 h
->flags
|= HTML_NOSPACE
;
855 print_text(h
, "BSD");
862 mdoc_it_block_pre(MDOC_ARGS
, int type
, int comp
,
863 struct roffsu
*offs
, struct roffsu
*width
)
866 const struct mdoc_node
*nn
;
869 nn
= n
->parent
->parent
;
872 /* XXX: see notes in mdoc_it_pre(). */
874 if (MDOC_Column
== type
) {
875 /* Don't width-pad on the left. */
876 SCALE_HS_INIT(width
, 0);
877 /* Also disallow non-compact. */
880 if (MDOC_Diag
== type
)
881 /* Mandate non-compact with empty prior. */
882 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
885 bufcat_style(h
, "clear", "both");
887 bufcat_su(h
, "margin-left", offs
);
888 if (width
->scale
> 0)
889 bufcat_su(h
, "padding-left", width
);
891 PAIR_STYLE_INIT(&tag
, h
);
893 /* Mandate compact following `Ss' and `Sh' starts. */
895 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
896 if (MDOC_BLOCK
!= nn
->type
)
898 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
905 SCALE_VS_INIT(&su
, 1);
906 bufcat_su(h
, "padding-top", &su
);
909 PAIR_STYLE_INIT(&tag
, h
);
910 print_otag(h
, TAG_DIV
, 1, &tag
);
917 mdoc_it_body_pre(MDOC_ARGS
, int type
)
931 * XXX: this tricks CSS into aligning the bodies with
932 * the right-padding in the head.
934 SCALE_HS_INIT(&su
, 2);
935 bufcat_su(h
, "margin-left", &su
);
936 PAIR_STYLE_INIT(&tag
, h
);
937 print_otag(h
, TAG_DIV
, 1, &tag
);
947 mdoc_it_head_pre(MDOC_ARGS
, int type
, struct roffsu
*width
)
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. */
1076 SCALE_HS_INIT(&width
, 0);
1079 if (0 == width
.scale
)
1080 SCALE_HS_INIT(&width
, INDENT
);
1084 /* Flip to body/block processing. */
1086 if (MDOC_BODY
== n
->type
)
1087 return(mdoc_it_body_pre(m
, n
, h
, type
));
1088 if (MDOC_BLOCK
== n
->type
)
1089 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1092 /* Override column widths. */
1094 if (MDOC_Column
== type
) {
1095 nn
= n
->parent
->child
;
1096 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1098 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1099 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1102 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1108 mdoc_bl_pre(MDOC_ARGS
)
1112 if (MDOC_BLOCK
!= n
->type
)
1114 if (MDOC_Enum
!= a2list(n
))
1117 ord
= malloc(sizeof(struct ord
));
1119 err(EXIT_FAILURE
, "malloc");
1122 ord
->next
= h
->ords
.head
;
1130 mdoc_bl_post(MDOC_ARGS
)
1134 if (MDOC_BLOCK
!= n
->type
)
1136 if (MDOC_Enum
!= a2list(n
))
1141 h
->ords
.head
= ord
->next
;
1148 mdoc_ex_pre(MDOC_ARGS
)
1150 const struct mdoc_node
*nn
;
1152 struct htmlpair tag
;
1154 PAIR_CLASS_INIT(&tag
, "utility");
1156 print_text(h
, "The");
1157 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1158 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1159 print_text(h
, nn
->string
);
1162 h
->flags
|= HTML_NOSPACE
;
1164 if (nn
->next
&& NULL
== nn
->next
->next
)
1165 print_text(h
, ", and");
1169 h
->flags
&= ~HTML_NOSPACE
;
1173 print_text(h
, "utilities exit");
1175 print_text(h
, "utility exits");
1177 print_text(h
, "0 on success, and >0 if an error occurs.");
1184 mdoc_dq_pre(MDOC_ARGS
)
1187 if (MDOC_BODY
!= n
->type
)
1189 print_text(h
, "\\(lq");
1190 h
->flags
|= HTML_NOSPACE
;
1197 mdoc_dq_post(MDOC_ARGS
)
1200 if (MDOC_BODY
!= n
->type
)
1202 h
->flags
|= HTML_NOSPACE
;
1203 print_text(h
, "\\(rq");
1209 mdoc_pq_pre(MDOC_ARGS
)
1212 if (MDOC_BODY
!= n
->type
)
1214 print_text(h
, "\\&(");
1215 h
->flags
|= HTML_NOSPACE
;
1222 mdoc_pq_post(MDOC_ARGS
)
1225 if (MDOC_BODY
!= n
->type
)
1233 mdoc_sq_pre(MDOC_ARGS
)
1236 if (MDOC_BODY
!= n
->type
)
1238 print_text(h
, "\\(oq");
1239 h
->flags
|= HTML_NOSPACE
;
1246 mdoc_sq_post(MDOC_ARGS
)
1249 if (MDOC_BODY
!= n
->type
)
1251 h
->flags
|= HTML_NOSPACE
;
1252 print_text(h
, "\\(aq");
1258 mdoc_em_pre(MDOC_ARGS
)
1260 struct htmlpair tag
;
1262 PAIR_CLASS_INIT(&tag
, "emph");
1263 print_otag(h
, TAG_SPAN
, 1, &tag
);
1270 mdoc_d1_pre(MDOC_ARGS
)
1272 struct htmlpair tag
[2];
1275 if (MDOC_BLOCK
!= n
->type
)
1278 /* FIXME: D1 shouldn't be literal. */
1280 SCALE_VS_INIT(&su
, INDENT
- 2);
1281 bufcat_su(h
, "margin-left", &su
);
1282 PAIR_CLASS_INIT(&tag
[0], "lit");
1283 PAIR_STYLE_INIT(&tag
[1], h
);
1284 print_otag(h
, TAG_DIV
, 2, tag
);
1291 mdoc_sx_pre(MDOC_ARGS
)
1293 struct htmlpair tag
[2];
1294 const struct mdoc_node
*nn
;
1297 /* FIXME: duplicates? */
1299 strlcpy(buf
, "#", BUFSIZ
);
1300 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1301 html_idcat(buf
, nn
->string
, BUFSIZ
);
1303 html_idcat(buf
, " ", BUFSIZ
);
1306 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1307 tag
[1].key
= ATTR_HREF
;
1310 print_otag(h
, TAG_A
, 2, tag
);
1317 mdoc_aq_pre(MDOC_ARGS
)
1320 if (MDOC_BODY
!= n
->type
)
1322 print_text(h
, "\\(la");
1323 h
->flags
|= HTML_NOSPACE
;
1330 mdoc_aq_post(MDOC_ARGS
)
1333 if (MDOC_BODY
!= n
->type
)
1335 h
->flags
|= HTML_NOSPACE
;
1336 print_text(h
, "\\(ra");
1342 mdoc_bd_pre(MDOC_ARGS
)
1344 struct htmlpair tag
[2];
1346 const struct mdoc_node
*bl
, *nn
;
1349 if (MDOC_BLOCK
== n
->type
)
1351 else if (MDOC_HEAD
== n
->type
)
1356 SCALE_VS_INIT(&su
, 0);
1359 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1360 switch (bl
->args
->argv
[i
].arg
) {
1362 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1364 case (MDOC_Compact
):
1367 case (MDOC_Centred
):
1373 case (MDOC_Unfilled
):
1375 case (MDOC_Literal
):
1376 type
= bl
->args
->argv
[i
].arg
;
1382 /* FIXME: -centered, etc. formatting. */
1384 if (MDOC_BLOCK
== n
->type
) {
1385 bufcat_su(h
, "margin-left", &su
);
1386 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1387 if (MDOC_BLOCK
!= nn
->type
)
1389 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1395 print_otag(h
, TAG_DIV
, 0, tag
);
1398 SCALE_VS_INIT(&su
, 1);
1399 bufcat_su(h
, "margin-top", &su
);
1400 PAIR_STYLE_INIT(&tag
[0], h
);
1401 print_otag(h
, TAG_DIV
, 1, tag
);
1405 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1408 PAIR_CLASS_INIT(&tag
[0], "lit");
1409 bufcat_style(h
, "white-space", "pre");
1410 PAIR_STYLE_INIT(&tag
[1], h
);
1411 print_otag(h
, TAG_DIV
, 2, tag
);
1413 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1414 h
->flags
|= HTML_NOSPACE
;
1415 print_mdoc_node(m
, nn
, h
);
1416 if (NULL
== nn
->next
)
1418 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1419 print_text(h
, "\n");
1420 else if (NULL
== nn
->prev
)
1421 print_text(h
, "\n");
1430 mdoc_pa_pre(MDOC_ARGS
)
1432 struct htmlpair tag
;
1434 PAIR_CLASS_INIT(&tag
, "file");
1435 print_otag(h
, TAG_SPAN
, 1, &tag
);
1442 mdoc_ad_pre(MDOC_ARGS
)
1444 struct htmlpair tag
;
1446 PAIR_CLASS_INIT(&tag
, "addr");
1447 print_otag(h
, TAG_SPAN
, 1, &tag
);
1454 mdoc_an_pre(MDOC_ARGS
)
1456 struct htmlpair tag
;
1458 /* TODO: -split and -nosplit (see termp_an_pre()). */
1460 PAIR_CLASS_INIT(&tag
, "author");
1461 print_otag(h
, TAG_SPAN
, 1, &tag
);
1468 mdoc_cd_pre(MDOC_ARGS
)
1470 struct htmlpair tag
;
1472 print_otag(h
, TAG_DIV
, 0, NULL
);
1473 PAIR_CLASS_INIT(&tag
, "config");
1474 print_otag(h
, TAG_SPAN
, 1, &tag
);
1481 mdoc_dv_pre(MDOC_ARGS
)
1483 struct htmlpair tag
;
1485 PAIR_CLASS_INIT(&tag
, "define");
1486 print_otag(h
, TAG_SPAN
, 1, &tag
);
1493 mdoc_ev_pre(MDOC_ARGS
)
1495 struct htmlpair tag
;
1497 PAIR_CLASS_INIT(&tag
, "env");
1498 print_otag(h
, TAG_SPAN
, 1, &tag
);
1505 mdoc_er_pre(MDOC_ARGS
)
1507 struct htmlpair tag
;
1509 PAIR_CLASS_INIT(&tag
, "errno");
1510 print_otag(h
, TAG_SPAN
, 1, &tag
);
1517 mdoc_fa_pre(MDOC_ARGS
)
1519 const struct mdoc_node
*nn
;
1520 struct htmlpair tag
;
1523 PAIR_CLASS_INIT(&tag
, "farg");
1524 if (n
->parent
->tok
!= MDOC_Fo
) {
1525 print_otag(h
, TAG_SPAN
, 1, &tag
);
1529 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1530 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1531 print_text(h
, nn
->string
);
1537 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1546 mdoc_fd_pre(MDOC_ARGS
)
1548 struct htmlpair tag
;
1551 if (SEC_SYNOPSIS
== n
->sec
) {
1552 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1553 SCALE_VS_INIT(&su
, 1);
1554 bufcat_su(h
, "margin-bottom", &su
);
1555 PAIR_STYLE_INIT(&tag
, h
);
1556 print_otag(h
, TAG_DIV
, 1, &tag
);
1558 print_otag(h
, TAG_DIV
, 0, NULL
);
1561 PAIR_CLASS_INIT(&tag
, "macro");
1562 print_otag(h
, TAG_SPAN
, 1, &tag
);
1569 mdoc_vt_pre(MDOC_ARGS
)
1571 struct htmlpair tag
;
1574 if (SEC_SYNOPSIS
== n
->sec
) {
1575 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1576 SCALE_VS_INIT(&su
, 1);
1577 bufcat_su(h
, "margin-bottom", &su
);
1578 PAIR_STYLE_INIT(&tag
, h
);
1579 print_otag(h
, TAG_DIV
, 1, &tag
);
1581 print_otag(h
, TAG_DIV
, 0, NULL
);
1584 PAIR_CLASS_INIT(&tag
, "type");
1585 print_otag(h
, TAG_SPAN
, 1, &tag
);
1592 mdoc_ft_pre(MDOC_ARGS
)
1594 struct htmlpair tag
;
1597 if (SEC_SYNOPSIS
== n
->sec
) {
1598 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1599 SCALE_VS_INIT(&su
, 1);
1600 bufcat_su(h
, "margin-top", &su
);
1601 PAIR_STYLE_INIT(&tag
, h
);
1602 print_otag(h
, TAG_DIV
, 1, &tag
);
1604 print_otag(h
, TAG_DIV
, 0, NULL
);
1607 PAIR_CLASS_INIT(&tag
, "ftype");
1608 print_otag(h
, TAG_SPAN
, 1, &tag
);
1615 mdoc_fn_pre(MDOC_ARGS
)
1618 struct htmlpair tag
[2];
1619 const struct mdoc_node
*nn
;
1621 const char *sp
, *ep
;
1625 if (SEC_SYNOPSIS
== n
->sec
) {
1626 SCALE_HS_INIT(&su
, INDENT
);
1627 bufcat_su(h
, "margin-left", &su
);
1628 su
.scale
= -su
.scale
;
1629 bufcat_su(h
, "text-indent", &su
);
1631 SCALE_VS_INIT(&su
, 1);
1632 bufcat_su(h
, "margin-bottom", &su
);
1634 PAIR_STYLE_INIT(&tag
[0], h
);
1635 print_otag(h
, TAG_DIV
, 1, tag
);
1638 /* Split apart into type and name. */
1639 assert(n
->child
->string
);
1640 sp
= n
->child
->string
;
1642 ep
= strchr(sp
, ' ');
1644 PAIR_CLASS_INIT(&tag
[0], "ftype");
1645 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1648 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1649 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1651 print_text(h
, nbuf
);
1653 ep
= strchr(sp
, ' ');
1658 PAIR_CLASS_INIT(&tag
[0], "fname");
1659 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1662 (void)strlcpy(nbuf
, sp
, BUFSIZ
);
1663 print_text(h
, nbuf
);
1668 h
->flags
|= HTML_NOSPACE
;
1672 PAIR_CLASS_INIT(&tag
[0], "farg");
1673 bufcat_style(h
, "white-space", "nowrap");
1674 PAIR_STYLE_INIT(&tag
[1], h
);
1676 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1678 if (SEC_SYNOPSIS
== n
->sec
)
1680 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1681 print_text(h
, nn
->string
);
1688 if (SEC_SYNOPSIS
== n
->sec
)
1697 mdoc_sp_pre(MDOC_ARGS
)
1700 struct htmlpair tag
;
1705 /* FIXME: can this have a scaling indicator? */
1706 len
= n
->child
? atoi(n
->child
->string
) : 1;
1716 SCALE_VS_INIT(&su
, len
);
1717 bufcat_su(h
, "height", &su
);
1718 PAIR_STYLE_INIT(&tag
, h
);
1719 print_otag(h
, TAG_DIV
, 1, &tag
);
1720 /* So the div isn't empty: */
1721 print_text(h
, "\\~");
1730 mdoc_brq_pre(MDOC_ARGS
)
1733 if (MDOC_BODY
!= n
->type
)
1735 print_text(h
, "\\(lC");
1736 h
->flags
|= HTML_NOSPACE
;
1743 mdoc_brq_post(MDOC_ARGS
)
1746 if (MDOC_BODY
!= n
->type
)
1748 h
->flags
|= HTML_NOSPACE
;
1749 print_text(h
, "\\(rC");
1755 mdoc_lk_pre(MDOC_ARGS
)
1757 const struct mdoc_node
*nn
;
1758 struct htmlpair tag
[2];
1762 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1763 tag
[1].key
= ATTR_HREF
;
1764 tag
[1].val
= nn
->string
;
1765 print_otag(h
, TAG_A
, 2, tag
);
1767 if (NULL
== nn
->next
)
1770 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1771 print_text(h
, nn
->string
);
1779 mdoc_mt_pre(MDOC_ARGS
)
1781 struct htmlpair tag
[2];
1783 const struct mdoc_node
*nn
;
1785 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1787 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1789 bufcat(h
, "mailto:");
1790 bufcat(h
, nn
->string
);
1791 PAIR_STYLE_INIT(&tag
[1], h
);
1792 t
= print_otag(h
, TAG_A
, 2, tag
);
1793 print_text(h
, nn
->string
);
1803 mdoc_fo_pre(MDOC_ARGS
)
1805 struct htmlpair tag
;
1807 if (MDOC_BODY
== n
->type
) {
1808 h
->flags
|= HTML_NOSPACE
;
1810 h
->flags
|= HTML_NOSPACE
;
1812 } else if (MDOC_BLOCK
== n
->type
)
1815 PAIR_CLASS_INIT(&tag
, "fname");
1816 print_otag(h
, TAG_SPAN
, 1, &tag
);
1823 mdoc_fo_post(MDOC_ARGS
)
1825 if (MDOC_BODY
!= n
->type
)
1827 h
->flags
|= HTML_NOSPACE
;
1829 h
->flags
|= HTML_NOSPACE
;
1836 mdoc_in_pre(MDOC_ARGS
)
1838 const struct mdoc_node
*nn
;
1840 struct htmlpair tag
[2];
1844 if (SEC_SYNOPSIS
== n
->sec
) {
1845 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1846 SCALE_VS_INIT(&su
, 1);
1847 bufcat_su(h
, "margin-bottom", &su
);
1848 PAIR_STYLE_INIT(&tag
[0], h
);
1849 print_otag(h
, TAG_DIV
, 1, tag
);
1851 print_otag(h
, TAG_DIV
, 0, NULL
);
1854 /* FIXME: there's a buffer bug in here somewhere. */
1856 PAIR_CLASS_INIT(&tag
[0], "includes");
1857 print_otag(h
, TAG_SPAN
, 1, tag
);
1859 if (SEC_SYNOPSIS
== n
->sec
)
1860 print_text(h
, "#include");
1863 h
->flags
|= HTML_NOSPACE
;
1865 /* XXX -- see warning in termp_in_post(). */
1867 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1868 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1871 if (h
->base_includes
) {
1872 buffmt_includes(h
, nn
->string
);
1873 tag
[i
].key
= ATTR_HREF
;
1874 tag
[i
++].val
= h
->buf
;
1876 t
= print_otag(h
, TAG_A
, i
, tag
);
1877 print_mdoc_node(m
, nn
, h
);
1881 h
->flags
|= HTML_NOSPACE
;
1890 mdoc_ic_pre(MDOC_ARGS
)
1892 struct htmlpair tag
;
1894 PAIR_CLASS_INIT(&tag
, "cmd");
1895 print_otag(h
, TAG_SPAN
, 1, &tag
);
1902 mdoc_rv_pre(MDOC_ARGS
)
1904 const struct mdoc_node
*nn
;
1905 struct htmlpair tag
;
1908 print_otag(h
, TAG_DIV
, 0, NULL
);
1909 print_text(h
, "The");
1911 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1912 PAIR_CLASS_INIT(&tag
, "fname");
1913 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1914 print_text(h
, nn
->string
);
1917 h
->flags
|= HTML_NOSPACE
;
1918 if (nn
->next
&& NULL
== nn
->next
->next
)
1919 print_text(h
, "(), and");
1921 print_text(h
, "(),");
1923 print_text(h
, "()");
1927 print_text(h
, "functions return");
1929 print_text(h
, "function returns");
1931 print_text(h
, "the value 0 if successful; otherwise the value "
1932 "-1 is returned and the global variable");
1934 PAIR_CLASS_INIT(&tag
, "var");
1935 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1936 print_text(h
, "errno");
1938 print_text(h
, "is set to indicate the error.");
1945 mdoc_va_pre(MDOC_ARGS
)
1947 struct htmlpair tag
;
1949 PAIR_CLASS_INIT(&tag
, "var");
1950 print_otag(h
, TAG_SPAN
, 1, &tag
);
1957 mdoc_bq_pre(MDOC_ARGS
)
1960 if (MDOC_BODY
!= n
->type
)
1962 print_text(h
, "\\(lB");
1963 h
->flags
|= HTML_NOSPACE
;
1970 mdoc_bq_post(MDOC_ARGS
)
1973 if (MDOC_BODY
!= n
->type
)
1975 h
->flags
|= HTML_NOSPACE
;
1976 print_text(h
, "\\(rB");
1982 mdoc_ap_pre(MDOC_ARGS
)
1985 h
->flags
|= HTML_NOSPACE
;
1986 print_text(h
, "\\(aq");
1987 h
->flags
|= HTML_NOSPACE
;
1994 mdoc_bf_pre(MDOC_ARGS
)
1997 struct htmlpair tag
[2];
2000 if (MDOC_HEAD
== n
->type
)
2002 else if (MDOC_BLOCK
!= n
->type
)
2005 PAIR_CLASS_INIT(&tag
[0], "lit");
2007 if (n
->head
->child
) {
2008 if ( ! strcmp("Em", n
->head
->child
->string
))
2009 PAIR_CLASS_INIT(&tag
[0], "emph");
2010 else if ( ! strcmp("Sy", n
->head
->child
->string
))
2011 PAIR_CLASS_INIT(&tag
[0], "symb");
2012 else if ( ! strcmp("Li", n
->head
->child
->string
))
2013 PAIR_CLASS_INIT(&tag
[0], "lit");
2016 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2017 switch (n
->args
->argv
[i
].arg
) {
2018 case (MDOC_Symbolic
):
2019 PAIR_CLASS_INIT(&tag
[0], "symb");
2021 case (MDOC_Literal
):
2022 PAIR_CLASS_INIT(&tag
[0], "lit");
2024 case (MDOC_Emphasis
):
2025 PAIR_CLASS_INIT(&tag
[0], "emph");
2032 /* FIXME: div's have spaces stripped--we want them. */
2034 bufcat_style(h
, "display", "inline");
2035 SCALE_HS_INIT(&su
, 1);
2036 bufcat_su(h
, "margin-right", &su
);
2037 PAIR_STYLE_INIT(&tag
[1], h
);
2038 print_otag(h
, TAG_DIV
, 2, tag
);
2045 mdoc_ms_pre(MDOC_ARGS
)
2047 struct htmlpair tag
;
2049 PAIR_CLASS_INIT(&tag
, "symb");
2050 print_otag(h
, TAG_SPAN
, 1, &tag
);
2057 mdoc_pf_pre(MDOC_ARGS
)
2060 h
->flags
|= HTML_IGNDELIM
;
2067 mdoc_pf_post(MDOC_ARGS
)
2070 h
->flags
&= ~HTML_IGNDELIM
;
2071 h
->flags
|= HTML_NOSPACE
;
2077 mdoc_rs_pre(MDOC_ARGS
)
2079 struct htmlpair tag
;
2082 if (MDOC_BLOCK
!= n
->type
)
2085 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2086 SCALE_VS_INIT(&su
, 1);
2087 bufcat_su(h
, "margin-top", &su
);
2088 PAIR_STYLE_INIT(&tag
, h
);
2089 print_otag(h
, TAG_DIV
, 1, &tag
);
2092 PAIR_CLASS_INIT(&tag
, "ref");
2093 print_otag(h
, TAG_SPAN
, 1, &tag
);
2101 mdoc_li_pre(MDOC_ARGS
)
2103 struct htmlpair tag
;
2105 PAIR_CLASS_INIT(&tag
, "lit");
2106 print_otag(h
, TAG_SPAN
, 1, &tag
);
2113 mdoc_sy_pre(MDOC_ARGS
)
2115 struct htmlpair tag
;
2117 PAIR_CLASS_INIT(&tag
, "symb");
2118 print_otag(h
, TAG_SPAN
, 1, &tag
);
2125 mdoc_bt_pre(MDOC_ARGS
)
2128 print_text(h
, "is currently in beta test.");
2135 mdoc_ud_pre(MDOC_ARGS
)
2138 print_text(h
, "currently under development.");
2145 mdoc_lb_pre(MDOC_ARGS
)
2147 struct htmlpair tag
;
2149 if (SEC_SYNOPSIS
== n
->sec
)
2150 print_otag(h
, TAG_DIV
, 0, NULL
);
2151 PAIR_CLASS_INIT(&tag
, "lib");
2152 print_otag(h
, TAG_SPAN
, 1, &tag
);
2159 mdoc__x_pre(MDOC_ARGS
)
2161 struct htmlpair tag
[2];
2165 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2168 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2171 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2174 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2177 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2180 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2183 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2186 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2189 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2192 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2195 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2198 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2199 print_text(h
, "\\(lq");
2200 h
->flags
|= HTML_NOSPACE
;
2203 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2206 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2213 if (MDOC__U
!= n
->tok
) {
2214 print_otag(h
, TAG_SPAN
, 1, tag
);
2218 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2219 print_otag(h
, TAG_A
, 2, tag
);
2226 mdoc__x_post(MDOC_ARGS
)
2229 h
->flags
|= HTML_NOSPACE
;
2232 print_text(h
, "\\(rq");
2233 h
->flags
|= HTML_NOSPACE
;
2238 print_text(h
, n
->next
? "," : ".");