]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.24 2009/10/07 14:39:00 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>
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
*);
52 static int a2list(const struct mdoc_node
*);
54 static void mdoc_root_post(MDOC_ARGS
);
55 static int mdoc_root_pre(MDOC_ARGS
);
56 static int mdoc_it_block_pre(MDOC_ARGS
, int,
59 static int mdoc_it_head_pre(MDOC_ARGS
, int,
61 static int mdoc_it_body_pre(MDOC_ARGS
, int);
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_ad_pre(MDOC_ARGS
);
66 static int mdoc_an_pre(MDOC_ARGS
);
67 static int mdoc_ap_pre(MDOC_ARGS
);
68 static void mdoc_aq_post(MDOC_ARGS
);
69 static int mdoc_aq_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bl_post(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static void mdoc_bq_post(MDOC_ARGS
);
76 static int mdoc_bq_pre(MDOC_ARGS
);
77 static void mdoc_brq_post(MDOC_ARGS
);
78 static int mdoc_brq_pre(MDOC_ARGS
);
79 static int mdoc_bt_pre(MDOC_ARGS
);
80 static int mdoc_bx_pre(MDOC_ARGS
);
81 static int mdoc_cd_pre(MDOC_ARGS
);
82 static int mdoc_d1_pre(MDOC_ARGS
);
83 static void mdoc_dq_post(MDOC_ARGS
);
84 static int mdoc_dq_pre(MDOC_ARGS
);
85 static int mdoc_dv_pre(MDOC_ARGS
);
86 static int mdoc_fa_pre(MDOC_ARGS
);
87 static int mdoc_fd_pre(MDOC_ARGS
);
88 static int mdoc_fl_pre(MDOC_ARGS
);
89 static int mdoc_fn_pre(MDOC_ARGS
);
90 static int mdoc_ft_pre(MDOC_ARGS
);
91 static int mdoc_em_pre(MDOC_ARGS
);
92 static int mdoc_er_pre(MDOC_ARGS
);
93 static int mdoc_ev_pre(MDOC_ARGS
);
94 static int mdoc_ex_pre(MDOC_ARGS
);
95 static void mdoc_fo_post(MDOC_ARGS
);
96 static int mdoc_fo_pre(MDOC_ARGS
);
97 static int mdoc_ic_pre(MDOC_ARGS
);
98 static int mdoc_in_pre(MDOC_ARGS
);
99 static int mdoc_it_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 */
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
)
332 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 if (0 == strcmp(p
, "left"))
346 SCALE_HS_INIT(su
, 0);
347 else if (0 == strcmp(p
, "indent"))
348 SCALE_HS_INIT(su
, INDENT
);
349 else if (0 == strcmp(p
, "indent-two"))
350 SCALE_HS_INIT(su
, INDENT
* 2);
351 else if ( ! a2roffsu(p
, su
)) {
353 su
->scale
= (int)strlen(p
);
359 print_mdoc(MDOC_ARGS
)
364 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
365 print_mdoc_head(m
, n
, h
);
368 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
370 tag
.key
= ATTR_CLASS
;
372 print_otag(h
, TAG_DIV
, 1, &tag
);
374 print_mdoc_nodelist(m
, n
, h
);
381 print_mdoc_head(MDOC_ARGS
)
386 buffmt(h
, "%s(%d)", m
->title
, m
->msec
);
394 print_otag(h
, TAG_TITLE
, 0, NULL
);
395 print_text(h
, h
->buf
);
400 print_mdoc_nodelist(MDOC_ARGS
)
403 print_mdoc_node(m
, n
, h
);
405 print_mdoc_nodelist(m
, n
->next
, h
);
410 print_mdoc_node(MDOC_ARGS
)
416 t
= SLIST_FIRST(&h
->tags
);
421 child
= mdoc_root_pre(m
, n
, h
);
424 print_text(h
, n
->string
);
427 if (mdocs
[n
->tok
].pre
)
428 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
432 if (child
&& n
->child
)
433 print_mdoc_nodelist(m
, n
->child
, h
);
440 mdoc_root_post(m
, n
, h
);
445 if (mdocs
[n
->tok
].post
)
446 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
454 mdoc_root_post(MDOC_ARGS
)
457 struct htmlpair tag
[2];
462 * XXX: this should use divs, but in Firefox, divs with nested
463 * divs for some reason puke when trying to put a border line
464 * below. So I use tables, instead.
467 (void)localtime_r(&m
->date
, &tm
);
469 if (0 == strftime(b
, BUFSIZ
- 1, "%B %e, %Y", &tm
))
470 err(EXIT_FAILURE
, "strftime");
472 PAIR_CLASS_INIT(&tag
[0], "footer");
473 bufcat_style(h
, "width", "100%");
474 PAIR_STYLE_INIT(&tag
[1], h
);
475 t
= print_otag(h
, TAG_TABLE
, 2, 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
[2];
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 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
520 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
523 bufcat_style(h
, "width", "10%");
524 PAIR_STYLE_INIT(&tag
[0], h
);
525 print_otag(h
, TAG_TD
, 1, tag
);
526 print_text(h
, title
);
530 bufcat_style(h
, "text-align", "center");
531 bufcat_style(h
, "white-space", "nowrap");
532 bufcat_style(h
, "width", "80%");
533 PAIR_STYLE_INIT(&tag
[0], h
);
534 print_otag(h
, TAG_TD
, 1, tag
);
539 bufcat_style(h
, "text-align", "right");
540 bufcat_style(h
, "width", "10%");
541 PAIR_STYLE_INIT(&tag
[0], h
);
542 print_otag(h
, TAG_TD
, 1, tag
);
543 print_text(h
, title
);
551 mdoc_sh_pre(MDOC_ARGS
)
553 struct htmlpair tag
[2];
554 const struct mdoc_node
*nn
;
558 if (MDOC_BODY
== n
->type
) {
559 SCALE_HS_INIT(&su
, INDENT
);
560 bufcat_su(h
, "margin-left", &su
);
561 PAIR_CLASS_INIT(&tag
[0], "sec-body");
562 PAIR_STYLE_INIT(&tag
[1], h
);
563 print_otag(h
, TAG_DIV
, 2, tag
);
565 } else if (MDOC_BLOCK
== n
->type
) {
566 PAIR_CLASS_INIT(&tag
[0], "sec-block");
567 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
568 print_otag(h
, TAG_DIV
, 1, tag
);
572 SCALE_VS_INIT(&su
, 1);
573 bufcat_su(h
, "margin-top", &su
);
575 bufcat_su(h
, "margin-bottom", &su
);
577 PAIR_STYLE_INIT(&tag
[1], h
);
578 print_otag(h
, TAG_DIV
, 2, tag
);
583 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
584 (void)strlcat(link
, nn
->string
, BUFSIZ
);
586 (void)strlcat(link
, "_", BUFSIZ
);
590 * TODO: make sure there are no duplicates, as HTML does not
591 * allow for multiple `id' tags of the same name.
594 PAIR_CLASS_INIT(&tag
[0], "sec-head");
595 tag
[1].key
= ATTR_ID
;
597 print_otag(h
, TAG_DIV
, 2, tag
);
604 mdoc_ss_pre(MDOC_ARGS
)
606 struct htmlpair tag
[3];
607 const struct mdoc_node
*nn
;
611 SCALE_VS_INIT(&su
, 1);
613 if (MDOC_BODY
== n
->type
) {
614 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
615 if (n
->parent
->next
&& n
->child
) {
616 bufcat_su(h
, "margin-bottom", &su
);
617 PAIR_STYLE_INIT(&tag
[1], h
);
618 print_otag(h
, TAG_DIV
, 2, tag
);
620 print_otag(h
, TAG_DIV
, 1, tag
);
622 } else if (MDOC_BLOCK
== n
->type
) {
623 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
625 bufcat_su(h
, "margin-top", &su
);
626 PAIR_STYLE_INIT(&tag
[1], h
);
627 print_otag(h
, TAG_DIV
, 2, tag
);
629 print_otag(h
, TAG_DIV
, 1, tag
);
633 /* TODO: see note in mdoc_sh_pre() about duplicates. */
636 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
637 (void)strlcat(link
, nn
->string
, BUFSIZ
);
639 (void)strlcat(link
, "_", BUFSIZ
);
642 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
643 su
.scale
= -su
.scale
;
644 bufcat_su(h
, "margin-left", &su
);
646 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
647 PAIR_STYLE_INIT(&tag
[1], h
);
648 tag
[2].key
= ATTR_ID
;
650 print_otag(h
, TAG_DIV
, 3, tag
);
657 mdoc_fl_pre(MDOC_ARGS
)
661 PAIR_CLASS_INIT(&tag
, "flag");
662 print_otag(h
, TAG_SPAN
, 1, &tag
);
663 if (MDOC_Fl
== n
->tok
) {
664 print_text(h
, "\\-");
665 h
->flags
|= HTML_NOSPACE
;
673 mdoc_nd_pre(MDOC_ARGS
)
677 if (MDOC_BODY
!= n
->type
)
680 /* XXX: this tag in theory can contain block elements. */
682 print_text(h
, "\\(em");
683 PAIR_CLASS_INIT(&tag
, "desc-body");
684 print_otag(h
, TAG_SPAN
, 1, &tag
);
691 mdoc_op_pre(MDOC_ARGS
)
695 if (MDOC_BODY
!= n
->type
)
698 /* XXX: this tag in theory can contain block elements. */
700 print_text(h
, "\\(lB");
701 h
->flags
|= HTML_NOSPACE
;
702 PAIR_CLASS_INIT(&tag
, "opt");
703 print_otag(h
, TAG_SPAN
, 1, &tag
);
710 mdoc_op_post(MDOC_ARGS
)
713 if (MDOC_BODY
!= n
->type
)
715 h
->flags
|= HTML_NOSPACE
;
716 print_text(h
, "\\(rB");
721 mdoc_nm_pre(MDOC_ARGS
)
725 if ( ! (HTML_NEWLINE
& h
->flags
))
726 if (SEC_SYNOPSIS
== n
->sec
) {
727 bufcat_style(h
, "clear", "both");
728 PAIR_STYLE_INIT(&tag
, h
);
729 print_otag(h
, TAG_BR
, 1, &tag
);
732 PAIR_CLASS_INIT(&tag
, "name");
733 print_otag(h
, TAG_SPAN
, 1, &tag
);
734 if (NULL
== n
->child
)
735 print_text(h
, m
->name
);
743 mdoc_xr_pre(MDOC_ARGS
)
745 struct htmlpair tag
[2];
746 const struct mdoc_node
*nn
;
748 PAIR_CLASS_INIT(&tag
[0], "link-man");
751 buffmt_man(h
, n
->child
->string
,
753 n
->child
->next
->string
: NULL
);
754 tag
[1].key
= ATTR_HREF
;
756 print_otag(h
, TAG_A
, 2, tag
);
758 print_otag(h
, TAG_A
, 1, tag
);
761 print_text(h
, nn
->string
);
763 if (NULL
== (nn
= nn
->next
))
766 h
->flags
|= HTML_NOSPACE
;
768 h
->flags
|= HTML_NOSPACE
;
769 print_text(h
, nn
->string
);
770 h
->flags
|= HTML_NOSPACE
;
778 mdoc_ns_pre(MDOC_ARGS
)
781 h
->flags
|= HTML_NOSPACE
;
788 mdoc_ar_pre(MDOC_ARGS
)
792 PAIR_CLASS_INIT(&tag
, "arg");
793 print_otag(h
, TAG_SPAN
, 1, &tag
);
800 mdoc_xx_pre(MDOC_ARGS
)
828 PAIR_CLASS_INIT(&tag
, "unix");
829 print_otag(h
, TAG_SPAN
, 1, &tag
);
837 mdoc_bx_pre(MDOC_ARGS
)
839 const struct mdoc_node
*nn
;
842 PAIR_CLASS_INIT(&tag
, "unix");
843 print_otag(h
, TAG_SPAN
, 1, &tag
);
845 for (nn
= n
->child
; nn
; nn
= nn
->next
)
846 print_mdoc_node(m
, nn
, h
);
849 h
->flags
|= HTML_NOSPACE
;
851 print_text(h
, "BSD");
858 mdoc_it_block_pre(MDOC_ARGS
, int type
, struct roffsu
*offs
,
859 int comp
, struct roffsu
*width
)
862 const struct mdoc_node
*nn
;
865 nn
= n
->parent
->parent
;
868 /* XXX: see notes in mdoc_it_pre(). */
870 if (MDOC_Column
== type
) {
871 /* Don't width-pad on the left. */
872 SCALE_HS_INIT(width
, 0);
873 /* Also disallow non-compact. */
876 if (MDOC_Diag
== type
)
877 /* Mandate non-compact with empty prior. */
878 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
881 bufcat_style(h
, "clear", "both");
883 bufcat_su(h
, "margin-left", offs
);
884 if (width
->scale
> 0)
885 bufcat_su(h
, "padding-left", width
);
887 PAIR_STYLE_INIT(&tag
, h
);
889 /* Mandate compact following `Ss' and `Sh' starts. */
891 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
892 if (MDOC_BLOCK
!= nn
->type
)
894 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
901 SCALE_VS_INIT(&su
, 1);
902 bufcat_su(h
, "padding-top", &su
);
905 PAIR_STYLE_INIT(&tag
, h
);
906 print_otag(h
, TAG_DIV
, 1, &tag
);
912 mdoc_it_body_pre(MDOC_ARGS
, int type
)
926 * XXX: this tricks CSS into aligning the bodies with
927 * the right-padding in the head.
929 SCALE_HS_INIT(&su
, 2);
930 bufcat_su(h
, "margin-left", &su
);
931 PAIR_STYLE_INIT(&tag
, h
);
932 print_otag(h
, TAG_DIV
, 1, &tag
);
941 mdoc_it_head_pre(MDOC_ARGS
, int type
, struct roffsu
*width
)
951 print_otag(h
, TAG_DIV
, 0, NULL
);
954 bufcat_su(h
, "min-width", width
);
955 bufcat_style(h
, "clear", "none");
956 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
957 bufcat_style(h
, "float", "left");
958 PAIR_STYLE_INIT(&tag
, h
);
959 print_otag(h
, TAG_DIV
, 1, &tag
);
962 bufcat_su(h
, "min-width", width
);
964 bufcat_su(h
, "margin-left", width
);
965 if (n
->next
&& n
->next
->child
)
966 bufcat_style(h
, "float", "left");
968 /* XXX: buffer if we run into body. */
969 SCALE_HS_INIT(width
, 1);
970 bufcat_su(h
, "margin-right", width
);
971 PAIR_STYLE_INIT(&tag
, h
);
972 print_otag(h
, TAG_DIV
, 1, &tag
);
978 PAIR_CLASS_INIT(&tag
, "diag");
979 print_otag(h
, TAG_SPAN
, 1, &tag
);
982 ord
= SLIST_FIRST(&h
->ords
);
984 nbuf
[BUFSIZ
- 1] = 0;
985 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
989 print_text(h
, "\\(en");
992 print_text(h
, "\\(hy");
995 print_text(h
, "\\(bu");
1006 mdoc_it_pre(MDOC_ARGS
)
1008 int i
, type
, wp
, comp
;
1009 const struct mdoc_node
*bl
, *nn
;
1010 struct roffsu width
, offs
;
1013 * XXX: be very careful in changing anything, here. Lists in
1014 * mandoc have many peculiarities; furthermore, they don't
1015 * translate well into HTML and require a bit of mangling.
1018 bl
= n
->parent
->parent
;
1019 if (MDOC_BLOCK
!= n
->type
)
1024 /* Set default width and offset. */
1026 SCALE_HS_INIT(&offs
, 0);
1036 SCALE_HS_INIT(&width
, 2);
1039 SCALE_HS_INIT(&width
, INDENT
);
1043 /* Get width, offset, and compact arguments. */
1045 for (wp
= -1, comp
= i
= 0; i
< (int)bl
->args
->argc
; i
++)
1046 switch (bl
->args
->argv
[i
].arg
) {
1048 wp
= i
; /* Save for later. */
1051 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1054 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1056 case (MDOC_Compact
):
1063 /* Override width in some cases. */
1069 SCALE_HS_INIT(&width
, 0);
1072 if (0 == width
.scale
)
1073 SCALE_HS_INIT(&width
, INDENT
);
1077 /* Flip to body/block processing. */
1079 if (MDOC_BODY
== n
->type
)
1080 return(mdoc_it_body_pre(m
, n
, h
, type
));
1081 if (MDOC_BLOCK
== n
->type
)
1082 return(mdoc_it_block_pre(m
, n
, h
, type
,
1083 &offs
, comp
, &width
));
1085 /* Override column widths. */
1087 if (MDOC_Column
== type
) {
1088 nn
= n
->parent
->child
;
1089 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1091 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1092 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1095 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1101 mdoc_bl_pre(MDOC_ARGS
)
1105 if (MDOC_BLOCK
!= n
->type
)
1107 if (MDOC_Enum
!= a2list(n
))
1110 ord
= malloc(sizeof(struct ord
));
1112 err(EXIT_FAILURE
, "malloc");
1115 SLIST_INSERT_HEAD(&h
->ords
, ord
, entry
);
1122 mdoc_bl_post(MDOC_ARGS
)
1126 if (MDOC_BLOCK
!= n
->type
)
1128 if (MDOC_Enum
!= a2list(n
))
1131 ord
= SLIST_FIRST(&h
->ords
);
1133 SLIST_REMOVE_HEAD(&h
->ords
, entry
);
1140 mdoc_ex_pre(MDOC_ARGS
)
1142 const struct mdoc_node
*nn
;
1144 struct htmlpair tag
;
1146 PAIR_CLASS_INIT(&tag
, "utility");
1148 print_text(h
, "The");
1149 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1150 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1151 print_text(h
, nn
->string
);
1154 h
->flags
|= HTML_NOSPACE
;
1156 if (nn
->next
&& NULL
== nn
->next
->next
)
1157 print_text(h
, ", and");
1161 h
->flags
&= ~HTML_NOSPACE
;
1165 print_text(h
, "utilities exit");
1167 print_text(h
, "utility exits");
1169 print_text(h
, "0 on success, and >0 if an error occurs.");
1176 mdoc_dq_pre(MDOC_ARGS
)
1179 if (MDOC_BODY
!= n
->type
)
1181 print_text(h
, "\\(lq");
1182 h
->flags
|= HTML_NOSPACE
;
1189 mdoc_dq_post(MDOC_ARGS
)
1192 if (MDOC_BODY
!= n
->type
)
1194 h
->flags
|= HTML_NOSPACE
;
1195 print_text(h
, "\\(rq");
1201 mdoc_pq_pre(MDOC_ARGS
)
1204 if (MDOC_BODY
!= n
->type
)
1206 print_text(h
, "\\&(");
1207 h
->flags
|= HTML_NOSPACE
;
1214 mdoc_pq_post(MDOC_ARGS
)
1217 if (MDOC_BODY
!= n
->type
)
1225 mdoc_sq_pre(MDOC_ARGS
)
1228 if (MDOC_BODY
!= n
->type
)
1230 print_text(h
, "\\(oq");
1231 h
->flags
|= HTML_NOSPACE
;
1238 mdoc_sq_post(MDOC_ARGS
)
1241 if (MDOC_BODY
!= n
->type
)
1243 h
->flags
|= HTML_NOSPACE
;
1244 print_text(h
, "\\(aq");
1250 mdoc_em_pre(MDOC_ARGS
)
1252 struct htmlpair tag
;
1254 PAIR_CLASS_INIT(&tag
, "emph");
1255 print_otag(h
, TAG_SPAN
, 1, &tag
);
1262 mdoc_d1_pre(MDOC_ARGS
)
1264 struct htmlpair tag
[2];
1267 if (MDOC_BLOCK
!= n
->type
)
1270 SCALE_VS_INIT(&su
, INDENT
- 2);
1271 bufcat_su(h
, "margin-left", &su
);
1272 PAIR_CLASS_INIT(&tag
[0], "lit");
1273 PAIR_STYLE_INIT(&tag
[1], h
);
1274 print_otag(h
, TAG_DIV
, 2, tag
);
1281 mdoc_sx_pre(MDOC_ARGS
)
1283 struct htmlpair tag
[2];
1284 const struct mdoc_node
*nn
;
1287 /* FIXME: duplicates? */
1289 (void)strlcpy(link
, "#", BUFSIZ
);
1290 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1291 (void)strlcat(link
, nn
->string
, BUFSIZ
);
1293 (void)strlcat(link
, "_", BUFSIZ
);
1296 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1297 tag
[1].key
= ATTR_HREF
;
1300 print_otag(h
, TAG_A
, 2, tag
);
1307 mdoc_aq_pre(MDOC_ARGS
)
1310 if (MDOC_BODY
!= n
->type
)
1312 print_text(h
, "\\(la");
1313 h
->flags
|= HTML_NOSPACE
;
1320 mdoc_aq_post(MDOC_ARGS
)
1323 if (MDOC_BODY
!= n
->type
)
1325 h
->flags
|= HTML_NOSPACE
;
1326 print_text(h
, "\\(ra");
1332 mdoc_bd_pre(MDOC_ARGS
)
1334 struct htmlpair tag
[2];
1336 const struct mdoc_node
*bl
, *nn
;
1339 if (MDOC_BLOCK
== n
->type
)
1341 else if (MDOC_HEAD
== n
->type
)
1346 SCALE_VS_INIT(&su
, 0);
1349 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1350 switch (bl
->args
->argv
[i
].arg
) {
1352 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1354 case (MDOC_Compact
):
1361 case (MDOC_Unfilled
):
1363 case (MDOC_Literal
):
1364 type
= bl
->args
->argv
[i
].arg
;
1368 if (MDOC_BLOCK
== n
->type
) {
1369 bufcat_su(h
, "margin-left", &su
);
1370 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1371 if (MDOC_BLOCK
!= nn
->type
)
1373 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1379 print_otag(h
, TAG_DIV
, 0, tag
);
1382 SCALE_VS_INIT(&su
, 1);
1383 bufcat_su(h
, "margin-top", &su
);
1384 PAIR_STYLE_INIT(&tag
[0], h
);
1385 print_otag(h
, TAG_DIV
, 1, tag
);
1389 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1392 PAIR_CLASS_INIT(&tag
[0], "lit");
1393 bufcat_style(h
, "white-space", "pre");
1394 PAIR_STYLE_INIT(&tag
[1], h
);
1395 print_otag(h
, TAG_DIV
, 2, tag
);
1397 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1398 h
->flags
|= HTML_NOSPACE
;
1399 print_mdoc_node(m
, nn
, h
);
1400 if (NULL
== nn
->next
)
1402 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1403 print_text(h
, "\n");
1404 else if (NULL
== nn
->prev
)
1405 print_text(h
, "\n");
1414 mdoc_pa_pre(MDOC_ARGS
)
1416 struct htmlpair tag
;
1418 PAIR_CLASS_INIT(&tag
, "file");
1419 print_otag(h
, TAG_SPAN
, 1, &tag
);
1426 mdoc_ad_pre(MDOC_ARGS
)
1428 struct htmlpair tag
;
1430 PAIR_CLASS_INIT(&tag
, "addr");
1431 print_otag(h
, TAG_SPAN
, 1, &tag
);
1438 mdoc_an_pre(MDOC_ARGS
)
1440 struct htmlpair tag
;
1442 /* TODO: -split and -nosplit (see termp_an_pre()). */
1444 PAIR_CLASS_INIT(&tag
, "author");
1445 print_otag(h
, TAG_SPAN
, 1, &tag
);
1452 mdoc_cd_pre(MDOC_ARGS
)
1454 struct htmlpair tag
;
1456 PAIR_CLASS_INIT(&tag
, "config");
1457 print_otag(h
, TAG_SPAN
, 1, &tag
);
1464 mdoc_dv_pre(MDOC_ARGS
)
1466 struct htmlpair tag
;
1468 PAIR_CLASS_INIT(&tag
, "define");
1469 print_otag(h
, TAG_SPAN
, 1, &tag
);
1476 mdoc_ev_pre(MDOC_ARGS
)
1478 struct htmlpair tag
;
1480 PAIR_CLASS_INIT(&tag
, "env");
1481 print_otag(h
, TAG_SPAN
, 1, &tag
);
1488 mdoc_er_pre(MDOC_ARGS
)
1490 struct htmlpair tag
;
1492 PAIR_CLASS_INIT(&tag
, "errno");
1493 print_otag(h
, TAG_SPAN
, 1, &tag
);
1500 mdoc_fa_pre(MDOC_ARGS
)
1502 const struct mdoc_node
*nn
;
1503 struct htmlpair tag
;
1506 PAIR_CLASS_INIT(&tag
, "farg");
1507 if (n
->parent
->tok
!= MDOC_Fo
) {
1508 print_otag(h
, TAG_SPAN
, 1, &tag
);
1512 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1513 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1514 print_text(h
, nn
->string
);
1520 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1529 mdoc_fd_pre(MDOC_ARGS
)
1531 struct htmlpair tag
;
1534 if (SEC_SYNOPSIS
== n
->sec
) {
1535 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1536 SCALE_VS_INIT(&su
, 1);
1537 bufcat_su(h
, "margin-bottom", &su
);
1538 PAIR_STYLE_INIT(&tag
, h
);
1539 print_otag(h
, TAG_DIV
, 1, &tag
);
1541 print_otag(h
, TAG_DIV
, 0, NULL
);
1544 PAIR_CLASS_INIT(&tag
, "macro");
1545 print_otag(h
, TAG_SPAN
, 1, &tag
);
1552 mdoc_vt_pre(MDOC_ARGS
)
1554 struct htmlpair tag
;
1557 if (SEC_SYNOPSIS
== n
->sec
) {
1558 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1559 SCALE_VS_INIT(&su
, 1);
1560 bufcat_su(h
, "margin-bottom", &su
);
1561 PAIR_STYLE_INIT(&tag
, h
);
1562 print_otag(h
, TAG_DIV
, 1, &tag
);
1564 print_otag(h
, TAG_DIV
, 0, NULL
);
1567 PAIR_CLASS_INIT(&tag
, "type");
1568 print_otag(h
, TAG_SPAN
, 1, &tag
);
1575 mdoc_ft_pre(MDOC_ARGS
)
1577 struct htmlpair tag
;
1580 if (SEC_SYNOPSIS
== n
->sec
) {
1581 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1582 SCALE_VS_INIT(&su
, 1);
1583 bufcat_su(h
, "margin-top", &su
);
1584 PAIR_STYLE_INIT(&tag
, h
);
1585 print_otag(h
, TAG_DIV
, 1, &tag
);
1587 print_otag(h
, TAG_DIV
, 0, NULL
);
1590 PAIR_CLASS_INIT(&tag
, "ftype");
1591 print_otag(h
, TAG_SPAN
, 1, &tag
);
1598 mdoc_fn_pre(MDOC_ARGS
)
1601 struct htmlpair tag
[2];
1602 const struct mdoc_node
*nn
;
1604 const char *sp
, *ep
;
1608 if (SEC_SYNOPSIS
== n
->sec
) {
1609 SCALE_HS_INIT(&su
, INDENT
);
1610 bufcat_su(h
, "margin-left", &su
);
1611 su
.scale
= -su
.scale
;
1612 bufcat_su(h
, "text-indent", &su
);
1614 SCALE_VS_INIT(&su
, 1);
1615 bufcat_su(h
, "margin-bottom", &su
);
1617 PAIR_STYLE_INIT(&tag
[0], h
);
1618 print_otag(h
, TAG_DIV
, 1, tag
);
1621 /* Split apart into type and name. */
1622 assert(n
->child
->string
);
1623 sp
= n
->child
->string
;
1625 if ((ep
= strchr(sp
, ' '))) {
1626 PAIR_CLASS_INIT(&tag
[0], "ftype");
1627 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1630 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1631 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1633 print_text(h
, nbuf
);
1635 ep
= strchr(sp
, ' ');
1640 PAIR_CLASS_INIT(&tag
[0], "fname");
1641 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1644 (void)strlcpy(nbuf
, sp
, BUFSIZ
);
1645 print_text(h
, nbuf
);
1650 h
->flags
|= HTML_NOSPACE
;
1654 PAIR_CLASS_INIT(&tag
[0], "farg");
1655 bufcat_style(h
, "white-space", "nowrap");
1656 PAIR_STYLE_INIT(&tag
[1], h
);
1658 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1660 if (SEC_SYNOPSIS
== n
->sec
)
1662 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1663 print_text(h
, nn
->string
);
1670 if (SEC_SYNOPSIS
== n
->sec
)
1679 mdoc_sp_pre(MDOC_ARGS
)
1682 struct htmlpair tag
;
1687 /* FIXME: can this have a scaling indicator? */
1688 len
= n
->child
? atoi(n
->child
->string
) : 1;
1698 SCALE_VS_INIT(&su
, len
);
1699 bufcat_su(h
, "height", &su
);
1700 PAIR_STYLE_INIT(&tag
, h
);
1701 print_otag(h
, TAG_DIV
, 1, &tag
);
1709 mdoc_brq_pre(MDOC_ARGS
)
1712 if (MDOC_BODY
!= n
->type
)
1714 print_text(h
, "\\(lC");
1715 h
->flags
|= HTML_NOSPACE
;
1722 mdoc_brq_post(MDOC_ARGS
)
1725 if (MDOC_BODY
!= n
->type
)
1727 h
->flags
|= HTML_NOSPACE
;
1728 print_text(h
, "\\(rC");
1734 mdoc_lk_pre(MDOC_ARGS
)
1736 const struct mdoc_node
*nn
;
1737 struct htmlpair tag
[2];
1741 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1742 tag
[1].key
= ATTR_HREF
;
1743 tag
[1].val
= nn
->string
;
1744 print_otag(h
, TAG_A
, 2, tag
);
1746 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1747 print_text(h
, nn
->string
);
1755 mdoc_mt_pre(MDOC_ARGS
)
1757 struct htmlpair tag
[2];
1759 const struct mdoc_node
*nn
;
1761 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1763 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1765 bufcat(h
, "mailto:");
1766 bufcat(h
, nn
->string
);
1767 PAIR_STYLE_INIT(&tag
[1], h
);
1768 t
= print_otag(h
, TAG_A
, 2, tag
);
1769 print_text(h
, nn
->string
);
1779 mdoc_fo_pre(MDOC_ARGS
)
1781 struct htmlpair tag
;
1783 if (MDOC_BODY
== n
->type
) {
1784 h
->flags
|= HTML_NOSPACE
;
1786 h
->flags
|= HTML_NOSPACE
;
1788 } else if (MDOC_BLOCK
== n
->type
)
1791 PAIR_CLASS_INIT(&tag
, "fname");
1792 print_otag(h
, TAG_SPAN
, 1, &tag
);
1799 mdoc_fo_post(MDOC_ARGS
)
1801 if (MDOC_BODY
!= n
->type
)
1803 h
->flags
|= HTML_NOSPACE
;
1805 h
->flags
|= HTML_NOSPACE
;
1812 mdoc_in_pre(MDOC_ARGS
)
1814 const struct mdoc_node
*nn
;
1816 struct htmlpair tag
[2];
1820 if (SEC_SYNOPSIS
== n
->sec
) {
1821 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1822 SCALE_VS_INIT(&su
, 1);
1823 bufcat_su(h
, "margin-bottom", &su
);
1824 PAIR_STYLE_INIT(&tag
[0], h
);
1825 print_otag(h
, TAG_DIV
, 1, tag
);
1827 print_otag(h
, TAG_DIV
, 0, NULL
);
1830 PAIR_CLASS_INIT(&tag
[0], "includes");
1831 print_otag(h
, TAG_SPAN
, 1, tag
);
1833 if (SEC_SYNOPSIS
== n
->sec
)
1834 print_text(h
, "#include");
1837 h
->flags
|= HTML_NOSPACE
;
1839 /* XXX -- see warning in termp_in_post(). */
1841 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1842 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1844 if (h
->base_includes
) {
1845 buffmt_includes(h
, nn
->string
);
1846 tag
[i
].key
= ATTR_HREF
;
1847 tag
[i
++].val
= h
->buf
;
1849 t
= print_otag(h
, TAG_A
, i
, tag
);
1850 print_mdoc_node(m
, nn
, h
);
1854 h
->flags
|= HTML_NOSPACE
;
1863 mdoc_ic_pre(MDOC_ARGS
)
1865 struct htmlpair tag
;
1867 PAIR_CLASS_INIT(&tag
, "cmd");
1868 print_otag(h
, TAG_SPAN
, 1, &tag
);
1875 mdoc_rv_pre(MDOC_ARGS
)
1877 const struct mdoc_node
*nn
;
1878 struct htmlpair tag
;
1881 print_otag(h
, TAG_DIV
, 0, NULL
);
1882 print_text(h
, "The");
1884 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1885 PAIR_CLASS_INIT(&tag
, "fname");
1886 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1887 print_text(h
, nn
->string
);
1890 h
->flags
|= HTML_NOSPACE
;
1891 if (nn
->next
&& NULL
== nn
->next
->next
)
1892 print_text(h
, "(), and");
1894 print_text(h
, "(),");
1896 print_text(h
, "()");
1900 print_text(h
, "functions return");
1902 print_text(h
, "function returns");
1904 print_text(h
, "the value 0 if successful; otherwise the value "
1905 "-1 is returned and the global variable");
1907 PAIR_CLASS_INIT(&tag
, "var");
1908 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1909 print_text(h
, "errno");
1911 print_text(h
, "is set to indicate the error.");
1918 mdoc_va_pre(MDOC_ARGS
)
1920 struct htmlpair tag
;
1922 PAIR_CLASS_INIT(&tag
, "var");
1923 print_otag(h
, TAG_SPAN
, 1, &tag
);
1930 mdoc_bq_pre(MDOC_ARGS
)
1933 if (MDOC_BODY
!= n
->type
)
1935 print_text(h
, "\\(lB");
1936 h
->flags
|= HTML_NOSPACE
;
1943 mdoc_bq_post(MDOC_ARGS
)
1946 if (MDOC_BODY
!= n
->type
)
1948 h
->flags
|= HTML_NOSPACE
;
1949 print_text(h
, "\\(rB");
1955 mdoc_ap_pre(MDOC_ARGS
)
1958 h
->flags
|= HTML_NOSPACE
;
1959 print_text(h
, "\\(aq");
1960 h
->flags
|= HTML_NOSPACE
;
1967 mdoc_bf_pre(MDOC_ARGS
)
1970 struct htmlpair tag
[2];
1973 if (MDOC_HEAD
== n
->type
)
1975 else if (MDOC_BLOCK
!= n
->type
)
1978 PAIR_CLASS_INIT(&tag
[0], "lit");
1980 if (n
->head
->child
) {
1981 if ( ! strcmp("Em", n
->head
->child
->string
))
1982 PAIR_CLASS_INIT(&tag
[0], "emph");
1983 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1984 PAIR_CLASS_INIT(&tag
[0], "symb");
1985 else if ( ! strcmp("Li", n
->head
->child
->string
))
1986 PAIR_CLASS_INIT(&tag
[0], "lit");
1989 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
1990 switch (n
->args
->argv
[i
].arg
) {
1991 case (MDOC_Symbolic
):
1992 PAIR_CLASS_INIT(&tag
[0], "symb");
1994 case (MDOC_Literal
):
1995 PAIR_CLASS_INIT(&tag
[0], "lit");
1997 case (MDOC_Emphasis
):
1998 PAIR_CLASS_INIT(&tag
[0], "emph");
2005 /* FIXME: div's have spaces stripped--we want them. */
2007 bufcat_style(h
, "display", "inline");
2008 SCALE_HS_INIT(&su
, 1);
2009 bufcat_su(h
, "margin-right", &su
);
2010 PAIR_STYLE_INIT(&tag
[1], h
);
2011 print_otag(h
, TAG_DIV
, 2, tag
);
2018 mdoc_ms_pre(MDOC_ARGS
)
2020 struct htmlpair tag
;
2022 PAIR_CLASS_INIT(&tag
, "symb");
2023 print_otag(h
, TAG_SPAN
, 1, &tag
);
2030 mdoc_pf_pre(MDOC_ARGS
)
2033 h
->flags
|= HTML_IGNDELIM
;
2040 mdoc_pf_post(MDOC_ARGS
)
2043 h
->flags
&= ~HTML_IGNDELIM
;
2044 h
->flags
|= HTML_NOSPACE
;
2050 mdoc_rs_pre(MDOC_ARGS
)
2052 struct htmlpair tag
;
2055 if (MDOC_BLOCK
!= n
->type
)
2058 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2059 SCALE_VS_INIT(&su
, 1);
2060 bufcat_su(h
, "margin-top", &su
);
2061 PAIR_STYLE_INIT(&tag
, h
);
2062 print_otag(h
, TAG_DIV
, 1, &tag
);
2065 PAIR_CLASS_INIT(&tag
, "ref");
2066 print_otag(h
, TAG_SPAN
, 1, &tag
);
2074 mdoc_li_pre(MDOC_ARGS
)
2076 struct htmlpair tag
;
2078 PAIR_CLASS_INIT(&tag
, "lit");
2079 print_otag(h
, TAG_SPAN
, 1, &tag
);
2086 mdoc_sy_pre(MDOC_ARGS
)
2088 struct htmlpair tag
;
2090 PAIR_CLASS_INIT(&tag
, "symb");
2091 print_otag(h
, TAG_SPAN
, 1, &tag
);
2098 mdoc_bt_pre(MDOC_ARGS
)
2101 print_text(h
, "is currently in beta test.");
2108 mdoc_ud_pre(MDOC_ARGS
)
2111 print_text(h
, "currently under development.");
2118 mdoc_lb_pre(MDOC_ARGS
)
2120 struct htmlpair tag
;
2122 if (SEC_SYNOPSIS
== n
->sec
)
2123 print_otag(h
, TAG_DIV
, 0, NULL
);
2124 PAIR_CLASS_INIT(&tag
, "lib");
2125 print_otag(h
, TAG_SPAN
, 1, &tag
);
2132 mdoc__x_pre(MDOC_ARGS
)
2134 struct htmlpair tag
;
2138 PAIR_CLASS_INIT(&tag
, "ref-auth");
2141 PAIR_CLASS_INIT(&tag
, "ref-book");
2144 PAIR_CLASS_INIT(&tag
, "ref-city");
2147 PAIR_CLASS_INIT(&tag
, "ref-date");
2150 PAIR_CLASS_INIT(&tag
, "ref-issue");
2153 PAIR_CLASS_INIT(&tag
, "ref-jrnl");
2156 PAIR_CLASS_INIT(&tag
, "ref-num");
2159 PAIR_CLASS_INIT(&tag
, "ref-opt");
2162 PAIR_CLASS_INIT(&tag
, "ref-page");
2165 PAIR_CLASS_INIT(&tag
, "ref-corp");
2168 PAIR_CLASS_INIT(&tag
, "ref-rep");
2171 PAIR_CLASS_INIT(&tag
, "ref-title");
2172 print_text(h
, "\\(lq");
2173 h
->flags
|= HTML_NOSPACE
;
2176 PAIR_CLASS_INIT(&tag
, "ref-vol");
2183 print_otag(h
, TAG_SPAN
, 1, &tag
);
2190 mdoc__x_post(MDOC_ARGS
)
2193 h
->flags
|= HTML_NOSPACE
;
2196 print_text(h
, "\\(rq");
2197 h
->flags
|= HTML_NOSPACE
;
2202 print_text(h
, n
->next
? "," : ".");