]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.112 2010/10/23 23:31:10 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 int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static void mdoc_bl_post(MDOC_ARGS
);
76 static int mdoc_bl_pre(MDOC_ARGS
);
77 static int mdoc_bt_pre(MDOC_ARGS
);
78 static int mdoc_bx_pre(MDOC_ARGS
);
79 static int mdoc_cd_pre(MDOC_ARGS
);
80 static int mdoc_d1_pre(MDOC_ARGS
);
81 static int mdoc_dv_pre(MDOC_ARGS
);
82 static int mdoc_fa_pre(MDOC_ARGS
);
83 static int mdoc_fd_pre(MDOC_ARGS
);
84 static int mdoc_fl_pre(MDOC_ARGS
);
85 static int mdoc_fn_pre(MDOC_ARGS
);
86 static int mdoc_ft_pre(MDOC_ARGS
);
87 static int mdoc_em_pre(MDOC_ARGS
);
88 static int mdoc_er_pre(MDOC_ARGS
);
89 static int mdoc_ev_pre(MDOC_ARGS
);
90 static int mdoc_ex_pre(MDOC_ARGS
);
91 static void mdoc_fo_post(MDOC_ARGS
);
92 static int mdoc_fo_pre(MDOC_ARGS
);
93 static int mdoc_ic_pre(MDOC_ARGS
);
94 static int mdoc_igndelim_pre(MDOC_ARGS
);
95 static int mdoc_in_pre(MDOC_ARGS
);
96 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
97 int, struct roffsu
*, struct roffsu
*);
98 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
100 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
,
102 static int mdoc_it_pre(MDOC_ARGS
);
103 static int mdoc_lb_pre(MDOC_ARGS
);
104 static int mdoc_li_pre(MDOC_ARGS
);
105 static int mdoc_lk_pre(MDOC_ARGS
);
106 static int mdoc_mt_pre(MDOC_ARGS
);
107 static int mdoc_ms_pre(MDOC_ARGS
);
108 static int mdoc_nd_pre(MDOC_ARGS
);
109 static int mdoc_nm_pre(MDOC_ARGS
);
110 static int mdoc_ns_pre(MDOC_ARGS
);
111 static int mdoc_pa_pre(MDOC_ARGS
);
112 static void mdoc_pf_post(MDOC_ARGS
);
113 static void mdoc_quote_post(MDOC_ARGS
);
114 static int mdoc_quote_pre(MDOC_ARGS
);
115 static int mdoc_rs_pre(MDOC_ARGS
);
116 static int mdoc_rv_pre(MDOC_ARGS
);
117 static int mdoc_sh_pre(MDOC_ARGS
);
118 static int mdoc_sm_pre(MDOC_ARGS
);
119 static int mdoc_sp_pre(MDOC_ARGS
);
120 static int mdoc_ss_pre(MDOC_ARGS
);
121 static int mdoc_sx_pre(MDOC_ARGS
);
122 static int mdoc_sy_pre(MDOC_ARGS
);
123 static int mdoc_ud_pre(MDOC_ARGS
);
124 static int mdoc_va_pre(MDOC_ARGS
);
125 static int mdoc_vt_pre(MDOC_ARGS
);
126 static int mdoc_xr_pre(MDOC_ARGS
);
127 static int mdoc_xx_pre(MDOC_ARGS
);
129 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
130 {mdoc_ap_pre
, NULL
}, /* Ap */
131 {NULL
, NULL
}, /* Dd */
132 {NULL
, NULL
}, /* Dt */
133 {NULL
, NULL
}, /* Os */
134 {mdoc_sh_pre
, NULL
}, /* Sh */
135 {mdoc_ss_pre
, NULL
}, /* Ss */
136 {mdoc_sp_pre
, NULL
}, /* Pp */
137 {mdoc_d1_pre
, NULL
}, /* D1 */
138 {mdoc_d1_pre
, NULL
}, /* Dl */
139 {mdoc_bd_pre
, NULL
}, /* Bd */
140 {NULL
, NULL
}, /* Ed */
141 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
142 {NULL
, NULL
}, /* El */
143 {mdoc_it_pre
, NULL
}, /* It */
144 {mdoc_ad_pre
, NULL
}, /* Ad */
145 {mdoc_an_pre
, NULL
}, /* An */
146 {mdoc_ar_pre
, NULL
}, /* Ar */
147 {mdoc_cd_pre
, NULL
}, /* Cd */
148 {mdoc_fl_pre
, NULL
}, /* Cm */
149 {mdoc_dv_pre
, NULL
}, /* Dv */
150 {mdoc_er_pre
, NULL
}, /* Er */
151 {mdoc_ev_pre
, NULL
}, /* Ev */
152 {mdoc_ex_pre
, NULL
}, /* Ex */
153 {mdoc_fa_pre
, NULL
}, /* Fa */
154 {mdoc_fd_pre
, NULL
}, /* Fd */
155 {mdoc_fl_pre
, NULL
}, /* Fl */
156 {mdoc_fn_pre
, NULL
}, /* Fn */
157 {mdoc_ft_pre
, NULL
}, /* Ft */
158 {mdoc_ic_pre
, NULL
}, /* Ic */
159 {mdoc_in_pre
, NULL
}, /* In */
160 {mdoc_li_pre
, NULL
}, /* Li */
161 {mdoc_nd_pre
, NULL
}, /* Nd */
162 {mdoc_nm_pre
, NULL
}, /* Nm */
163 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
164 {NULL
, NULL
}, /* Ot */
165 {mdoc_pa_pre
, NULL
}, /* Pa */
166 {mdoc_rv_pre
, NULL
}, /* Rv */
167 {NULL
, NULL
}, /* St */
168 {mdoc_va_pre
, NULL
}, /* Va */
169 {mdoc_vt_pre
, NULL
}, /* Vt */
170 {mdoc_xr_pre
, NULL
}, /* Xr */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
178 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
179 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
180 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
182 {NULL
, NULL
}, /* Ac */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
185 {NULL
, NULL
}, /* At */
186 {NULL
, NULL
}, /* Bc */
187 {mdoc_bf_pre
, NULL
}, /* Bf */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
190 {mdoc_xx_pre
, NULL
}, /* Bsx */
191 {mdoc_bx_pre
, NULL
}, /* Bx */
192 {NULL
, NULL
}, /* Db */
193 {NULL
, NULL
}, /* Dc */
194 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
195 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
196 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
197 {NULL
, NULL
}, /* Ef */
198 {mdoc_em_pre
, NULL
}, /* Em */
199 {NULL
, NULL
}, /* Eo */
200 {mdoc_xx_pre
, NULL
}, /* Fx */
201 {mdoc_ms_pre
, NULL
}, /* Ms */
202 {mdoc_igndelim_pre
, NULL
}, /* No */
203 {mdoc_ns_pre
, NULL
}, /* Ns */
204 {mdoc_xx_pre
, NULL
}, /* Nx */
205 {mdoc_xx_pre
, NULL
}, /* Ox */
206 {NULL
, NULL
}, /* Pc */
207 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
209 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
210 {NULL
, NULL
}, /* Qc */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
214 {NULL
, NULL
}, /* Re */
215 {mdoc_rs_pre
, NULL
}, /* Rs */
216 {NULL
, NULL
}, /* Sc */
217 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
218 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
219 {mdoc_sm_pre
, NULL
}, /* Sm */
220 {mdoc_sx_pre
, NULL
}, /* Sx */
221 {mdoc_sy_pre
, NULL
}, /* Sy */
222 {NULL
, NULL
}, /* Tn */
223 {mdoc_xx_pre
, NULL
}, /* Ux */
224 {NULL
, NULL
}, /* Xc */
225 {NULL
, NULL
}, /* Xo */
226 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
227 {NULL
, NULL
}, /* Fc */
228 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
229 {NULL
, NULL
}, /* Oc */
230 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
231 {NULL
, NULL
}, /* Ek */
232 {mdoc_bt_pre
, NULL
}, /* Bt */
233 {NULL
, NULL
}, /* Hf */
234 {NULL
, NULL
}, /* Fr */
235 {mdoc_ud_pre
, NULL
}, /* Ud */
236 {mdoc_lb_pre
, NULL
}, /* Lb */
237 {mdoc_sp_pre
, NULL
}, /* Lp */
238 {mdoc_lk_pre
, NULL
}, /* Lk */
239 {mdoc_mt_pre
, NULL
}, /* Mt */
240 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
241 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
242 {NULL
, NULL
}, /* Brc */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
244 {NULL
, NULL
}, /* Es */ /* TODO */
245 {NULL
, NULL
}, /* En */ /* TODO */
246 {mdoc_xx_pre
, NULL
}, /* Dx */
247 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
248 {mdoc_sp_pre
, NULL
}, /* br */
249 {mdoc_sp_pre
, NULL
}, /* sp */
250 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
251 {NULL
, NULL
}, /* Ta */
256 html_mdoc(void *arg
, const struct mdoc
*m
)
261 h
= (struct html
*)arg
;
264 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
265 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
273 * Calculate the scaling unit passed in a `-width' argument. This uses
274 * either a native scaling unit (e.g., 1i, 2m) or the string length of
278 a2width(const char *p
, struct roffsu
*su
)
281 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
283 su
->scale
= (int)strlen(p
);
289 * See the same function in mdoc_term.c for documentation.
292 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
297 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
300 SCALE_VS_INIT(&su
, 1);
301 bufcat_su(h
, "margin-top", &su
);
302 PAIR_STYLE_INIT(&tag
, h
);
304 if (n
->prev
->tok
== n
->tok
&&
308 print_otag(h
, TAG_DIV
, 0, NULL
);
312 switch (n
->prev
->tok
) {
322 print_otag(h
, TAG_DIV
, 1, &tag
);
325 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
326 print_otag(h
, TAG_DIV
, 1, &tag
);
331 print_otag(h
, TAG_DIV
, 0, NULL
);
338 * Calculate the scaling unit passed in an `-offset' argument. This
339 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
340 * predefined strings (indent, etc.), or the string length of the value.
343 a2offs(const char *p
, struct roffsu
*su
)
346 /* FIXME: "right"? */
348 if (0 == strcmp(p
, "left"))
349 SCALE_HS_INIT(su
, 0);
350 else if (0 == strcmp(p
, "indent"))
351 SCALE_HS_INIT(su
, INDENT
);
352 else if (0 == strcmp(p
, "indent-two"))
353 SCALE_HS_INIT(su
, INDENT
* 2);
354 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
356 su
->scale
= (int)strlen(p
);
362 print_mdoc(MDOC_ARGS
)
367 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
368 print_mdoc_head(m
, n
, h
);
371 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
373 tag
.key
= ATTR_CLASS
;
375 print_otag(h
, TAG_DIV
, 1, &tag
);
377 print_mdoc_nodelist(m
, n
, h
);
384 print_mdoc_head(MDOC_ARGS
)
389 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
397 print_otag(h
, TAG_TITLE
, 0, NULL
);
398 print_text(h
, h
->buf
);
403 print_mdoc_nodelist(MDOC_ARGS
)
406 print_mdoc_node(m
, n
, h
);
408 print_mdoc_nodelist(m
, n
->next
, h
);
413 print_mdoc_node(MDOC_ARGS
)
424 child
= mdoc_root_pre(m
, n
, h
);
427 print_text(h
, n
->string
);
430 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
431 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
435 if (HTML_KEEP
& h
->flags
) {
436 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
437 h
->flags
&= ~HTML_KEEP
;
438 h
->flags
|= HTML_PREKEEP
;
439 } else if (NULL
== n
->prev
) {
440 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
441 h
->flags
&= ~HTML_KEEP
;
442 h
->flags
|= HTML_PREKEEP
;
447 if (child
&& n
->child
)
448 print_mdoc_nodelist(m
, n
->child
, h
);
455 mdoc_root_post(m
, n
, h
);
458 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
459 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
467 mdoc_root_post(MDOC_ARGS
)
469 struct htmlpair tag
[3];
473 time2a(m
->date
, b
, DATESIZ
);
476 * XXX: this should use divs, but in Firefox, divs with nested
477 * divs for some reason puke when trying to put a border line
478 * below. So I use tables, instead.
481 PAIR_CLASS_INIT(&tag
[0], "footer");
482 bufcat_style(h
, "width", "100%");
483 PAIR_STYLE_INIT(&tag
[1], h
);
484 PAIR_SUMMARY_INIT(&tag
[2], "footer");
486 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
487 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
490 bufcat_style(h
, "width", "50%");
491 PAIR_STYLE_INIT(&tag
[0], h
);
492 print_otag(h
, TAG_TD
, 1, tag
);
497 bufcat_style(h
, "width", "50%");
498 bufcat_style(h
, "text-align", "right");
499 PAIR_STYLE_INIT(&tag
[0], h
);
500 print_otag(h
, TAG_TD
, 1, tag
);
501 print_text(h
, m
->os
);
508 mdoc_root_pre(MDOC_ARGS
)
510 struct htmlpair tag
[3];
512 char b
[BUFSIZ
], title
[BUFSIZ
];
514 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
517 (void)strlcat(b
, " (", BUFSIZ
);
518 (void)strlcat(b
, m
->arch
, BUFSIZ
);
519 (void)strlcat(b
, ")", BUFSIZ
);
522 (void)snprintf(title
, BUFSIZ
- 1,
523 "%s(%s)", m
->title
, m
->msec
);
525 /* XXX: see note in mdoc_root_post() about divs. */
527 PAIR_CLASS_INIT(&tag
[0], "header");
528 bufcat_style(h
, "width", "100%");
529 PAIR_STYLE_INIT(&tag
[1], h
);
530 PAIR_SUMMARY_INIT(&tag
[2], "header");
532 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
534 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
537 bufcat_style(h
, "width", "10%");
538 PAIR_STYLE_INIT(&tag
[0], h
);
539 print_otag(h
, TAG_TD
, 1, tag
);
540 print_text(h
, title
);
544 bufcat_style(h
, "text-align", "center");
545 bufcat_style(h
, "white-space", "nowrap");
546 bufcat_style(h
, "width", "80%");
547 PAIR_STYLE_INIT(&tag
[0], h
);
548 print_otag(h
, TAG_TD
, 1, tag
);
553 bufcat_style(h
, "text-align", "right");
554 bufcat_style(h
, "width", "10%");
555 PAIR_STYLE_INIT(&tag
[0], h
);
556 print_otag(h
, TAG_TD
, 1, tag
);
557 print_text(h
, title
);
565 mdoc_sh_pre(MDOC_ARGS
)
567 struct htmlpair tag
[2];
568 const struct mdoc_node
*nn
;
572 if (MDOC_BODY
== n
->type
) {
573 SCALE_HS_INIT(&su
, INDENT
);
574 bufcat_su(h
, "margin-left", &su
);
575 PAIR_CLASS_INIT(&tag
[0], "sec-body");
576 PAIR_STYLE_INIT(&tag
[1], h
);
577 print_otag(h
, TAG_DIV
, 2, tag
);
579 } else if (MDOC_BLOCK
== n
->type
) {
580 PAIR_CLASS_INIT(&tag
[0], "sec-block");
581 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
582 print_otag(h
, TAG_DIV
, 1, tag
);
586 SCALE_VS_INIT(&su
, 1);
587 bufcat_su(h
, "margin-top", &su
);
589 bufcat_su(h
, "margin-bottom", &su
);
591 PAIR_STYLE_INIT(&tag
[1], h
);
592 print_otag(h
, TAG_DIV
, 2, tag
);
597 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
598 html_idcat(buf
, nn
->string
, BUFSIZ
);
600 html_idcat(buf
, " ", BUFSIZ
);
603 PAIR_CLASS_INIT(&tag
[0], "sec-head");
604 PAIR_ID_INIT(&tag
[1], buf
);
606 print_otag(h
, TAG_DIV
, 2, tag
);
613 mdoc_ss_pre(MDOC_ARGS
)
615 struct htmlpair tag
[3];
616 const struct mdoc_node
*nn
;
620 SCALE_VS_INIT(&su
, 1);
622 if (MDOC_BODY
== n
->type
) {
623 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
624 if (n
->parent
->next
&& n
->child
) {
625 bufcat_su(h
, "margin-bottom", &su
);
626 PAIR_STYLE_INIT(&tag
[1], h
);
627 print_otag(h
, TAG_DIV
, 2, tag
);
629 print_otag(h
, TAG_DIV
, 1, tag
);
631 } else if (MDOC_BLOCK
== n
->type
) {
632 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
634 bufcat_su(h
, "margin-top", &su
);
635 PAIR_STYLE_INIT(&tag
[1], h
);
636 print_otag(h
, TAG_DIV
, 2, tag
);
638 print_otag(h
, TAG_DIV
, 1, tag
);
642 /* TODO: see note in mdoc_sh_pre() about duplicates. */
645 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
646 html_idcat(buf
, nn
->string
, BUFSIZ
);
648 html_idcat(buf
, " ", BUFSIZ
);
651 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
652 su
.scale
= -su
.scale
;
653 bufcat_su(h
, "margin-left", &su
);
655 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
656 PAIR_STYLE_INIT(&tag
[1], h
);
657 PAIR_ID_INIT(&tag
[2], buf
);
659 print_otag(h
, TAG_DIV
, 3, tag
);
666 mdoc_fl_pre(MDOC_ARGS
)
670 PAIR_CLASS_INIT(&tag
, "flag");
671 print_otag(h
, TAG_SPAN
, 1, &tag
);
673 /* `Cm' has no leading hyphen. */
675 if (MDOC_Cm
== n
->tok
)
678 print_text(h
, "\\-");
681 h
->flags
|= HTML_NOSPACE
;
682 else if (n
->next
&& n
->next
->line
== n
->line
)
683 h
->flags
|= HTML_NOSPACE
;
691 mdoc_nd_pre(MDOC_ARGS
)
695 if (MDOC_BODY
!= n
->type
)
698 /* XXX: this tag in theory can contain block elements. */
700 print_text(h
, "\\(em");
701 PAIR_CLASS_INIT(&tag
, "desc-body");
702 print_otag(h
, TAG_SPAN
, 1, &tag
);
708 mdoc_nm_pre(MDOC_ARGS
)
715 * Accomodate for `Nm' being both an element (which may have
716 * NULL children AND no m->name) and a block.
721 if (MDOC_ELEM
== n
->type
) {
722 if (NULL
== n
->child
&& NULL
== m
->name
)
725 PAIR_CLASS_INIT(&tag
, "name");
726 print_otag(h
, TAG_SPAN
, 1, &tag
);
727 if (NULL
== n
->child
)
728 print_text(h
, m
->name
);
729 } else if (MDOC_BLOCK
== n
->type
) {
732 bufcat_style(h
, "clear", "both");
733 if (n
->head
->child
|| m
->name
) {
734 if (n
->head
->child
&& MDOC_TEXT
==
735 n
->head
->child
->type
)
736 cp
= n
->head
->child
->string
;
737 if (NULL
== cp
|| '\0' == *cp
)
740 SCALE_HS_INIT(&su
, (double)strlen(cp
));
741 bufcat_su(h
, "padding-left", &su
);
744 PAIR_STYLE_INIT(&tag
, h
);
745 print_otag(h
, TAG_DIV
, 1, &tag
);
746 } else if (MDOC_HEAD
== n
->type
) {
747 if (NULL
== n
->child
&& NULL
== m
->name
)
750 if (n
->child
&& MDOC_TEXT
== n
->child
->type
)
751 cp
= n
->child
->string
;
752 if (NULL
== cp
|| '\0' == *cp
)
755 SCALE_HS_INIT(&su
, (double)strlen(cp
));
757 bufcat_style(h
, "float", "left");
758 bufcat_su(h
, "min-width", &su
);
760 bufcat_su(h
, "margin-left", &su
);
762 PAIR_STYLE_INIT(&tag
, h
);
763 print_otag(h
, TAG_DIV
, 1, &tag
);
765 if (NULL
== n
->child
)
766 print_text(h
, m
->name
);
767 } else if (MDOC_BODY
== n
->type
) {
768 SCALE_HS_INIT(&su
, 2);
769 bufcat_su(h
, "margin-left", &su
);
770 PAIR_STYLE_INIT(&tag
, h
);
771 print_otag(h
, TAG_DIV
, 1, &tag
);
780 mdoc_xr_pre(MDOC_ARGS
)
782 struct htmlpair tag
[2];
783 const struct mdoc_node
*nn
;
785 if (NULL
== n
->child
)
788 PAIR_CLASS_INIT(&tag
[0], "link-man");
791 buffmt_man(h
, n
->child
->string
,
793 n
->child
->next
->string
: NULL
);
794 PAIR_HREF_INIT(&tag
[1], h
->buf
);
795 print_otag(h
, TAG_A
, 2, tag
);
797 print_otag(h
, TAG_A
, 1, tag
);
800 print_text(h
, nn
->string
);
802 if (NULL
== (nn
= nn
->next
))
805 h
->flags
|= HTML_NOSPACE
;
807 h
->flags
|= HTML_NOSPACE
;
808 print_text(h
, nn
->string
);
809 h
->flags
|= HTML_NOSPACE
;
817 mdoc_ns_pre(MDOC_ARGS
)
820 h
->flags
|= HTML_NOSPACE
;
827 mdoc_ar_pre(MDOC_ARGS
)
831 PAIR_CLASS_INIT(&tag
, "arg");
832 print_otag(h
, TAG_SPAN
, 1, &tag
);
839 mdoc_xx_pre(MDOC_ARGS
)
867 PAIR_CLASS_INIT(&tag
, "unix");
868 print_otag(h
, TAG_SPAN
, 1, &tag
);
876 mdoc_bx_pre(MDOC_ARGS
)
878 const struct mdoc_node
*nn
;
881 PAIR_CLASS_INIT(&tag
, "unix");
882 print_otag(h
, TAG_SPAN
, 1, &tag
);
884 for (nn
= n
->child
; nn
; nn
= nn
->next
)
885 print_mdoc_node(m
, nn
, h
);
888 h
->flags
|= HTML_NOSPACE
;
890 print_text(h
, "BSD");
897 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
898 struct roffsu
*offs
, struct roffsu
*width
)
901 const struct mdoc_node
*nn
;
904 nn
= n
->parent
->parent
;
906 /* XXX: see notes in mdoc_it_pre(). */
908 if (LIST_column
== type
) {
909 /* Don't width-pad on the left. */
910 SCALE_HS_INIT(width
, 0);
911 /* Also disallow non-compact. */
914 if (LIST_diag
== type
)
915 /* Mandate non-compact with empty prior. */
916 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
919 bufcat_style(h
, "clear", "both");
921 bufcat_su(h
, "margin-left", offs
);
922 if (width
->scale
> 0)
923 bufcat_su(h
, "padding-left", width
);
925 PAIR_STYLE_INIT(&tag
, h
);
927 /* Mandate compact following `Ss' and `Sh' starts. */
929 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
930 if (MDOC_BLOCK
!= nn
->type
)
932 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
939 SCALE_VS_INIT(&su
, 1);
940 bufcat_su(h
, "padding-top", &su
);
943 PAIR_STYLE_INIT(&tag
, h
);
944 print_otag(h
, TAG_DIV
, 1, &tag
);
951 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
962 bufcat_su(h
, "min-width", width
);
963 bufcat_style(h
, "clear", "none");
965 bufcat_style(h
, "float", "left");
966 PAIR_STYLE_INIT(&tag
, h
);
967 print_otag(h
, TAG_DIV
, 1, &tag
);
971 * XXX: this tricks CSS into aligning the bodies with
972 * the right-padding in the head.
974 SCALE_HS_INIT(&su
, 2);
975 bufcat_su(h
, "margin-left", &su
);
976 PAIR_STYLE_INIT(&tag
, h
);
977 print_otag(h
, TAG_DIV
, 1, &tag
);
987 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
997 print_otag(h
, TAG_DIV
, 0, &tag
);
1002 bufcat_su(h
, "min-width", width
);
1003 SCALE_INVERT(width
);
1004 bufcat_su(h
, "margin-left", width
);
1005 if (n
->next
&& n
->next
->child
)
1006 bufcat_style(h
, "float", "left");
1008 /* XXX: buffer if we run into body. */
1009 SCALE_HS_INIT(width
, 1);
1010 bufcat_su(h
, "margin-right", width
);
1011 PAIR_STYLE_INIT(&tag
, h
);
1012 print_otag(h
, TAG_DIV
, 1, &tag
);
1018 PAIR_CLASS_INIT(&tag
, "diag");
1019 print_otag(h
, TAG_SPAN
, 1, &tag
);
1024 nbuf
[BUFSIZ
- 1] = 0;
1025 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1026 print_text(h
, nbuf
);
1029 print_text(h
, "\\(en");
1032 print_text(h
, "\\(hy");
1035 print_text(h
, "\\(bu");
1046 mdoc_it_pre(MDOC_ARGS
)
1049 const struct mdoc_node
*bl
, *nn
;
1050 struct roffsu width
, offs
;
1051 enum mdoc_list type
;
1054 * XXX: be very careful in changing anything, here. Lists in
1055 * mandoc have many peculiarities; furthermore, they don't
1056 * translate well into HTML and require a bit of mangling.
1059 bl
= n
->parent
->parent
;
1060 if (MDOC_BLOCK
!= n
->type
)
1063 SCALE_HS_INIT(&offs
, 0);
1065 assert(bl
->data
.Bl
);
1066 type
= bl
->data
.Bl
->type
;
1067 comp
= bl
->data
.Bl
->comp
;
1069 if (bl
->data
.Bl
->offs
)
1070 a2offs(bl
->data
.Bl
->offs
, &offs
);
1080 SCALE_HS_INIT(&width
, 2);
1083 SCALE_HS_INIT(&width
, INDENT
);
1087 if (bl
->data
.Bl
->width
)
1088 a2width(bl
->data
.Bl
->width
, &width
);
1090 /* Override width in some cases. */
1100 SCALE_HS_INIT(&width
, 0);
1103 if (0 == width
.scale
)
1104 SCALE_HS_INIT(&width
, INDENT
);
1108 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1109 nn
= n
->parent
->child
;
1110 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1111 if (MDOC_BODY
== nn
->type
)
1113 if (i
< (int)bl
->data
.Bl
->ncols
)
1114 a2width(bl
->data
.Bl
->cols
[i
], &width
);
1117 if (MDOC_HEAD
== n
->type
)
1118 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1119 else if (MDOC_BODY
== n
->type
)
1120 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1122 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1128 mdoc_bl_pre(MDOC_ARGS
)
1132 if (MDOC_HEAD
== n
->type
)
1134 if (MDOC_BLOCK
!= n
->type
)
1137 if (LIST_enum
!= n
->data
.Bl
->type
)
1140 ord
= malloc(sizeof(struct ord
));
1143 exit((int)MANDOCLEVEL_SYSERR
);
1147 ord
->next
= h
->ords
.head
;
1155 mdoc_bl_post(MDOC_ARGS
)
1159 if (MDOC_BLOCK
!= n
->type
)
1161 if (LIST_enum
!= n
->data
.Bl
->type
)
1166 h
->ords
.head
= ord
->next
;
1173 mdoc_ex_pre(MDOC_ARGS
)
1175 const struct mdoc_node
*nn
;
1177 struct htmlpair tag
;
1179 PAIR_CLASS_INIT(&tag
, "utility");
1181 print_text(h
, "The");
1182 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1183 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1184 print_text(h
, nn
->string
);
1187 h
->flags
|= HTML_NOSPACE
;
1189 if (nn
->next
&& NULL
== nn
->next
->next
)
1190 print_text(h
, ", and");
1194 h
->flags
&= ~HTML_NOSPACE
;
1197 if (n
->child
&& n
->child
->next
)
1198 print_text(h
, "utilities exit");
1200 print_text(h
, "utility exits");
1202 print_text(h
, "0 on success, and >0 if an error occurs.");
1209 mdoc_em_pre(MDOC_ARGS
)
1211 struct htmlpair tag
;
1213 PAIR_CLASS_INIT(&tag
, "emph");
1214 print_otag(h
, TAG_SPAN
, 1, &tag
);
1221 mdoc_d1_pre(MDOC_ARGS
)
1223 struct htmlpair tag
[2];
1226 if (MDOC_BLOCK
!= n
->type
)
1229 /* FIXME: D1 shouldn't be literal. */
1231 SCALE_VS_INIT(&su
, INDENT
- 2);
1232 bufcat_su(h
, "margin-left", &su
);
1233 PAIR_CLASS_INIT(&tag
[0], "lit");
1234 PAIR_STYLE_INIT(&tag
[1], h
);
1235 print_otag(h
, TAG_DIV
, 2, tag
);
1242 mdoc_sx_pre(MDOC_ARGS
)
1244 struct htmlpair tag
[2];
1245 const struct mdoc_node
*nn
;
1248 strlcpy(buf
, "#", BUFSIZ
);
1249 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1250 html_idcat(buf
, nn
->string
, BUFSIZ
);
1252 html_idcat(buf
, " ", BUFSIZ
);
1255 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1256 PAIR_HREF_INIT(&tag
[1], buf
);
1258 print_otag(h
, TAG_A
, 2, tag
);
1265 mdoc_bd_pre(MDOC_ARGS
)
1267 struct htmlpair tag
[2];
1269 const struct mdoc_node
*nn
;
1272 if (MDOC_HEAD
== n
->type
)
1275 SCALE_VS_INIT(&su
, 0);
1278 if (n
->data
.Bd
->offs
)
1279 a2offs(n
->data
.Bd
->offs
, &su
);
1281 comp
= n
->data
.Bd
->comp
;
1283 /* FIXME: -centered, etc. formatting. */
1284 /* FIXME: does not respect -offset ??? */
1286 if (MDOC_BLOCK
== n
->type
) {
1287 bufcat_su(h
, "margin-left", &su
);
1288 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1289 if (MDOC_BLOCK
!= nn
->type
)
1291 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1297 PAIR_STYLE_INIT(&tag
[0], h
);
1298 print_otag(h
, TAG_DIV
, 1, tag
);
1301 SCALE_VS_INIT(&su
, 1);
1302 bufcat_su(h
, "margin-top", &su
);
1303 PAIR_STYLE_INIT(&tag
[0], h
);
1304 print_otag(h
, TAG_DIV
, 1, tag
);
1308 if (DISP_unfilled
!= n
->data
.Bd
->type
&&
1309 DISP_literal
!= n
->data
.Bd
->type
)
1312 PAIR_CLASS_INIT(&tag
[0], "lit");
1313 bufcat_style(h
, "white-space", "pre");
1314 PAIR_STYLE_INIT(&tag
[1], h
);
1315 print_otag(h
, TAG_DIV
, 2, tag
);
1317 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1318 print_mdoc_node(m
, nn
, h
);
1320 * If the printed node flushes its own line, then we
1321 * needn't do it here as well. This is hacky, but the
1322 * notion of selective eoln whitespace is pretty dumb
1323 * anyway, so don't sweat it.
1341 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1343 print_text(h
, "\n");
1344 h
->flags
|= HTML_NOSPACE
;
1353 mdoc_pa_pre(MDOC_ARGS
)
1355 struct htmlpair tag
;
1357 PAIR_CLASS_INIT(&tag
, "file");
1358 print_otag(h
, TAG_SPAN
, 1, &tag
);
1365 mdoc_ad_pre(MDOC_ARGS
)
1367 struct htmlpair tag
;
1369 PAIR_CLASS_INIT(&tag
, "addr");
1370 print_otag(h
, TAG_SPAN
, 1, &tag
);
1377 mdoc_an_pre(MDOC_ARGS
)
1379 struct htmlpair tag
;
1381 /* TODO: -split and -nosplit (see termp_an_pre()). */
1383 PAIR_CLASS_INIT(&tag
, "author");
1384 print_otag(h
, TAG_SPAN
, 1, &tag
);
1391 mdoc_cd_pre(MDOC_ARGS
)
1393 struct htmlpair tag
;
1396 PAIR_CLASS_INIT(&tag
, "config");
1397 print_otag(h
, TAG_SPAN
, 1, &tag
);
1404 mdoc_dv_pre(MDOC_ARGS
)
1406 struct htmlpair tag
;
1408 PAIR_CLASS_INIT(&tag
, "define");
1409 print_otag(h
, TAG_SPAN
, 1, &tag
);
1416 mdoc_ev_pre(MDOC_ARGS
)
1418 struct htmlpair tag
;
1420 PAIR_CLASS_INIT(&tag
, "env");
1421 print_otag(h
, TAG_SPAN
, 1, &tag
);
1428 mdoc_er_pre(MDOC_ARGS
)
1430 struct htmlpair tag
;
1432 PAIR_CLASS_INIT(&tag
, "errno");
1433 print_otag(h
, TAG_SPAN
, 1, &tag
);
1440 mdoc_fa_pre(MDOC_ARGS
)
1442 const struct mdoc_node
*nn
;
1443 struct htmlpair tag
;
1446 PAIR_CLASS_INIT(&tag
, "farg");
1447 if (n
->parent
->tok
!= MDOC_Fo
) {
1448 print_otag(h
, TAG_SPAN
, 1, &tag
);
1452 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1453 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1454 print_text(h
, nn
->string
);
1460 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1469 mdoc_fd_pre(MDOC_ARGS
)
1471 struct htmlpair tag
;
1475 PAIR_CLASS_INIT(&tag
, "macro");
1476 print_otag(h
, TAG_SPAN
, 1, &tag
);
1483 mdoc_vt_pre(MDOC_ARGS
)
1485 struct htmlpair tag
;
1487 if (MDOC_BLOCK
== n
->type
) {
1490 } else if (MDOC_ELEM
== n
->type
) {
1492 } else if (MDOC_HEAD
== n
->type
)
1495 PAIR_CLASS_INIT(&tag
, "type");
1496 print_otag(h
, TAG_SPAN
, 1, &tag
);
1503 mdoc_ft_pre(MDOC_ARGS
)
1505 struct htmlpair tag
;
1508 PAIR_CLASS_INIT(&tag
, "ftype");
1509 print_otag(h
, TAG_SPAN
, 1, &tag
);
1516 mdoc_fn_pre(MDOC_ARGS
)
1519 struct htmlpair tag
[2];
1520 const struct mdoc_node
*nn
;
1522 const char *sp
, *ep
;
1527 /* Split apart into type and name. */
1528 assert(n
->child
->string
);
1529 sp
= n
->child
->string
;
1531 ep
= strchr(sp
, ' ');
1533 PAIR_CLASS_INIT(&tag
[0], "ftype");
1534 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1537 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1538 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1540 print_text(h
, nbuf
);
1542 ep
= strchr(sp
, ' ');
1547 PAIR_CLASS_INIT(&tag
[0], "fname");
1550 * FIXME: only refer to IDs that we know exist.
1554 if (MDOC_SYNPRETTY
& n
->flags
) {
1556 html_idcat(nbuf
, sp
, BUFSIZ
);
1557 PAIR_ID_INIT(&tag
[1], nbuf
);
1559 strlcpy(nbuf
, "#", BUFSIZ
);
1560 html_idcat(nbuf
, sp
, BUFSIZ
);
1561 PAIR_HREF_INIT(&tag
[1], nbuf
);
1565 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1568 strlcpy(nbuf
, sp
, BUFSIZ
);
1569 print_text(h
, nbuf
);
1574 h
->flags
|= HTML_NOSPACE
;
1578 PAIR_CLASS_INIT(&tag
[0], "farg");
1579 bufcat_style(h
, "white-space", "nowrap");
1580 PAIR_STYLE_INIT(&tag
[1], h
);
1582 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1584 if (MDOC_SYNPRETTY
& n
->flags
)
1586 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1587 print_text(h
, nn
->string
);
1594 if (MDOC_SYNPRETTY
& n
->flags
)
1603 mdoc_sm_pre(MDOC_ARGS
)
1606 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1607 if (0 == strcmp("on", n
->child
->string
)) {
1609 * FIXME: no p->col to check. Thus, if we have
1616 * the "3" is preceded by a space.
1618 h
->flags
&= ~HTML_NOSPACE
;
1619 h
->flags
&= ~HTML_NONOSPACE
;
1621 h
->flags
|= HTML_NONOSPACE
;
1629 mdoc_sp_pre(MDOC_ARGS
)
1632 struct htmlpair tag
;
1637 /* FIXME: can this have a scaling indicator? */
1638 len
= n
->child
? atoi(n
->child
->string
) : 1;
1645 if ((NULL
== n
->next
|| NULL
== n
->prev
) &&
1646 (MDOC_Ss
== n
->parent
->tok
||
1647 MDOC_Sh
== n
->parent
->tok
))
1653 SCALE_VS_INIT(&su
, len
);
1654 bufcat_su(h
, "height", &su
);
1655 PAIR_STYLE_INIT(&tag
, h
);
1656 print_otag(h
, TAG_DIV
, 1, &tag
);
1657 /* So the div isn't empty: */
1658 print_text(h
, "\\~");
1667 mdoc_lk_pre(MDOC_ARGS
)
1669 const struct mdoc_node
*nn
;
1670 struct htmlpair tag
[2];
1674 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1675 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1676 print_otag(h
, TAG_A
, 2, tag
);
1678 if (NULL
== nn
->next
)
1681 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1682 print_text(h
, nn
->string
);
1690 mdoc_mt_pre(MDOC_ARGS
)
1692 struct htmlpair tag
[2];
1694 const struct mdoc_node
*nn
;
1696 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1698 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1700 bufcat(h
, "mailto:");
1701 bufcat(h
, nn
->string
);
1702 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1703 t
= print_otag(h
, TAG_A
, 2, tag
);
1704 print_text(h
, nn
->string
);
1714 mdoc_fo_pre(MDOC_ARGS
)
1716 struct htmlpair tag
;
1719 if (MDOC_BODY
== n
->type
) {
1720 h
->flags
|= HTML_NOSPACE
;
1722 h
->flags
|= HTML_NOSPACE
;
1724 } else if (MDOC_BLOCK
== n
->type
) {
1729 /* XXX: we drop non-initial arguments as per groff. */
1732 assert(n
->child
->string
);
1734 PAIR_CLASS_INIT(&tag
, "fname");
1735 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1736 print_text(h
, n
->child
->string
);
1744 mdoc_fo_post(MDOC_ARGS
)
1747 if (MDOC_BODY
!= n
->type
)
1756 mdoc_in_pre(MDOC_ARGS
)
1758 const struct mdoc_node
*nn
;
1760 struct htmlpair tag
[2];
1765 PAIR_CLASS_INIT(&tag
[0], "includes");
1766 print_otag(h
, TAG_SPAN
, 1, tag
);
1768 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1769 print_text(h
, "#include");
1772 h
->flags
|= HTML_NOSPACE
;
1774 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1775 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1778 if (h
->base_includes
) {
1779 buffmt_includes(h
, nn
->string
);
1780 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1783 t
= print_otag(h
, TAG_A
, i
, tag
);
1784 print_mdoc_node(m
, nn
, h
);
1788 h
->flags
|= HTML_NOSPACE
;
1797 mdoc_ic_pre(MDOC_ARGS
)
1799 struct htmlpair tag
;
1801 PAIR_CLASS_INIT(&tag
, "cmd");
1802 print_otag(h
, TAG_SPAN
, 1, &tag
);
1809 mdoc_rv_pre(MDOC_ARGS
)
1811 const struct mdoc_node
*nn
;
1812 struct htmlpair tag
;
1815 print_otag(h
, TAG_DIV
, 0, NULL
);
1816 print_text(h
, "The");
1818 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1819 PAIR_CLASS_INIT(&tag
, "fname");
1820 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1821 print_text(h
, nn
->string
);
1824 h
->flags
|= HTML_NOSPACE
;
1825 if (nn
->next
&& NULL
== nn
->next
->next
)
1826 print_text(h
, "(), and");
1828 print_text(h
, "(),");
1830 print_text(h
, "()");
1833 if (n
->child
&& n
->child
->next
)
1834 print_text(h
, "functions return");
1836 print_text(h
, "function returns");
1838 print_text(h
, "the value 0 if successful; otherwise the value "
1839 "-1 is returned and the global variable");
1841 PAIR_CLASS_INIT(&tag
, "var");
1842 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1843 print_text(h
, "errno");
1845 print_text(h
, "is set to indicate the error.");
1852 mdoc_va_pre(MDOC_ARGS
)
1854 struct htmlpair tag
;
1856 PAIR_CLASS_INIT(&tag
, "var");
1857 print_otag(h
, TAG_SPAN
, 1, &tag
);
1864 mdoc_ap_pre(MDOC_ARGS
)
1867 h
->flags
|= HTML_NOSPACE
;
1868 print_text(h
, "\\(aq");
1869 h
->flags
|= HTML_NOSPACE
;
1876 mdoc_bf_pre(MDOC_ARGS
)
1878 struct htmlpair tag
[2];
1881 if (MDOC_HEAD
== n
->type
)
1883 else if (MDOC_BODY
!= n
->type
)
1888 if (FONT_Em
== n
->data
.Bf
->font
)
1889 PAIR_CLASS_INIT(&tag
[0], "emph");
1890 else if (FONT_Sy
== n
->data
.Bf
->font
)
1891 PAIR_CLASS_INIT(&tag
[0], "symb");
1892 else if (FONT_Li
== n
->data
.Bf
->font
)
1893 PAIR_CLASS_INIT(&tag
[0], "lit");
1895 PAIR_CLASS_INIT(&tag
[0], "none");
1898 * We want this to be inline-formatted, but needs to be div to
1899 * accept block children.
1901 bufcat_style(h
, "display", "inline");
1902 SCALE_HS_INIT(&su
, 1);
1903 /* Needs a left-margin for spacing. */
1904 bufcat_su(h
, "margin-left", &su
);
1905 PAIR_STYLE_INIT(&tag
[1], h
);
1906 print_otag(h
, TAG_DIV
, 2, tag
);
1913 mdoc_ms_pre(MDOC_ARGS
)
1915 struct htmlpair tag
;
1917 PAIR_CLASS_INIT(&tag
, "symb");
1918 print_otag(h
, TAG_SPAN
, 1, &tag
);
1925 mdoc_igndelim_pre(MDOC_ARGS
)
1928 h
->flags
|= HTML_IGNDELIM
;
1935 mdoc_pf_post(MDOC_ARGS
)
1938 h
->flags
|= HTML_NOSPACE
;
1944 mdoc_rs_pre(MDOC_ARGS
)
1946 struct htmlpair tag
;
1948 if (MDOC_BLOCK
!= n
->type
)
1951 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
1952 print_otag(h
, TAG_BR
, 0, NULL
);
1953 print_otag(h
, TAG_BR
, 0, NULL
);
1956 PAIR_CLASS_INIT(&tag
, "ref");
1957 print_otag(h
, TAG_SPAN
, 1, &tag
);
1965 mdoc_li_pre(MDOC_ARGS
)
1967 struct htmlpair tag
;
1969 PAIR_CLASS_INIT(&tag
, "lit");
1970 print_otag(h
, TAG_SPAN
, 1, &tag
);
1977 mdoc_sy_pre(MDOC_ARGS
)
1979 struct htmlpair tag
;
1981 PAIR_CLASS_INIT(&tag
, "symb");
1982 print_otag(h
, TAG_SPAN
, 1, &tag
);
1989 mdoc_bt_pre(MDOC_ARGS
)
1992 print_text(h
, "is currently in beta test.");
1999 mdoc_ud_pre(MDOC_ARGS
)
2002 print_text(h
, "currently under development.");
2009 mdoc_lb_pre(MDOC_ARGS
)
2011 struct htmlpair tag
;
2013 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2014 print_otag(h
, TAG_DIV
, 0, NULL
);
2015 PAIR_CLASS_INIT(&tag
, "lib");
2016 print_otag(h
, TAG_SPAN
, 1, &tag
);
2023 mdoc__x_pre(MDOC_ARGS
)
2025 struct htmlpair tag
[2];
2029 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2030 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2031 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2032 print_text(h
, "and");
2035 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2038 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2041 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2044 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2047 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2050 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2053 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2056 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2059 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2062 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2065 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2068 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2071 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2078 if (MDOC__U
!= n
->tok
) {
2079 print_otag(h
, TAG_SPAN
, 1, tag
);
2083 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2084 print_otag(h
, TAG_A
, 2, tag
);
2092 mdoc__x_post(MDOC_ARGS
)
2095 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2096 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2097 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2102 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2105 print_text(h
, n
->next
? "," : ".");
2111 mdoc_bk_pre(MDOC_ARGS
)
2120 h
->flags
|= HTML_PREKEEP
;
2133 mdoc_bk_post(MDOC_ARGS
)
2136 if (MDOC_BODY
== n
->type
)
2137 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2143 mdoc_quote_pre(MDOC_ARGS
)
2145 struct htmlpair tag
;
2147 if (MDOC_BODY
!= n
->type
)
2154 print_text(h
, "\\(la");
2159 print_text(h
, "\\(lC");
2164 print_text(h
, "\\(lB");
2169 print_text(h
, "\\(lB");
2170 h
->flags
|= HTML_NOSPACE
;
2171 PAIR_CLASS_INIT(&tag
, "opt");
2172 print_otag(h
, TAG_SPAN
, 1, &tag
);
2181 print_text(h
, "\\(lq");
2193 print_text(h
, "\\(oq");
2200 h
->flags
|= HTML_NOSPACE
;
2207 mdoc_quote_post(MDOC_ARGS
)
2210 if (MDOC_BODY
!= n
->type
)
2213 h
->flags
|= HTML_NOSPACE
;
2219 print_text(h
, "\\(ra");
2224 print_text(h
, "\\(rC");
2233 print_text(h
, "\\(rB");
2242 print_text(h
, "\\(rq");
2254 print_text(h
, "\\(aq");