]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.54 2010/01/30 08:42:20 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
38 #define MDOC_ARGS const struct mdoc_meta *m, \
39 const struct mdoc_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static void print_mdoc(MDOC_ARGS
);
52 static void print_mdoc_head(MDOC_ARGS
);
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
56 static void a2width(const char *, struct roffsu
*);
57 static void a2offs(const char *, struct roffsu
*);
59 static int a2list(const struct mdoc_node
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static void mdoc_aq_post(MDOC_ARGS
);
70 static int mdoc_aq_pre(MDOC_ARGS
);
71 static int mdoc_ar_pre(MDOC_ARGS
);
72 static int mdoc_bd_pre(MDOC_ARGS
);
73 static int mdoc_bf_pre(MDOC_ARGS
);
74 static void mdoc_bl_post(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static void mdoc_bq_post(MDOC_ARGS
);
77 static int mdoc_bq_pre(MDOC_ARGS
);
78 static void mdoc_brq_post(MDOC_ARGS
);
79 static int mdoc_brq_pre(MDOC_ARGS
);
80 static int mdoc_bt_pre(MDOC_ARGS
);
81 static int mdoc_bx_pre(MDOC_ARGS
);
82 static int mdoc_cd_pre(MDOC_ARGS
);
83 static int mdoc_d1_pre(MDOC_ARGS
);
84 static void mdoc_dq_post(MDOC_ARGS
);
85 static int mdoc_dq_pre(MDOC_ARGS
);
86 static int mdoc_dv_pre(MDOC_ARGS
);
87 static int mdoc_fa_pre(MDOC_ARGS
);
88 static int mdoc_fd_pre(MDOC_ARGS
);
89 static int mdoc_fl_pre(MDOC_ARGS
);
90 static int mdoc_fn_pre(MDOC_ARGS
);
91 static int mdoc_ft_pre(MDOC_ARGS
);
92 static int mdoc_em_pre(MDOC_ARGS
);
93 static int mdoc_er_pre(MDOC_ARGS
);
94 static int mdoc_ev_pre(MDOC_ARGS
);
95 static int mdoc_ex_pre(MDOC_ARGS
);
96 static void mdoc_fo_post(MDOC_ARGS
);
97 static int mdoc_fo_pre(MDOC_ARGS
);
98 static int mdoc_ic_pre(MDOC_ARGS
);
99 static int mdoc_in_pre(MDOC_ARGS
);
100 static int mdoc_it_block_pre(MDOC_ARGS
, int, int,
101 struct roffsu
*, struct roffsu
*);
102 static int mdoc_it_head_pre(MDOC_ARGS
, int,
104 static int mdoc_it_body_pre(MDOC_ARGS
, int);
105 static int mdoc_it_pre(MDOC_ARGS
);
106 static int mdoc_lb_pre(MDOC_ARGS
);
107 static int mdoc_li_pre(MDOC_ARGS
);
108 static int mdoc_lk_pre(MDOC_ARGS
);
109 static int mdoc_mt_pre(MDOC_ARGS
);
110 static int mdoc_ms_pre(MDOC_ARGS
);
111 static int mdoc_nd_pre(MDOC_ARGS
);
112 static int mdoc_nm_pre(MDOC_ARGS
);
113 static int mdoc_ns_pre(MDOC_ARGS
);
114 static void mdoc_op_post(MDOC_ARGS
);
115 static int mdoc_op_pre(MDOC_ARGS
);
116 static int mdoc_pa_pre(MDOC_ARGS
);
117 static void mdoc_pf_post(MDOC_ARGS
);
118 static int mdoc_pf_pre(MDOC_ARGS
);
119 static void mdoc_pq_post(MDOC_ARGS
);
120 static int mdoc_pq_pre(MDOC_ARGS
);
121 static int mdoc_rs_pre(MDOC_ARGS
);
122 static int mdoc_rv_pre(MDOC_ARGS
);
123 static int mdoc_sh_pre(MDOC_ARGS
);
124 static int mdoc_sp_pre(MDOC_ARGS
);
125 static void mdoc_sq_post(MDOC_ARGS
);
126 static int mdoc_sq_pre(MDOC_ARGS
);
127 static int mdoc_ss_pre(MDOC_ARGS
);
128 static int mdoc_sx_pre(MDOC_ARGS
);
129 static int mdoc_sy_pre(MDOC_ARGS
);
130 static int mdoc_ud_pre(MDOC_ARGS
);
131 static int mdoc_va_pre(MDOC_ARGS
);
132 static int mdoc_vt_pre(MDOC_ARGS
);
133 static int mdoc_xr_pre(MDOC_ARGS
);
134 static int mdoc_xx_pre(MDOC_ARGS
);
136 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
137 {mdoc_ap_pre
, NULL
}, /* Ap */
138 {NULL
, NULL
}, /* Dd */
139 {NULL
, NULL
}, /* Dt */
140 {NULL
, NULL
}, /* Os */
141 {mdoc_sh_pre
, NULL
}, /* Sh */
142 {mdoc_ss_pre
, NULL
}, /* Ss */
143 {mdoc_sp_pre
, NULL
}, /* Pp */
144 {mdoc_d1_pre
, NULL
}, /* D1 */
145 {mdoc_d1_pre
, NULL
}, /* Dl */
146 {mdoc_bd_pre
, NULL
}, /* Bd */
147 {NULL
, NULL
}, /* Ed */
148 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
149 {NULL
, NULL
}, /* El */
150 {mdoc_it_pre
, NULL
}, /* It */
151 {mdoc_ad_pre
, NULL
}, /* Ad */
152 {mdoc_an_pre
, NULL
}, /* An */
153 {mdoc_ar_pre
, NULL
}, /* Ar */
154 {mdoc_cd_pre
, NULL
}, /* Cd */
155 {mdoc_fl_pre
, NULL
}, /* Cm */
156 {mdoc_dv_pre
, NULL
}, /* Dv */
157 {mdoc_er_pre
, NULL
}, /* Er */
158 {mdoc_ev_pre
, NULL
}, /* Ev */
159 {mdoc_ex_pre
, NULL
}, /* Ex */
160 {mdoc_fa_pre
, NULL
}, /* Fa */
161 {mdoc_fd_pre
, NULL
}, /* Fd */
162 {mdoc_fl_pre
, NULL
}, /* Fl */
163 {mdoc_fn_pre
, NULL
}, /* Fn */
164 {mdoc_ft_pre
, NULL
}, /* Ft */
165 {mdoc_ic_pre
, NULL
}, /* Ic */
166 {mdoc_in_pre
, NULL
}, /* In */
167 {mdoc_li_pre
, NULL
}, /* Li */
168 {mdoc_nd_pre
, NULL
}, /* Nd */
169 {mdoc_nm_pre
, NULL
}, /* Nm */
170 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
171 {NULL
, NULL
}, /* Ot */
172 {mdoc_pa_pre
, NULL
}, /* Pa */
173 {mdoc_rv_pre
, NULL
}, /* Rv */
174 {NULL
, NULL
}, /* St */
175 {mdoc_va_pre
, NULL
}, /* Va */
176 {mdoc_vt_pre
, NULL
}, /* Vt */
177 {mdoc_xr_pre
, NULL
}, /* Xr */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
189 {NULL
, NULL
}, /* Ac */
190 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
191 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
192 {NULL
, NULL
}, /* At */
193 {NULL
, NULL
}, /* Bc */
194 {mdoc_bf_pre
, NULL
}, /* Bf */
195 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
196 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
197 {mdoc_xx_pre
, NULL
}, /* Bsx */
198 {mdoc_bx_pre
, NULL
}, /* Bx */
199 {NULL
, NULL
}, /* Db */
200 {NULL
, NULL
}, /* Dc */
201 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
202 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
203 {NULL
, NULL
}, /* Ec */
204 {NULL
, NULL
}, /* Ef */
205 {mdoc_em_pre
, NULL
}, /* Em */
206 {NULL
, NULL
}, /* Eo */
207 {mdoc_xx_pre
, NULL
}, /* Fx */
208 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
209 {NULL
, NULL
}, /* No */
210 {mdoc_ns_pre
, NULL
}, /* Ns */
211 {mdoc_xx_pre
, NULL
}, /* Nx */
212 {mdoc_xx_pre
, NULL
}, /* Ox */
213 {NULL
, NULL
}, /* Pc */
214 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
215 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
216 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
217 {NULL
, NULL
}, /* Qc */
218 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
219 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
220 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
221 {NULL
, NULL
}, /* Re */
222 {mdoc_rs_pre
, NULL
}, /* Rs */
223 {NULL
, NULL
}, /* Sc */
224 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
225 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
226 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
227 {mdoc_sx_pre
, NULL
}, /* Sx */
228 {mdoc_sy_pre
, NULL
}, /* Sy */
229 {NULL
, NULL
}, /* Tn */
230 {mdoc_xx_pre
, NULL
}, /* Ux */
231 {NULL
, NULL
}, /* Xc */
232 {NULL
, NULL
}, /* Xo */
233 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
234 {NULL
, NULL
}, /* Fc */
235 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
236 {NULL
, NULL
}, /* Oc */
237 {NULL
, NULL
}, /* Bk */
238 {NULL
, NULL
}, /* Ek */
239 {mdoc_bt_pre
, NULL
}, /* Bt */
240 {NULL
, NULL
}, /* Hf */
241 {NULL
, NULL
}, /* Fr */
242 {mdoc_ud_pre
, NULL
}, /* Ud */
243 {mdoc_lb_pre
, NULL
}, /* Lb */
244 {mdoc_sp_pre
, NULL
}, /* Lp */
245 {mdoc_lk_pre
, NULL
}, /* Lk */
246 {mdoc_mt_pre
, NULL
}, /* Mt */
247 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
248 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
249 {NULL
, NULL
}, /* Brc */
250 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
251 {NULL
, NULL
}, /* Es */ /* TODO */
252 {NULL
, NULL
}, /* En */ /* TODO */
253 {mdoc_xx_pre
, NULL
}, /* Dx */
254 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
255 {mdoc_sp_pre
, NULL
}, /* br */
256 {mdoc_sp_pre
, NULL
}, /* sp */
257 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
262 html_mdoc(void *arg
, const struct mdoc
*m
)
267 h
= (struct html
*)arg
;
270 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
271 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
279 * Return the list type for `Bl', e.g., `Bl -column' returns
280 * MDOC_Column. This can ONLY be run for lists; it will abort() if no
281 * list type is found.
284 a2list(const struct mdoc_node
*n
)
289 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
290 switch (n
->args
->argv
[i
].arg
) {
312 return(n
->args
->argv
[i
].arg
);
323 * Calculate the scaling unit passed in a `-width' argument. This uses
324 * either a native scaling unit (e.g., 1i, 2m) or the string length of
328 a2width(const char *p
, struct roffsu
*su
)
331 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
333 su
->scale
= (int)strlen(p
);
339 * Calculate the scaling unit passed in an `-offset' argument. This
340 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
341 * predefined strings (indent, etc.), or the string length of the value.
344 a2offs(const char *p
, struct roffsu
*su
)
347 /* FIXME: "right"? */
349 if (0 == strcmp(p
, "left"))
350 SCALE_HS_INIT(su
, 0);
351 else if (0 == strcmp(p
, "indent"))
352 SCALE_HS_INIT(su
, INDENT
);
353 else if (0 == strcmp(p
, "indent-two"))
354 SCALE_HS_INIT(su
, INDENT
* 2);
355 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
357 su
->scale
= (int)strlen(p
);
363 print_mdoc(MDOC_ARGS
)
368 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
369 print_mdoc_head(m
, n
, h
);
372 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
374 tag
.key
= ATTR_CLASS
;
376 print_otag(h
, TAG_DIV
, 1, &tag
);
378 print_mdoc_nodelist(m
, n
, h
);
385 print_mdoc_head(MDOC_ARGS
)
390 buffmt(h
, "%s(%d)", m
->title
, m
->msec
);
398 print_otag(h
, TAG_TITLE
, 0, NULL
);
399 print_text(h
, h
->buf
);
404 print_mdoc_nodelist(MDOC_ARGS
)
407 print_mdoc_node(m
, n
, h
);
409 print_mdoc_nodelist(m
, n
->next
, h
);
414 print_mdoc_node(MDOC_ARGS
)
425 child
= mdoc_root_pre(m
, n
, h
);
428 print_text(h
, n
->string
);
431 if (mdocs
[n
->tok
].pre
)
432 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
436 if (child
&& n
->child
)
437 print_mdoc_nodelist(m
, n
->child
, h
);
444 mdoc_root_post(m
, n
, h
);
447 if (mdocs
[n
->tok
].post
)
448 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
456 mdoc_root_post(MDOC_ARGS
)
458 struct htmlpair tag
[3];
462 time2a(m
->date
, b
, DATESIZ
);
465 * XXX: this should use divs, but in Firefox, divs with nested
466 * divs for some reason puke when trying to put a border line
467 * below. So I use tables, instead.
470 PAIR_CLASS_INIT(&tag
[0], "footer");
471 bufcat_style(h
, "width", "100%");
472 PAIR_STYLE_INIT(&tag
[1], h
);
473 PAIR_SUMMARY_INIT(&tag
[2], "footer");
475 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
476 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
479 bufcat_style(h
, "width", "50%");
480 PAIR_STYLE_INIT(&tag
[0], h
);
481 print_otag(h
, TAG_TD
, 1, tag
);
486 bufcat_style(h
, "width", "50%");
487 bufcat_style(h
, "text-align", "right");
488 PAIR_STYLE_INIT(&tag
[0], h
);
489 print_otag(h
, TAG_TD
, 1, tag
);
490 print_text(h
, m
->os
);
497 mdoc_root_pre(MDOC_ARGS
)
499 struct htmlpair tag
[3];
501 char b
[BUFSIZ
], title
[BUFSIZ
];
503 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
506 (void)strlcat(b
, " (", BUFSIZ
);
507 (void)strlcat(b
, m
->arch
, BUFSIZ
);
508 (void)strlcat(b
, ")", BUFSIZ
);
511 (void)snprintf(title
, BUFSIZ
- 1,
512 "%s(%d)", m
->title
, m
->msec
);
514 /* XXX: see note in mdoc_root_post() about divs. */
516 PAIR_CLASS_INIT(&tag
[0], "header");
517 bufcat_style(h
, "width", "100%");
518 PAIR_STYLE_INIT(&tag
[1], h
);
519 PAIR_SUMMARY_INIT(&tag
[2], "header");
521 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
523 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
526 bufcat_style(h
, "width", "10%");
527 PAIR_STYLE_INIT(&tag
[0], h
);
528 print_otag(h
, TAG_TD
, 1, tag
);
529 print_text(h
, title
);
533 bufcat_style(h
, "text-align", "center");
534 bufcat_style(h
, "white-space", "nowrap");
535 bufcat_style(h
, "width", "80%");
536 PAIR_STYLE_INIT(&tag
[0], h
);
537 print_otag(h
, TAG_TD
, 1, tag
);
542 bufcat_style(h
, "text-align", "right");
543 bufcat_style(h
, "width", "10%");
544 PAIR_STYLE_INIT(&tag
[0], h
);
545 print_otag(h
, TAG_TD
, 1, tag
);
546 print_text(h
, title
);
554 mdoc_sh_pre(MDOC_ARGS
)
556 struct htmlpair tag
[2];
557 const struct mdoc_node
*nn
;
561 if (MDOC_BODY
== n
->type
) {
562 SCALE_HS_INIT(&su
, INDENT
);
563 bufcat_su(h
, "margin-left", &su
);
564 PAIR_CLASS_INIT(&tag
[0], "sec-body");
565 PAIR_STYLE_INIT(&tag
[1], h
);
566 print_otag(h
, TAG_DIV
, 2, tag
);
568 } else if (MDOC_BLOCK
== n
->type
) {
569 PAIR_CLASS_INIT(&tag
[0], "sec-block");
570 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
571 print_otag(h
, TAG_DIV
, 1, tag
);
575 SCALE_VS_INIT(&su
, 1);
576 bufcat_su(h
, "margin-top", &su
);
578 bufcat_su(h
, "margin-bottom", &su
);
580 PAIR_STYLE_INIT(&tag
[1], h
);
581 print_otag(h
, TAG_DIV
, 2, tag
);
586 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
587 html_idcat(buf
, nn
->string
, BUFSIZ
);
589 html_idcat(buf
, " ", BUFSIZ
);
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
);
667 /* `Cm' has no leading hyphen. */
669 if (MDOC_Cm
== n
->tok
)
672 print_text(h
, "\\-");
674 /* A blank `Fl' should incur a subsequent space. */
677 h
->flags
|= HTML_NOSPACE
;
685 mdoc_nd_pre(MDOC_ARGS
)
689 if (MDOC_BODY
!= n
->type
)
692 /* XXX: this tag in theory can contain block elements. */
694 print_text(h
, "\\(em");
695 PAIR_CLASS_INIT(&tag
, "desc-body");
696 print_otag(h
, TAG_SPAN
, 1, &tag
);
703 mdoc_op_pre(MDOC_ARGS
)
707 if (MDOC_BODY
!= n
->type
)
710 /* XXX: this tag in theory can contain block elements. */
712 print_text(h
, "\\(lB");
713 h
->flags
|= HTML_NOSPACE
;
714 PAIR_CLASS_INIT(&tag
, "opt");
715 print_otag(h
, TAG_SPAN
, 1, &tag
);
722 mdoc_op_post(MDOC_ARGS
)
725 if (MDOC_BODY
!= n
->type
)
727 h
->flags
|= HTML_NOSPACE
;
728 print_text(h
, "\\(rB");
733 mdoc_nm_pre(MDOC_ARGS
)
737 if (SEC_SYNOPSIS
== n
->sec
&& n
->prev
) {
738 bufcat_style(h
, "clear", "both");
739 PAIR_STYLE_INIT(&tag
, h
);
740 print_otag(h
, TAG_BR
, 1, &tag
);
743 PAIR_CLASS_INIT(&tag
, "name");
744 print_otag(h
, TAG_SPAN
, 1, &tag
);
745 if (NULL
== n
->child
)
746 print_text(h
, m
->name
);
754 mdoc_xr_pre(MDOC_ARGS
)
756 struct htmlpair tag
[2];
757 const struct mdoc_node
*nn
;
759 PAIR_CLASS_INIT(&tag
[0], "link-man");
762 buffmt_man(h
, n
->child
->string
,
764 n
->child
->next
->string
: NULL
);
765 tag
[1].key
= ATTR_HREF
;
767 print_otag(h
, TAG_A
, 2, tag
);
769 print_otag(h
, TAG_A
, 1, tag
);
772 print_text(h
, nn
->string
);
774 if (NULL
== (nn
= nn
->next
))
777 h
->flags
|= HTML_NOSPACE
;
779 h
->flags
|= HTML_NOSPACE
;
780 print_text(h
, nn
->string
);
781 h
->flags
|= HTML_NOSPACE
;
789 mdoc_ns_pre(MDOC_ARGS
)
792 h
->flags
|= HTML_NOSPACE
;
799 mdoc_ar_pre(MDOC_ARGS
)
803 PAIR_CLASS_INIT(&tag
, "arg");
804 print_otag(h
, TAG_SPAN
, 1, &tag
);
811 mdoc_xx_pre(MDOC_ARGS
)
839 PAIR_CLASS_INIT(&tag
, "unix");
840 print_otag(h
, TAG_SPAN
, 1, &tag
);
848 mdoc_bx_pre(MDOC_ARGS
)
850 const struct mdoc_node
*nn
;
853 PAIR_CLASS_INIT(&tag
, "unix");
854 print_otag(h
, TAG_SPAN
, 1, &tag
);
856 for (nn
= n
->child
; nn
; nn
= nn
->next
)
857 print_mdoc_node(m
, nn
, h
);
860 h
->flags
|= HTML_NOSPACE
;
862 print_text(h
, "BSD");
869 mdoc_it_block_pre(MDOC_ARGS
, int type
, int comp
,
870 struct roffsu
*offs
, struct roffsu
*width
)
873 const struct mdoc_node
*nn
;
876 nn
= n
->parent
->parent
;
879 /* XXX: see notes in mdoc_it_pre(). */
881 if (MDOC_Column
== type
) {
882 /* Don't width-pad on the left. */
883 SCALE_HS_INIT(width
, 0);
884 /* Also disallow non-compact. */
887 if (MDOC_Diag
== type
)
888 /* Mandate non-compact with empty prior. */
889 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
892 bufcat_style(h
, "clear", "both");
894 bufcat_su(h
, "margin-left", offs
);
895 if (width
->scale
> 0)
896 bufcat_su(h
, "padding-left", width
);
898 PAIR_STYLE_INIT(&tag
, h
);
900 /* Mandate compact following `Ss' and `Sh' starts. */
902 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
903 if (MDOC_BLOCK
!= nn
->type
)
905 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
912 SCALE_VS_INIT(&su
, 1);
913 bufcat_su(h
, "padding-top", &su
);
916 PAIR_STYLE_INIT(&tag
, h
);
917 print_otag(h
, TAG_DIV
, 1, &tag
);
924 mdoc_it_body_pre(MDOC_ARGS
, int type
)
938 * XXX: this tricks CSS into aligning the bodies with
939 * the right-padding in the head.
941 SCALE_HS_INIT(&su
, 2);
942 bufcat_su(h
, "margin-left", &su
);
943 PAIR_STYLE_INIT(&tag
, h
);
944 print_otag(h
, TAG_DIV
, 1, &tag
);
954 mdoc_it_head_pre(MDOC_ARGS
, int type
, struct roffsu
*width
)
964 print_otag(h
, TAG_DIV
, 0, &tag
);
967 bufcat_su(h
, "min-width", width
);
968 bufcat_style(h
, "clear", "none");
969 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
970 bufcat_style(h
, "float", "left");
971 PAIR_STYLE_INIT(&tag
, h
);
972 print_otag(h
, TAG_DIV
, 1, &tag
);
975 bufcat_su(h
, "min-width", width
);
977 bufcat_su(h
, "margin-left", width
);
978 if (n
->next
&& n
->next
->child
)
979 bufcat_style(h
, "float", "left");
981 /* XXX: buffer if we run into body. */
982 SCALE_HS_INIT(width
, 1);
983 bufcat_su(h
, "margin-right", width
);
984 PAIR_STYLE_INIT(&tag
, h
);
985 print_otag(h
, TAG_DIV
, 1, &tag
);
991 PAIR_CLASS_INIT(&tag
, "diag");
992 print_otag(h
, TAG_SPAN
, 1, &tag
);
997 nbuf
[BUFSIZ
- 1] = 0;
998 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1002 print_text(h
, "\\(en");
1005 print_text(h
, "\\(hy");
1008 print_text(h
, "\\(bu");
1019 mdoc_it_pre(MDOC_ARGS
)
1021 int i
, type
, wp
, comp
;
1022 const struct mdoc_node
*bl
, *nn
;
1023 struct roffsu width
, offs
;
1026 * XXX: be very careful in changing anything, here. Lists in
1027 * mandoc have many peculiarities; furthermore, they don't
1028 * translate well into HTML and require a bit of mangling.
1031 bl
= n
->parent
->parent
;
1032 if (MDOC_BLOCK
!= n
->type
)
1037 /* Set default width and offset. */
1039 SCALE_HS_INIT(&offs
, 0);
1049 SCALE_HS_INIT(&width
, 2);
1052 SCALE_HS_INIT(&width
, INDENT
);
1056 /* Get width, offset, and compact arguments. */
1058 for (wp
= -1, comp
= i
= 0; i
< (int)bl
->args
->argc
; i
++)
1059 switch (bl
->args
->argv
[i
].arg
) {
1061 wp
= i
; /* Save for later. */
1064 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1067 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1069 case (MDOC_Compact
):
1076 /* Override width in some cases. */
1086 SCALE_HS_INIT(&width
, 0);
1089 if (0 == width
.scale
)
1090 SCALE_HS_INIT(&width
, INDENT
);
1094 /* Flip to body/block processing. */
1096 if (MDOC_BODY
== n
->type
)
1097 return(mdoc_it_body_pre(m
, n
, h
, type
));
1098 if (MDOC_BLOCK
== n
->type
)
1099 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
,
1102 /* Override column widths. */
1104 if (MDOC_Column
== type
) {
1105 nn
= n
->parent
->child
;
1106 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
1108 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1109 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1112 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1118 mdoc_bl_pre(MDOC_ARGS
)
1122 if (MDOC_BLOCK
!= n
->type
)
1124 if (MDOC_Enum
!= a2list(n
))
1127 ord
= malloc(sizeof(struct ord
));
1134 ord
->next
= h
->ords
.head
;
1142 mdoc_bl_post(MDOC_ARGS
)
1146 if (MDOC_BLOCK
!= n
->type
)
1148 if (MDOC_Enum
!= a2list(n
))
1153 h
->ords
.head
= ord
->next
;
1160 mdoc_ex_pre(MDOC_ARGS
)
1162 const struct mdoc_node
*nn
;
1164 struct htmlpair tag
;
1166 PAIR_CLASS_INIT(&tag
, "utility");
1168 print_text(h
, "The");
1169 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1170 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1171 print_text(h
, nn
->string
);
1174 h
->flags
|= HTML_NOSPACE
;
1176 if (nn
->next
&& NULL
== nn
->next
->next
)
1177 print_text(h
, ", and");
1181 h
->flags
&= ~HTML_NOSPACE
;
1185 print_text(h
, "utilities exit");
1187 print_text(h
, "utility exits");
1189 print_text(h
, "0 on success, and >0 if an error occurs.");
1196 mdoc_dq_pre(MDOC_ARGS
)
1199 if (MDOC_BODY
!= n
->type
)
1201 print_text(h
, "\\(lq");
1202 h
->flags
|= HTML_NOSPACE
;
1209 mdoc_dq_post(MDOC_ARGS
)
1212 if (MDOC_BODY
!= n
->type
)
1214 h
->flags
|= HTML_NOSPACE
;
1215 print_text(h
, "\\(rq");
1221 mdoc_pq_pre(MDOC_ARGS
)
1224 if (MDOC_BODY
!= n
->type
)
1226 print_text(h
, "\\&(");
1227 h
->flags
|= HTML_NOSPACE
;
1234 mdoc_pq_post(MDOC_ARGS
)
1237 if (MDOC_BODY
!= n
->type
)
1245 mdoc_sq_pre(MDOC_ARGS
)
1248 if (MDOC_BODY
!= n
->type
)
1250 print_text(h
, "\\(oq");
1251 h
->flags
|= HTML_NOSPACE
;
1258 mdoc_sq_post(MDOC_ARGS
)
1261 if (MDOC_BODY
!= n
->type
)
1263 h
->flags
|= HTML_NOSPACE
;
1264 print_text(h
, "\\(aq");
1270 mdoc_em_pre(MDOC_ARGS
)
1272 struct htmlpair tag
;
1274 PAIR_CLASS_INIT(&tag
, "emph");
1275 print_otag(h
, TAG_SPAN
, 1, &tag
);
1282 mdoc_d1_pre(MDOC_ARGS
)
1284 struct htmlpair tag
[2];
1287 if (MDOC_BLOCK
!= n
->type
)
1290 /* FIXME: D1 shouldn't be literal. */
1292 SCALE_VS_INIT(&su
, INDENT
- 2);
1293 bufcat_su(h
, "margin-left", &su
);
1294 PAIR_CLASS_INIT(&tag
[0], "lit");
1295 PAIR_STYLE_INIT(&tag
[1], h
);
1296 print_otag(h
, TAG_DIV
, 2, tag
);
1303 mdoc_sx_pre(MDOC_ARGS
)
1305 struct htmlpair tag
[2];
1306 const struct mdoc_node
*nn
;
1309 /* FIXME: duplicates? */
1311 strlcpy(buf
, "#", BUFSIZ
);
1312 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1313 html_idcat(buf
, nn
->string
, BUFSIZ
);
1315 html_idcat(buf
, " ", BUFSIZ
);
1318 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1319 tag
[1].key
= ATTR_HREF
;
1322 print_otag(h
, TAG_A
, 2, tag
);
1329 mdoc_aq_pre(MDOC_ARGS
)
1332 if (MDOC_BODY
!= n
->type
)
1334 print_text(h
, "\\(la");
1335 h
->flags
|= HTML_NOSPACE
;
1342 mdoc_aq_post(MDOC_ARGS
)
1345 if (MDOC_BODY
!= n
->type
)
1347 h
->flags
|= HTML_NOSPACE
;
1348 print_text(h
, "\\(ra");
1354 mdoc_bd_pre(MDOC_ARGS
)
1356 struct htmlpair tag
[2];
1358 const struct mdoc_node
*bl
, *nn
;
1361 if (MDOC_BLOCK
== n
->type
)
1363 else if (MDOC_HEAD
== n
->type
)
1368 SCALE_VS_INIT(&su
, 0);
1371 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1372 switch (bl
->args
->argv
[i
].arg
) {
1374 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1376 case (MDOC_Compact
):
1379 case (MDOC_Centred
):
1385 case (MDOC_Unfilled
):
1387 case (MDOC_Literal
):
1388 type
= bl
->args
->argv
[i
].arg
;
1394 /* FIXME: -centered, etc. formatting. */
1396 if (MDOC_BLOCK
== n
->type
) {
1397 bufcat_su(h
, "margin-left", &su
);
1398 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1399 if (MDOC_BLOCK
!= nn
->type
)
1401 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1407 print_otag(h
, TAG_DIV
, 0, tag
);
1410 SCALE_VS_INIT(&su
, 1);
1411 bufcat_su(h
, "margin-top", &su
);
1412 PAIR_STYLE_INIT(&tag
[0], h
);
1413 print_otag(h
, TAG_DIV
, 1, tag
);
1417 if (MDOC_Unfilled
!= type
&& MDOC_Literal
!= type
)
1420 PAIR_CLASS_INIT(&tag
[0], "lit");
1421 bufcat_style(h
, "white-space", "pre");
1422 PAIR_STYLE_INIT(&tag
[1], h
);
1423 print_otag(h
, TAG_DIV
, 2, tag
);
1425 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1426 h
->flags
|= HTML_NOSPACE
;
1427 print_mdoc_node(m
, nn
, h
);
1428 if (NULL
== nn
->next
)
1430 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1431 print_text(h
, "\n");
1432 else if (NULL
== nn
->prev
)
1433 print_text(h
, "\n");
1442 mdoc_pa_pre(MDOC_ARGS
)
1444 struct htmlpair tag
;
1446 PAIR_CLASS_INIT(&tag
, "file");
1447 print_otag(h
, TAG_SPAN
, 1, &tag
);
1454 mdoc_ad_pre(MDOC_ARGS
)
1456 struct htmlpair tag
;
1458 PAIR_CLASS_INIT(&tag
, "addr");
1459 print_otag(h
, TAG_SPAN
, 1, &tag
);
1466 mdoc_an_pre(MDOC_ARGS
)
1468 struct htmlpair tag
;
1470 /* TODO: -split and -nosplit (see termp_an_pre()). */
1472 PAIR_CLASS_INIT(&tag
, "author");
1473 print_otag(h
, TAG_SPAN
, 1, &tag
);
1480 mdoc_cd_pre(MDOC_ARGS
)
1482 struct htmlpair tag
;
1484 print_otag(h
, TAG_DIV
, 0, NULL
);
1485 PAIR_CLASS_INIT(&tag
, "config");
1486 print_otag(h
, TAG_SPAN
, 1, &tag
);
1493 mdoc_dv_pre(MDOC_ARGS
)
1495 struct htmlpair tag
;
1497 PAIR_CLASS_INIT(&tag
, "define");
1498 print_otag(h
, TAG_SPAN
, 1, &tag
);
1505 mdoc_ev_pre(MDOC_ARGS
)
1507 struct htmlpair tag
;
1509 PAIR_CLASS_INIT(&tag
, "env");
1510 print_otag(h
, TAG_SPAN
, 1, &tag
);
1517 mdoc_er_pre(MDOC_ARGS
)
1519 struct htmlpair tag
;
1521 PAIR_CLASS_INIT(&tag
, "errno");
1522 print_otag(h
, TAG_SPAN
, 1, &tag
);
1529 mdoc_fa_pre(MDOC_ARGS
)
1531 const struct mdoc_node
*nn
;
1532 struct htmlpair tag
;
1535 PAIR_CLASS_INIT(&tag
, "farg");
1536 if (n
->parent
->tok
!= MDOC_Fo
) {
1537 print_otag(h
, TAG_SPAN
, 1, &tag
);
1541 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1542 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1543 print_text(h
, nn
->string
);
1549 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1558 mdoc_fd_pre(MDOC_ARGS
)
1560 struct htmlpair tag
;
1563 if (SEC_SYNOPSIS
== n
->sec
) {
1564 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1565 SCALE_VS_INIT(&su
, 1);
1566 bufcat_su(h
, "margin-bottom", &su
);
1567 PAIR_STYLE_INIT(&tag
, h
);
1568 print_otag(h
, TAG_DIV
, 1, &tag
);
1570 print_otag(h
, TAG_DIV
, 0, NULL
);
1573 PAIR_CLASS_INIT(&tag
, "macro");
1574 print_otag(h
, TAG_SPAN
, 1, &tag
);
1581 mdoc_vt_pre(MDOC_ARGS
)
1583 struct htmlpair tag
;
1586 if (MDOC_BLOCK
== n
->type
) {
1587 if (n
->prev
&& MDOC_Vt
!= n
->prev
->tok
) {
1588 SCALE_VS_INIT(&su
, 1);
1589 bufcat_su(h
, "margin-top", &su
);
1590 PAIR_STYLE_INIT(&tag
, h
);
1591 print_otag(h
, TAG_DIV
, 1, &tag
);
1593 print_otag(h
, TAG_DIV
, 0, NULL
);
1596 } else if (MDOC_HEAD
== n
->type
)
1599 PAIR_CLASS_INIT(&tag
, "type");
1600 print_otag(h
, TAG_SPAN
, 1, &tag
);
1607 mdoc_ft_pre(MDOC_ARGS
)
1609 struct htmlpair tag
;
1612 if (SEC_SYNOPSIS
== n
->sec
) {
1613 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1614 SCALE_VS_INIT(&su
, 1);
1615 bufcat_su(h
, "margin-top", &su
);
1616 PAIR_STYLE_INIT(&tag
, h
);
1617 print_otag(h
, TAG_DIV
, 1, &tag
);
1619 print_otag(h
, TAG_DIV
, 0, NULL
);
1622 PAIR_CLASS_INIT(&tag
, "ftype");
1623 print_otag(h
, TAG_SPAN
, 1, &tag
);
1630 mdoc_fn_pre(MDOC_ARGS
)
1633 struct htmlpair tag
[2];
1634 const struct mdoc_node
*nn
;
1636 const char *sp
, *ep
;
1640 if (SEC_SYNOPSIS
== n
->sec
) {
1641 SCALE_HS_INIT(&su
, INDENT
);
1642 bufcat_su(h
, "margin-left", &su
);
1643 su
.scale
= -su
.scale
;
1644 bufcat_su(h
, "text-indent", &su
);
1646 SCALE_VS_INIT(&su
, 1);
1647 bufcat_su(h
, "margin-bottom", &su
);
1649 PAIR_STYLE_INIT(&tag
[0], h
);
1650 print_otag(h
, TAG_DIV
, 1, tag
);
1653 /* Split apart into type and name. */
1654 assert(n
->child
->string
);
1655 sp
= n
->child
->string
;
1657 ep
= strchr(sp
, ' ');
1659 PAIR_CLASS_INIT(&tag
[0], "ftype");
1660 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1663 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1664 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1666 print_text(h
, nbuf
);
1668 ep
= strchr(sp
, ' ');
1673 PAIR_CLASS_INIT(&tag
[0], "fname");
1674 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1677 (void)strlcpy(nbuf
, sp
, BUFSIZ
);
1678 print_text(h
, nbuf
);
1683 h
->flags
|= HTML_NOSPACE
;
1687 PAIR_CLASS_INIT(&tag
[0], "farg");
1688 bufcat_style(h
, "white-space", "nowrap");
1689 PAIR_STYLE_INIT(&tag
[1], h
);
1691 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1693 if (SEC_SYNOPSIS
== n
->sec
)
1695 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1696 print_text(h
, nn
->string
);
1703 if (SEC_SYNOPSIS
== n
->sec
)
1712 mdoc_sp_pre(MDOC_ARGS
)
1715 struct htmlpair tag
;
1720 /* FIXME: can this have a scaling indicator? */
1721 len
= n
->child
? atoi(n
->child
->string
) : 1;
1731 SCALE_VS_INIT(&su
, len
);
1732 bufcat_su(h
, "height", &su
);
1733 PAIR_STYLE_INIT(&tag
, h
);
1734 print_otag(h
, TAG_DIV
, 1, &tag
);
1735 /* So the div isn't empty: */
1736 print_text(h
, "\\~");
1745 mdoc_brq_pre(MDOC_ARGS
)
1748 if (MDOC_BODY
!= n
->type
)
1750 print_text(h
, "\\(lC");
1751 h
->flags
|= HTML_NOSPACE
;
1758 mdoc_brq_post(MDOC_ARGS
)
1761 if (MDOC_BODY
!= n
->type
)
1763 h
->flags
|= HTML_NOSPACE
;
1764 print_text(h
, "\\(rC");
1770 mdoc_lk_pre(MDOC_ARGS
)
1772 const struct mdoc_node
*nn
;
1773 struct htmlpair tag
[2];
1777 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1778 tag
[1].key
= ATTR_HREF
;
1779 tag
[1].val
= nn
->string
;
1780 print_otag(h
, TAG_A
, 2, tag
);
1782 if (NULL
== nn
->next
)
1785 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1786 print_text(h
, nn
->string
);
1794 mdoc_mt_pre(MDOC_ARGS
)
1796 struct htmlpair tag
[2];
1798 const struct mdoc_node
*nn
;
1800 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1802 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1804 bufcat(h
, "mailto:");
1805 bufcat(h
, nn
->string
);
1806 PAIR_STYLE_INIT(&tag
[1], h
);
1807 t
= print_otag(h
, TAG_A
, 2, tag
);
1808 print_text(h
, nn
->string
);
1818 mdoc_fo_pre(MDOC_ARGS
)
1820 struct htmlpair tag
;
1822 if (MDOC_BODY
== n
->type
) {
1823 h
->flags
|= HTML_NOSPACE
;
1825 h
->flags
|= HTML_NOSPACE
;
1827 } else if (MDOC_BLOCK
== n
->type
)
1830 PAIR_CLASS_INIT(&tag
, "fname");
1831 print_otag(h
, TAG_SPAN
, 1, &tag
);
1838 mdoc_fo_post(MDOC_ARGS
)
1840 if (MDOC_BODY
!= n
->type
)
1842 h
->flags
|= HTML_NOSPACE
;
1844 h
->flags
|= HTML_NOSPACE
;
1851 mdoc_in_pre(MDOC_ARGS
)
1853 const struct mdoc_node
*nn
;
1855 struct htmlpair tag
[2];
1859 if (SEC_SYNOPSIS
== n
->sec
) {
1860 if (n
->next
&& MDOC_In
!= n
->next
->tok
) {
1861 SCALE_VS_INIT(&su
, 1);
1862 bufcat_su(h
, "margin-bottom", &su
);
1863 PAIR_STYLE_INIT(&tag
[0], h
);
1864 print_otag(h
, TAG_DIV
, 1, tag
);
1866 print_otag(h
, TAG_DIV
, 0, NULL
);
1869 /* FIXME: there's a buffer bug in here somewhere. */
1871 PAIR_CLASS_INIT(&tag
[0], "includes");
1872 print_otag(h
, TAG_SPAN
, 1, tag
);
1874 if (SEC_SYNOPSIS
== n
->sec
)
1875 print_text(h
, "#include");
1878 h
->flags
|= HTML_NOSPACE
;
1880 /* XXX -- see warning in termp_in_post(). */
1882 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1883 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1886 if (h
->base_includes
) {
1887 buffmt_includes(h
, nn
->string
);
1888 tag
[i
].key
= ATTR_HREF
;
1889 tag
[i
++].val
= h
->buf
;
1891 t
= print_otag(h
, TAG_A
, i
, tag
);
1892 print_mdoc_node(m
, nn
, h
);
1896 h
->flags
|= HTML_NOSPACE
;
1905 mdoc_ic_pre(MDOC_ARGS
)
1907 struct htmlpair tag
;
1909 PAIR_CLASS_INIT(&tag
, "cmd");
1910 print_otag(h
, TAG_SPAN
, 1, &tag
);
1917 mdoc_rv_pre(MDOC_ARGS
)
1919 const struct mdoc_node
*nn
;
1920 struct htmlpair tag
;
1923 print_otag(h
, TAG_DIV
, 0, NULL
);
1924 print_text(h
, "The");
1926 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1927 PAIR_CLASS_INIT(&tag
, "fname");
1928 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1929 print_text(h
, nn
->string
);
1932 h
->flags
|= HTML_NOSPACE
;
1933 if (nn
->next
&& NULL
== nn
->next
->next
)
1934 print_text(h
, "(), and");
1936 print_text(h
, "(),");
1938 print_text(h
, "()");
1942 print_text(h
, "functions return");
1944 print_text(h
, "function returns");
1946 print_text(h
, "the value 0 if successful; otherwise the value "
1947 "-1 is returned and the global variable");
1949 PAIR_CLASS_INIT(&tag
, "var");
1950 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1951 print_text(h
, "errno");
1953 print_text(h
, "is set to indicate the error.");
1960 mdoc_va_pre(MDOC_ARGS
)
1962 struct htmlpair tag
;
1964 PAIR_CLASS_INIT(&tag
, "var");
1965 print_otag(h
, TAG_SPAN
, 1, &tag
);
1972 mdoc_bq_pre(MDOC_ARGS
)
1975 if (MDOC_BODY
!= n
->type
)
1977 print_text(h
, "\\(lB");
1978 h
->flags
|= HTML_NOSPACE
;
1985 mdoc_bq_post(MDOC_ARGS
)
1988 if (MDOC_BODY
!= n
->type
)
1990 h
->flags
|= HTML_NOSPACE
;
1991 print_text(h
, "\\(rB");
1997 mdoc_ap_pre(MDOC_ARGS
)
2000 h
->flags
|= HTML_NOSPACE
;
2001 print_text(h
, "\\(aq");
2002 h
->flags
|= HTML_NOSPACE
;
2009 mdoc_bf_pre(MDOC_ARGS
)
2012 struct htmlpair tag
[2];
2015 if (MDOC_HEAD
== n
->type
)
2017 else if (MDOC_BLOCK
!= n
->type
)
2020 PAIR_CLASS_INIT(&tag
[0], "lit");
2022 if (n
->head
->child
) {
2023 if ( ! strcmp("Em", n
->head
->child
->string
))
2024 PAIR_CLASS_INIT(&tag
[0], "emph");
2025 else if ( ! strcmp("Sy", n
->head
->child
->string
))
2026 PAIR_CLASS_INIT(&tag
[0], "symb");
2027 else if ( ! strcmp("Li", n
->head
->child
->string
))
2028 PAIR_CLASS_INIT(&tag
[0], "lit");
2031 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
2032 switch (n
->args
->argv
[i
].arg
) {
2033 case (MDOC_Symbolic
):
2034 PAIR_CLASS_INIT(&tag
[0], "symb");
2036 case (MDOC_Literal
):
2037 PAIR_CLASS_INIT(&tag
[0], "lit");
2039 case (MDOC_Emphasis
):
2040 PAIR_CLASS_INIT(&tag
[0], "emph");
2047 /* FIXME: div's have spaces stripped--we want them. */
2049 bufcat_style(h
, "display", "inline");
2050 SCALE_HS_INIT(&su
, 1);
2051 bufcat_su(h
, "margin-right", &su
);
2052 PAIR_STYLE_INIT(&tag
[1], h
);
2053 print_otag(h
, TAG_DIV
, 2, tag
);
2060 mdoc_ms_pre(MDOC_ARGS
)
2062 struct htmlpair tag
;
2064 PAIR_CLASS_INIT(&tag
, "symb");
2065 print_otag(h
, TAG_SPAN
, 1, &tag
);
2072 mdoc_pf_pre(MDOC_ARGS
)
2075 h
->flags
|= HTML_IGNDELIM
;
2082 mdoc_pf_post(MDOC_ARGS
)
2085 h
->flags
&= ~HTML_IGNDELIM
;
2086 h
->flags
|= HTML_NOSPACE
;
2092 mdoc_rs_pre(MDOC_ARGS
)
2094 struct htmlpair tag
;
2097 if (MDOC_BLOCK
!= n
->type
)
2100 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2101 SCALE_VS_INIT(&su
, 1);
2102 bufcat_su(h
, "margin-top", &su
);
2103 PAIR_STYLE_INIT(&tag
, h
);
2104 print_otag(h
, TAG_DIV
, 1, &tag
);
2107 PAIR_CLASS_INIT(&tag
, "ref");
2108 print_otag(h
, TAG_SPAN
, 1, &tag
);
2116 mdoc_li_pre(MDOC_ARGS
)
2118 struct htmlpair tag
;
2120 PAIR_CLASS_INIT(&tag
, "lit");
2121 print_otag(h
, TAG_SPAN
, 1, &tag
);
2128 mdoc_sy_pre(MDOC_ARGS
)
2130 struct htmlpair tag
;
2132 PAIR_CLASS_INIT(&tag
, "symb");
2133 print_otag(h
, TAG_SPAN
, 1, &tag
);
2140 mdoc_bt_pre(MDOC_ARGS
)
2143 print_text(h
, "is currently in beta test.");
2150 mdoc_ud_pre(MDOC_ARGS
)
2153 print_text(h
, "currently under development.");
2160 mdoc_lb_pre(MDOC_ARGS
)
2162 struct htmlpair tag
;
2164 if (SEC_SYNOPSIS
== n
->sec
)
2165 print_otag(h
, TAG_DIV
, 0, NULL
);
2166 PAIR_CLASS_INIT(&tag
, "lib");
2167 print_otag(h
, TAG_SPAN
, 1, &tag
);
2174 mdoc__x_pre(MDOC_ARGS
)
2176 struct htmlpair tag
[2];
2180 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2183 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2186 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2189 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2192 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2195 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2198 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2201 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2204 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2207 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2210 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2213 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2214 print_text(h
, "\\(lq");
2215 h
->flags
|= HTML_NOSPACE
;
2218 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2221 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2228 if (MDOC__U
!= n
->tok
) {
2229 print_otag(h
, TAG_SPAN
, 1, tag
);
2233 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2234 print_otag(h
, TAG_A
, 2, tag
);
2241 mdoc__x_post(MDOC_ARGS
)
2244 h
->flags
|= HTML_NOSPACE
;
2247 print_text(h
, "\\(rq");
2248 h
->flags
|= HTML_NOSPACE
;
2253 print_text(h
, n
->next
? "," : ".");