]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.93 2010/07/04 21:59:30 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 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>
40 #define MDOC_ARGS const struct mdoc_meta *m, \
41 const struct mdoc_node *n, \
45 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
49 int (*pre
)(MDOC_ARGS
);
50 void (*post
)(MDOC_ARGS
);
53 static void print_mdoc(MDOC_ARGS
);
54 static void print_mdoc_head(MDOC_ARGS
);
55 static void print_mdoc_node(MDOC_ARGS
);
56 static void print_mdoc_nodelist(MDOC_ARGS
);
57 static void synopsis_pre(struct html
*,
58 const struct mdoc_node
*);
60 static void a2width(const char *, struct roffsu
*);
61 static void a2offs(const char *, struct roffsu
*);
63 static void mdoc_root_post(MDOC_ARGS
);
64 static int mdoc_root_pre(MDOC_ARGS
);
66 static void mdoc__x_post(MDOC_ARGS
);
67 static int mdoc__x_pre(MDOC_ARGS
);
68 static int mdoc_ad_pre(MDOC_ARGS
);
69 static int mdoc_an_pre(MDOC_ARGS
);
70 static int mdoc_ap_pre(MDOC_ARGS
);
71 static void mdoc_aq_post(MDOC_ARGS
);
72 static int mdoc_aq_pre(MDOC_ARGS
);
73 static int mdoc_ar_pre(MDOC_ARGS
);
74 static int mdoc_bd_pre(MDOC_ARGS
);
75 static int mdoc_bf_pre(MDOC_ARGS
);
76 static void mdoc_bl_post(MDOC_ARGS
);
77 static int mdoc_bl_pre(MDOC_ARGS
);
78 static void mdoc_bq_post(MDOC_ARGS
);
79 static int mdoc_bq_pre(MDOC_ARGS
);
80 static void mdoc_brq_post(MDOC_ARGS
);
81 static int mdoc_brq_pre(MDOC_ARGS
);
82 static int mdoc_bt_pre(MDOC_ARGS
);
83 static int mdoc_bx_pre(MDOC_ARGS
);
84 static int mdoc_cd_pre(MDOC_ARGS
);
85 static int mdoc_d1_pre(MDOC_ARGS
);
86 static void mdoc_dq_post(MDOC_ARGS
);
87 static int mdoc_dq_pre(MDOC_ARGS
);
88 static int mdoc_dv_pre(MDOC_ARGS
);
89 static int mdoc_fa_pre(MDOC_ARGS
);
90 static int mdoc_fd_pre(MDOC_ARGS
);
91 static int mdoc_fl_pre(MDOC_ARGS
);
92 static int mdoc_fn_pre(MDOC_ARGS
);
93 static int mdoc_ft_pre(MDOC_ARGS
);
94 static int mdoc_em_pre(MDOC_ARGS
);
95 static int mdoc_er_pre(MDOC_ARGS
);
96 static int mdoc_ev_pre(MDOC_ARGS
);
97 static int mdoc_ex_pre(MDOC_ARGS
);
98 static void mdoc_fo_post(MDOC_ARGS
);
99 static int mdoc_fo_pre(MDOC_ARGS
);
100 static int mdoc_ic_pre(MDOC_ARGS
);
101 static int mdoc_in_pre(MDOC_ARGS
);
102 static int mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list
,
103 int, struct roffsu
*, struct roffsu
*);
104 static int mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list
,
106 static int mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list
,
108 static int mdoc_it_pre(MDOC_ARGS
);
109 static int mdoc_lb_pre(MDOC_ARGS
);
110 static int mdoc_li_pre(MDOC_ARGS
);
111 static int mdoc_lk_pre(MDOC_ARGS
);
112 static int mdoc_mt_pre(MDOC_ARGS
);
113 static int mdoc_ms_pre(MDOC_ARGS
);
114 static int mdoc_nd_pre(MDOC_ARGS
);
115 static int mdoc_nm_pre(MDOC_ARGS
);
116 static int mdoc_ns_pre(MDOC_ARGS
);
117 static void mdoc_op_post(MDOC_ARGS
);
118 static int mdoc_op_pre(MDOC_ARGS
);
119 static int mdoc_pa_pre(MDOC_ARGS
);
120 static void mdoc_pf_post(MDOC_ARGS
);
121 static int mdoc_pf_pre(MDOC_ARGS
);
122 static void mdoc_pq_post(MDOC_ARGS
);
123 static int mdoc_pq_pre(MDOC_ARGS
);
124 static int mdoc_rs_pre(MDOC_ARGS
);
125 static int mdoc_rv_pre(MDOC_ARGS
);
126 static int mdoc_sh_pre(MDOC_ARGS
);
127 static int mdoc_sp_pre(MDOC_ARGS
);
128 static void mdoc_sq_post(MDOC_ARGS
);
129 static int mdoc_sq_pre(MDOC_ARGS
);
130 static int mdoc_ss_pre(MDOC_ARGS
);
131 static int mdoc_sx_pre(MDOC_ARGS
);
132 static int mdoc_sy_pre(MDOC_ARGS
);
133 static int mdoc_ud_pre(MDOC_ARGS
);
134 static int mdoc_va_pre(MDOC_ARGS
);
135 static int mdoc_vt_pre(MDOC_ARGS
);
136 static int mdoc_xr_pre(MDOC_ARGS
);
137 static int mdoc_xx_pre(MDOC_ARGS
);
139 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
140 {mdoc_ap_pre
, NULL
}, /* Ap */
141 {NULL
, NULL
}, /* Dd */
142 {NULL
, NULL
}, /* Dt */
143 {NULL
, NULL
}, /* Os */
144 {mdoc_sh_pre
, NULL
}, /* Sh */
145 {mdoc_ss_pre
, NULL
}, /* Ss */
146 {mdoc_sp_pre
, NULL
}, /* Pp */
147 {mdoc_d1_pre
, NULL
}, /* D1 */
148 {mdoc_d1_pre
, NULL
}, /* Dl */
149 {mdoc_bd_pre
, NULL
}, /* Bd */
150 {NULL
, NULL
}, /* Ed */
151 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
152 {NULL
, NULL
}, /* El */
153 {mdoc_it_pre
, NULL
}, /* It */
154 {mdoc_ad_pre
, NULL
}, /* Ad */
155 {mdoc_an_pre
, NULL
}, /* An */
156 {mdoc_ar_pre
, NULL
}, /* Ar */
157 {mdoc_cd_pre
, NULL
}, /* Cd */
158 {mdoc_fl_pre
, NULL
}, /* Cm */
159 {mdoc_dv_pre
, NULL
}, /* Dv */
160 {mdoc_er_pre
, NULL
}, /* Er */
161 {mdoc_ev_pre
, NULL
}, /* Ev */
162 {mdoc_ex_pre
, NULL
}, /* Ex */
163 {mdoc_fa_pre
, NULL
}, /* Fa */
164 {mdoc_fd_pre
, NULL
}, /* Fd */
165 {mdoc_fl_pre
, NULL
}, /* Fl */
166 {mdoc_fn_pre
, NULL
}, /* Fn */
167 {mdoc_ft_pre
, NULL
}, /* Ft */
168 {mdoc_ic_pre
, NULL
}, /* Ic */
169 {mdoc_in_pre
, NULL
}, /* In */
170 {mdoc_li_pre
, NULL
}, /* Li */
171 {mdoc_nd_pre
, NULL
}, /* Nd */
172 {mdoc_nm_pre
, NULL
}, /* Nm */
173 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
174 {NULL
, NULL
}, /* Ot */
175 {mdoc_pa_pre
, NULL
}, /* Pa */
176 {mdoc_rv_pre
, NULL
}, /* Rv */
177 {NULL
, NULL
}, /* St */
178 {mdoc_va_pre
, NULL
}, /* Va */
179 {mdoc_vt_pre
, NULL
}, /* Vt */
180 {mdoc_xr_pre
, NULL
}, /* Xr */
181 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
182 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
183 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
184 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
185 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
186 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
187 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
188 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
189 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
190 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
191 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
192 {NULL
, NULL
}, /* Ac */
193 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
194 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
195 {NULL
, NULL
}, /* At */
196 {NULL
, NULL
}, /* Bc */
197 {mdoc_bf_pre
, NULL
}, /* Bf */
198 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bo */
199 {mdoc_bq_pre
, mdoc_bq_post
}, /* Bq */
200 {mdoc_xx_pre
, NULL
}, /* Bsx */
201 {mdoc_bx_pre
, NULL
}, /* Bx */
202 {NULL
, NULL
}, /* Db */
203 {NULL
, NULL
}, /* Dc */
204 {mdoc_dq_pre
, mdoc_dq_post
}, /* Do */
205 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
206 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
207 {NULL
, NULL
}, /* Ef */
208 {mdoc_em_pre
, NULL
}, /* Em */
209 {NULL
, NULL
}, /* Eo */
210 {mdoc_xx_pre
, NULL
}, /* Fx */
211 {mdoc_ms_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
212 {NULL
, NULL
}, /* No */
213 {mdoc_ns_pre
, NULL
}, /* Ns */
214 {mdoc_xx_pre
, NULL
}, /* Nx */
215 {mdoc_xx_pre
, NULL
}, /* Ox */
216 {NULL
, NULL
}, /* Pc */
217 {mdoc_pf_pre
, mdoc_pf_post
}, /* Pf */
218 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
219 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
220 {NULL
, NULL
}, /* Qc */
221 {mdoc_sq_pre
, mdoc_sq_post
}, /* Ql */
222 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qo */
223 {mdoc_dq_pre
, mdoc_dq_post
}, /* Qq */
224 {NULL
, NULL
}, /* Re */
225 {mdoc_rs_pre
, NULL
}, /* Rs */
226 {NULL
, NULL
}, /* Sc */
227 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
228 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
229 {NULL
, NULL
}, /* Sm */ /* FIXME - no idea. */
230 {mdoc_sx_pre
, NULL
}, /* Sx */
231 {mdoc_sy_pre
, NULL
}, /* Sy */
232 {NULL
, NULL
}, /* Tn */
233 {mdoc_xx_pre
, NULL
}, /* Ux */
234 {NULL
, NULL
}, /* Xc */
235 {NULL
, NULL
}, /* Xo */
236 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
237 {NULL
, NULL
}, /* Fc */
238 {mdoc_op_pre
, mdoc_op_post
}, /* Oo */
239 {NULL
, NULL
}, /* Oc */
240 {NULL
, NULL
}, /* Bk */
241 {NULL
, NULL
}, /* Ek */
242 {mdoc_bt_pre
, NULL
}, /* Bt */
243 {NULL
, NULL
}, /* Hf */
244 {NULL
, NULL
}, /* Fr */
245 {mdoc_ud_pre
, NULL
}, /* Ud */
246 {mdoc_lb_pre
, NULL
}, /* Lb */
247 {mdoc_sp_pre
, NULL
}, /* Lp */
248 {mdoc_lk_pre
, NULL
}, /* Lk */
249 {mdoc_mt_pre
, NULL
}, /* Mt */
250 {mdoc_brq_pre
, mdoc_brq_post
}, /* Brq */
251 {mdoc_brq_pre
, mdoc_brq_post
}, /* Bro */
252 {NULL
, NULL
}, /* Brc */
253 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
254 {NULL
, NULL
}, /* Es */ /* TODO */
255 {NULL
, NULL
}, /* En */ /* TODO */
256 {mdoc_xx_pre
, NULL
}, /* Dx */
257 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
258 {mdoc_sp_pre
, NULL
}, /* br */
259 {mdoc_sp_pre
, NULL
}, /* sp */
260 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
261 {NULL
, NULL
}, /* Ta */
266 html_mdoc(void *arg
, const struct mdoc
*m
)
271 h
= (struct html
*)arg
;
274 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
275 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
283 * Calculate the scaling unit passed in a `-width' argument. This uses
284 * either a native scaling unit (e.g., 1i, 2m) or the string length of
288 a2width(const char *p
, struct roffsu
*su
)
291 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
293 su
->scale
= (int)strlen(p
);
299 * See the same function in mdoc_term.c for documentation.
302 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
307 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
310 SCALE_VS_INIT(&su
, 1);
311 bufcat_su(h
, "margin-top", &su
);
312 PAIR_STYLE_INIT(&tag
, h
);
314 if (n
->prev
->tok
== n
->tok
&&
318 print_otag(h
, TAG_DIV
, 0, NULL
);
322 switch (n
->prev
->tok
) {
332 print_otag(h
, TAG_DIV
, 1, &tag
);
335 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
336 print_otag(h
, TAG_DIV
, 1, &tag
);
341 print_otag(h
, TAG_DIV
, 0, NULL
);
348 * Calculate the scaling unit passed in an `-offset' argument. This
349 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
350 * predefined strings (indent, etc.), or the string length of the value.
353 a2offs(const char *p
, struct roffsu
*su
)
356 /* FIXME: "right"? */
358 if (0 == strcmp(p
, "left"))
359 SCALE_HS_INIT(su
, 0);
360 else if (0 == strcmp(p
, "indent"))
361 SCALE_HS_INIT(su
, INDENT
);
362 else if (0 == strcmp(p
, "indent-two"))
363 SCALE_HS_INIT(su
, INDENT
* 2);
364 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
366 su
->scale
= (int)strlen(p
);
372 print_mdoc(MDOC_ARGS
)
377 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
378 print_mdoc_head(m
, n
, h
);
381 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
383 tag
.key
= ATTR_CLASS
;
385 print_otag(h
, TAG_DIV
, 1, &tag
);
387 print_mdoc_nodelist(m
, n
, h
);
394 print_mdoc_head(MDOC_ARGS
)
399 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
407 print_otag(h
, TAG_TITLE
, 0, NULL
);
408 print_text(h
, h
->buf
);
413 print_mdoc_nodelist(MDOC_ARGS
)
416 print_mdoc_node(m
, n
, h
);
418 print_mdoc_nodelist(m
, n
->next
, h
);
423 print_mdoc_node(MDOC_ARGS
)
434 child
= mdoc_root_pre(m
, n
, h
);
437 print_text(h
, n
->string
);
440 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
441 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
445 if (child
&& n
->child
)
446 print_mdoc_nodelist(m
, n
->child
, h
);
453 mdoc_root_post(m
, n
, h
);
456 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
457 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
465 mdoc_root_post(MDOC_ARGS
)
467 struct htmlpair tag
[3];
471 time2a(m
->date
, b
, DATESIZ
);
474 * XXX: this should use divs, but in Firefox, divs with nested
475 * divs for some reason puke when trying to put a border line
476 * below. So I use tables, instead.
479 PAIR_CLASS_INIT(&tag
[0], "footer");
480 bufcat_style(h
, "width", "100%");
481 PAIR_STYLE_INIT(&tag
[1], h
);
482 PAIR_SUMMARY_INIT(&tag
[2], "footer");
484 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
485 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
488 bufcat_style(h
, "width", "50%");
489 PAIR_STYLE_INIT(&tag
[0], h
);
490 print_otag(h
, TAG_TD
, 1, tag
);
495 bufcat_style(h
, "width", "50%");
496 bufcat_style(h
, "text-align", "right");
497 PAIR_STYLE_INIT(&tag
[0], h
);
498 print_otag(h
, TAG_TD
, 1, tag
);
499 print_text(h
, m
->os
);
506 mdoc_root_pre(MDOC_ARGS
)
508 struct htmlpair tag
[3];
510 char b
[BUFSIZ
], title
[BUFSIZ
];
512 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
515 (void)strlcat(b
, " (", BUFSIZ
);
516 (void)strlcat(b
, m
->arch
, BUFSIZ
);
517 (void)strlcat(b
, ")", BUFSIZ
);
520 (void)snprintf(title
, BUFSIZ
- 1,
521 "%s(%s)", m
->title
, m
->msec
);
523 /* XXX: see note in mdoc_root_post() about divs. */
525 PAIR_CLASS_INIT(&tag
[0], "header");
526 bufcat_style(h
, "width", "100%");
527 PAIR_STYLE_INIT(&tag
[1], h
);
528 PAIR_SUMMARY_INIT(&tag
[2], "header");
530 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
532 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
535 bufcat_style(h
, "width", "10%");
536 PAIR_STYLE_INIT(&tag
[0], h
);
537 print_otag(h
, TAG_TD
, 1, tag
);
538 print_text(h
, title
);
542 bufcat_style(h
, "text-align", "center");
543 bufcat_style(h
, "white-space", "nowrap");
544 bufcat_style(h
, "width", "80%");
545 PAIR_STYLE_INIT(&tag
[0], h
);
546 print_otag(h
, TAG_TD
, 1, tag
);
551 bufcat_style(h
, "text-align", "right");
552 bufcat_style(h
, "width", "10%");
553 PAIR_STYLE_INIT(&tag
[0], h
);
554 print_otag(h
, TAG_TD
, 1, tag
);
555 print_text(h
, title
);
563 mdoc_sh_pre(MDOC_ARGS
)
565 struct htmlpair tag
[2];
566 const struct mdoc_node
*nn
;
570 if (MDOC_BODY
== n
->type
) {
571 SCALE_HS_INIT(&su
, INDENT
);
572 bufcat_su(h
, "margin-left", &su
);
573 PAIR_CLASS_INIT(&tag
[0], "sec-body");
574 PAIR_STYLE_INIT(&tag
[1], h
);
575 print_otag(h
, TAG_DIV
, 2, tag
);
577 } else if (MDOC_BLOCK
== n
->type
) {
578 PAIR_CLASS_INIT(&tag
[0], "sec-block");
579 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
580 print_otag(h
, TAG_DIV
, 1, tag
);
584 SCALE_VS_INIT(&su
, 1);
585 bufcat_su(h
, "margin-top", &su
);
587 bufcat_su(h
, "margin-bottom", &su
);
589 PAIR_STYLE_INIT(&tag
[1], h
);
590 print_otag(h
, TAG_DIV
, 2, tag
);
595 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
596 html_idcat(buf
, nn
->string
, BUFSIZ
);
598 html_idcat(buf
, " ", BUFSIZ
);
601 PAIR_CLASS_INIT(&tag
[0], "sec-head");
602 PAIR_ID_INIT(&tag
[1], buf
);
604 print_otag(h
, TAG_DIV
, 2, tag
);
611 mdoc_ss_pre(MDOC_ARGS
)
613 struct htmlpair tag
[3];
614 const struct mdoc_node
*nn
;
618 SCALE_VS_INIT(&su
, 1);
620 if (MDOC_BODY
== n
->type
) {
621 PAIR_CLASS_INIT(&tag
[0], "ssec-body");
622 if (n
->parent
->next
&& n
->child
) {
623 bufcat_su(h
, "margin-bottom", &su
);
624 PAIR_STYLE_INIT(&tag
[1], h
);
625 print_otag(h
, TAG_DIV
, 2, tag
);
627 print_otag(h
, TAG_DIV
, 1, tag
);
629 } else if (MDOC_BLOCK
== n
->type
) {
630 PAIR_CLASS_INIT(&tag
[0], "ssec-block");
632 bufcat_su(h
, "margin-top", &su
);
633 PAIR_STYLE_INIT(&tag
[1], h
);
634 print_otag(h
, TAG_DIV
, 2, tag
);
636 print_otag(h
, TAG_DIV
, 1, tag
);
640 /* TODO: see note in mdoc_sh_pre() about duplicates. */
643 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
644 html_idcat(buf
, nn
->string
, BUFSIZ
);
646 html_idcat(buf
, " ", BUFSIZ
);
649 SCALE_HS_INIT(&su
, INDENT
- HALFINDENT
);
650 su
.scale
= -su
.scale
;
651 bufcat_su(h
, "margin-left", &su
);
653 PAIR_CLASS_INIT(&tag
[0], "ssec-head");
654 PAIR_STYLE_INIT(&tag
[1], h
);
655 PAIR_ID_INIT(&tag
[2], buf
);
657 print_otag(h
, TAG_DIV
, 3, tag
);
664 mdoc_fl_pre(MDOC_ARGS
)
668 PAIR_CLASS_INIT(&tag
, "flag");
669 print_otag(h
, TAG_SPAN
, 1, &tag
);
671 /* `Cm' has no leading hyphen. */
673 if (MDOC_Cm
== n
->tok
)
676 print_text(h
, "\\-");
679 h
->flags
|= HTML_NOSPACE
;
680 else if (n
->next
&& n
->next
->line
== n
->line
)
681 h
->flags
|= HTML_NOSPACE
;
689 mdoc_nd_pre(MDOC_ARGS
)
693 if (MDOC_BODY
!= n
->type
)
696 /* XXX: this tag in theory can contain block elements. */
698 print_text(h
, "\\(em");
699 PAIR_CLASS_INIT(&tag
, "desc-body");
700 print_otag(h
, TAG_SPAN
, 1, &tag
);
707 mdoc_op_pre(MDOC_ARGS
)
711 if (MDOC_BODY
!= n
->type
)
714 /* XXX: this tag in theory can contain block elements. */
716 print_text(h
, "\\(lB");
717 h
->flags
|= HTML_NOSPACE
;
718 PAIR_CLASS_INIT(&tag
, "opt");
719 print_otag(h
, TAG_SPAN
, 1, &tag
);
726 mdoc_op_post(MDOC_ARGS
)
729 if (MDOC_BODY
!= n
->type
)
731 h
->flags
|= HTML_NOSPACE
;
732 print_text(h
, "\\(rB");
737 mdoc_nm_pre(MDOC_ARGS
)
744 * Accomodate for `Nm' being both an element (which may have
745 * NULL children AND no m->name) and a block.
750 if (MDOC_ELEM
== n
->type
) {
751 if (NULL
== n
->child
&& NULL
== m
->name
)
754 PAIR_CLASS_INIT(&tag
, "name");
755 print_otag(h
, TAG_SPAN
, 1, &tag
);
756 if (NULL
== n
->child
)
757 print_text(h
, m
->name
);
758 } else if (MDOC_BLOCK
== n
->type
) {
761 bufcat_style(h
, "clear", "both");
762 if (n
->head
->child
|| m
->name
) {
763 if (n
->head
->child
&& MDOC_TEXT
==
764 n
->head
->child
->type
)
765 cp
= n
->head
->child
->string
;
766 if (NULL
== cp
|| '\0' == *cp
)
769 SCALE_HS_INIT(&su
, (double)strlen(cp
));
770 bufcat_su(h
, "padding-left", &su
);
773 PAIR_STYLE_INIT(&tag
, h
);
774 print_otag(h
, TAG_DIV
, 1, &tag
);
775 } else if (MDOC_HEAD
== n
->type
) {
776 if (NULL
== n
->child
&& NULL
== m
->name
)
779 if (n
->child
&& MDOC_TEXT
== n
->child
->type
)
780 cp
= n
->child
->string
;
781 if (NULL
== cp
|| '\0' == *cp
)
784 SCALE_HS_INIT(&su
, (double)strlen(cp
));
786 bufcat_style(h
, "float", "left");
787 bufcat_su(h
, "min-width", &su
);
789 bufcat_su(h
, "margin-left", &su
);
791 PAIR_STYLE_INIT(&tag
, h
);
792 print_otag(h
, TAG_DIV
, 1, &tag
);
794 if (NULL
== n
->child
)
795 print_text(h
, m
->name
);
796 } else if (MDOC_BODY
== n
->type
) {
797 SCALE_HS_INIT(&su
, 2);
798 bufcat_su(h
, "margin-left", &su
);
799 PAIR_STYLE_INIT(&tag
, h
);
800 print_otag(h
, TAG_DIV
, 1, &tag
);
809 mdoc_xr_pre(MDOC_ARGS
)
811 struct htmlpair tag
[2];
812 const struct mdoc_node
*nn
;
814 if (NULL
== n
->child
)
817 PAIR_CLASS_INIT(&tag
[0], "link-man");
820 buffmt_man(h
, n
->child
->string
,
822 n
->child
->next
->string
: NULL
);
823 PAIR_HREF_INIT(&tag
[1], h
->buf
);
824 print_otag(h
, TAG_A
, 2, tag
);
826 print_otag(h
, TAG_A
, 1, tag
);
829 print_text(h
, nn
->string
);
831 if (NULL
== (nn
= nn
->next
))
834 h
->flags
|= HTML_NOSPACE
;
836 h
->flags
|= HTML_NOSPACE
;
837 print_text(h
, nn
->string
);
838 h
->flags
|= HTML_NOSPACE
;
846 mdoc_ns_pre(MDOC_ARGS
)
849 h
->flags
|= HTML_NOSPACE
;
856 mdoc_ar_pre(MDOC_ARGS
)
860 PAIR_CLASS_INIT(&tag
, "arg");
861 print_otag(h
, TAG_SPAN
, 1, &tag
);
868 mdoc_xx_pre(MDOC_ARGS
)
896 PAIR_CLASS_INIT(&tag
, "unix");
897 print_otag(h
, TAG_SPAN
, 1, &tag
);
905 mdoc_bx_pre(MDOC_ARGS
)
907 const struct mdoc_node
*nn
;
910 PAIR_CLASS_INIT(&tag
, "unix");
911 print_otag(h
, TAG_SPAN
, 1, &tag
);
913 for (nn
= n
->child
; nn
; nn
= nn
->next
)
914 print_mdoc_node(m
, nn
, h
);
917 h
->flags
|= HTML_NOSPACE
;
919 print_text(h
, "BSD");
926 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
927 struct roffsu
*offs
, struct roffsu
*width
)
930 const struct mdoc_node
*nn
;
933 nn
= n
->parent
->parent
;
935 /* XXX: see notes in mdoc_it_pre(). */
937 if (LIST_column
== type
) {
938 /* Don't width-pad on the left. */
939 SCALE_HS_INIT(width
, 0);
940 /* Also disallow non-compact. */
943 if (LIST_diag
== type
)
944 /* Mandate non-compact with empty prior. */
945 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
948 bufcat_style(h
, "clear", "both");
950 bufcat_su(h
, "margin-left", offs
);
951 if (width
->scale
> 0)
952 bufcat_su(h
, "padding-left", width
);
954 PAIR_STYLE_INIT(&tag
, h
);
956 /* Mandate compact following `Ss' and `Sh' starts. */
958 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
959 if (MDOC_BLOCK
!= nn
->type
)
961 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
968 SCALE_VS_INIT(&su
, 1);
969 bufcat_su(h
, "padding-top", &su
);
972 PAIR_STYLE_INIT(&tag
, h
);
973 print_otag(h
, TAG_DIV
, 1, &tag
);
980 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
991 bufcat_su(h
, "min-width", width
);
992 bufcat_style(h
, "clear", "none");
994 bufcat_style(h
, "float", "left");
995 PAIR_STYLE_INIT(&tag
, h
);
996 print_otag(h
, TAG_DIV
, 1, &tag
);
1000 * XXX: this tricks CSS into aligning the bodies with
1001 * the right-padding in the head.
1003 SCALE_HS_INIT(&su
, 2);
1004 bufcat_su(h
, "margin-left", &su
);
1005 PAIR_STYLE_INIT(&tag
, h
);
1006 print_otag(h
, TAG_DIV
, 1, &tag
);
1016 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
1018 struct htmlpair tag
;
1026 print_otag(h
, TAG_DIV
, 0, &tag
);
1031 bufcat_su(h
, "min-width", width
);
1032 SCALE_INVERT(width
);
1033 bufcat_su(h
, "margin-left", width
);
1034 if (n
->next
&& n
->next
->child
)
1035 bufcat_style(h
, "float", "left");
1037 /* XXX: buffer if we run into body. */
1038 SCALE_HS_INIT(width
, 1);
1039 bufcat_su(h
, "margin-right", width
);
1040 PAIR_STYLE_INIT(&tag
, h
);
1041 print_otag(h
, TAG_DIV
, 1, &tag
);
1047 PAIR_CLASS_INIT(&tag
, "diag");
1048 print_otag(h
, TAG_SPAN
, 1, &tag
);
1053 nbuf
[BUFSIZ
- 1] = 0;
1054 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1055 print_text(h
, nbuf
);
1058 print_text(h
, "\\(en");
1061 print_text(h
, "\\(hy");
1064 print_text(h
, "\\(bu");
1075 mdoc_it_pre(MDOC_ARGS
)
1078 const struct mdoc_node
*bl
, *nn
;
1079 struct roffsu width
, offs
;
1080 enum mdoc_list type
;
1083 * XXX: be very careful in changing anything, here. Lists in
1084 * mandoc have many peculiarities; furthermore, they don't
1085 * translate well into HTML and require a bit of mangling.
1088 bl
= n
->parent
->parent
;
1089 if (MDOC_BLOCK
!= n
->type
)
1092 SCALE_HS_INIT(&offs
, 0);
1094 assert(bl
->data
.Bl
);
1095 type
= bl
->data
.Bl
->type
;
1096 comp
= bl
->data
.Bl
->comp
;
1098 if (bl
->data
.Bl
->offs
)
1099 a2offs(bl
->data
.Bl
->offs
, &offs
);
1109 SCALE_HS_INIT(&width
, 2);
1112 SCALE_HS_INIT(&width
, INDENT
);
1116 if (bl
->data
.Bl
->width
)
1117 a2width(bl
->data
.Bl
->width
, &width
);
1119 /* Override width in some cases. */
1129 SCALE_HS_INIT(&width
, 0);
1132 if (0 == width
.scale
)
1133 SCALE_HS_INIT(&width
, INDENT
);
1137 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1138 nn
= n
->parent
->child
;
1139 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1140 if (MDOC_BODY
== nn
->type
)
1142 if (i
< (int)bl
->data
.Bl
->ncols
)
1143 a2width(bl
->data
.Bl
->cols
[i
], &width
);
1146 if (MDOC_HEAD
== n
->type
)
1147 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1148 else if (MDOC_BODY
== n
->type
)
1149 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1151 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1157 mdoc_bl_pre(MDOC_ARGS
)
1161 if (MDOC_HEAD
== n
->type
)
1163 if (MDOC_BLOCK
!= n
->type
)
1166 if (LIST_enum
!= n
->data
.Bl
->type
)
1169 ord
= malloc(sizeof(struct ord
));
1176 ord
->next
= h
->ords
.head
;
1184 mdoc_bl_post(MDOC_ARGS
)
1188 if (MDOC_BLOCK
!= n
->type
)
1190 if (LIST_enum
!= n
->data
.Bl
->type
)
1195 h
->ords
.head
= ord
->next
;
1202 mdoc_ex_pre(MDOC_ARGS
)
1204 const struct mdoc_node
*nn
;
1206 struct htmlpair tag
;
1208 PAIR_CLASS_INIT(&tag
, "utility");
1210 print_text(h
, "The");
1211 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1212 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1213 print_text(h
, nn
->string
);
1216 h
->flags
|= HTML_NOSPACE
;
1218 if (nn
->next
&& NULL
== nn
->next
->next
)
1219 print_text(h
, ", and");
1223 h
->flags
&= ~HTML_NOSPACE
;
1226 if (n
->child
&& n
->child
->next
)
1227 print_text(h
, "utilities exit");
1229 print_text(h
, "utility exits");
1231 print_text(h
, "0 on success, and >0 if an error occurs.");
1238 mdoc_dq_pre(MDOC_ARGS
)
1241 if (MDOC_BODY
!= n
->type
)
1243 print_text(h
, "\\(lq");
1244 h
->flags
|= HTML_NOSPACE
;
1251 mdoc_dq_post(MDOC_ARGS
)
1254 if (MDOC_BODY
!= n
->type
)
1256 h
->flags
|= HTML_NOSPACE
;
1257 print_text(h
, "\\(rq");
1263 mdoc_pq_pre(MDOC_ARGS
)
1266 if (MDOC_BODY
!= n
->type
)
1268 print_text(h
, "\\&(");
1269 h
->flags
|= HTML_NOSPACE
;
1276 mdoc_pq_post(MDOC_ARGS
)
1279 if (MDOC_BODY
!= n
->type
)
1287 mdoc_sq_pre(MDOC_ARGS
)
1290 if (MDOC_BODY
!= n
->type
)
1292 print_text(h
, "\\(oq");
1293 h
->flags
|= HTML_NOSPACE
;
1300 mdoc_sq_post(MDOC_ARGS
)
1303 if (MDOC_BODY
!= n
->type
)
1305 h
->flags
|= HTML_NOSPACE
;
1306 print_text(h
, "\\(aq");
1312 mdoc_em_pre(MDOC_ARGS
)
1314 struct htmlpair tag
;
1316 PAIR_CLASS_INIT(&tag
, "emph");
1317 print_otag(h
, TAG_SPAN
, 1, &tag
);
1324 mdoc_d1_pre(MDOC_ARGS
)
1326 struct htmlpair tag
[2];
1329 if (MDOC_BLOCK
!= n
->type
)
1332 /* FIXME: D1 shouldn't be literal. */
1334 SCALE_VS_INIT(&su
, INDENT
- 2);
1335 bufcat_su(h
, "margin-left", &su
);
1336 PAIR_CLASS_INIT(&tag
[0], "lit");
1337 PAIR_STYLE_INIT(&tag
[1], h
);
1338 print_otag(h
, TAG_DIV
, 2, tag
);
1345 mdoc_sx_pre(MDOC_ARGS
)
1347 struct htmlpair tag
[2];
1348 const struct mdoc_node
*nn
;
1351 strlcpy(buf
, "#", BUFSIZ
);
1352 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1353 html_idcat(buf
, nn
->string
, BUFSIZ
);
1355 html_idcat(buf
, " ", BUFSIZ
);
1358 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1359 PAIR_HREF_INIT(&tag
[1], buf
);
1361 print_otag(h
, TAG_A
, 2, tag
);
1368 mdoc_aq_pre(MDOC_ARGS
)
1371 if (MDOC_BODY
!= n
->type
)
1373 print_text(h
, "\\(la");
1374 h
->flags
|= HTML_NOSPACE
;
1381 mdoc_aq_post(MDOC_ARGS
)
1384 if (MDOC_BODY
!= n
->type
)
1386 h
->flags
|= HTML_NOSPACE
;
1387 print_text(h
, "\\(ra");
1393 mdoc_bd_pre(MDOC_ARGS
)
1395 struct htmlpair tag
[2];
1397 const struct mdoc_node
*nn
;
1400 if (MDOC_HEAD
== n
->type
)
1403 SCALE_VS_INIT(&su
, 0);
1406 if (n
->data
.Bd
->offs
)
1407 a2offs(n
->data
.Bd
->offs
, &su
);
1409 comp
= n
->data
.Bd
->comp
;
1411 /* FIXME: -centered, etc. formatting. */
1412 /* FIXME: does not respect -offset ??? */
1414 if (MDOC_BLOCK
== n
->type
) {
1415 bufcat_su(h
, "margin-left", &su
);
1416 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1417 if (MDOC_BLOCK
!= nn
->type
)
1419 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1425 PAIR_STYLE_INIT(&tag
[0], h
);
1426 print_otag(h
, TAG_DIV
, 1, tag
);
1429 SCALE_VS_INIT(&su
, 1);
1430 bufcat_su(h
, "margin-top", &su
);
1431 PAIR_STYLE_INIT(&tag
[0], h
);
1432 print_otag(h
, TAG_DIV
, 1, tag
);
1436 if (DISP_unfilled
!= n
->data
.Bd
->type
&&
1437 DISP_literal
!= n
->data
.Bd
->type
)
1440 PAIR_CLASS_INIT(&tag
[0], "lit");
1441 bufcat_style(h
, "white-space", "pre");
1442 PAIR_STYLE_INIT(&tag
[1], h
);
1443 print_otag(h
, TAG_DIV
, 2, tag
);
1445 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1446 h
->flags
|= HTML_NOSPACE
;
1447 print_mdoc_node(m
, nn
, h
);
1448 if (NULL
== nn
->next
)
1450 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1451 print_text(h
, "\n");
1452 else if (NULL
== nn
->prev
)
1453 print_text(h
, "\n");
1462 mdoc_pa_pre(MDOC_ARGS
)
1464 struct htmlpair tag
;
1466 PAIR_CLASS_INIT(&tag
, "file");
1467 print_otag(h
, TAG_SPAN
, 1, &tag
);
1474 mdoc_ad_pre(MDOC_ARGS
)
1476 struct htmlpair tag
;
1478 PAIR_CLASS_INIT(&tag
, "addr");
1479 print_otag(h
, TAG_SPAN
, 1, &tag
);
1486 mdoc_an_pre(MDOC_ARGS
)
1488 struct htmlpair tag
;
1490 /* TODO: -split and -nosplit (see termp_an_pre()). */
1492 PAIR_CLASS_INIT(&tag
, "author");
1493 print_otag(h
, TAG_SPAN
, 1, &tag
);
1500 mdoc_cd_pre(MDOC_ARGS
)
1502 struct htmlpair tag
;
1505 PAIR_CLASS_INIT(&tag
, "config");
1506 print_otag(h
, TAG_SPAN
, 1, &tag
);
1513 mdoc_dv_pre(MDOC_ARGS
)
1515 struct htmlpair tag
;
1517 PAIR_CLASS_INIT(&tag
, "define");
1518 print_otag(h
, TAG_SPAN
, 1, &tag
);
1525 mdoc_ev_pre(MDOC_ARGS
)
1527 struct htmlpair tag
;
1529 PAIR_CLASS_INIT(&tag
, "env");
1530 print_otag(h
, TAG_SPAN
, 1, &tag
);
1537 mdoc_er_pre(MDOC_ARGS
)
1539 struct htmlpair tag
;
1541 PAIR_CLASS_INIT(&tag
, "errno");
1542 print_otag(h
, TAG_SPAN
, 1, &tag
);
1549 mdoc_fa_pre(MDOC_ARGS
)
1551 const struct mdoc_node
*nn
;
1552 struct htmlpair tag
;
1555 PAIR_CLASS_INIT(&tag
, "farg");
1556 if (n
->parent
->tok
!= MDOC_Fo
) {
1557 print_otag(h
, TAG_SPAN
, 1, &tag
);
1561 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1562 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1563 print_text(h
, nn
->string
);
1569 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1578 mdoc_fd_pre(MDOC_ARGS
)
1580 struct htmlpair tag
;
1584 PAIR_CLASS_INIT(&tag
, "macro");
1585 print_otag(h
, TAG_SPAN
, 1, &tag
);
1592 mdoc_vt_pre(MDOC_ARGS
)
1594 struct htmlpair tag
;
1596 if (MDOC_BLOCK
== n
->type
) {
1599 } else if (MDOC_ELEM
== n
->type
) {
1601 } else if (MDOC_HEAD
== n
->type
)
1604 PAIR_CLASS_INIT(&tag
, "type");
1605 print_otag(h
, TAG_SPAN
, 1, &tag
);
1612 mdoc_ft_pre(MDOC_ARGS
)
1614 struct htmlpair tag
;
1617 PAIR_CLASS_INIT(&tag
, "ftype");
1618 print_otag(h
, TAG_SPAN
, 1, &tag
);
1625 mdoc_fn_pre(MDOC_ARGS
)
1628 struct htmlpair tag
[2];
1629 const struct mdoc_node
*nn
;
1631 const char *sp
, *ep
;
1636 /* Split apart into type and name. */
1637 assert(n
->child
->string
);
1638 sp
= n
->child
->string
;
1640 ep
= strchr(sp
, ' ');
1642 PAIR_CLASS_INIT(&tag
[0], "ftype");
1643 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1646 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1647 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1649 print_text(h
, nbuf
);
1651 ep
= strchr(sp
, ' ');
1656 PAIR_CLASS_INIT(&tag
[0], "fname");
1659 * FIXME: only refer to IDs that we know exist.
1663 if (MDOC_SYNPRETTY
& n
->flags
) {
1665 html_idcat(nbuf
, sp
, BUFSIZ
);
1666 PAIR_ID_INIT(&tag
[1], nbuf
);
1668 strlcpy(nbuf
, "#", BUFSIZ
);
1669 html_idcat(nbuf
, sp
, BUFSIZ
);
1670 PAIR_HREF_INIT(&tag
[1], nbuf
);
1674 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1677 strlcpy(nbuf
, sp
, BUFSIZ
);
1678 print_text(h
, nbuf
);
1683 h
->flags
|= HTML_NOSPACE
;
1687 PAIR_CLASS_INIT(&tag
[0], "farg");
1688 bufcat_style(h
, "white-space", "nowrap");
1689 PAIR_STYLE_INIT(&tag
[1], h
);
1691 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1693 if (MDOC_SYNPRETTY
& n
->flags
)
1695 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1696 print_text(h
, nn
->string
);
1703 if (MDOC_SYNPRETTY
& n
->flags
)
1712 mdoc_sp_pre(MDOC_ARGS
)
1715 struct htmlpair tag
;
1720 /* FIXME: can this have a scaling indicator? */
1721 len
= n
->child
? atoi(n
->child
->string
) : 1;
1731 SCALE_VS_INIT(&su
, len
);
1732 bufcat_su(h
, "height", &su
);
1733 PAIR_STYLE_INIT(&tag
, h
);
1734 print_otag(h
, TAG_DIV
, 1, &tag
);
1735 /* So the div isn't empty: */
1736 print_text(h
, "\\~");
1745 mdoc_brq_pre(MDOC_ARGS
)
1748 if (MDOC_BODY
!= n
->type
)
1750 print_text(h
, "\\(lC");
1751 h
->flags
|= HTML_NOSPACE
;
1758 mdoc_brq_post(MDOC_ARGS
)
1761 if (MDOC_BODY
!= n
->type
)
1763 h
->flags
|= HTML_NOSPACE
;
1764 print_text(h
, "\\(rC");
1770 mdoc_lk_pre(MDOC_ARGS
)
1772 const struct mdoc_node
*nn
;
1773 struct htmlpair tag
[2];
1777 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1778 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1779 print_otag(h
, TAG_A
, 2, tag
);
1781 if (NULL
== nn
->next
)
1784 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1785 print_text(h
, nn
->string
);
1793 mdoc_mt_pre(MDOC_ARGS
)
1795 struct htmlpair tag
[2];
1797 const struct mdoc_node
*nn
;
1799 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1801 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1803 bufcat(h
, "mailto:");
1804 bufcat(h
, nn
->string
);
1805 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1806 t
= print_otag(h
, TAG_A
, 2, tag
);
1807 print_text(h
, nn
->string
);
1817 mdoc_fo_pre(MDOC_ARGS
)
1819 struct htmlpair tag
;
1822 if (MDOC_BODY
== n
->type
) {
1823 h
->flags
|= HTML_NOSPACE
;
1825 h
->flags
|= HTML_NOSPACE
;
1827 } else if (MDOC_BLOCK
== n
->type
) {
1832 /* XXX: we drop non-initial arguments as per groff. */
1835 assert(n
->child
->string
);
1837 PAIR_CLASS_INIT(&tag
, "fname");
1838 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1839 print_text(h
, n
->child
->string
);
1847 mdoc_fo_post(MDOC_ARGS
)
1850 if (MDOC_BODY
!= n
->type
)
1852 h
->flags
|= HTML_NOSPACE
;
1854 h
->flags
|= HTML_NOSPACE
;
1861 mdoc_in_pre(MDOC_ARGS
)
1863 const struct mdoc_node
*nn
;
1865 struct htmlpair tag
[2];
1870 PAIR_CLASS_INIT(&tag
[0], "includes");
1871 print_otag(h
, TAG_SPAN
, 1, tag
);
1873 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1874 print_text(h
, "#include");
1877 h
->flags
|= HTML_NOSPACE
;
1879 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1880 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1883 if (h
->base_includes
) {
1884 buffmt_includes(h
, nn
->string
);
1885 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1888 t
= print_otag(h
, TAG_A
, i
, tag
);
1889 print_mdoc_node(m
, nn
, h
);
1893 h
->flags
|= HTML_NOSPACE
;
1902 mdoc_ic_pre(MDOC_ARGS
)
1904 struct htmlpair tag
;
1906 PAIR_CLASS_INIT(&tag
, "cmd");
1907 print_otag(h
, TAG_SPAN
, 1, &tag
);
1914 mdoc_rv_pre(MDOC_ARGS
)
1916 const struct mdoc_node
*nn
;
1917 struct htmlpair tag
;
1920 print_otag(h
, TAG_DIV
, 0, NULL
);
1921 print_text(h
, "The");
1923 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1924 PAIR_CLASS_INIT(&tag
, "fname");
1925 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1926 print_text(h
, nn
->string
);
1929 h
->flags
|= HTML_NOSPACE
;
1930 if (nn
->next
&& NULL
== nn
->next
->next
)
1931 print_text(h
, "(), and");
1933 print_text(h
, "(),");
1935 print_text(h
, "()");
1938 if (n
->child
&& n
->child
->next
)
1939 print_text(h
, "functions return");
1941 print_text(h
, "function returns");
1943 print_text(h
, "the value 0 if successful; otherwise the value "
1944 "-1 is returned and the global variable");
1946 PAIR_CLASS_INIT(&tag
, "var");
1947 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1948 print_text(h
, "errno");
1950 print_text(h
, "is set to indicate the error.");
1957 mdoc_va_pre(MDOC_ARGS
)
1959 struct htmlpair tag
;
1961 PAIR_CLASS_INIT(&tag
, "var");
1962 print_otag(h
, TAG_SPAN
, 1, &tag
);
1969 mdoc_bq_pre(MDOC_ARGS
)
1972 if (MDOC_BODY
!= n
->type
)
1974 print_text(h
, "\\(lB");
1975 h
->flags
|= HTML_NOSPACE
;
1982 mdoc_bq_post(MDOC_ARGS
)
1985 if (MDOC_BODY
!= n
->type
)
1987 h
->flags
|= HTML_NOSPACE
;
1988 print_text(h
, "\\(rB");
1994 mdoc_ap_pre(MDOC_ARGS
)
1997 h
->flags
|= HTML_NOSPACE
;
1998 print_text(h
, "\\(aq");
1999 h
->flags
|= HTML_NOSPACE
;
2006 mdoc_bf_pre(MDOC_ARGS
)
2008 struct htmlpair tag
[2];
2011 if (MDOC_HEAD
== n
->type
)
2013 else if (MDOC_BODY
!= n
->type
)
2018 if (FONT_Em
== n
->data
.Bf
->font
)
2019 PAIR_CLASS_INIT(&tag
[0], "emph");
2020 else if (FONT_Sy
== n
->data
.Bf
->font
)
2021 PAIR_CLASS_INIT(&tag
[0], "symb");
2022 else if (FONT_Li
== n
->data
.Bf
->font
)
2023 PAIR_CLASS_INIT(&tag
[0], "lit");
2025 PAIR_CLASS_INIT(&tag
[0], "none");
2028 * We want this to be inline-formatted, but needs to be div to
2029 * accept block children.
2031 bufcat_style(h
, "display", "inline");
2032 SCALE_HS_INIT(&su
, 1);
2033 /* Needs a left-margin for spacing. */
2034 bufcat_su(h
, "margin-left", &su
);
2035 PAIR_STYLE_INIT(&tag
[1], h
);
2036 print_otag(h
, TAG_DIV
, 2, tag
);
2043 mdoc_ms_pre(MDOC_ARGS
)
2045 struct htmlpair tag
;
2047 PAIR_CLASS_INIT(&tag
, "symb");
2048 print_otag(h
, TAG_SPAN
, 1, &tag
);
2055 mdoc_pf_pre(MDOC_ARGS
)
2058 h
->flags
|= HTML_IGNDELIM
;
2065 mdoc_pf_post(MDOC_ARGS
)
2068 h
->flags
&= ~HTML_IGNDELIM
;
2069 h
->flags
|= HTML_NOSPACE
;
2075 mdoc_rs_pre(MDOC_ARGS
)
2077 struct htmlpair tag
;
2080 if (MDOC_BLOCK
!= n
->type
)
2083 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2084 SCALE_VS_INIT(&su
, 1);
2085 bufcat_su(h
, "margin-top", &su
);
2086 PAIR_STYLE_INIT(&tag
, h
);
2087 print_otag(h
, TAG_DIV
, 1, &tag
);
2090 PAIR_CLASS_INIT(&tag
, "ref");
2091 print_otag(h
, TAG_SPAN
, 1, &tag
);
2099 mdoc_li_pre(MDOC_ARGS
)
2101 struct htmlpair tag
;
2103 PAIR_CLASS_INIT(&tag
, "lit");
2104 print_otag(h
, TAG_SPAN
, 1, &tag
);
2111 mdoc_sy_pre(MDOC_ARGS
)
2113 struct htmlpair tag
;
2115 PAIR_CLASS_INIT(&tag
, "symb");
2116 print_otag(h
, TAG_SPAN
, 1, &tag
);
2123 mdoc_bt_pre(MDOC_ARGS
)
2126 print_text(h
, "is currently in beta test.");
2133 mdoc_ud_pre(MDOC_ARGS
)
2136 print_text(h
, "currently under development.");
2143 mdoc_lb_pre(MDOC_ARGS
)
2145 struct htmlpair tag
;
2147 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2148 print_otag(h
, TAG_DIV
, 0, NULL
);
2149 PAIR_CLASS_INIT(&tag
, "lib");
2150 print_otag(h
, TAG_SPAN
, 1, &tag
);
2157 mdoc__x_pre(MDOC_ARGS
)
2159 struct htmlpair tag
[2];
2163 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2166 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2169 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2172 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2175 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2178 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2181 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2184 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2187 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2190 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2193 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2196 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2199 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2202 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2209 if (MDOC__U
!= n
->tok
) {
2210 print_otag(h
, TAG_SPAN
, 1, tag
);
2214 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2215 print_otag(h
, TAG_A
, 2, tag
);
2222 mdoc__x_post(MDOC_ARGS
)
2227 h
->flags
|= HTML_NOSPACE
;
2228 print_text(h
, n
->next
? "," : ".");