]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.104 2010/09/04 20:18:53 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
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_bk_post(MDOC_ARGS
);
76 static int mdoc_bk_pre(MDOC_ARGS
);
77 static void mdoc_bl_post(MDOC_ARGS
);
78 static int mdoc_bl_pre(MDOC_ARGS
);
79 static void mdoc_bq_post(MDOC_ARGS
);
80 static int mdoc_bq_pre(MDOC_ARGS
);
81 static void mdoc_brq_post(MDOC_ARGS
);
82 static int mdoc_brq_pre(MDOC_ARGS
);
83 static int mdoc_bt_pre(MDOC_ARGS
);
84 static int mdoc_bx_pre(MDOC_ARGS
);
85 static int mdoc_cd_pre(MDOC_ARGS
);
86 static int mdoc_d1_pre(MDOC_ARGS
);
87 static void mdoc_dq_post(MDOC_ARGS
);
88 static int mdoc_dq_pre(MDOC_ARGS
);
89 static int mdoc_dv_pre(MDOC_ARGS
);
90 static int mdoc_fa_pre(MDOC_ARGS
);
91 static int mdoc_fd_pre(MDOC_ARGS
);
92 static int mdoc_fl_pre(MDOC_ARGS
);
93 static int mdoc_fn_pre(MDOC_ARGS
);
94 static int mdoc_ft_pre(MDOC_ARGS
);
95 static int mdoc_em_pre(MDOC_ARGS
);
96 static int mdoc_er_pre(MDOC_ARGS
);
97 static int mdoc_ev_pre(MDOC_ARGS
);
98 static int mdoc_ex_pre(MDOC_ARGS
);
99 static void mdoc_fo_post(MDOC_ARGS
);
100 static int mdoc_fo_pre(MDOC_ARGS
);
101 static int mdoc_ic_pre(MDOC_ARGS
);
102 static int mdoc_in_pre(MDOC_ARGS
);
103 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
104 int, struct roffsu
*, struct roffsu
*);
105 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
107 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
,
109 static int mdoc_it_pre(MDOC_ARGS
);
110 static int mdoc_lb_pre(MDOC_ARGS
);
111 static int mdoc_li_pre(MDOC_ARGS
);
112 static int mdoc_lk_pre(MDOC_ARGS
);
113 static int mdoc_mt_pre(MDOC_ARGS
);
114 static int mdoc_ms_pre(MDOC_ARGS
);
115 static int mdoc_nd_pre(MDOC_ARGS
);
116 static int mdoc_nm_pre(MDOC_ARGS
);
117 static int mdoc_ns_pre(MDOC_ARGS
);
118 static void mdoc_op_post(MDOC_ARGS
);
119 static int mdoc_op_pre(MDOC_ARGS
);
120 static int mdoc_pa_pre(MDOC_ARGS
);
121 static void mdoc_pf_post(MDOC_ARGS
);
122 static int mdoc_pf_pre(MDOC_ARGS
);
123 static void mdoc_pq_post(MDOC_ARGS
);
124 static int mdoc_pq_pre(MDOC_ARGS
);
125 static int mdoc_rs_pre(MDOC_ARGS
);
126 static int mdoc_rv_pre(MDOC_ARGS
);
127 static int mdoc_sh_pre(MDOC_ARGS
);
128 static int mdoc_sm_pre(MDOC_ARGS
);
129 static int mdoc_sp_pre(MDOC_ARGS
);
130 static void mdoc_sq_post(MDOC_ARGS
);
131 static int mdoc_sq_pre(MDOC_ARGS
);
132 static int mdoc_ss_pre(MDOC_ARGS
);
133 static int mdoc_sx_pre(MDOC_ARGS
);
134 static int mdoc_sy_pre(MDOC_ARGS
);
135 static int mdoc_ud_pre(MDOC_ARGS
);
136 static int mdoc_va_pre(MDOC_ARGS
);
137 static int mdoc_vt_pre(MDOC_ARGS
);
138 static int mdoc_xr_pre(MDOC_ARGS
);
139 static int mdoc_xx_pre(MDOC_ARGS
);
141 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
142 {mdoc_ap_pre
, NULL
}, /* Ap */
143 {NULL
, NULL
}, /* Dd */
144 {NULL
, NULL
}, /* Dt */
145 {NULL
, NULL
}, /* Os */
146 {mdoc_sh_pre
, NULL
}, /* Sh */
147 {mdoc_ss_pre
, NULL
}, /* Ss */
148 {mdoc_sp_pre
, NULL
}, /* Pp */
149 {mdoc_d1_pre
, NULL
}, /* D1 */
150 {mdoc_d1_pre
, NULL
}, /* Dl */
151 {mdoc_bd_pre
, NULL
}, /* Bd */
152 {NULL
, NULL
}, /* Ed */
153 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
154 {NULL
, NULL
}, /* El */
155 {mdoc_it_pre
, NULL
}, /* It */
156 {mdoc_ad_pre
, NULL
}, /* Ad */
157 {mdoc_an_pre
, NULL
}, /* An */
158 {mdoc_ar_pre
, NULL
}, /* Ar */
159 {mdoc_cd_pre
, NULL
}, /* Cd */
160 {mdoc_fl_pre
, NULL
}, /* Cm */
161 {mdoc_dv_pre
, NULL
}, /* Dv */
162 {mdoc_er_pre
, NULL
}, /* Er */
163 {mdoc_ev_pre
, NULL
}, /* Ev */
164 {mdoc_ex_pre
, NULL
}, /* Ex */
165 {mdoc_fa_pre
, NULL
}, /* Fa */
166 {mdoc_fd_pre
, NULL
}, /* Fd */
167 {mdoc_fl_pre
, NULL
}, /* Fl */
168 {mdoc_fn_pre
, NULL
}, /* Fn */
169 {mdoc_ft_pre
, NULL
}, /* Ft */
170 {mdoc_ic_pre
, NULL
}, /* Ic */
171 {mdoc_in_pre
, NULL
}, /* In */
172 {mdoc_li_pre
, NULL
}, /* Li */
173 {mdoc_nd_pre
, NULL
}, /* Nd */
174 {mdoc_nm_pre
, NULL
}, /* Nm */
175 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
176 {NULL
, NULL
}, /* Ot */
177 {mdoc_pa_pre
, NULL
}, /* Pa */
178 {mdoc_rv_pre
, NULL
}, /* Rv */
179 {NULL
, NULL
}, /* St */
180 {mdoc_va_pre
, NULL
}, /* Va */
181 {mdoc_vt_pre
, NULL
}, /* Vt */
182 {mdoc_xr_pre
, NULL
}, /* Xr */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
189 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
190 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
191 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
192 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
193 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
194 {NULL
, NULL
}, /* Ac */
195 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
196 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
197 {NULL
, NULL
}, /* At */
198 {NULL
, NULL
}, /* Bc */
199 {mdoc_bf_pre
, NULL
}, /* Bf */
200 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
201 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
202 {mdoc_xx_pre
, NULL
}, /* Bsx */
203 {mdoc_bx_pre
, NULL
}, /* Bx */
204 {NULL
, NULL
}, /* Db */
205 {NULL
, NULL
}, /* Dc */
206 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
207 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
208 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
209 {NULL
, NULL
}, /* Ef */
210 {mdoc_em_pre
, NULL
}, /* Em */
211 {NULL
, NULL
}, /* Eo */
212 {mdoc_xx_pre
, NULL
}, /* Fx */
213 {mdoc_ms_pre
, NULL
}, /* Ms */
214 {NULL
, NULL
}, /* No */
215 {mdoc_ns_pre
, NULL
}, /* Ns */
216 {mdoc_xx_pre
, NULL
}, /* Nx */
217 {mdoc_xx_pre
, NULL
}, /* Ox */
218 {NULL
, NULL
}, /* Pc */
219 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
220 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
221 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
222 {NULL
, NULL
}, /* Qc */
223 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
224 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
225 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
226 {NULL
, NULL
}, /* Re */
227 {mdoc_rs_pre
, NULL
}, /* Rs */
228 {NULL
, NULL
}, /* Sc */
229 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
230 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
231 {mdoc_sm_pre
, NULL
}, /* Sm */
232 {mdoc_sx_pre
, NULL
}, /* Sx */
233 {mdoc_sy_pre
, NULL
}, /* Sy */
234 {NULL
, NULL
}, /* Tn */
235 {mdoc_xx_pre
, NULL
}, /* Ux */
236 {NULL
, NULL
}, /* Xc */
237 {NULL
, NULL
}, /* Xo */
238 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
239 {NULL
, NULL
}, /* Fc */
240 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
241 {NULL
, NULL
}, /* Oc */
242 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
243 {NULL
, NULL
}, /* Ek */
244 {mdoc_bt_pre
, NULL
}, /* Bt */
245 {NULL
, NULL
}, /* Hf */
246 {NULL
, NULL
}, /* Fr */
247 {mdoc_ud_pre
, NULL
}, /* Ud */
248 {mdoc_lb_pre
, NULL
}, /* Lb */
249 {mdoc_sp_pre
, NULL
}, /* Lp */
250 {mdoc_lk_pre
, NULL
}, /* Lk */
251 {mdoc_mt_pre
, NULL
}, /* Mt */
252 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
253 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
254 {NULL
, NULL
}, /* Brc */
255 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
256 {NULL
, NULL
}, /* Es */ /* TODO */
257 {NULL
, NULL
}, /* En */ /* TODO */
258 {mdoc_xx_pre
, NULL
}, /* Dx */
259 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
260 {mdoc_sp_pre
, NULL
}, /* br */
261 {mdoc_sp_pre
, NULL
}, /* sp */
262 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
263 {NULL
, NULL
}, /* Ta */
268 html_mdoc(void *arg
, const struct mdoc
*m
)
273 h
= (struct html
*)arg
;
276 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
277 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
285 * Calculate the scaling unit passed in a `-width' argument. This uses
286 * either a native scaling unit (e.g., 1i, 2m) or the string length of
290 a2width(const char *p
, struct roffsu
*su
)
293 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
295 su
->scale
= (int)strlen(p
);
301 * See the same function in mdoc_term.c for documentation.
304 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
309 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
312 SCALE_VS_INIT(&su
, 1);
313 bufcat_su(h
, "margin-top", &su
);
314 PAIR_STYLE_INIT(&tag
, h
);
316 if (n
->prev
->tok
== n
->tok
&&
320 print_otag(h
, TAG_DIV
, 0, NULL
);
324 switch (n
->prev
->tok
) {
334 print_otag(h
, TAG_DIV
, 1, &tag
);
337 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
338 print_otag(h
, TAG_DIV
, 1, &tag
);
343 print_otag(h
, TAG_DIV
, 0, NULL
);
350 * Calculate the scaling unit passed in an `-offset' argument. This
351 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
352 * predefined strings (indent, etc.), or the string length of the value.
355 a2offs(const char *p
, struct roffsu
*su
)
358 /* FIXME: "right"? */
360 if (0 == strcmp(p
, "left"))
361 SCALE_HS_INIT(su
, 0);
362 else if (0 == strcmp(p
, "indent"))
363 SCALE_HS_INIT(su
, INDENT
);
364 else if (0 == strcmp(p
, "indent-two"))
365 SCALE_HS_INIT(su
, INDENT
* 2);
366 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
368 su
->scale
= (int)strlen(p
);
374 print_mdoc(MDOC_ARGS
)
379 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
380 print_mdoc_head(m
, n
, h
);
383 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
385 tag
.key
= ATTR_CLASS
;
387 print_otag(h
, TAG_DIV
, 1, &tag
);
389 print_mdoc_nodelist(m
, n
, h
);
396 print_mdoc_head(MDOC_ARGS
)
401 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
409 print_otag(h
, TAG_TITLE
, 0, NULL
);
410 print_text(h
, h
->buf
);
415 print_mdoc_nodelist(MDOC_ARGS
)
418 print_mdoc_node(m
, n
, h
);
420 print_mdoc_nodelist(m
, n
->next
, h
);
425 print_mdoc_node(MDOC_ARGS
)
436 child
= mdoc_root_pre(m
, n
, h
);
439 print_text(h
, n
->string
);
442 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
443 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
447 if (HTML_KEEP
& h
->flags
) {
448 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
449 h
->flags
&= ~HTML_KEEP
;
450 h
->flags
|= HTML_PREKEEP
;
451 } else if (NULL
== n
->prev
) {
452 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
453 h
->flags
&= ~HTML_KEEP
;
454 h
->flags
|= HTML_PREKEEP
;
459 if (child
&& n
->child
)
460 print_mdoc_nodelist(m
, n
->child
, h
);
467 mdoc_root_post(m
, n
, h
);
470 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
471 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
479 mdoc_root_post(MDOC_ARGS
)
481 struct htmlpair tag
[3];
485 time2a(m
->date
, b
, DATESIZ
);
488 * XXX: this should use divs, but in Firefox, divs with nested
489 * divs for some reason puke when trying to put a border line
490 * below. So I use tables, instead.
493 PAIR_CLASS_INIT(&tag
[0], "footer");
494 bufcat_style(h
, "width", "100%");
495 PAIR_STYLE_INIT(&tag
[1], h
);
496 PAIR_SUMMARY_INIT(&tag
[2], "footer");
498 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
499 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
502 bufcat_style(h
, "width", "50%");
503 PAIR_STYLE_INIT(&tag
[0], h
);
504 print_otag(h
, TAG_TD
, 1, tag
);
509 bufcat_style(h
, "width", "50%");
510 bufcat_style(h
, "text-align", "right");
511 PAIR_STYLE_INIT(&tag
[0], h
);
512 print_otag(h
, TAG_TD
, 1, tag
);
513 print_text(h
, m
->os
);
520 mdoc_root_pre(MDOC_ARGS
)
522 struct htmlpair tag
[3];
524 char b
[BUFSIZ
], title
[BUFSIZ
];
526 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
529 (void)strlcat(b
, " (", BUFSIZ
);
530 (void)strlcat(b
, m
->arch
, BUFSIZ
);
531 (void)strlcat(b
, ")", BUFSIZ
);
534 (void)snprintf(title
, BUFSIZ
- 1,
535 "%s(%s)", m
->title
, m
->msec
);
537 /* XXX: see note in mdoc_root_post() about divs. */
539 PAIR_CLASS_INIT(&tag
[0], "header");
540 bufcat_style(h
, "width", "100%");
541 PAIR_STYLE_INIT(&tag
[1], h
);
542 PAIR_SUMMARY_INIT(&tag
[2], "header");
544 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
546 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
549 bufcat_style(h
, "width", "10%");
550 PAIR_STYLE_INIT(&tag
[0], h
);
551 print_otag(h
, TAG_TD
, 1, tag
);
552 print_text(h
, title
);
556 bufcat_style(h
, "text-align", "center");
557 bufcat_style(h
, "white-space", "nowrap");
558 bufcat_style(h
, "width", "80%");
559 PAIR_STYLE_INIT(&tag
[0], h
);
560 print_otag(h
, TAG_TD
, 1, tag
);
565 bufcat_style(h
, "text-align", "right");
566 bufcat_style(h
, "width", "10%");
567 PAIR_STYLE_INIT(&tag
[0], h
);
568 print_otag(h
, TAG_TD
, 1, tag
);
569 print_text(h
, title
);
577 mdoc_sh_pre(MDOC_ARGS
)
579 struct htmlpair tag
[2];
580 const struct mdoc_node
*nn
;
584 if (MDOC_BODY
== n
->type
) {
585 SCALE_HS_INIT(&su
, INDENT
);
586 bufcat_su(h
, "margin-left", &su
);
587 PAIR_CLASS_INIT(&tag
[0], "sec-body");
588 PAIR_STYLE_INIT(&tag
[1], h
);
589 print_otag(h
, TAG_DIV
, 2, tag
);
591 } else if (MDOC_BLOCK
== n
->type
) {
592 PAIR_CLASS_INIT(&tag
[0], "sec-block");
593 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
594 print_otag(h
, TAG_DIV
, 1, tag
);
598 SCALE_VS_INIT(&su
, 1);
599 bufcat_su(h
, "margin-top", &su
);
601 bufcat_su(h
, "margin-bottom", &su
);
603 PAIR_STYLE_INIT(&tag
[1], h
);
604 print_otag(h
, TAG_DIV
, 2, tag
);
609 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
610 html_idcat(buf
, nn
->string
, BUFSIZ
);
612 html_idcat(buf
, " ", BUFSIZ
);
615 PAIR_CLASS_INIT(&tag
[0], "sec-head");
616 PAIR_ID_INIT(&tag
[1], buf
);
618 print_otag(h
, TAG_DIV
, 2, tag
);
625 mdoc_ss_pre(MDOC_ARGS
)
627 struct htmlpair tag
[3];
628 const struct mdoc_node
*nn
;
632 SCALE_VS_INIT(&su
, 1);
634 if (MDOC_BODY
== n
->type
) {
635 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
636 if (n
->parent
->next
&& n
->child
) {
637 bufcat_su(h
, "margin-bottom", &su
);
638 PAIR_STYLE_INIT(&tag
[1], h
);
639 print_otag(h
, TAG_DIV
, 2, tag
);
641 print_otag(h
, TAG_DIV
, 1, tag
);
643 } else if (MDOC_BLOCK
== n
->type
) {
644 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
646 bufcat_su(h
, "margin-top", &su
);
647 PAIR_STYLE_INIT(&tag
[1], h
);
648 print_otag(h
, TAG_DIV
, 2, tag
);
650 print_otag(h
, TAG_DIV
, 1, tag
);
654 /* TODO: see note in mdoc_sh_pre() about duplicates. */
657 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
658 html_idcat(buf
, nn
->string
, BUFSIZ
);
660 html_idcat(buf
, " ", BUFSIZ
);
663 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
664 su
.scale
= -su
.scale
;
665 bufcat_su(h
, "margin-left", &su
);
667 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
668 PAIR_STYLE_INIT(&tag
[1], h
);
669 PAIR_ID_INIT(&tag
[2], buf
);
671 print_otag(h
, TAG_DIV
, 3, tag
);
678 mdoc_fl_pre(MDOC_ARGS
)
682 PAIR_CLASS_INIT(&tag
, "flag");
683 print_otag(h
, TAG_SPAN
, 1, &tag
);
685 /* `Cm' has no leading hyphen. */
687 if (MDOC_Cm
== n
->tok
)
690 print_text(h
, "\\-");
693 h
->flags
|= HTML_NOSPACE
;
694 else if (n
->next
&& n
->next
->line
== n
->line
)
695 h
->flags
|= HTML_NOSPACE
;
703 mdoc_nd_pre(MDOC_ARGS
)
707 if (MDOC_BODY
!= n
->type
)
710 /* XXX: this tag in theory can contain block elements. */
712 print_text(h
, "\\(em");
713 PAIR_CLASS_INIT(&tag
, "desc-body");
714 print_otag(h
, TAG_SPAN
, 1, &tag
);
721 mdoc_op_pre(MDOC_ARGS
)
725 if (MDOC_BODY
!= n
->type
)
728 /* XXX: this tag in theory can contain block elements. */
730 print_text(h
, "\\(lB");
731 h
->flags
|= HTML_NOSPACE
;
732 PAIR_CLASS_INIT(&tag
, "opt");
733 print_otag(h
, TAG_SPAN
, 1, &tag
);
740 mdoc_op_post(MDOC_ARGS
)
743 if (MDOC_BODY
!= n
->type
)
745 h
->flags
|= HTML_NOSPACE
;
746 print_text(h
, "\\(rB");
751 mdoc_nm_pre(MDOC_ARGS
)
758 * Accomodate for `Nm' being both an element (which may have
759 * NULL children AND no m->name) and a block.
764 if (MDOC_ELEM
== n
->type
) {
765 if (NULL
== n
->child
&& NULL
== m
->name
)
768 PAIR_CLASS_INIT(&tag
, "name");
769 print_otag(h
, TAG_SPAN
, 1, &tag
);
770 if (NULL
== n
->child
)
771 print_text(h
, m
->name
);
772 } else if (MDOC_BLOCK
== n
->type
) {
775 bufcat_style(h
, "clear", "both");
776 if (n
->head
->child
|| m
->name
) {
777 if (n
->head
->child
&& MDOC_TEXT
==
778 n
->head
->child
->type
)
779 cp
= n
->head
->child
->string
;
780 if (NULL
== cp
|| '\0' == *cp
)
783 SCALE_HS_INIT(&su
, (double)strlen(cp
));
784 bufcat_su(h
, "padding-left", &su
);
787 PAIR_STYLE_INIT(&tag
, h
);
788 print_otag(h
, TAG_DIV
, 1, &tag
);
789 } else if (MDOC_HEAD
== n
->type
) {
790 if (NULL
== n
->child
&& NULL
== m
->name
)
793 if (n
->child
&& MDOC_TEXT
== n
->child
->type
)
794 cp
= n
->child
->string
;
795 if (NULL
== cp
|| '\0' == *cp
)
798 SCALE_HS_INIT(&su
, (double)strlen(cp
));
800 bufcat_style(h
, "float", "left");
801 bufcat_su(h
, "min-width", &su
);
803 bufcat_su(h
, "margin-left", &su
);
805 PAIR_STYLE_INIT(&tag
, h
);
806 print_otag(h
, TAG_DIV
, 1, &tag
);
808 if (NULL
== n
->child
)
809 print_text(h
, m
->name
);
810 } else if (MDOC_BODY
== n
->type
) {
811 SCALE_HS_INIT(&su
, 2);
812 bufcat_su(h
, "margin-left", &su
);
813 PAIR_STYLE_INIT(&tag
, h
);
814 print_otag(h
, TAG_DIV
, 1, &tag
);
823 mdoc_xr_pre(MDOC_ARGS
)
825 struct htmlpair tag
[2];
826 const struct mdoc_node
*nn
;
828 if (NULL
== n
->child
)
831 PAIR_CLASS_INIT(&tag
[0], "link-man");
834 buffmt_man(h
, n
->child
->string
,
836 n
->child
->next
->string
: NULL
);
837 PAIR_HREF_INIT(&tag
[1], h
->buf
);
838 print_otag(h
, TAG_A
, 2, tag
);
840 print_otag(h
, TAG_A
, 1, tag
);
843 print_text(h
, nn
->string
);
845 if (NULL
== (nn
= nn
->next
))
848 h
->flags
|= HTML_NOSPACE
;
850 h
->flags
|= HTML_NOSPACE
;
851 print_text(h
, nn
->string
);
852 h
->flags
|= HTML_NOSPACE
;
860 mdoc_ns_pre(MDOC_ARGS
)
863 h
->flags
|= HTML_NOSPACE
;
870 mdoc_ar_pre(MDOC_ARGS
)
874 PAIR_CLASS_INIT(&tag
, "arg");
875 print_otag(h
, TAG_SPAN
, 1, &tag
);
882 mdoc_xx_pre(MDOC_ARGS
)
910 PAIR_CLASS_INIT(&tag
, "unix");
911 print_otag(h
, TAG_SPAN
, 1, &tag
);
919 mdoc_bx_pre(MDOC_ARGS
)
921 const struct mdoc_node
*nn
;
924 PAIR_CLASS_INIT(&tag
, "unix");
925 print_otag(h
, TAG_SPAN
, 1, &tag
);
927 for (nn
= n
->child
; nn
; nn
= nn
->next
)
928 print_mdoc_node(m
, nn
, h
);
931 h
->flags
|= HTML_NOSPACE
;
933 print_text(h
, "BSD");
940 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
941 struct roffsu
*offs
, struct roffsu
*width
)
944 const struct mdoc_node
*nn
;
947 nn
= n
->parent
->parent
;
949 /* XXX: see notes in mdoc_it_pre(). */
951 if (LIST_column
== type
) {
952 /* Don't width-pad on the left. */
953 SCALE_HS_INIT(width
, 0);
954 /* Also disallow non-compact. */
957 if (LIST_diag
== type
)
958 /* Mandate non-compact with empty prior. */
959 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
962 bufcat_style(h
, "clear", "both");
964 bufcat_su(h
, "margin-left", offs
);
965 if (width
->scale
> 0)
966 bufcat_su(h
, "padding-left", width
);
968 PAIR_STYLE_INIT(&tag
, h
);
970 /* Mandate compact following `Ss' and `Sh' starts. */
972 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
973 if (MDOC_BLOCK
!= nn
->type
)
975 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
982 SCALE_VS_INIT(&su
, 1);
983 bufcat_su(h
, "padding-top", &su
);
986 PAIR_STYLE_INIT(&tag
, h
);
987 print_otag(h
, TAG_DIV
, 1, &tag
);
994 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
1005 bufcat_su(h
, "min-width", width
);
1006 bufcat_style(h
, "clear", "none");
1008 bufcat_style(h
, "float", "left");
1009 PAIR_STYLE_INIT(&tag
, h
);
1010 print_otag(h
, TAG_DIV
, 1, &tag
);
1014 * XXX: this tricks CSS into aligning the bodies with
1015 * the right-padding in the head.
1017 SCALE_HS_INIT(&su
, 2);
1018 bufcat_su(h
, "margin-left", &su
);
1019 PAIR_STYLE_INIT(&tag
, h
);
1020 print_otag(h
, TAG_DIV
, 1, &tag
);
1030 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
1032 struct htmlpair tag
;
1040 print_otag(h
, TAG_DIV
, 0, &tag
);
1045 bufcat_su(h
, "min-width", width
);
1046 SCALE_INVERT(width
);
1047 bufcat_su(h
, "margin-left", width
);
1048 if (n
->next
&& n
->next
->child
)
1049 bufcat_style(h
, "float", "left");
1051 /* XXX: buffer if we run into body. */
1052 SCALE_HS_INIT(width
, 1);
1053 bufcat_su(h
, "margin-right", width
);
1054 PAIR_STYLE_INIT(&tag
, h
);
1055 print_otag(h
, TAG_DIV
, 1, &tag
);
1061 PAIR_CLASS_INIT(&tag
, "diag");
1062 print_otag(h
, TAG_SPAN
, 1, &tag
);
1067 nbuf
[BUFSIZ
- 1] = 0;
1068 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1069 print_text(h
, nbuf
);
1072 print_text(h
, "\\(en");
1075 print_text(h
, "\\(hy");
1078 print_text(h
, "\\(bu");
1089 mdoc_it_pre(MDOC_ARGS
)
1092 const struct mdoc_node
*bl
, *nn
;
1093 struct roffsu width
, offs
;
1094 enum mdoc_list type
;
1097 * XXX: be very careful in changing anything, here. Lists in
1098 * mandoc have many peculiarities; furthermore, they don't
1099 * translate well into HTML and require a bit of mangling.
1102 bl
= n
->parent
->parent
;
1103 if (MDOC_BLOCK
!= n
->type
)
1106 SCALE_HS_INIT(&offs
, 0);
1108 assert(bl
->data
.Bl
);
1109 type
= bl
->data
.Bl
->type
;
1110 comp
= bl
->data
.Bl
->comp
;
1112 if (bl
->data
.Bl
->offs
)
1113 a2offs(bl
->data
.Bl
->offs
, &offs
);
1123 SCALE_HS_INIT(&width
, 2);
1126 SCALE_HS_INIT(&width
, INDENT
);
1130 if (bl
->data
.Bl
->width
)
1131 a2width(bl
->data
.Bl
->width
, &width
);
1133 /* Override width in some cases. */
1143 SCALE_HS_INIT(&width
, 0);
1146 if (0 == width
.scale
)
1147 SCALE_HS_INIT(&width
, INDENT
);
1151 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1152 nn
= n
->parent
->child
;
1153 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1154 if (MDOC_BODY
== nn
->type
)
1156 if (i
< (int)bl
->data
.Bl
->ncols
)
1157 a2width(bl
->data
.Bl
->cols
[i
], &width
);
1160 if (MDOC_HEAD
== n
->type
)
1161 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1162 else if (MDOC_BODY
== n
->type
)
1163 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1165 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1171 mdoc_bl_pre(MDOC_ARGS
)
1175 if (MDOC_HEAD
== n
->type
)
1177 if (MDOC_BLOCK
!= n
->type
)
1180 if (LIST_enum
!= n
->data
.Bl
->type
)
1183 ord
= malloc(sizeof(struct ord
));
1186 exit((int)MANDOCLEVEL_SYSERR
);
1190 ord
->next
= h
->ords
.head
;
1198 mdoc_bl_post(MDOC_ARGS
)
1202 if (MDOC_BLOCK
!= n
->type
)
1204 if (LIST_enum
!= n
->data
.Bl
->type
)
1209 h
->ords
.head
= ord
->next
;
1216 mdoc_ex_pre(MDOC_ARGS
)
1218 const struct mdoc_node
*nn
;
1220 struct htmlpair tag
;
1222 PAIR_CLASS_INIT(&tag
, "utility");
1224 print_text(h
, "The");
1225 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1226 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1227 print_text(h
, nn
->string
);
1230 h
->flags
|= HTML_NOSPACE
;
1232 if (nn
->next
&& NULL
== nn
->next
->next
)
1233 print_text(h
, ", and");
1237 h
->flags
&= ~HTML_NOSPACE
;
1240 if (n
->child
&& n
->child
->next
)
1241 print_text(h
, "utilities exit");
1243 print_text(h
, "utility exits");
1245 print_text(h
, "0 on success, and >0 if an error occurs.");
1252 mdoc_dq_pre(MDOC_ARGS
)
1255 if (MDOC_BODY
!= n
->type
)
1257 print_text(h
, "\\(lq");
1258 h
->flags
|= HTML_NOSPACE
;
1265 mdoc_dq_post(MDOC_ARGS
)
1268 if (MDOC_BODY
!= n
->type
)
1270 h
->flags
|= HTML_NOSPACE
;
1271 print_text(h
, "\\(rq");
1277 mdoc_pq_pre(MDOC_ARGS
)
1280 if (MDOC_BODY
!= n
->type
)
1282 print_text(h
, "\\&(");
1283 h
->flags
|= HTML_NOSPACE
;
1290 mdoc_pq_post(MDOC_ARGS
)
1293 if (MDOC_BODY
!= n
->type
)
1301 mdoc_sq_pre(MDOC_ARGS
)
1304 if (MDOC_BODY
!= n
->type
)
1306 print_text(h
, "\\(oq");
1307 h
->flags
|= HTML_NOSPACE
;
1314 mdoc_sq_post(MDOC_ARGS
)
1317 if (MDOC_BODY
!= n
->type
)
1319 h
->flags
|= HTML_NOSPACE
;
1320 print_text(h
, "\\(aq");
1326 mdoc_em_pre(MDOC_ARGS
)
1328 struct htmlpair tag
;
1330 PAIR_CLASS_INIT(&tag
, "emph");
1331 print_otag(h
, TAG_SPAN
, 1, &tag
);
1338 mdoc_d1_pre(MDOC_ARGS
)
1340 struct htmlpair tag
[2];
1343 if (MDOC_BLOCK
!= n
->type
)
1346 /* FIXME: D1 shouldn't be literal. */
1348 SCALE_VS_INIT(&su
, INDENT
- 2);
1349 bufcat_su(h
, "margin-left", &su
);
1350 PAIR_CLASS_INIT(&tag
[0], "lit");
1351 PAIR_STYLE_INIT(&tag
[1], h
);
1352 print_otag(h
, TAG_DIV
, 2, tag
);
1359 mdoc_sx_pre(MDOC_ARGS
)
1361 struct htmlpair tag
[2];
1362 const struct mdoc_node
*nn
;
1365 strlcpy(buf
, "#", BUFSIZ
);
1366 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1367 html_idcat(buf
, nn
->string
, BUFSIZ
);
1369 html_idcat(buf
, " ", BUFSIZ
);
1372 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1373 PAIR_HREF_INIT(&tag
[1], buf
);
1375 print_otag(h
, TAG_A
, 2, tag
);
1382 mdoc_aq_pre(MDOC_ARGS
)
1385 if (MDOC_BODY
!= n
->type
)
1387 print_text(h
, "\\(la");
1388 h
->flags
|= HTML_NOSPACE
;
1395 mdoc_aq_post(MDOC_ARGS
)
1398 if (MDOC_BODY
!= n
->type
)
1400 h
->flags
|= HTML_NOSPACE
;
1401 print_text(h
, "\\(ra");
1407 mdoc_bd_pre(MDOC_ARGS
)
1409 struct htmlpair tag
[2];
1411 const struct mdoc_node
*nn
;
1414 if (MDOC_HEAD
== n
->type
)
1417 SCALE_VS_INIT(&su
, 0);
1420 if (n
->data
.Bd
->offs
)
1421 a2offs(n
->data
.Bd
->offs
, &su
);
1423 comp
= n
->data
.Bd
->comp
;
1425 /* FIXME: -centered, etc. formatting. */
1426 /* FIXME: does not respect -offset ??? */
1428 if (MDOC_BLOCK
== n
->type
) {
1429 bufcat_su(h
, "margin-left", &su
);
1430 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1431 if (MDOC_BLOCK
!= nn
->type
)
1433 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1439 PAIR_STYLE_INIT(&tag
[0], h
);
1440 print_otag(h
, TAG_DIV
, 1, tag
);
1443 SCALE_VS_INIT(&su
, 1);
1444 bufcat_su(h
, "margin-top", &su
);
1445 PAIR_STYLE_INIT(&tag
[0], h
);
1446 print_otag(h
, TAG_DIV
, 1, tag
);
1450 if (DISP_unfilled
!= n
->data
.Bd
->type
&&
1451 DISP_literal
!= n
->data
.Bd
->type
)
1454 PAIR_CLASS_INIT(&tag
[0], "lit");
1455 bufcat_style(h
, "white-space", "pre");
1456 PAIR_STYLE_INIT(&tag
[1], h
);
1457 print_otag(h
, TAG_DIV
, 2, tag
);
1459 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1460 print_mdoc_node(m
, nn
, h
);
1461 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1463 print_text(h
, "\n");
1464 h
->flags
|= HTML_NOSPACE
;
1473 mdoc_pa_pre(MDOC_ARGS
)
1475 struct htmlpair tag
;
1477 PAIR_CLASS_INIT(&tag
, "file");
1478 print_otag(h
, TAG_SPAN
, 1, &tag
);
1485 mdoc_ad_pre(MDOC_ARGS
)
1487 struct htmlpair tag
;
1489 PAIR_CLASS_INIT(&tag
, "addr");
1490 print_otag(h
, TAG_SPAN
, 1, &tag
);
1497 mdoc_an_pre(MDOC_ARGS
)
1499 struct htmlpair tag
;
1501 /* TODO: -split and -nosplit (see termp_an_pre()). */
1503 PAIR_CLASS_INIT(&tag
, "author");
1504 print_otag(h
, TAG_SPAN
, 1, &tag
);
1511 mdoc_cd_pre(MDOC_ARGS
)
1513 struct htmlpair tag
;
1516 PAIR_CLASS_INIT(&tag
, "config");
1517 print_otag(h
, TAG_SPAN
, 1, &tag
);
1524 mdoc_dv_pre(MDOC_ARGS
)
1526 struct htmlpair tag
;
1528 PAIR_CLASS_INIT(&tag
, "define");
1529 print_otag(h
, TAG_SPAN
, 1, &tag
);
1536 mdoc_ev_pre(MDOC_ARGS
)
1538 struct htmlpair tag
;
1540 PAIR_CLASS_INIT(&tag
, "env");
1541 print_otag(h
, TAG_SPAN
, 1, &tag
);
1548 mdoc_er_pre(MDOC_ARGS
)
1550 struct htmlpair tag
;
1552 PAIR_CLASS_INIT(&tag
, "errno");
1553 print_otag(h
, TAG_SPAN
, 1, &tag
);
1560 mdoc_fa_pre(MDOC_ARGS
)
1562 const struct mdoc_node
*nn
;
1563 struct htmlpair tag
;
1566 PAIR_CLASS_INIT(&tag
, "farg");
1567 if (n
->parent
->tok
!= MDOC_Fo
) {
1568 print_otag(h
, TAG_SPAN
, 1, &tag
);
1572 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1573 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1574 print_text(h
, nn
->string
);
1580 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1589 mdoc_fd_pre(MDOC_ARGS
)
1591 struct htmlpair tag
;
1595 PAIR_CLASS_INIT(&tag
, "macro");
1596 print_otag(h
, TAG_SPAN
, 1, &tag
);
1603 mdoc_vt_pre(MDOC_ARGS
)
1605 struct htmlpair tag
;
1607 if (MDOC_BLOCK
== n
->type
) {
1610 } else if (MDOC_ELEM
== n
->type
) {
1612 } else if (MDOC_HEAD
== n
->type
)
1615 PAIR_CLASS_INIT(&tag
, "type");
1616 print_otag(h
, TAG_SPAN
, 1, &tag
);
1623 mdoc_ft_pre(MDOC_ARGS
)
1625 struct htmlpair tag
;
1628 PAIR_CLASS_INIT(&tag
, "ftype");
1629 print_otag(h
, TAG_SPAN
, 1, &tag
);
1636 mdoc_fn_pre(MDOC_ARGS
)
1639 struct htmlpair tag
[2];
1640 const struct mdoc_node
*nn
;
1642 const char *sp
, *ep
;
1647 /* Split apart into type and name. */
1648 assert(n
->child
->string
);
1649 sp
= n
->child
->string
;
1651 ep
= strchr(sp
, ' ');
1653 PAIR_CLASS_INIT(&tag
[0], "ftype");
1654 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1657 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1658 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1660 print_text(h
, nbuf
);
1662 ep
= strchr(sp
, ' ');
1667 PAIR_CLASS_INIT(&tag
[0], "fname");
1670 * FIXME: only refer to IDs that we know exist.
1674 if (MDOC_SYNPRETTY
& n
->flags
) {
1676 html_idcat(nbuf
, sp
, BUFSIZ
);
1677 PAIR_ID_INIT(&tag
[1], nbuf
);
1679 strlcpy(nbuf
, "#", BUFSIZ
);
1680 html_idcat(nbuf
, sp
, BUFSIZ
);
1681 PAIR_HREF_INIT(&tag
[1], nbuf
);
1685 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1688 strlcpy(nbuf
, sp
, BUFSIZ
);
1689 print_text(h
, nbuf
);
1694 h
->flags
|= HTML_NOSPACE
;
1698 PAIR_CLASS_INIT(&tag
[0], "farg");
1699 bufcat_style(h
, "white-space", "nowrap");
1700 PAIR_STYLE_INIT(&tag
[1], h
);
1702 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1704 if (MDOC_SYNPRETTY
& n
->flags
)
1706 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1707 print_text(h
, nn
->string
);
1714 if (MDOC_SYNPRETTY
& n
->flags
)
1723 mdoc_sm_pre(MDOC_ARGS
)
1726 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1727 if (0 == strcmp("on", n
->child
->string
)) {
1728 /* FIXME: no p->col to check... */
1729 h
->flags
&= ~HTML_NOSPACE
;
1730 h
->flags
&= ~HTML_NONOSPACE
;
1732 h
->flags
|= HTML_NONOSPACE
;
1740 mdoc_sp_pre(MDOC_ARGS
)
1743 struct htmlpair tag
;
1748 /* FIXME: can this have a scaling indicator? */
1749 len
= n
->child
? atoi(n
->child
->string
) : 1;
1756 if ((NULL
== n
->next
|| NULL
== n
->prev
) &&
1757 (MDOC_Ss
== n
->parent
->tok
||
1758 MDOC_Sh
== n
->parent
->tok
))
1764 SCALE_VS_INIT(&su
, len
);
1765 bufcat_su(h
, "height", &su
);
1766 PAIR_STYLE_INIT(&tag
, h
);
1767 print_otag(h
, TAG_DIV
, 1, &tag
);
1768 /* So the div isn't empty: */
1769 print_text(h
, "\\~");
1778 mdoc_brq_pre(MDOC_ARGS
)
1781 if (MDOC_BODY
!= n
->type
)
1783 print_text(h
, "\\(lC");
1784 h
->flags
|= HTML_NOSPACE
;
1791 mdoc_brq_post(MDOC_ARGS
)
1794 if (MDOC_BODY
!= n
->type
)
1796 h
->flags
|= HTML_NOSPACE
;
1797 print_text(h
, "\\(rC");
1803 mdoc_lk_pre(MDOC_ARGS
)
1805 const struct mdoc_node
*nn
;
1806 struct htmlpair tag
[2];
1810 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1811 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1812 print_otag(h
, TAG_A
, 2, tag
);
1814 if (NULL
== nn
->next
)
1817 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1818 print_text(h
, nn
->string
);
1826 mdoc_mt_pre(MDOC_ARGS
)
1828 struct htmlpair tag
[2];
1830 const struct mdoc_node
*nn
;
1832 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1834 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1836 bufcat(h
, "mailto:");
1837 bufcat(h
, nn
->string
);
1838 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1839 t
= print_otag(h
, TAG_A
, 2, tag
);
1840 print_text(h
, nn
->string
);
1850 mdoc_fo_pre(MDOC_ARGS
)
1852 struct htmlpair tag
;
1855 if (MDOC_BODY
== n
->type
) {
1856 h
->flags
|= HTML_NOSPACE
;
1858 h
->flags
|= HTML_NOSPACE
;
1860 } else if (MDOC_BLOCK
== n
->type
) {
1865 /* XXX: we drop non-initial arguments as per groff. */
1868 assert(n
->child
->string
);
1870 PAIR_CLASS_INIT(&tag
, "fname");
1871 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1872 print_text(h
, n
->child
->string
);
1880 mdoc_fo_post(MDOC_ARGS
)
1883 if (MDOC_BODY
!= n
->type
)
1885 h
->flags
|= HTML_NOSPACE
;
1887 h
->flags
|= HTML_NOSPACE
;
1894 mdoc_in_pre(MDOC_ARGS
)
1896 const struct mdoc_node
*nn
;
1898 struct htmlpair tag
[2];
1903 PAIR_CLASS_INIT(&tag
[0], "includes");
1904 print_otag(h
, TAG_SPAN
, 1, tag
);
1906 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1907 print_text(h
, "#include");
1910 h
->flags
|= HTML_NOSPACE
;
1912 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1913 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1916 if (h
->base_includes
) {
1917 buffmt_includes(h
, nn
->string
);
1918 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1921 t
= print_otag(h
, TAG_A
, i
, tag
);
1922 print_mdoc_node(m
, nn
, h
);
1926 h
->flags
|= HTML_NOSPACE
;
1935 mdoc_ic_pre(MDOC_ARGS
)
1937 struct htmlpair tag
;
1939 PAIR_CLASS_INIT(&tag
, "cmd");
1940 print_otag(h
, TAG_SPAN
, 1, &tag
);
1947 mdoc_rv_pre(MDOC_ARGS
)
1949 const struct mdoc_node
*nn
;
1950 struct htmlpair tag
;
1953 print_otag(h
, TAG_DIV
, 0, NULL
);
1954 print_text(h
, "The");
1956 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1957 PAIR_CLASS_INIT(&tag
, "fname");
1958 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1959 print_text(h
, nn
->string
);
1962 h
->flags
|= HTML_NOSPACE
;
1963 if (nn
->next
&& NULL
== nn
->next
->next
)
1964 print_text(h
, "(), and");
1966 print_text(h
, "(),");
1968 print_text(h
, "()");
1971 if (n
->child
&& n
->child
->next
)
1972 print_text(h
, "functions return");
1974 print_text(h
, "function returns");
1976 print_text(h
, "the value 0 if successful; otherwise the value "
1977 "-1 is returned and the global variable");
1979 PAIR_CLASS_INIT(&tag
, "var");
1980 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1981 print_text(h
, "errno");
1983 print_text(h
, "is set to indicate the error.");
1990 mdoc_va_pre(MDOC_ARGS
)
1992 struct htmlpair tag
;
1994 PAIR_CLASS_INIT(&tag
, "var");
1995 print_otag(h
, TAG_SPAN
, 1, &tag
);
2002 mdoc_bq_pre(MDOC_ARGS
)
2005 if (MDOC_BODY
!= n
->type
)
2007 print_text(h
, "\\(lB");
2008 h
->flags
|= HTML_NOSPACE
;
2015 mdoc_bq_post(MDOC_ARGS
)
2018 if (MDOC_BODY
!= n
->type
)
2020 h
->flags
|= HTML_NOSPACE
;
2021 print_text(h
, "\\(rB");
2027 mdoc_ap_pre(MDOC_ARGS
)
2030 h
->flags
|= HTML_NOSPACE
;
2031 print_text(h
, "\\(aq");
2032 h
->flags
|= HTML_NOSPACE
;
2039 mdoc_bf_pre(MDOC_ARGS
)
2041 struct htmlpair tag
[2];
2044 if (MDOC_HEAD
== n
->type
)
2046 else if (MDOC_BODY
!= n
->type
)
2051 if (FONT_Em
== n
->data
.Bf
->font
)
2052 PAIR_CLASS_INIT(&tag
[0], "emph");
2053 else if (FONT_Sy
== n
->data
.Bf
->font
)
2054 PAIR_CLASS_INIT(&tag
[0], "symb");
2055 else if (FONT_Li
== n
->data
.Bf
->font
)
2056 PAIR_CLASS_INIT(&tag
[0], "lit");
2058 PAIR_CLASS_INIT(&tag
[0], "none");
2061 * We want this to be inline-formatted, but needs to be div to
2062 * accept block children.
2064 bufcat_style(h
, "display", "inline");
2065 SCALE_HS_INIT(&su
, 1);
2066 /* Needs a left-margin for spacing. */
2067 bufcat_su(h
, "margin-left", &su
);
2068 PAIR_STYLE_INIT(&tag
[1], h
);
2069 print_otag(h
, TAG_DIV
, 2, tag
);
2076 mdoc_ms_pre(MDOC_ARGS
)
2078 struct htmlpair tag
;
2080 PAIR_CLASS_INIT(&tag
, "symb");
2081 print_otag(h
, TAG_SPAN
, 1, &tag
);
2088 mdoc_pf_pre(MDOC_ARGS
)
2091 h
->flags
|= HTML_IGNDELIM
;
2098 mdoc_pf_post(MDOC_ARGS
)
2101 h
->flags
&= ~HTML_IGNDELIM
;
2102 h
->flags
|= HTML_NOSPACE
;
2108 mdoc_rs_pre(MDOC_ARGS
)
2110 struct htmlpair tag
;
2113 if (MDOC_BLOCK
!= n
->type
)
2116 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2117 SCALE_VS_INIT(&su
, 1);
2118 bufcat_su(h
, "margin-top", &su
);
2119 PAIR_STYLE_INIT(&tag
, h
);
2120 print_otag(h
, TAG_DIV
, 1, &tag
);
2123 PAIR_CLASS_INIT(&tag
, "ref");
2124 print_otag(h
, TAG_SPAN
, 1, &tag
);
2132 mdoc_li_pre(MDOC_ARGS
)
2134 struct htmlpair tag
;
2136 PAIR_CLASS_INIT(&tag
, "lit");
2137 print_otag(h
, TAG_SPAN
, 1, &tag
);
2144 mdoc_sy_pre(MDOC_ARGS
)
2146 struct htmlpair tag
;
2148 PAIR_CLASS_INIT(&tag
, "symb");
2149 print_otag(h
, TAG_SPAN
, 1, &tag
);
2156 mdoc_bt_pre(MDOC_ARGS
)
2159 print_text(h
, "is currently in beta test.");
2166 mdoc_ud_pre(MDOC_ARGS
)
2169 print_text(h
, "currently under development.");
2176 mdoc_lb_pre(MDOC_ARGS
)
2178 struct htmlpair tag
;
2180 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2181 print_otag(h
, TAG_DIV
, 0, NULL
);
2182 PAIR_CLASS_INIT(&tag
, "lib");
2183 print_otag(h
, TAG_SPAN
, 1, &tag
);
2190 mdoc__x_pre(MDOC_ARGS
)
2192 struct htmlpair tag
[2];
2196 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2197 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2198 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2199 print_text(h
, "and");
2202 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2205 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2208 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2211 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2214 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2217 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2220 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2223 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2226 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2229 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2232 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2235 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2238 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2245 if (MDOC__U
!= n
->tok
) {
2246 print_otag(h
, TAG_SPAN
, 1, tag
);
2250 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2251 print_otag(h
, TAG_A
, 2, tag
);
2259 mdoc__x_post(MDOC_ARGS
)
2262 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2263 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2264 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2269 h
->flags
|= HTML_NOSPACE
;
2270 print_text(h
, n
->next
? "," : ".");
2276 mdoc_bk_pre(MDOC_ARGS
)
2285 h
->flags
|= HTML_PREKEEP
;
2298 mdoc_bk_post(MDOC_ARGS
)
2301 if (MDOC_BODY
== n
->type
)
2302 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);