]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.79 2010/06/12 10:09:19 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>
39 #define MDOC_ARGS const struct mdoc_meta *m, \
40 const struct mdoc_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static void print_mdoc(MDOC_ARGS
);
53 static void print_mdoc_head(MDOC_ARGS
);
54 static void print_mdoc_node(MDOC_ARGS
);
55 static void print_mdoc_nodelist(MDOC_ARGS
);
56 static void synopsis_pre(struct html
*,
57 const struct mdoc_node
*);
59 static void a2width(const char *, struct roffsu
*);
60 static void a2offs(const char *, struct roffsu
*);
62 static void mdoc_root_post(MDOC_ARGS
);
63 static int mdoc_root_pre(MDOC_ARGS
);
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static void mdoc_aq_post(MDOC_ARGS
);
71 static int mdoc_aq_pre(MDOC_ARGS
);
72 static int mdoc_ar_pre(MDOC_ARGS
);
73 static int mdoc_bd_pre(MDOC_ARGS
);
74 static int mdoc_bf_pre(MDOC_ARGS
);
75 static void mdoc_bl_post(MDOC_ARGS
);
76 static int mdoc_bl_pre(MDOC_ARGS
);
77 static void mdoc_bq_post(MDOC_ARGS
);
78 static int mdoc_bq_pre(MDOC_ARGS
);
79 static void mdoc_brq_post(MDOC_ARGS
);
80 static int mdoc_brq_pre(MDOC_ARGS
);
81 static int mdoc_bt_pre(MDOC_ARGS
);
82 static int mdoc_bx_pre(MDOC_ARGS
);
83 static int mdoc_cd_pre(MDOC_ARGS
);
84 static int mdoc_d1_pre(MDOC_ARGS
);
85 static void mdoc_dq_post(MDOC_ARGS
);
86 static int mdoc_dq_pre(MDOC_ARGS
);
87 static int mdoc_dv_pre(MDOC_ARGS
);
88 static int mdoc_fa_pre(MDOC_ARGS
);
89 static int mdoc_fd_pre(MDOC_ARGS
);
90 static int mdoc_fl_pre(MDOC_ARGS
);
91 static int mdoc_fn_pre(MDOC_ARGS
);
92 static int mdoc_ft_pre(MDOC_ARGS
);
93 static int mdoc_em_pre(MDOC_ARGS
);
94 static int mdoc_er_pre(MDOC_ARGS
);
95 static int mdoc_ev_pre(MDOC_ARGS
);
96 static int mdoc_ex_pre(MDOC_ARGS
);
97 static void mdoc_fo_post(MDOC_ARGS
);
98 static int mdoc_fo_pre(MDOC_ARGS
);
99 static int mdoc_ic_pre(MDOC_ARGS
);
100 static int mdoc_in_pre(MDOC_ARGS
);
101 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
102 int, struct roffsu
*, struct roffsu
*);
103 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
105 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
,
107 static int mdoc_it_pre(MDOC_ARGS
);
108 static int mdoc_lb_pre(MDOC_ARGS
);
109 static int mdoc_li_pre(MDOC_ARGS
);
110 static int mdoc_lk_pre(MDOC_ARGS
);
111 static int mdoc_mt_pre(MDOC_ARGS
);
112 static int mdoc_ms_pre(MDOC_ARGS
);
113 static int mdoc_nd_pre(MDOC_ARGS
);
114 static int mdoc_nm_pre(MDOC_ARGS
);
115 static int mdoc_ns_pre(MDOC_ARGS
);
116 static void mdoc_op_post(MDOC_ARGS
);
117 static int mdoc_op_pre(MDOC_ARGS
);
118 static int mdoc_pa_pre(MDOC_ARGS
);
119 static void mdoc_pf_post(MDOC_ARGS
);
120 static int mdoc_pf_pre(MDOC_ARGS
);
121 static void mdoc_pq_post(MDOC_ARGS
);
122 static int mdoc_pq_pre(MDOC_ARGS
);
123 static int mdoc_rs_pre(MDOC_ARGS
);
124 static int mdoc_rv_pre(MDOC_ARGS
);
125 static int mdoc_sh_pre(MDOC_ARGS
);
126 static int mdoc_sp_pre(MDOC_ARGS
);
127 static void mdoc_sq_post(MDOC_ARGS
);
128 static int mdoc_sq_pre(MDOC_ARGS
);
129 static int mdoc_ss_pre(MDOC_ARGS
);
130 static int mdoc_sx_pre(MDOC_ARGS
);
131 static int mdoc_sy_pre(MDOC_ARGS
);
132 static int mdoc_ud_pre(MDOC_ARGS
);
133 static int mdoc_va_pre(MDOC_ARGS
);
134 static int mdoc_vt_pre(MDOC_ARGS
);
135 static int mdoc_xr_pre(MDOC_ARGS
);
136 static int mdoc_xx_pre(MDOC_ARGS
);
138 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
139 {mdoc_ap_pre
, NULL
}, /* Ap */
140 {NULL
, NULL
}, /* Dd */
141 {NULL
, NULL
}, /* Dt */
142 {NULL
, NULL
}, /* Os */
143 {mdoc_sh_pre
, NULL
}, /* Sh */
144 {mdoc_ss_pre
, NULL
}, /* Ss */
145 {mdoc_sp_pre
, NULL
}, /* Pp */
146 {mdoc_d1_pre
, NULL
}, /* D1 */
147 {mdoc_d1_pre
, NULL
}, /* Dl */
148 {mdoc_bd_pre
, NULL
}, /* Bd */
149 {NULL
, NULL
}, /* Ed */
150 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
151 {NULL
, NULL
}, /* El */
152 {mdoc_it_pre
, NULL
}, /* It */
153 {mdoc_ad_pre
, NULL
}, /* Ad */
154 {mdoc_an_pre
, NULL
}, /* An */
155 {mdoc_ar_pre
, NULL
}, /* Ar */
156 {mdoc_cd_pre
, NULL
}, /* Cd */
157 {mdoc_fl_pre
, NULL
}, /* Cm */
158 {mdoc_dv_pre
, NULL
}, /* Dv */
159 {mdoc_er_pre
, NULL
}, /* Er */
160 {mdoc_ev_pre
, NULL
}, /* Ev */
161 {mdoc_ex_pre
, NULL
}, /* Ex */
162 {mdoc_fa_pre
, NULL
}, /* Fa */
163 {mdoc_fd_pre
, NULL
}, /* Fd */
164 {mdoc_fl_pre
, NULL
}, /* Fl */
165 {mdoc_fn_pre
, NULL
}, /* Fn */
166 {mdoc_ft_pre
, NULL
}, /* Ft */
167 {mdoc_ic_pre
, NULL
}, /* Ic */
168 {mdoc_in_pre
, NULL
}, /* In */
169 {mdoc_li_pre
, NULL
}, /* Li */
170 {mdoc_nd_pre
, NULL
}, /* Nd */
171 {mdoc_nm_pre
, NULL
}, /* Nm */
172 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
173 {NULL
, NULL
}, /* Ot */
174 {mdoc_pa_pre
, NULL
}, /* Pa */
175 {mdoc_rv_pre
, NULL
}, /* Rv */
176 {NULL
, NULL
}, /* St */
177 {mdoc_va_pre
, NULL
}, /* Va */
178 {mdoc_vt_pre
, NULL
}, /* Vt */
179 {mdoc_xr_pre
, NULL
}, /* Xr */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
189 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
190 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
191 {NULL
, NULL
}, /* Ac */
192 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
193 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
194 {NULL
, NULL
}, /* At */
195 {NULL
, NULL
}, /* Bc */
196 {mdoc_bf_pre
, NULL
}, /* Bf */
197 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
198 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
199 {mdoc_xx_pre
, NULL
}, /* Bsx */
200 {mdoc_bx_pre
, NULL
}, /* Bx */
201 {NULL
, NULL
}, /* Db */
202 {NULL
, NULL
}, /* Dc */
203 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
204 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
205 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
206 {NULL
, NULL
}, /* Ef */
207 {mdoc_em_pre
, NULL
}, /* Em */
208 {NULL
, NULL
}, /* Eo */
209 {mdoc_xx_pre
, NULL
}, /* Fx */
210 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
211 {NULL
, NULL
}, /* No */
212 {mdoc_ns_pre
, NULL
}, /* Ns */
213 {mdoc_xx_pre
, NULL
}, /* Nx */
214 {mdoc_xx_pre
, NULL
}, /* Ox */
215 {NULL
, NULL
}, /* Pc */
216 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
217 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
218 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
219 {NULL
, NULL
}, /* Qc */
220 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
221 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
222 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
223 {NULL
, NULL
}, /* Re */
224 {mdoc_rs_pre
, NULL
}, /* Rs */
225 {NULL
, NULL
}, /* Sc */
226 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
227 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
228 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
229 {mdoc_sx_pre
, NULL
}, /* Sx */
230 {mdoc_sy_pre
, NULL
}, /* Sy */
231 {NULL
, NULL
}, /* Tn */
232 {mdoc_xx_pre
, NULL
}, /* Ux */
233 {NULL
, NULL
}, /* Xc */
234 {NULL
, NULL
}, /* Xo */
235 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
236 {NULL
, NULL
}, /* Fc */
237 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
238 {NULL
, NULL
}, /* Oc */
239 {NULL
, NULL
}, /* Bk */
240 {NULL
, NULL
}, /* Ek */
241 {mdoc_bt_pre
, NULL
}, /* Bt */
242 {NULL
, NULL
}, /* Hf */
243 {NULL
, NULL
}, /* Fr */
244 {mdoc_ud_pre
, NULL
}, /* Ud */
245 {mdoc_lb_pre
, NULL
}, /* Lb */
246 {mdoc_sp_pre
, NULL
}, /* Lp */
247 {mdoc_lk_pre
, NULL
}, /* Lk */
248 {mdoc_mt_pre
, NULL
}, /* Mt */
249 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
250 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
251 {NULL
, NULL
}, /* Brc */
252 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
253 {NULL
, NULL
}, /* Es */ /* TODO */
254 {NULL
, NULL
}, /* En */ /* TODO */
255 {mdoc_xx_pre
, NULL
}, /* Dx */
256 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
257 {mdoc_sp_pre
, NULL
}, /* br */
258 {mdoc_sp_pre
, NULL
}, /* sp */
259 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
260 {NULL
, NULL
}, /* Ta */
265 html_mdoc(void *arg
, const struct mdoc
*m
)
270 h
= (struct html
*)arg
;
273 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
274 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
282 * Calculate the scaling unit passed in a `-width' argument. This uses
283 * either a native scaling unit (e.g., 1i, 2m) or the string length of
287 a2width(const char *p
, struct roffsu
*su
)
290 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
292 su
->scale
= (int)strlen(p
);
298 * See the same function in mdoc_term.c for documentation.
301 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
306 if (NULL
== n
->prev
|| SEC_SYNOPSIS
!= n
->sec
)
309 SCALE_VS_INIT(&su
, 1);
310 bufcat_su(h
, "margin-top", &su
);
311 PAIR_STYLE_INIT(&tag
, h
);
313 if (n
->prev
->tok
== n
->tok
&&
317 print_otag(h
, TAG_DIV
, 0, NULL
);
321 switch (n
->prev
->tok
) {
331 print_otag(h
, TAG_DIV
, 1, &tag
);
334 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
335 print_otag(h
, TAG_DIV
, 1, &tag
);
340 print_otag(h
, TAG_DIV
, 0, NULL
);
347 * Calculate the scaling unit passed in an `-offset' argument. This
348 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
349 * predefined strings (indent, etc.), or the string length of the value.
352 a2offs(const char *p
, struct roffsu
*su
)
355 /* FIXME: "right"? */
357 if (0 == strcmp(p
, "left"))
358 SCALE_HS_INIT(su
, 0);
359 else if (0 == strcmp(p
, "indent"))
360 SCALE_HS_INIT(su
, INDENT
);
361 else if (0 == strcmp(p
, "indent-two"))
362 SCALE_HS_INIT(su
, INDENT
* 2);
363 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
365 su
->scale
= (int)strlen(p
);
371 print_mdoc(MDOC_ARGS
)
376 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
377 print_mdoc_head(m
, n
, h
);
380 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
382 tag
.key
= ATTR_CLASS
;
384 print_otag(h
, TAG_DIV
, 1, &tag
);
386 print_mdoc_nodelist(m
, n
, h
);
393 print_mdoc_head(MDOC_ARGS
)
398 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
406 print_otag(h
, TAG_TITLE
, 0, NULL
);
407 print_text(h
, h
->buf
);
412 print_mdoc_nodelist(MDOC_ARGS
)
415 print_mdoc_node(m
, n
, h
);
417 print_mdoc_nodelist(m
, n
->next
, h
);
422 print_mdoc_node(MDOC_ARGS
)
433 child
= mdoc_root_pre(m
, n
, h
);
436 print_text(h
, n
->string
);
439 if (mdocs
[n
->tok
].pre
)
440 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
444 if (child
&& n
->child
)
445 print_mdoc_nodelist(m
, n
->child
, h
);
452 mdoc_root_post(m
, n
, h
);
455 if (mdocs
[n
->tok
].post
)
456 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
464 mdoc_root_post(MDOC_ARGS
)
466 struct htmlpair tag
[3];
470 time2a(m
->date
, b
, DATESIZ
);
473 * XXX: this should use divs, but in Firefox, divs with nested
474 * divs for some reason puke when trying to put a border line
475 * below. So I use tables, instead.
478 PAIR_CLASS_INIT(&tag
[0], "footer");
479 bufcat_style(h
, "width", "100%");
480 PAIR_STYLE_INIT(&tag
[1], h
);
481 PAIR_SUMMARY_INIT(&tag
[2], "footer");
483 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
484 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
487 bufcat_style(h
, "width", "50%");
488 PAIR_STYLE_INIT(&tag
[0], h
);
489 print_otag(h
, TAG_TD
, 1, tag
);
494 bufcat_style(h
, "width", "50%");
495 bufcat_style(h
, "text-align", "right");
496 PAIR_STYLE_INIT(&tag
[0], h
);
497 print_otag(h
, TAG_TD
, 1, tag
);
498 print_text(h
, m
->os
);
505 mdoc_root_pre(MDOC_ARGS
)
507 struct htmlpair tag
[3];
509 char b
[BUFSIZ
], title
[BUFSIZ
];
511 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
514 (void)strlcat(b
, " (", BUFSIZ
);
515 (void)strlcat(b
, m
->arch
, BUFSIZ
);
516 (void)strlcat(b
, ")", BUFSIZ
);
519 (void)snprintf(title
, BUFSIZ
- 1,
520 "%s(%s)", m
->title
, m
->msec
);
522 /* XXX: see note in mdoc_root_post() about divs. */
524 PAIR_CLASS_INIT(&tag
[0], "header");
525 bufcat_style(h
, "width", "100%");
526 PAIR_STYLE_INIT(&tag
[1], h
);
527 PAIR_SUMMARY_INIT(&tag
[2], "header");
529 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
531 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
534 bufcat_style(h
, "width", "10%");
535 PAIR_STYLE_INIT(&tag
[0], h
);
536 print_otag(h
, TAG_TD
, 1, tag
);
537 print_text(h
, title
);
541 bufcat_style(h
, "text-align", "center");
542 bufcat_style(h
, "white-space", "nowrap");
543 bufcat_style(h
, "width", "80%");
544 PAIR_STYLE_INIT(&tag
[0], h
);
545 print_otag(h
, TAG_TD
, 1, tag
);
550 bufcat_style(h
, "text-align", "right");
551 bufcat_style(h
, "width", "10%");
552 PAIR_STYLE_INIT(&tag
[0], h
);
553 print_otag(h
, TAG_TD
, 1, tag
);
554 print_text(h
, title
);
562 mdoc_sh_pre(MDOC_ARGS
)
564 struct htmlpair tag
[2];
565 const struct mdoc_node
*nn
;
569 if (MDOC_BODY
== n
->type
) {
570 SCALE_HS_INIT(&su
, INDENT
);
571 bufcat_su(h
, "margin-left", &su
);
572 PAIR_CLASS_INIT(&tag
[0], "sec-body");
573 PAIR_STYLE_INIT(&tag
[1], h
);
574 print_otag(h
, TAG_DIV
, 2, tag
);
576 } else if (MDOC_BLOCK
== n
->type
) {
577 PAIR_CLASS_INIT(&tag
[0], "sec-block");
578 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
579 print_otag(h
, TAG_DIV
, 1, tag
);
583 SCALE_VS_INIT(&su
, 1);
584 bufcat_su(h
, "margin-top", &su
);
586 bufcat_su(h
, "margin-bottom", &su
);
588 PAIR_STYLE_INIT(&tag
[1], h
);
589 print_otag(h
, TAG_DIV
, 2, tag
);
594 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
595 html_idcat(buf
, nn
->string
, BUFSIZ
);
597 html_idcat(buf
, " ", BUFSIZ
);
600 PAIR_CLASS_INIT(&tag
[0], "sec-head");
601 PAIR_ID_INIT(&tag
[1], buf
);
603 print_otag(h
, TAG_DIV
, 2, tag
);
610 mdoc_ss_pre(MDOC_ARGS
)
612 struct htmlpair tag
[3];
613 const struct mdoc_node
*nn
;
617 SCALE_VS_INIT(&su
, 1);
619 if (MDOC_BODY
== n
->type
) {
620 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
621 if (n
->parent
->next
&& n
->child
) {
622 bufcat_su(h
, "margin-bottom", &su
);
623 PAIR_STYLE_INIT(&tag
[1], h
);
624 print_otag(h
, TAG_DIV
, 2, tag
);
626 print_otag(h
, TAG_DIV
, 1, tag
);
628 } else if (MDOC_BLOCK
== n
->type
) {
629 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
631 bufcat_su(h
, "margin-top", &su
);
632 PAIR_STYLE_INIT(&tag
[1], h
);
633 print_otag(h
, TAG_DIV
, 2, tag
);
635 print_otag(h
, TAG_DIV
, 1, tag
);
639 /* TODO: see note in mdoc_sh_pre() about duplicates. */
642 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
643 html_idcat(buf
, nn
->string
, BUFSIZ
);
645 html_idcat(buf
, " ", BUFSIZ
);
648 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
649 su
.scale
= -su
.scale
;
650 bufcat_su(h
, "margin-left", &su
);
652 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
653 PAIR_STYLE_INIT(&tag
[1], h
);
654 PAIR_ID_INIT(&tag
[2], buf
);
656 print_otag(h
, TAG_DIV
, 3, tag
);
663 mdoc_fl_pre(MDOC_ARGS
)
667 PAIR_CLASS_INIT(&tag
, "flag");
668 print_otag(h
, TAG_SPAN
, 1, &tag
);
670 /* `Cm' has no leading hyphen. */
672 if (MDOC_Cm
== n
->tok
)
675 print_text(h
, "\\-");
678 h
->flags
|= HTML_NOSPACE
;
679 else if (n
->next
&& n
->next
->line
== n
->line
)
680 h
->flags
|= HTML_NOSPACE
;
688 mdoc_nd_pre(MDOC_ARGS
)
692 if (MDOC_BODY
!= n
->type
)
695 /* XXX: this tag in theory can contain block elements. */
697 print_text(h
, "\\(em");
698 PAIR_CLASS_INIT(&tag
, "desc-body");
699 print_otag(h
, TAG_SPAN
, 1, &tag
);
706 mdoc_op_pre(MDOC_ARGS
)
710 if (MDOC_BODY
!= n
->type
)
713 /* XXX: this tag in theory can contain block elements. */
715 print_text(h
, "\\(lB");
716 h
->flags
|= HTML_NOSPACE
;
717 PAIR_CLASS_INIT(&tag
, "opt");
718 print_otag(h
, TAG_SPAN
, 1, &tag
);
725 mdoc_op_post(MDOC_ARGS
)
728 if (MDOC_BODY
!= n
->type
)
730 h
->flags
|= HTML_NOSPACE
;
731 print_text(h
, "\\(rB");
736 mdoc_nm_pre(MDOC_ARGS
)
740 if (NULL
== n
->child
&& NULL
== m
->name
)
745 PAIR_CLASS_INIT(&tag
, "name");
746 print_otag(h
, TAG_SPAN
, 1, &tag
);
747 if (NULL
== n
->child
)
748 print_text(h
, m
->name
);
755 mdoc_xr_pre(MDOC_ARGS
)
757 struct htmlpair tag
[2];
758 const struct mdoc_node
*nn
;
760 if (NULL
== n
->child
)
763 PAIR_CLASS_INIT(&tag
[0], "link-man");
766 buffmt_man(h
, n
->child
->string
,
768 n
->child
->next
->string
: NULL
);
769 PAIR_HREF_INIT(&tag
[1], h
->buf
);
770 print_otag(h
, TAG_A
, 2, tag
);
772 print_otag(h
, TAG_A
, 1, tag
);
775 print_text(h
, nn
->string
);
777 if (NULL
== (nn
= nn
->next
))
780 h
->flags
|= HTML_NOSPACE
;
782 h
->flags
|= HTML_NOSPACE
;
783 print_text(h
, nn
->string
);
784 h
->flags
|= HTML_NOSPACE
;
792 mdoc_ns_pre(MDOC_ARGS
)
795 h
->flags
|= HTML_NOSPACE
;
802 mdoc_ar_pre(MDOC_ARGS
)
806 PAIR_CLASS_INIT(&tag
, "arg");
807 print_otag(h
, TAG_SPAN
, 1, &tag
);
814 mdoc_xx_pre(MDOC_ARGS
)
842 PAIR_CLASS_INIT(&tag
, "unix");
843 print_otag(h
, TAG_SPAN
, 1, &tag
);
851 mdoc_bx_pre(MDOC_ARGS
)
853 const struct mdoc_node
*nn
;
856 PAIR_CLASS_INIT(&tag
, "unix");
857 print_otag(h
, TAG_SPAN
, 1, &tag
);
859 for (nn
= n
->child
; nn
; nn
= nn
->next
)
860 print_mdoc_node(m
, nn
, h
);
863 h
->flags
|= HTML_NOSPACE
;
865 print_text(h
, "BSD");
872 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
873 struct roffsu
*offs
, struct roffsu
*width
)
876 const struct mdoc_node
*nn
;
879 nn
= n
->parent
->parent
;
881 /* XXX: see notes in mdoc_it_pre(). */
883 if (LIST_column
== type
) {
884 /* Don't width-pad on the left. */
885 SCALE_HS_INIT(width
, 0);
886 /* Also disallow non-compact. */
889 if (LIST_diag
== type
)
890 /* Mandate non-compact with empty prior. */
891 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
894 bufcat_style(h
, "clear", "both");
896 bufcat_su(h
, "margin-left", offs
);
897 if (width
->scale
> 0)
898 bufcat_su(h
, "padding-left", width
);
900 PAIR_STYLE_INIT(&tag
, h
);
902 /* Mandate compact following `Ss' and `Sh' starts. */
904 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
905 if (MDOC_BLOCK
!= nn
->type
)
907 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
914 SCALE_VS_INIT(&su
, 1);
915 bufcat_su(h
, "padding-top", &su
);
918 PAIR_STYLE_INIT(&tag
, h
);
919 print_otag(h
, TAG_DIV
, 1, &tag
);
926 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
937 bufcat_su(h
, "min-width", width
);
938 bufcat_style(h
, "clear", "none");
940 bufcat_style(h
, "float", "left");
941 PAIR_STYLE_INIT(&tag
, h
);
942 print_otag(h
, TAG_DIV
, 1, &tag
);
946 * XXX: this tricks CSS into aligning the bodies with
947 * the right-padding in the head.
949 SCALE_HS_INIT(&su
, 2);
950 bufcat_su(h
, "margin-left", &su
);
951 PAIR_STYLE_INIT(&tag
, h
);
952 print_otag(h
, TAG_DIV
, 1, &tag
);
962 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
972 print_otag(h
, TAG_DIV
, 0, &tag
);
977 bufcat_su(h
, "min-width", width
);
979 bufcat_su(h
, "margin-left", width
);
980 if (n
->next
&& n
->next
->child
)
981 bufcat_style(h
, "float", "left");
983 /* XXX: buffer if we run into body. */
984 SCALE_HS_INIT(width
, 1);
985 bufcat_su(h
, "margin-right", width
);
986 PAIR_STYLE_INIT(&tag
, h
);
987 print_otag(h
, TAG_DIV
, 1, &tag
);
993 PAIR_CLASS_INIT(&tag
, "diag");
994 print_otag(h
, TAG_SPAN
, 1, &tag
);
999 nbuf
[BUFSIZ
- 1] = 0;
1000 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1001 print_text(h
, nbuf
);
1004 print_text(h
, "\\(en");
1007 print_text(h
, "\\(hy");
1010 print_text(h
, "\\(bu");
1021 mdoc_it_pre(MDOC_ARGS
)
1024 const struct mdoc_node
*bl
, *nn
;
1025 struct roffsu width
, offs
;
1026 enum mdoc_list type
;
1029 * XXX: be very careful in changing anything, here. Lists in
1030 * mandoc have many peculiarities; furthermore, they don't
1031 * translate well into HTML and require a bit of mangling.
1034 bl
= n
->parent
->parent
;
1035 if (MDOC_BLOCK
!= n
->type
)
1038 type
= bl
->data
.list
;
1040 /* Set default width and offset. */
1042 SCALE_HS_INIT(&offs
, 0);
1052 SCALE_HS_INIT(&width
, 2);
1055 SCALE_HS_INIT(&width
, INDENT
);
1059 /* Get width, offset, and compact arguments. */
1062 for (comp
= i
= 0; bl
->args
&& i
< (int)bl
->args
->argc
; i
++)
1063 switch (bl
->args
->argv
[i
].arg
) {
1065 wp
= i
; /* Save for later. */
1068 a2width(bl
->args
->argv
[i
].value
[0], &width
);
1071 a2offs(bl
->args
->argv
[i
].value
[0], &offs
);
1073 case (MDOC_Compact
):
1080 /* Override width in some cases. */
1090 SCALE_HS_INIT(&width
, 0);
1093 if (0 == width
.scale
)
1094 SCALE_HS_INIT(&width
, INDENT
);
1098 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1099 nn
= n
->parent
->child
;
1100 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1101 if (MDOC_BODY
== nn
->type
)
1103 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1104 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1107 if (MDOC_HEAD
== n
->type
)
1108 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1109 else if (MDOC_BODY
== n
->type
)
1110 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1112 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1118 mdoc_bl_pre(MDOC_ARGS
)
1122 if (MDOC_HEAD
== n
->type
)
1124 if (MDOC_BLOCK
!= n
->type
)
1126 if (LIST_enum
!= n
->data
.list
)
1129 ord
= malloc(sizeof(struct ord
));
1136 ord
->next
= h
->ords
.head
;
1144 mdoc_bl_post(MDOC_ARGS
)
1148 if (MDOC_BLOCK
!= n
->type
)
1150 if (LIST_enum
!= n
->data
.list
)
1155 h
->ords
.head
= ord
->next
;
1162 mdoc_ex_pre(MDOC_ARGS
)
1164 const struct mdoc_node
*nn
;
1166 struct htmlpair tag
;
1168 PAIR_CLASS_INIT(&tag
, "utility");
1170 print_text(h
, "The");
1171 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1172 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1173 print_text(h
, nn
->string
);
1176 h
->flags
|= HTML_NOSPACE
;
1178 if (nn
->next
&& NULL
== nn
->next
->next
)
1179 print_text(h
, ", and");
1183 h
->flags
&= ~HTML_NOSPACE
;
1186 if (n
->child
&& n
->child
->next
)
1187 print_text(h
, "utilities exit");
1189 print_text(h
, "utility exits");
1191 print_text(h
, "0 on success, and >0 if an error occurs.");
1198 mdoc_dq_pre(MDOC_ARGS
)
1201 if (MDOC_BODY
!= n
->type
)
1203 print_text(h
, "\\(lq");
1204 h
->flags
|= HTML_NOSPACE
;
1211 mdoc_dq_post(MDOC_ARGS
)
1214 if (MDOC_BODY
!= n
->type
)
1216 h
->flags
|= HTML_NOSPACE
;
1217 print_text(h
, "\\(rq");
1223 mdoc_pq_pre(MDOC_ARGS
)
1226 if (MDOC_BODY
!= n
->type
)
1228 print_text(h
, "\\&(");
1229 h
->flags
|= HTML_NOSPACE
;
1236 mdoc_pq_post(MDOC_ARGS
)
1239 if (MDOC_BODY
!= n
->type
)
1247 mdoc_sq_pre(MDOC_ARGS
)
1250 if (MDOC_BODY
!= n
->type
)
1252 print_text(h
, "\\(oq");
1253 h
->flags
|= HTML_NOSPACE
;
1260 mdoc_sq_post(MDOC_ARGS
)
1263 if (MDOC_BODY
!= n
->type
)
1265 h
->flags
|= HTML_NOSPACE
;
1266 print_text(h
, "\\(aq");
1272 mdoc_em_pre(MDOC_ARGS
)
1274 struct htmlpair tag
;
1276 PAIR_CLASS_INIT(&tag
, "emph");
1277 print_otag(h
, TAG_SPAN
, 1, &tag
);
1284 mdoc_d1_pre(MDOC_ARGS
)
1286 struct htmlpair tag
[2];
1289 if (MDOC_BLOCK
!= n
->type
)
1292 /* FIXME: D1 shouldn't be literal. */
1294 SCALE_VS_INIT(&su
, INDENT
- 2);
1295 bufcat_su(h
, "margin-left", &su
);
1296 PAIR_CLASS_INIT(&tag
[0], "lit");
1297 PAIR_STYLE_INIT(&tag
[1], h
);
1298 print_otag(h
, TAG_DIV
, 2, tag
);
1305 mdoc_sx_pre(MDOC_ARGS
)
1307 struct htmlpair tag
[2];
1308 const struct mdoc_node
*nn
;
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 PAIR_HREF_INIT(&tag
[1], buf
);
1321 print_otag(h
, TAG_A
, 2, tag
);
1328 mdoc_aq_pre(MDOC_ARGS
)
1331 if (MDOC_BODY
!= n
->type
)
1333 print_text(h
, "\\(la");
1334 h
->flags
|= HTML_NOSPACE
;
1341 mdoc_aq_post(MDOC_ARGS
)
1344 if (MDOC_BODY
!= n
->type
)
1346 h
->flags
|= HTML_NOSPACE
;
1347 print_text(h
, "\\(ra");
1353 mdoc_bd_pre(MDOC_ARGS
)
1355 struct htmlpair tag
[2];
1357 const struct mdoc_node
*bl
, *nn
;
1360 if (MDOC_BLOCK
== n
->type
)
1362 else if (MDOC_HEAD
== n
->type
)
1367 SCALE_VS_INIT(&su
, 0);
1370 for (i
= 0; bl
->args
&& i
< (int)bl
->args
->argc
; i
++)
1371 switch (bl
->args
->argv
[i
].arg
) {
1373 a2offs(bl
->args
->argv
[i
].value
[0], &su
);
1375 case (MDOC_Compact
):
1382 /* FIXME: -centered, etc. formatting. */
1383 /* FIXME: does not respect -offset ??? */
1385 if (MDOC_BLOCK
== n
->type
) {
1386 bufcat_su(h
, "margin-left", &su
);
1387 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1388 if (MDOC_BLOCK
!= nn
->type
)
1390 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1396 PAIR_STYLE_INIT(&tag
[0], h
);
1397 print_otag(h
, TAG_DIV
, 1, tag
);
1400 SCALE_VS_INIT(&su
, 1);
1401 bufcat_su(h
, "margin-top", &su
);
1402 PAIR_STYLE_INIT(&tag
[0], h
);
1403 print_otag(h
, TAG_DIV
, 1, tag
);
1407 if (DISP_unfilled
!= n
->data
.disp
&&
1408 DISP_literal
!= n
->data
.disp
)
1411 PAIR_CLASS_INIT(&tag
[0], "lit");
1412 bufcat_style(h
, "white-space", "pre");
1413 PAIR_STYLE_INIT(&tag
[1], h
);
1414 print_otag(h
, TAG_DIV
, 2, tag
);
1416 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1417 h
->flags
|= HTML_NOSPACE
;
1418 print_mdoc_node(m
, nn
, h
);
1419 if (NULL
== nn
->next
)
1421 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1422 print_text(h
, "\n");
1423 else if (NULL
== nn
->prev
)
1424 print_text(h
, "\n");
1433 mdoc_pa_pre(MDOC_ARGS
)
1435 struct htmlpair tag
;
1437 PAIR_CLASS_INIT(&tag
, "file");
1438 print_otag(h
, TAG_SPAN
, 1, &tag
);
1445 mdoc_ad_pre(MDOC_ARGS
)
1447 struct htmlpair tag
;
1449 PAIR_CLASS_INIT(&tag
, "addr");
1450 print_otag(h
, TAG_SPAN
, 1, &tag
);
1457 mdoc_an_pre(MDOC_ARGS
)
1459 struct htmlpair tag
;
1461 /* TODO: -split and -nosplit (see termp_an_pre()). */
1463 PAIR_CLASS_INIT(&tag
, "author");
1464 print_otag(h
, TAG_SPAN
, 1, &tag
);
1471 mdoc_cd_pre(MDOC_ARGS
)
1473 struct htmlpair tag
;
1476 PAIR_CLASS_INIT(&tag
, "config");
1477 print_otag(h
, TAG_SPAN
, 1, &tag
);
1484 mdoc_dv_pre(MDOC_ARGS
)
1486 struct htmlpair tag
;
1488 PAIR_CLASS_INIT(&tag
, "define");
1489 print_otag(h
, TAG_SPAN
, 1, &tag
);
1496 mdoc_ev_pre(MDOC_ARGS
)
1498 struct htmlpair tag
;
1500 PAIR_CLASS_INIT(&tag
, "env");
1501 print_otag(h
, TAG_SPAN
, 1, &tag
);
1508 mdoc_er_pre(MDOC_ARGS
)
1510 struct htmlpair tag
;
1512 PAIR_CLASS_INIT(&tag
, "errno");
1513 print_otag(h
, TAG_SPAN
, 1, &tag
);
1520 mdoc_fa_pre(MDOC_ARGS
)
1522 const struct mdoc_node
*nn
;
1523 struct htmlpair tag
;
1526 PAIR_CLASS_INIT(&tag
, "farg");
1527 if (n
->parent
->tok
!= MDOC_Fo
) {
1528 print_otag(h
, TAG_SPAN
, 1, &tag
);
1532 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1533 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1534 print_text(h
, nn
->string
);
1540 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1549 mdoc_fd_pre(MDOC_ARGS
)
1551 struct htmlpair tag
;
1555 PAIR_CLASS_INIT(&tag
, "macro");
1556 print_otag(h
, TAG_SPAN
, 1, &tag
);
1563 mdoc_vt_pre(MDOC_ARGS
)
1565 struct htmlpair tag
;
1567 if (MDOC_BLOCK
== n
->type
) {
1570 } else if (MDOC_ELEM
== n
->type
) {
1572 } else if (MDOC_HEAD
== n
->type
)
1575 PAIR_CLASS_INIT(&tag
, "type");
1576 print_otag(h
, TAG_SPAN
, 1, &tag
);
1583 mdoc_ft_pre(MDOC_ARGS
)
1585 struct htmlpair tag
;
1588 PAIR_CLASS_INIT(&tag
, "ftype");
1589 print_otag(h
, TAG_SPAN
, 1, &tag
);
1596 mdoc_fn_pre(MDOC_ARGS
)
1599 struct htmlpair tag
[2];
1600 const struct mdoc_node
*nn
;
1602 const char *sp
, *ep
;
1607 /* Split apart into type and name. */
1608 assert(n
->child
->string
);
1609 sp
= n
->child
->string
;
1611 ep
= strchr(sp
, ' ');
1613 PAIR_CLASS_INIT(&tag
[0], "ftype");
1614 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1617 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1618 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1620 print_text(h
, nbuf
);
1622 ep
= strchr(sp
, ' ');
1627 PAIR_CLASS_INIT(&tag
[0], "fname");
1630 * FIXME: only refer to IDs that we know exist.
1634 if (SEC_SYNOPSIS
== n
->sec
) {
1636 html_idcat(nbuf
, sp
, BUFSIZ
);
1637 PAIR_ID_INIT(&tag
[1], nbuf
);
1639 strlcpy(nbuf
, "#", BUFSIZ
);
1640 html_idcat(nbuf
, sp
, BUFSIZ
);
1641 PAIR_HREF_INIT(&tag
[1], nbuf
);
1645 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1648 strlcpy(nbuf
, sp
, BUFSIZ
);
1649 print_text(h
, nbuf
);
1654 h
->flags
|= HTML_NOSPACE
;
1658 PAIR_CLASS_INIT(&tag
[0], "farg");
1659 bufcat_style(h
, "white-space", "nowrap");
1660 PAIR_STYLE_INIT(&tag
[1], h
);
1662 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1664 if (SEC_SYNOPSIS
== n
->sec
)
1666 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1667 print_text(h
, nn
->string
);
1674 if (SEC_SYNOPSIS
== n
->sec
)
1683 mdoc_sp_pre(MDOC_ARGS
)
1686 struct htmlpair tag
;
1691 /* FIXME: can this have a scaling indicator? */
1692 len
= n
->child
? atoi(n
->child
->string
) : 1;
1702 SCALE_VS_INIT(&su
, len
);
1703 bufcat_su(h
, "height", &su
);
1704 PAIR_STYLE_INIT(&tag
, h
);
1705 print_otag(h
, TAG_DIV
, 1, &tag
);
1706 /* So the div isn't empty: */
1707 print_text(h
, "\\~");
1716 mdoc_brq_pre(MDOC_ARGS
)
1719 if (MDOC_BODY
!= n
->type
)
1721 print_text(h
, "\\(lC");
1722 h
->flags
|= HTML_NOSPACE
;
1729 mdoc_brq_post(MDOC_ARGS
)
1732 if (MDOC_BODY
!= n
->type
)
1734 h
->flags
|= HTML_NOSPACE
;
1735 print_text(h
, "\\(rC");
1741 mdoc_lk_pre(MDOC_ARGS
)
1743 const struct mdoc_node
*nn
;
1744 struct htmlpair tag
[2];
1748 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1749 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1750 print_otag(h
, TAG_A
, 2, tag
);
1752 if (NULL
== nn
->next
)
1755 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1756 print_text(h
, nn
->string
);
1764 mdoc_mt_pre(MDOC_ARGS
)
1766 struct htmlpair tag
[2];
1768 const struct mdoc_node
*nn
;
1770 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1772 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1774 bufcat(h
, "mailto:");
1775 bufcat(h
, nn
->string
);
1776 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1777 t
= print_otag(h
, TAG_A
, 2, tag
);
1778 print_text(h
, nn
->string
);
1788 mdoc_fo_pre(MDOC_ARGS
)
1790 struct htmlpair tag
;
1793 if (MDOC_BODY
== n
->type
) {
1794 h
->flags
|= HTML_NOSPACE
;
1796 h
->flags
|= HTML_NOSPACE
;
1798 } else if (MDOC_BLOCK
== n
->type
) {
1803 /* XXX: we drop non-initial arguments as per groff. */
1806 assert(n
->child
->string
);
1808 PAIR_CLASS_INIT(&tag
, "fname");
1809 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1810 print_text(h
, n
->child
->string
);
1818 mdoc_fo_post(MDOC_ARGS
)
1821 if (MDOC_BODY
!= n
->type
)
1823 h
->flags
|= HTML_NOSPACE
;
1825 h
->flags
|= HTML_NOSPACE
;
1832 mdoc_in_pre(MDOC_ARGS
)
1834 const struct mdoc_node
*nn
;
1836 struct htmlpair tag
[2];
1841 PAIR_CLASS_INIT(&tag
[0], "includes");
1842 print_otag(h
, TAG_SPAN
, 1, tag
);
1844 if (SEC_SYNOPSIS
== n
->sec
&& MDOC_LINE
& n
->flags
)
1845 print_text(h
, "#include");
1848 h
->flags
|= HTML_NOSPACE
;
1850 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1851 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1854 if (h
->base_includes
) {
1855 buffmt_includes(h
, nn
->string
);
1856 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1859 t
= print_otag(h
, TAG_A
, i
, tag
);
1860 print_mdoc_node(m
, nn
, h
);
1864 h
->flags
|= HTML_NOSPACE
;
1873 mdoc_ic_pre(MDOC_ARGS
)
1875 struct htmlpair tag
;
1877 PAIR_CLASS_INIT(&tag
, "cmd");
1878 print_otag(h
, TAG_SPAN
, 1, &tag
);
1885 mdoc_rv_pre(MDOC_ARGS
)
1887 const struct mdoc_node
*nn
;
1888 struct htmlpair tag
;
1891 print_otag(h
, TAG_DIV
, 0, NULL
);
1892 print_text(h
, "The");
1894 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1895 PAIR_CLASS_INIT(&tag
, "fname");
1896 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1897 print_text(h
, nn
->string
);
1900 h
->flags
|= HTML_NOSPACE
;
1901 if (nn
->next
&& NULL
== nn
->next
->next
)
1902 print_text(h
, "(), and");
1904 print_text(h
, "(),");
1906 print_text(h
, "()");
1909 if (n
->child
&& n
->child
->next
)
1910 print_text(h
, "functions return");
1912 print_text(h
, "function returns");
1914 print_text(h
, "the value 0 if successful; otherwise the value "
1915 "-1 is returned and the global variable");
1917 PAIR_CLASS_INIT(&tag
, "var");
1918 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1919 print_text(h
, "errno");
1921 print_text(h
, "is set to indicate the error.");
1928 mdoc_va_pre(MDOC_ARGS
)
1930 struct htmlpair tag
;
1932 PAIR_CLASS_INIT(&tag
, "var");
1933 print_otag(h
, TAG_SPAN
, 1, &tag
);
1940 mdoc_bq_pre(MDOC_ARGS
)
1943 if (MDOC_BODY
!= n
->type
)
1945 print_text(h
, "\\(lB");
1946 h
->flags
|= HTML_NOSPACE
;
1953 mdoc_bq_post(MDOC_ARGS
)
1956 if (MDOC_BODY
!= n
->type
)
1958 h
->flags
|= HTML_NOSPACE
;
1959 print_text(h
, "\\(rB");
1965 mdoc_ap_pre(MDOC_ARGS
)
1968 h
->flags
|= HTML_NOSPACE
;
1969 print_text(h
, "\\(aq");
1970 h
->flags
|= HTML_NOSPACE
;
1977 mdoc_bf_pre(MDOC_ARGS
)
1980 struct htmlpair tag
[2];
1983 if (MDOC_HEAD
== n
->type
)
1985 else if (MDOC_BLOCK
!= n
->type
)
1988 PAIR_CLASS_INIT(&tag
[0], "lit");
1990 if (n
->head
->child
) {
1991 if ( ! strcmp("Em", n
->head
->child
->string
))
1992 PAIR_CLASS_INIT(&tag
[0], "emph");
1993 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1994 PAIR_CLASS_INIT(&tag
[0], "symb");
1995 else if ( ! strcmp("Li", n
->head
->child
->string
))
1996 PAIR_CLASS_INIT(&tag
[0], "lit");
1998 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++)
1999 switch (n
->args
->argv
[i
].arg
) {
2000 case (MDOC_Symbolic
):
2001 PAIR_CLASS_INIT(&tag
[0], "symb");
2003 case (MDOC_Literal
):
2004 PAIR_CLASS_INIT(&tag
[0], "lit");
2006 case (MDOC_Emphasis
):
2007 PAIR_CLASS_INIT(&tag
[0], "emph");
2014 /* FIXME: div's have spaces stripped--we want them. */
2016 bufcat_style(h
, "display", "inline");
2017 SCALE_HS_INIT(&su
, 1);
2018 bufcat_su(h
, "margin-right", &su
);
2019 PAIR_STYLE_INIT(&tag
[1], h
);
2020 print_otag(h
, TAG_DIV
, 2, tag
);
2027 mdoc_ms_pre(MDOC_ARGS
)
2029 struct htmlpair tag
;
2031 PAIR_CLASS_INIT(&tag
, "symb");
2032 print_otag(h
, TAG_SPAN
, 1, &tag
);
2039 mdoc_pf_pre(MDOC_ARGS
)
2042 h
->flags
|= HTML_IGNDELIM
;
2049 mdoc_pf_post(MDOC_ARGS
)
2052 h
->flags
&= ~HTML_IGNDELIM
;
2053 h
->flags
|= HTML_NOSPACE
;
2059 mdoc_rs_pre(MDOC_ARGS
)
2061 struct htmlpair tag
;
2064 if (MDOC_BLOCK
!= n
->type
)
2067 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2068 SCALE_VS_INIT(&su
, 1);
2069 bufcat_su(h
, "margin-top", &su
);
2070 PAIR_STYLE_INIT(&tag
, h
);
2071 print_otag(h
, TAG_DIV
, 1, &tag
);
2074 PAIR_CLASS_INIT(&tag
, "ref");
2075 print_otag(h
, TAG_SPAN
, 1, &tag
);
2083 mdoc_li_pre(MDOC_ARGS
)
2085 struct htmlpair tag
;
2087 PAIR_CLASS_INIT(&tag
, "lit");
2088 print_otag(h
, TAG_SPAN
, 1, &tag
);
2095 mdoc_sy_pre(MDOC_ARGS
)
2097 struct htmlpair tag
;
2099 PAIR_CLASS_INIT(&tag
, "symb");
2100 print_otag(h
, TAG_SPAN
, 1, &tag
);
2107 mdoc_bt_pre(MDOC_ARGS
)
2110 print_text(h
, "is currently in beta test.");
2117 mdoc_ud_pre(MDOC_ARGS
)
2120 print_text(h
, "currently under development.");
2127 mdoc_lb_pre(MDOC_ARGS
)
2129 struct htmlpair tag
;
2131 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2132 print_otag(h
, TAG_DIV
, 0, NULL
);
2133 PAIR_CLASS_INIT(&tag
, "lib");
2134 print_otag(h
, TAG_SPAN
, 1, &tag
);
2141 mdoc__x_pre(MDOC_ARGS
)
2143 struct htmlpair tag
[2];
2147 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2150 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2153 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2156 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2159 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2162 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2165 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2168 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2171 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2174 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2177 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2180 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2183 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2186 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2193 if (MDOC__U
!= n
->tok
) {
2194 print_otag(h
, TAG_SPAN
, 1, tag
);
2198 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2199 print_otag(h
, TAG_A
, 2, tag
);
2206 mdoc__x_post(MDOC_ARGS
)
2211 h
->flags
|= HTML_NOSPACE
;
2212 print_text(h
, n
->next
? "," : ".");