]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.96 2010/07/13 23:53:20 schwarze 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_sp_pre(MDOC_ARGS
);
129 static void mdoc_sq_post(MDOC_ARGS
);
130 static int mdoc_sq_pre(MDOC_ARGS
);
131 static int mdoc_ss_pre(MDOC_ARGS
);
132 static int mdoc_sx_pre(MDOC_ARGS
);
133 static int mdoc_sy_pre(MDOC_ARGS
);
134 static int mdoc_ud_pre(MDOC_ARGS
);
135 static int mdoc_va_pre(MDOC_ARGS
);
136 static int mdoc_vt_pre(MDOC_ARGS
);
137 static int mdoc_xr_pre(MDOC_ARGS
);
138 static int mdoc_xx_pre(MDOC_ARGS
);
140 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
141 {mdoc_ap_pre
, NULL
}, /* Ap */
142 {NULL
, NULL
}, /* Dd */
143 {NULL
, NULL
}, /* Dt */
144 {NULL
, NULL
}, /* Os */
145 {mdoc_sh_pre
, NULL
}, /* Sh */
146 {mdoc_ss_pre
, NULL
}, /* Ss */
147 {mdoc_sp_pre
, NULL
}, /* Pp */
148 {mdoc_d1_pre
, NULL
}, /* D1 */
149 {mdoc_d1_pre
, NULL
}, /* Dl */
150 {mdoc_bd_pre
, NULL
}, /* Bd */
151 {NULL
, NULL
}, /* Ed */
152 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
153 {NULL
, NULL
}, /* El */
154 {mdoc_it_pre
, NULL
}, /* It */
155 {mdoc_ad_pre
, NULL
}, /* Ad */
156 {mdoc_an_pre
, NULL
}, /* An */
157 {mdoc_ar_pre
, NULL
}, /* Ar */
158 {mdoc_cd_pre
, NULL
}, /* Cd */
159 {mdoc_fl_pre
, NULL
}, /* Cm */
160 {mdoc_dv_pre
, NULL
}, /* Dv */
161 {mdoc_er_pre
, NULL
}, /* Er */
162 {mdoc_ev_pre
, NULL
}, /* Ev */
163 {mdoc_ex_pre
, NULL
}, /* Ex */
164 {mdoc_fa_pre
, NULL
}, /* Fa */
165 {mdoc_fd_pre
, NULL
}, /* Fd */
166 {mdoc_fl_pre
, NULL
}, /* Fl */
167 {mdoc_fn_pre
, NULL
}, /* Fn */
168 {mdoc_ft_pre
, NULL
}, /* Ft */
169 {mdoc_ic_pre
, NULL
}, /* Ic */
170 {mdoc_in_pre
, NULL
}, /* In */
171 {mdoc_li_pre
, NULL
}, /* Li */
172 {mdoc_nd_pre
, NULL
}, /* Nd */
173 {mdoc_nm_pre
, NULL
}, /* Nm */
174 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
175 {NULL
, NULL
}, /* Ot */
176 {mdoc_pa_pre
, NULL
}, /* Pa */
177 {mdoc_rv_pre
, NULL
}, /* Rv */
178 {NULL
, NULL
}, /* St */
179 {mdoc_va_pre
, NULL
}, /* Va */
180 {mdoc_vt_pre
, NULL
}, /* Vt */
181 {mdoc_xr_pre
, NULL
}, /* Xr */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
189 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
190 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
191 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
192 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
193 {NULL
, NULL
}, /* Ac */
194 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
195 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
196 {NULL
, NULL
}, /* At */
197 {NULL
, NULL
}, /* Bc */
198 {mdoc_bf_pre
, NULL
}, /* Bf */
199 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
200 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
201 {mdoc_xx_pre
, NULL
}, /* Bsx */
202 {mdoc_bx_pre
, NULL
}, /* Bx */
203 {NULL
, NULL
}, /* Db */
204 {NULL
, NULL
}, /* Dc */
205 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
206 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
207 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
208 {NULL
, NULL
}, /* Ef */
209 {mdoc_em_pre
, NULL
}, /* Em */
210 {NULL
, NULL
}, /* Eo */
211 {mdoc_xx_pre
, NULL
}, /* Fx */
212 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
213 {NULL
, NULL
}, /* No */
214 {mdoc_ns_pre
, NULL
}, /* Ns */
215 {mdoc_xx_pre
, NULL
}, /* Nx */
216 {mdoc_xx_pre
, NULL
}, /* Ox */
217 {NULL
, NULL
}, /* Pc */
218 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
219 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
220 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
221 {NULL
, NULL
}, /* Qc */
222 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
223 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
224 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
225 {NULL
, NULL
}, /* Re */
226 {mdoc_rs_pre
, NULL
}, /* Rs */
227 {NULL
, NULL
}, /* Sc */
228 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
229 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
230 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
231 {mdoc_sx_pre
, NULL
}, /* Sx */
232 {mdoc_sy_pre
, NULL
}, /* Sy */
233 {NULL
, NULL
}, /* Tn */
234 {mdoc_xx_pre
, NULL
}, /* Ux */
235 {NULL
, NULL
}, /* Xc */
236 {NULL
, NULL
}, /* Xo */
237 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
238 {NULL
, NULL
}, /* Fc */
239 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
240 {NULL
, NULL
}, /* Oc */
241 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
242 {NULL
, NULL
}, /* Ek */
243 {mdoc_bt_pre
, NULL
}, /* Bt */
244 {NULL
, NULL
}, /* Hf */
245 {NULL
, NULL
}, /* Fr */
246 {mdoc_ud_pre
, NULL
}, /* Ud */
247 {mdoc_lb_pre
, NULL
}, /* Lb */
248 {mdoc_sp_pre
, NULL
}, /* Lp */
249 {mdoc_lk_pre
, NULL
}, /* Lk */
250 {mdoc_mt_pre
, NULL
}, /* Mt */
251 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
252 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
253 {NULL
, NULL
}, /* Brc */
254 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
255 {NULL
, NULL
}, /* Es */ /* TODO */
256 {NULL
, NULL
}, /* En */ /* TODO */
257 {mdoc_xx_pre
, NULL
}, /* Dx */
258 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
259 {mdoc_sp_pre
, NULL
}, /* br */
260 {mdoc_sp_pre
, NULL
}, /* sp */
261 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
262 {NULL
, NULL
}, /* Ta */
267 html_mdoc(void *arg
, const struct mdoc
*m
)
272 h
= (struct html
*)arg
;
275 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
276 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
284 * Calculate the scaling unit passed in a `-width' argument. This uses
285 * either a native scaling unit (e.g., 1i, 2m) or the string length of
289 a2width(const char *p
, struct roffsu
*su
)
292 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
294 su
->scale
= (int)strlen(p
);
300 * See the same function in mdoc_term.c for documentation.
303 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
308 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
311 SCALE_VS_INIT(&su
, 1);
312 bufcat_su(h
, "margin-top", &su
);
313 PAIR_STYLE_INIT(&tag
, h
);
315 if (n
->prev
->tok
== n
->tok
&&
319 print_otag(h
, TAG_DIV
, 0, NULL
);
323 switch (n
->prev
->tok
) {
333 print_otag(h
, TAG_DIV
, 1, &tag
);
336 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
337 print_otag(h
, TAG_DIV
, 1, &tag
);
342 print_otag(h
, TAG_DIV
, 0, NULL
);
349 * Calculate the scaling unit passed in an `-offset' argument. This
350 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
351 * predefined strings (indent, etc.), or the string length of the value.
354 a2offs(const char *p
, struct roffsu
*su
)
357 /* FIXME: "right"? */
359 if (0 == strcmp(p
, "left"))
360 SCALE_HS_INIT(su
, 0);
361 else if (0 == strcmp(p
, "indent"))
362 SCALE_HS_INIT(su
, INDENT
);
363 else if (0 == strcmp(p
, "indent-two"))
364 SCALE_HS_INIT(su
, INDENT
* 2);
365 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
367 su
->scale
= (int)strlen(p
);
373 print_mdoc(MDOC_ARGS
)
378 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
379 print_mdoc_head(m
, n
, h
);
382 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
384 tag
.key
= ATTR_CLASS
;
386 print_otag(h
, TAG_DIV
, 1, &tag
);
388 print_mdoc_nodelist(m
, n
, h
);
395 print_mdoc_head(MDOC_ARGS
)
400 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
408 print_otag(h
, TAG_TITLE
, 0, NULL
);
409 print_text(h
, h
->buf
);
414 print_mdoc_nodelist(MDOC_ARGS
)
417 print_mdoc_node(m
, n
, h
);
419 print_mdoc_nodelist(m
, n
->next
, h
);
424 print_mdoc_node(MDOC_ARGS
)
435 child
= mdoc_root_pre(m
, n
, h
);
438 print_text(h
, n
->string
);
441 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
442 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
446 if (HTML_KEEP
& h
->flags
) {
447 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
448 h
->flags
&= ~HTML_KEEP
;
449 h
->flags
|= HTML_PREKEEP
;
450 } else if (NULL
== n
->prev
) {
451 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
452 h
->flags
&= ~HTML_KEEP
;
453 h
->flags
|= HTML_PREKEEP
;
458 if (child
&& n
->child
)
459 print_mdoc_nodelist(m
, n
->child
, h
);
466 mdoc_root_post(m
, n
, h
);
469 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
470 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
478 mdoc_root_post(MDOC_ARGS
)
480 struct htmlpair tag
[3];
484 time2a(m
->date
, b
, DATESIZ
);
487 * XXX: this should use divs, but in Firefox, divs with nested
488 * divs for some reason puke when trying to put a border line
489 * below. So I use tables, instead.
492 PAIR_CLASS_INIT(&tag
[0], "footer");
493 bufcat_style(h
, "width", "100%");
494 PAIR_STYLE_INIT(&tag
[1], h
);
495 PAIR_SUMMARY_INIT(&tag
[2], "footer");
497 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
498 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
501 bufcat_style(h
, "width", "50%");
502 PAIR_STYLE_INIT(&tag
[0], h
);
503 print_otag(h
, TAG_TD
, 1, tag
);
508 bufcat_style(h
, "width", "50%");
509 bufcat_style(h
, "text-align", "right");
510 PAIR_STYLE_INIT(&tag
[0], h
);
511 print_otag(h
, TAG_TD
, 1, tag
);
512 print_text(h
, m
->os
);
519 mdoc_root_pre(MDOC_ARGS
)
521 struct htmlpair tag
[3];
523 char b
[BUFSIZ
], title
[BUFSIZ
];
525 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
528 (void)strlcat(b
, " (", BUFSIZ
);
529 (void)strlcat(b
, m
->arch
, BUFSIZ
);
530 (void)strlcat(b
, ")", BUFSIZ
);
533 (void)snprintf(title
, BUFSIZ
- 1,
534 "%s(%s)", m
->title
, m
->msec
);
536 /* XXX: see note in mdoc_root_post() about divs. */
538 PAIR_CLASS_INIT(&tag
[0], "header");
539 bufcat_style(h
, "width", "100%");
540 PAIR_STYLE_INIT(&tag
[1], h
);
541 PAIR_SUMMARY_INIT(&tag
[2], "header");
543 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
545 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
548 bufcat_style(h
, "width", "10%");
549 PAIR_STYLE_INIT(&tag
[0], h
);
550 print_otag(h
, TAG_TD
, 1, tag
);
551 print_text(h
, title
);
555 bufcat_style(h
, "text-align", "center");
556 bufcat_style(h
, "white-space", "nowrap");
557 bufcat_style(h
, "width", "80%");
558 PAIR_STYLE_INIT(&tag
[0], h
);
559 print_otag(h
, TAG_TD
, 1, tag
);
564 bufcat_style(h
, "text-align", "right");
565 bufcat_style(h
, "width", "10%");
566 PAIR_STYLE_INIT(&tag
[0], h
);
567 print_otag(h
, TAG_TD
, 1, tag
);
568 print_text(h
, title
);
576 mdoc_sh_pre(MDOC_ARGS
)
578 struct htmlpair tag
[2];
579 const struct mdoc_node
*nn
;
583 if (MDOC_BODY
== n
->type
) {
584 SCALE_HS_INIT(&su
, INDENT
);
585 bufcat_su(h
, "margin-left", &su
);
586 PAIR_CLASS_INIT(&tag
[0], "sec-body");
587 PAIR_STYLE_INIT(&tag
[1], h
);
588 print_otag(h
, TAG_DIV
, 2, tag
);
590 } else if (MDOC_BLOCK
== n
->type
) {
591 PAIR_CLASS_INIT(&tag
[0], "sec-block");
592 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
593 print_otag(h
, TAG_DIV
, 1, tag
);
597 SCALE_VS_INIT(&su
, 1);
598 bufcat_su(h
, "margin-top", &su
);
600 bufcat_su(h
, "margin-bottom", &su
);
602 PAIR_STYLE_INIT(&tag
[1], h
);
603 print_otag(h
, TAG_DIV
, 2, tag
);
608 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
609 html_idcat(buf
, nn
->string
, BUFSIZ
);
611 html_idcat(buf
, " ", BUFSIZ
);
614 PAIR_CLASS_INIT(&tag
[0], "sec-head");
615 PAIR_ID_INIT(&tag
[1], buf
);
617 print_otag(h
, TAG_DIV
, 2, tag
);
624 mdoc_ss_pre(MDOC_ARGS
)
626 struct htmlpair tag
[3];
627 const struct mdoc_node
*nn
;
631 SCALE_VS_INIT(&su
, 1);
633 if (MDOC_BODY
== n
->type
) {
634 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
635 if (n
->parent
->next
&& n
->child
) {
636 bufcat_su(h
, "margin-bottom", &su
);
637 PAIR_STYLE_INIT(&tag
[1], h
);
638 print_otag(h
, TAG_DIV
, 2, tag
);
640 print_otag(h
, TAG_DIV
, 1, tag
);
642 } else if (MDOC_BLOCK
== n
->type
) {
643 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
645 bufcat_su(h
, "margin-top", &su
);
646 PAIR_STYLE_INIT(&tag
[1], h
);
647 print_otag(h
, TAG_DIV
, 2, tag
);
649 print_otag(h
, TAG_DIV
, 1, tag
);
653 /* TODO: see note in mdoc_sh_pre() about duplicates. */
656 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
657 html_idcat(buf
, nn
->string
, BUFSIZ
);
659 html_idcat(buf
, " ", BUFSIZ
);
662 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
663 su
.scale
= -su
.scale
;
664 bufcat_su(h
, "margin-left", &su
);
666 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
667 PAIR_STYLE_INIT(&tag
[1], h
);
668 PAIR_ID_INIT(&tag
[2], buf
);
670 print_otag(h
, TAG_DIV
, 3, tag
);
677 mdoc_fl_pre(MDOC_ARGS
)
681 PAIR_CLASS_INIT(&tag
, "flag");
682 print_otag(h
, TAG_SPAN
, 1, &tag
);
684 /* `Cm' has no leading hyphen. */
686 if (MDOC_Cm
== n
->tok
)
689 print_text(h
, "\\-");
692 h
->flags
|= HTML_NOSPACE
;
693 else if (n
->next
&& n
->next
->line
== n
->line
)
694 h
->flags
|= HTML_NOSPACE
;
702 mdoc_nd_pre(MDOC_ARGS
)
706 if (MDOC_BODY
!= n
->type
)
709 /* XXX: this tag in theory can contain block elements. */
711 print_text(h
, "\\(em");
712 PAIR_CLASS_INIT(&tag
, "desc-body");
713 print_otag(h
, TAG_SPAN
, 1, &tag
);
720 mdoc_op_pre(MDOC_ARGS
)
724 if (MDOC_BODY
!= n
->type
)
727 /* XXX: this tag in theory can contain block elements. */
729 print_text(h
, "\\(lB");
730 h
->flags
|= HTML_NOSPACE
;
731 PAIR_CLASS_INIT(&tag
, "opt");
732 print_otag(h
, TAG_SPAN
, 1, &tag
);
739 mdoc_op_post(MDOC_ARGS
)
742 if (MDOC_BODY
!= n
->type
)
744 h
->flags
|= HTML_NOSPACE
;
745 print_text(h
, "\\(rB");
750 mdoc_nm_pre(MDOC_ARGS
)
757 * Accomodate for `Nm' being both an element (which may have
758 * NULL children AND no m->name) and a block.
763 if (MDOC_ELEM
== n
->type
) {
764 if (NULL
== n
->child
&& NULL
== m
->name
)
767 PAIR_CLASS_INIT(&tag
, "name");
768 print_otag(h
, TAG_SPAN
, 1, &tag
);
769 if (NULL
== n
->child
)
770 print_text(h
, m
->name
);
771 } else if (MDOC_BLOCK
== n
->type
) {
774 bufcat_style(h
, "clear", "both");
775 if (n
->head
->child
|| m
->name
) {
776 if (n
->head
->child
&& MDOC_TEXT
==
777 n
->head
->child
->type
)
778 cp
= n
->head
->child
->string
;
779 if (NULL
== cp
|| '\0' == *cp
)
782 SCALE_HS_INIT(&su
, (double)strlen(cp
));
783 bufcat_su(h
, "padding-left", &su
);
786 PAIR_STYLE_INIT(&tag
, h
);
787 print_otag(h
, TAG_DIV
, 1, &tag
);
788 } else if (MDOC_HEAD
== n
->type
) {
789 if (NULL
== n
->child
&& NULL
== m
->name
)
792 if (n
->child
&& MDOC_TEXT
== n
->child
->type
)
793 cp
= n
->child
->string
;
794 if (NULL
== cp
|| '\0' == *cp
)
797 SCALE_HS_INIT(&su
, (double)strlen(cp
));
799 bufcat_style(h
, "float", "left");
800 bufcat_su(h
, "min-width", &su
);
802 bufcat_su(h
, "margin-left", &su
);
804 PAIR_STYLE_INIT(&tag
, h
);
805 print_otag(h
, TAG_DIV
, 1, &tag
);
807 if (NULL
== n
->child
)
808 print_text(h
, m
->name
);
809 } else if (MDOC_BODY
== n
->type
) {
810 SCALE_HS_INIT(&su
, 2);
811 bufcat_su(h
, "margin-left", &su
);
812 PAIR_STYLE_INIT(&tag
, h
);
813 print_otag(h
, TAG_DIV
, 1, &tag
);
822 mdoc_xr_pre(MDOC_ARGS
)
824 struct htmlpair tag
[2];
825 const struct mdoc_node
*nn
;
827 if (NULL
== n
->child
)
830 PAIR_CLASS_INIT(&tag
[0], "link-man");
833 buffmt_man(h
, n
->child
->string
,
835 n
->child
->next
->string
: NULL
);
836 PAIR_HREF_INIT(&tag
[1], h
->buf
);
837 print_otag(h
, TAG_A
, 2, tag
);
839 print_otag(h
, TAG_A
, 1, tag
);
842 print_text(h
, nn
->string
);
844 if (NULL
== (nn
= nn
->next
))
847 h
->flags
|= HTML_NOSPACE
;
849 h
->flags
|= HTML_NOSPACE
;
850 print_text(h
, nn
->string
);
851 h
->flags
|= HTML_NOSPACE
;
859 mdoc_ns_pre(MDOC_ARGS
)
862 h
->flags
|= HTML_NOSPACE
;
869 mdoc_ar_pre(MDOC_ARGS
)
873 PAIR_CLASS_INIT(&tag
, "arg");
874 print_otag(h
, TAG_SPAN
, 1, &tag
);
881 mdoc_xx_pre(MDOC_ARGS
)
909 PAIR_CLASS_INIT(&tag
, "unix");
910 print_otag(h
, TAG_SPAN
, 1, &tag
);
918 mdoc_bx_pre(MDOC_ARGS
)
920 const struct mdoc_node
*nn
;
923 PAIR_CLASS_INIT(&tag
, "unix");
924 print_otag(h
, TAG_SPAN
, 1, &tag
);
926 for (nn
= n
->child
; nn
; nn
= nn
->next
)
927 print_mdoc_node(m
, nn
, h
);
930 h
->flags
|= HTML_NOSPACE
;
932 print_text(h
, "BSD");
939 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
940 struct roffsu
*offs
, struct roffsu
*width
)
943 const struct mdoc_node
*nn
;
946 nn
= n
->parent
->parent
;
948 /* XXX: see notes in mdoc_it_pre(). */
950 if (LIST_column
== type
) {
951 /* Don't width-pad on the left. */
952 SCALE_HS_INIT(width
, 0);
953 /* Also disallow non-compact. */
956 if (LIST_diag
== type
)
957 /* Mandate non-compact with empty prior. */
958 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
961 bufcat_style(h
, "clear", "both");
963 bufcat_su(h
, "margin-left", offs
);
964 if (width
->scale
> 0)
965 bufcat_su(h
, "padding-left", width
);
967 PAIR_STYLE_INIT(&tag
, h
);
969 /* Mandate compact following `Ss' and `Sh' starts. */
971 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
972 if (MDOC_BLOCK
!= nn
->type
)
974 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
981 SCALE_VS_INIT(&su
, 1);
982 bufcat_su(h
, "padding-top", &su
);
985 PAIR_STYLE_INIT(&tag
, h
);
986 print_otag(h
, TAG_DIV
, 1, &tag
);
993 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
1004 bufcat_su(h
, "min-width", width
);
1005 bufcat_style(h
, "clear", "none");
1007 bufcat_style(h
, "float", "left");
1008 PAIR_STYLE_INIT(&tag
, h
);
1009 print_otag(h
, TAG_DIV
, 1, &tag
);
1013 * XXX: this tricks CSS into aligning the bodies with
1014 * the right-padding in the head.
1016 SCALE_HS_INIT(&su
, 2);
1017 bufcat_su(h
, "margin-left", &su
);
1018 PAIR_STYLE_INIT(&tag
, h
);
1019 print_otag(h
, TAG_DIV
, 1, &tag
);
1029 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
1031 struct htmlpair tag
;
1039 print_otag(h
, TAG_DIV
, 0, &tag
);
1044 bufcat_su(h
, "min-width", width
);
1045 SCALE_INVERT(width
);
1046 bufcat_su(h
, "margin-left", width
);
1047 if (n
->next
&& n
->next
->child
)
1048 bufcat_style(h
, "float", "left");
1050 /* XXX: buffer if we run into body. */
1051 SCALE_HS_INIT(width
, 1);
1052 bufcat_su(h
, "margin-right", width
);
1053 PAIR_STYLE_INIT(&tag
, h
);
1054 print_otag(h
, TAG_DIV
, 1, &tag
);
1060 PAIR_CLASS_INIT(&tag
, "diag");
1061 print_otag(h
, TAG_SPAN
, 1, &tag
);
1066 nbuf
[BUFSIZ
- 1] = 0;
1067 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1068 print_text(h
, nbuf
);
1071 print_text(h
, "\\(en");
1074 print_text(h
, "\\(hy");
1077 print_text(h
, "\\(bu");
1088 mdoc_it_pre(MDOC_ARGS
)
1091 const struct mdoc_node
*bl
, *nn
;
1092 struct roffsu width
, offs
;
1093 enum mdoc_list type
;
1096 * XXX: be very careful in changing anything, here. Lists in
1097 * mandoc have many peculiarities; furthermore, they don't
1098 * translate well into HTML and require a bit of mangling.
1101 bl
= n
->parent
->parent
;
1102 if (MDOC_BLOCK
!= n
->type
)
1105 SCALE_HS_INIT(&offs
, 0);
1107 assert(bl
->data
.Bl
);
1108 type
= bl
->data
.Bl
->type
;
1109 comp
= bl
->data
.Bl
->comp
;
1111 if (bl
->data
.Bl
->offs
)
1112 a2offs(bl
->data
.Bl
->offs
, &offs
);
1122 SCALE_HS_INIT(&width
, 2);
1125 SCALE_HS_INIT(&width
, INDENT
);
1129 if (bl
->data
.Bl
->width
)
1130 a2width(bl
->data
.Bl
->width
, &width
);
1132 /* Override width in some cases. */
1142 SCALE_HS_INIT(&width
, 0);
1145 if (0 == width
.scale
)
1146 SCALE_HS_INIT(&width
, INDENT
);
1150 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1151 nn
= n
->parent
->child
;
1152 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1153 if (MDOC_BODY
== nn
->type
)
1155 if (i
< (int)bl
->data
.Bl
->ncols
)
1156 a2width(bl
->data
.Bl
->cols
[i
], &width
);
1159 if (MDOC_HEAD
== n
->type
)
1160 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1161 else if (MDOC_BODY
== n
->type
)
1162 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1164 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1170 mdoc_bl_pre(MDOC_ARGS
)
1174 if (MDOC_HEAD
== n
->type
)
1176 if (MDOC_BLOCK
!= n
->type
)
1179 if (LIST_enum
!= n
->data
.Bl
->type
)
1182 ord
= malloc(sizeof(struct ord
));
1189 ord
->next
= h
->ords
.head
;
1197 mdoc_bl_post(MDOC_ARGS
)
1201 if (MDOC_BLOCK
!= n
->type
)
1203 if (LIST_enum
!= n
->data
.Bl
->type
)
1208 h
->ords
.head
= ord
->next
;
1215 mdoc_ex_pre(MDOC_ARGS
)
1217 const struct mdoc_node
*nn
;
1219 struct htmlpair tag
;
1221 PAIR_CLASS_INIT(&tag
, "utility");
1223 print_text(h
, "The");
1224 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1225 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1226 print_text(h
, nn
->string
);
1229 h
->flags
|= HTML_NOSPACE
;
1231 if (nn
->next
&& NULL
== nn
->next
->next
)
1232 print_text(h
, ", and");
1236 h
->flags
&= ~HTML_NOSPACE
;
1239 if (n
->child
&& n
->child
->next
)
1240 print_text(h
, "utilities exit");
1242 print_text(h
, "utility exits");
1244 print_text(h
, "0 on success, and >0 if an error occurs.");
1251 mdoc_dq_pre(MDOC_ARGS
)
1254 if (MDOC_BODY
!= n
->type
)
1256 print_text(h
, "\\(lq");
1257 h
->flags
|= HTML_NOSPACE
;
1264 mdoc_dq_post(MDOC_ARGS
)
1267 if (MDOC_BODY
!= n
->type
)
1269 h
->flags
|= HTML_NOSPACE
;
1270 print_text(h
, "\\(rq");
1276 mdoc_pq_pre(MDOC_ARGS
)
1279 if (MDOC_BODY
!= n
->type
)
1281 print_text(h
, "\\&(");
1282 h
->flags
|= HTML_NOSPACE
;
1289 mdoc_pq_post(MDOC_ARGS
)
1292 if (MDOC_BODY
!= n
->type
)
1300 mdoc_sq_pre(MDOC_ARGS
)
1303 if (MDOC_BODY
!= n
->type
)
1305 print_text(h
, "\\(oq");
1306 h
->flags
|= HTML_NOSPACE
;
1313 mdoc_sq_post(MDOC_ARGS
)
1316 if (MDOC_BODY
!= n
->type
)
1318 h
->flags
|= HTML_NOSPACE
;
1319 print_text(h
, "\\(aq");
1325 mdoc_em_pre(MDOC_ARGS
)
1327 struct htmlpair tag
;
1329 PAIR_CLASS_INIT(&tag
, "emph");
1330 print_otag(h
, TAG_SPAN
, 1, &tag
);
1337 mdoc_d1_pre(MDOC_ARGS
)
1339 struct htmlpair tag
[2];
1342 if (MDOC_BLOCK
!= n
->type
)
1345 /* FIXME: D1 shouldn't be literal. */
1347 SCALE_VS_INIT(&su
, INDENT
- 2);
1348 bufcat_su(h
, "margin-left", &su
);
1349 PAIR_CLASS_INIT(&tag
[0], "lit");
1350 PAIR_STYLE_INIT(&tag
[1], h
);
1351 print_otag(h
, TAG_DIV
, 2, tag
);
1358 mdoc_sx_pre(MDOC_ARGS
)
1360 struct htmlpair tag
[2];
1361 const struct mdoc_node
*nn
;
1364 strlcpy(buf
, "#", BUFSIZ
);
1365 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1366 html_idcat(buf
, nn
->string
, BUFSIZ
);
1368 html_idcat(buf
, " ", BUFSIZ
);
1371 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1372 PAIR_HREF_INIT(&tag
[1], buf
);
1374 print_otag(h
, TAG_A
, 2, tag
);
1381 mdoc_aq_pre(MDOC_ARGS
)
1384 if (MDOC_BODY
!= n
->type
)
1386 print_text(h
, "\\(la");
1387 h
->flags
|= HTML_NOSPACE
;
1394 mdoc_aq_post(MDOC_ARGS
)
1397 if (MDOC_BODY
!= n
->type
)
1399 h
->flags
|= HTML_NOSPACE
;
1400 print_text(h
, "\\(ra");
1406 mdoc_bd_pre(MDOC_ARGS
)
1408 struct htmlpair tag
[2];
1410 const struct mdoc_node
*nn
;
1413 if (MDOC_HEAD
== n
->type
)
1416 SCALE_VS_INIT(&su
, 0);
1419 if (n
->data
.Bd
->offs
)
1420 a2offs(n
->data
.Bd
->offs
, &su
);
1422 comp
= n
->data
.Bd
->comp
;
1424 /* FIXME: -centered, etc. formatting. */
1425 /* FIXME: does not respect -offset ??? */
1427 if (MDOC_BLOCK
== n
->type
) {
1428 bufcat_su(h
, "margin-left", &su
);
1429 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1430 if (MDOC_BLOCK
!= nn
->type
)
1432 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1438 PAIR_STYLE_INIT(&tag
[0], h
);
1439 print_otag(h
, TAG_DIV
, 1, tag
);
1442 SCALE_VS_INIT(&su
, 1);
1443 bufcat_su(h
, "margin-top", &su
);
1444 PAIR_STYLE_INIT(&tag
[0], h
);
1445 print_otag(h
, TAG_DIV
, 1, tag
);
1449 if (DISP_unfilled
!= n
->data
.Bd
->type
&&
1450 DISP_literal
!= n
->data
.Bd
->type
)
1453 PAIR_CLASS_INIT(&tag
[0], "lit");
1454 bufcat_style(h
, "white-space", "pre");
1455 PAIR_STYLE_INIT(&tag
[1], h
);
1456 print_otag(h
, TAG_DIV
, 2, tag
);
1458 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1459 h
->flags
|= HTML_NOSPACE
;
1460 print_mdoc_node(m
, nn
, h
);
1461 if (NULL
== nn
->next
)
1463 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1464 print_text(h
, "\n");
1465 else if (NULL
== nn
->prev
)
1466 print_text(h
, "\n");
1475 mdoc_pa_pre(MDOC_ARGS
)
1477 struct htmlpair tag
;
1479 PAIR_CLASS_INIT(&tag
, "file");
1480 print_otag(h
, TAG_SPAN
, 1, &tag
);
1487 mdoc_ad_pre(MDOC_ARGS
)
1489 struct htmlpair tag
;
1491 PAIR_CLASS_INIT(&tag
, "addr");
1492 print_otag(h
, TAG_SPAN
, 1, &tag
);
1499 mdoc_an_pre(MDOC_ARGS
)
1501 struct htmlpair tag
;
1503 /* TODO: -split and -nosplit (see termp_an_pre()). */
1505 PAIR_CLASS_INIT(&tag
, "author");
1506 print_otag(h
, TAG_SPAN
, 1, &tag
);
1513 mdoc_cd_pre(MDOC_ARGS
)
1515 struct htmlpair tag
;
1518 PAIR_CLASS_INIT(&tag
, "config");
1519 print_otag(h
, TAG_SPAN
, 1, &tag
);
1526 mdoc_dv_pre(MDOC_ARGS
)
1528 struct htmlpair tag
;
1530 PAIR_CLASS_INIT(&tag
, "define");
1531 print_otag(h
, TAG_SPAN
, 1, &tag
);
1538 mdoc_ev_pre(MDOC_ARGS
)
1540 struct htmlpair tag
;
1542 PAIR_CLASS_INIT(&tag
, "env");
1543 print_otag(h
, TAG_SPAN
, 1, &tag
);
1550 mdoc_er_pre(MDOC_ARGS
)
1552 struct htmlpair tag
;
1554 PAIR_CLASS_INIT(&tag
, "errno");
1555 print_otag(h
, TAG_SPAN
, 1, &tag
);
1562 mdoc_fa_pre(MDOC_ARGS
)
1564 const struct mdoc_node
*nn
;
1565 struct htmlpair tag
;
1568 PAIR_CLASS_INIT(&tag
, "farg");
1569 if (n
->parent
->tok
!= MDOC_Fo
) {
1570 print_otag(h
, TAG_SPAN
, 1, &tag
);
1574 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1575 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1576 print_text(h
, nn
->string
);
1582 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1591 mdoc_fd_pre(MDOC_ARGS
)
1593 struct htmlpair tag
;
1597 PAIR_CLASS_INIT(&tag
, "macro");
1598 print_otag(h
, TAG_SPAN
, 1, &tag
);
1605 mdoc_vt_pre(MDOC_ARGS
)
1607 struct htmlpair tag
;
1609 if (MDOC_BLOCK
== n
->type
) {
1612 } else if (MDOC_ELEM
== n
->type
) {
1614 } else if (MDOC_HEAD
== n
->type
)
1617 PAIR_CLASS_INIT(&tag
, "type");
1618 print_otag(h
, TAG_SPAN
, 1, &tag
);
1625 mdoc_ft_pre(MDOC_ARGS
)
1627 struct htmlpair tag
;
1630 PAIR_CLASS_INIT(&tag
, "ftype");
1631 print_otag(h
, TAG_SPAN
, 1, &tag
);
1638 mdoc_fn_pre(MDOC_ARGS
)
1641 struct htmlpair tag
[2];
1642 const struct mdoc_node
*nn
;
1644 const char *sp
, *ep
;
1649 /* Split apart into type and name. */
1650 assert(n
->child
->string
);
1651 sp
= n
->child
->string
;
1653 ep
= strchr(sp
, ' ');
1655 PAIR_CLASS_INIT(&tag
[0], "ftype");
1656 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1659 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1660 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1662 print_text(h
, nbuf
);
1664 ep
= strchr(sp
, ' ');
1669 PAIR_CLASS_INIT(&tag
[0], "fname");
1672 * FIXME: only refer to IDs that we know exist.
1676 if (MDOC_SYNPRETTY
& n
->flags
) {
1678 html_idcat(nbuf
, sp
, BUFSIZ
);
1679 PAIR_ID_INIT(&tag
[1], nbuf
);
1681 strlcpy(nbuf
, "#", BUFSIZ
);
1682 html_idcat(nbuf
, sp
, BUFSIZ
);
1683 PAIR_HREF_INIT(&tag
[1], nbuf
);
1687 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1690 strlcpy(nbuf
, sp
, BUFSIZ
);
1691 print_text(h
, nbuf
);
1696 h
->flags
|= HTML_NOSPACE
;
1700 PAIR_CLASS_INIT(&tag
[0], "farg");
1701 bufcat_style(h
, "white-space", "nowrap");
1702 PAIR_STYLE_INIT(&tag
[1], h
);
1704 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1706 if (MDOC_SYNPRETTY
& n
->flags
)
1708 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1709 print_text(h
, nn
->string
);
1716 if (MDOC_SYNPRETTY
& n
->flags
)
1725 mdoc_sp_pre(MDOC_ARGS
)
1728 struct htmlpair tag
;
1733 /* FIXME: can this have a scaling indicator? */
1734 len
= n
->child
? atoi(n
->child
->string
) : 1;
1744 SCALE_VS_INIT(&su
, len
);
1745 bufcat_su(h
, "height", &su
);
1746 PAIR_STYLE_INIT(&tag
, h
);
1747 print_otag(h
, TAG_DIV
, 1, &tag
);
1748 /* So the div isn't empty: */
1749 print_text(h
, "\\~");
1758 mdoc_brq_pre(MDOC_ARGS
)
1761 if (MDOC_BODY
!= n
->type
)
1763 print_text(h
, "\\(lC");
1764 h
->flags
|= HTML_NOSPACE
;
1771 mdoc_brq_post(MDOC_ARGS
)
1774 if (MDOC_BODY
!= n
->type
)
1776 h
->flags
|= HTML_NOSPACE
;
1777 print_text(h
, "\\(rC");
1783 mdoc_lk_pre(MDOC_ARGS
)
1785 const struct mdoc_node
*nn
;
1786 struct htmlpair tag
[2];
1790 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1791 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1792 print_otag(h
, TAG_A
, 2, tag
);
1794 if (NULL
== nn
->next
)
1797 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1798 print_text(h
, nn
->string
);
1806 mdoc_mt_pre(MDOC_ARGS
)
1808 struct htmlpair tag
[2];
1810 const struct mdoc_node
*nn
;
1812 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1814 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1816 bufcat(h
, "mailto:");
1817 bufcat(h
, nn
->string
);
1818 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1819 t
= print_otag(h
, TAG_A
, 2, tag
);
1820 print_text(h
, nn
->string
);
1830 mdoc_fo_pre(MDOC_ARGS
)
1832 struct htmlpair tag
;
1835 if (MDOC_BODY
== n
->type
) {
1836 h
->flags
|= HTML_NOSPACE
;
1838 h
->flags
|= HTML_NOSPACE
;
1840 } else if (MDOC_BLOCK
== n
->type
) {
1845 /* XXX: we drop non-initial arguments as per groff. */
1848 assert(n
->child
->string
);
1850 PAIR_CLASS_INIT(&tag
, "fname");
1851 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1852 print_text(h
, n
->child
->string
);
1860 mdoc_fo_post(MDOC_ARGS
)
1863 if (MDOC_BODY
!= n
->type
)
1865 h
->flags
|= HTML_NOSPACE
;
1867 h
->flags
|= HTML_NOSPACE
;
1874 mdoc_in_pre(MDOC_ARGS
)
1876 const struct mdoc_node
*nn
;
1878 struct htmlpair tag
[2];
1883 PAIR_CLASS_INIT(&tag
[0], "includes");
1884 print_otag(h
, TAG_SPAN
, 1, tag
);
1886 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1887 print_text(h
, "#include");
1890 h
->flags
|= HTML_NOSPACE
;
1892 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1893 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1896 if (h
->base_includes
) {
1897 buffmt_includes(h
, nn
->string
);
1898 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1901 t
= print_otag(h
, TAG_A
, i
, tag
);
1902 print_mdoc_node(m
, nn
, h
);
1906 h
->flags
|= HTML_NOSPACE
;
1915 mdoc_ic_pre(MDOC_ARGS
)
1917 struct htmlpair tag
;
1919 PAIR_CLASS_INIT(&tag
, "cmd");
1920 print_otag(h
, TAG_SPAN
, 1, &tag
);
1927 mdoc_rv_pre(MDOC_ARGS
)
1929 const struct mdoc_node
*nn
;
1930 struct htmlpair tag
;
1933 print_otag(h
, TAG_DIV
, 0, NULL
);
1934 print_text(h
, "The");
1936 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1937 PAIR_CLASS_INIT(&tag
, "fname");
1938 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1939 print_text(h
, nn
->string
);
1942 h
->flags
|= HTML_NOSPACE
;
1943 if (nn
->next
&& NULL
== nn
->next
->next
)
1944 print_text(h
, "(), and");
1946 print_text(h
, "(),");
1948 print_text(h
, "()");
1951 if (n
->child
&& n
->child
->next
)
1952 print_text(h
, "functions return");
1954 print_text(h
, "function returns");
1956 print_text(h
, "the value 0 if successful; otherwise the value "
1957 "-1 is returned and the global variable");
1959 PAIR_CLASS_INIT(&tag
, "var");
1960 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1961 print_text(h
, "errno");
1963 print_text(h
, "is set to indicate the error.");
1970 mdoc_va_pre(MDOC_ARGS
)
1972 struct htmlpair tag
;
1974 PAIR_CLASS_INIT(&tag
, "var");
1975 print_otag(h
, TAG_SPAN
, 1, &tag
);
1982 mdoc_bq_pre(MDOC_ARGS
)
1985 if (MDOC_BODY
!= n
->type
)
1987 print_text(h
, "\\(lB");
1988 h
->flags
|= HTML_NOSPACE
;
1995 mdoc_bq_post(MDOC_ARGS
)
1998 if (MDOC_BODY
!= n
->type
)
2000 h
->flags
|= HTML_NOSPACE
;
2001 print_text(h
, "\\(rB");
2007 mdoc_ap_pre(MDOC_ARGS
)
2010 h
->flags
|= HTML_NOSPACE
;
2011 print_text(h
, "\\(aq");
2012 h
->flags
|= HTML_NOSPACE
;
2019 mdoc_bf_pre(MDOC_ARGS
)
2021 struct htmlpair tag
[2];
2024 if (MDOC_HEAD
== n
->type
)
2026 else if (MDOC_BODY
!= n
->type
)
2031 if (FONT_Em
== n
->data
.Bf
->font
)
2032 PAIR_CLASS_INIT(&tag
[0], "emph");
2033 else if (FONT_Sy
== n
->data
.Bf
->font
)
2034 PAIR_CLASS_INIT(&tag
[0], "symb");
2035 else if (FONT_Li
== n
->data
.Bf
->font
)
2036 PAIR_CLASS_INIT(&tag
[0], "lit");
2038 PAIR_CLASS_INIT(&tag
[0], "none");
2041 * We want this to be inline-formatted, but needs to be div to
2042 * accept block children.
2044 bufcat_style(h
, "display", "inline");
2045 SCALE_HS_INIT(&su
, 1);
2046 /* Needs a left-margin for spacing. */
2047 bufcat_su(h
, "margin-left", &su
);
2048 PAIR_STYLE_INIT(&tag
[1], h
);
2049 print_otag(h
, TAG_DIV
, 2, tag
);
2056 mdoc_ms_pre(MDOC_ARGS
)
2058 struct htmlpair tag
;
2060 PAIR_CLASS_INIT(&tag
, "symb");
2061 print_otag(h
, TAG_SPAN
, 1, &tag
);
2068 mdoc_pf_pre(MDOC_ARGS
)
2071 h
->flags
|= HTML_IGNDELIM
;
2078 mdoc_pf_post(MDOC_ARGS
)
2081 h
->flags
&= ~HTML_IGNDELIM
;
2082 h
->flags
|= HTML_NOSPACE
;
2088 mdoc_rs_pre(MDOC_ARGS
)
2090 struct htmlpair tag
;
2093 if (MDOC_BLOCK
!= n
->type
)
2096 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2097 SCALE_VS_INIT(&su
, 1);
2098 bufcat_su(h
, "margin-top", &su
);
2099 PAIR_STYLE_INIT(&tag
, h
);
2100 print_otag(h
, TAG_DIV
, 1, &tag
);
2103 PAIR_CLASS_INIT(&tag
, "ref");
2104 print_otag(h
, TAG_SPAN
, 1, &tag
);
2112 mdoc_li_pre(MDOC_ARGS
)
2114 struct htmlpair tag
;
2116 PAIR_CLASS_INIT(&tag
, "lit");
2117 print_otag(h
, TAG_SPAN
, 1, &tag
);
2124 mdoc_sy_pre(MDOC_ARGS
)
2126 struct htmlpair tag
;
2128 PAIR_CLASS_INIT(&tag
, "symb");
2129 print_otag(h
, TAG_SPAN
, 1, &tag
);
2136 mdoc_bt_pre(MDOC_ARGS
)
2139 print_text(h
, "is currently in beta test.");
2146 mdoc_ud_pre(MDOC_ARGS
)
2149 print_text(h
, "currently under development.");
2156 mdoc_lb_pre(MDOC_ARGS
)
2158 struct htmlpair tag
;
2160 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2161 print_otag(h
, TAG_DIV
, 0, NULL
);
2162 PAIR_CLASS_INIT(&tag
, "lib");
2163 print_otag(h
, TAG_SPAN
, 1, &tag
);
2170 mdoc__x_pre(MDOC_ARGS
)
2172 struct htmlpair tag
[2];
2176 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2179 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2182 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2185 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2188 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2191 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2194 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2197 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2200 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2203 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2206 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2209 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2212 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2215 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2222 if (MDOC__U
!= n
->tok
) {
2223 print_otag(h
, TAG_SPAN
, 1, tag
);
2227 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2228 print_otag(h
, TAG_A
, 2, tag
);
2235 mdoc__x_post(MDOC_ARGS
)
2240 h
->flags
|= HTML_NOSPACE
;
2241 print_text(h
, n
->next
? "," : ".");
2247 mdoc_bk_pre(MDOC_ARGS
)
2256 h
->flags
|= HTML_PREKEEP
;
2269 mdoc_bk_post(MDOC_ARGS
)
2272 if (MDOC_BODY
== n
->type
)
2273 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);