]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.87 2010/06/27 16:18:13 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
)
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
)
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
)
741 if (NULL
== n
->child
&& NULL
== m
->name
)
746 PAIR_CLASS_INIT(&tag
, "name");
747 print_otag(h
, TAG_SPAN
, 1, &tag
);
748 if (NULL
== n
->child
)
749 print_text(h
, m
->name
);
756 mdoc_xr_pre(MDOC_ARGS
)
758 struct htmlpair tag
[2];
759 const struct mdoc_node
*nn
;
761 if (NULL
== n
->child
)
764 PAIR_CLASS_INIT(&tag
[0], "link-man");
767 buffmt_man(h
, n
->child
->string
,
769 n
->child
->next
->string
: NULL
);
770 PAIR_HREF_INIT(&tag
[1], h
->buf
);
771 print_otag(h
, TAG_A
, 2, tag
);
773 print_otag(h
, TAG_A
, 1, tag
);
776 print_text(h
, nn
->string
);
778 if (NULL
== (nn
= nn
->next
))
781 h
->flags
|= HTML_NOSPACE
;
783 h
->flags
|= HTML_NOSPACE
;
784 print_text(h
, nn
->string
);
785 h
->flags
|= HTML_NOSPACE
;
793 mdoc_ns_pre(MDOC_ARGS
)
796 h
->flags
|= HTML_NOSPACE
;
803 mdoc_ar_pre(MDOC_ARGS
)
807 PAIR_CLASS_INIT(&tag
, "arg");
808 print_otag(h
, TAG_SPAN
, 1, &tag
);
815 mdoc_xx_pre(MDOC_ARGS
)
843 PAIR_CLASS_INIT(&tag
, "unix");
844 print_otag(h
, TAG_SPAN
, 1, &tag
);
852 mdoc_bx_pre(MDOC_ARGS
)
854 const struct mdoc_node
*nn
;
857 PAIR_CLASS_INIT(&tag
, "unix");
858 print_otag(h
, TAG_SPAN
, 1, &tag
);
860 for (nn
= n
->child
; nn
; nn
= nn
->next
)
861 print_mdoc_node(m
, nn
, h
);
864 h
->flags
|= HTML_NOSPACE
;
866 print_text(h
, "BSD");
873 mdoc_it_block_pre(MDOC_ARGS
, enum mdoc_list type
, int comp
,
874 struct roffsu
*offs
, struct roffsu
*width
)
877 const struct mdoc_node
*nn
;
880 nn
= n
->parent
->parent
;
882 /* XXX: see notes in mdoc_it_pre(). */
884 if (LIST_column
== type
) {
885 /* Don't width-pad on the left. */
886 SCALE_HS_INIT(width
, 0);
887 /* Also disallow non-compact. */
890 if (LIST_diag
== type
)
891 /* Mandate non-compact with empty prior. */
892 if (n
->prev
&& NULL
== n
->prev
->body
->child
)
895 bufcat_style(h
, "clear", "both");
897 bufcat_su(h
, "margin-left", offs
);
898 if (width
->scale
> 0)
899 bufcat_su(h
, "padding-left", width
);
901 PAIR_STYLE_INIT(&tag
, h
);
903 /* Mandate compact following `Ss' and `Sh' starts. */
905 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
906 if (MDOC_BLOCK
!= nn
->type
)
908 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
915 SCALE_VS_INIT(&su
, 1);
916 bufcat_su(h
, "padding-top", &su
);
919 PAIR_STYLE_INIT(&tag
, h
);
920 print_otag(h
, TAG_DIV
, 1, &tag
);
927 mdoc_it_body_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
938 bufcat_su(h
, "min-width", width
);
939 bufcat_style(h
, "clear", "none");
941 bufcat_style(h
, "float", "left");
942 PAIR_STYLE_INIT(&tag
, h
);
943 print_otag(h
, TAG_DIV
, 1, &tag
);
947 * XXX: this tricks CSS into aligning the bodies with
948 * the right-padding in the head.
950 SCALE_HS_INIT(&su
, 2);
951 bufcat_su(h
, "margin-left", &su
);
952 PAIR_STYLE_INIT(&tag
, h
);
953 print_otag(h
, TAG_DIV
, 1, &tag
);
963 mdoc_it_head_pre(MDOC_ARGS
, enum mdoc_list type
, struct roffsu
*width
)
973 print_otag(h
, TAG_DIV
, 0, &tag
);
978 bufcat_su(h
, "min-width", width
);
980 bufcat_su(h
, "margin-left", width
);
981 if (n
->next
&& n
->next
->child
)
982 bufcat_style(h
, "float", "left");
984 /* XXX: buffer if we run into body. */
985 SCALE_HS_INIT(width
, 1);
986 bufcat_su(h
, "margin-right", width
);
987 PAIR_STYLE_INIT(&tag
, h
);
988 print_otag(h
, TAG_DIV
, 1, &tag
);
994 PAIR_CLASS_INIT(&tag
, "diag");
995 print_otag(h
, TAG_SPAN
, 1, &tag
);
1000 nbuf
[BUFSIZ
- 1] = 0;
1001 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
1002 print_text(h
, nbuf
);
1005 print_text(h
, "\\(en");
1008 print_text(h
, "\\(hy");
1011 print_text(h
, "\\(bu");
1022 mdoc_it_pre(MDOC_ARGS
)
1025 const struct mdoc_node
*bl
, *nn
;
1026 struct roffsu width
, offs
;
1027 enum mdoc_list type
;
1030 * XXX: be very careful in changing anything, here. Lists in
1031 * mandoc have many peculiarities; furthermore, they don't
1032 * translate well into HTML and require a bit of mangling.
1035 bl
= n
->parent
->parent
;
1036 if (MDOC_BLOCK
!= n
->type
)
1039 SCALE_HS_INIT(&offs
, 0);
1041 type
= bl
->data
.Bl
.type
;
1042 comp
= bl
->data
.Bl
.comp
;
1044 if (bl
->data
.Bl
.offs
)
1045 a2offs(bl
->data
.Bl
.offs
, &offs
);
1055 SCALE_HS_INIT(&width
, 2);
1058 SCALE_HS_INIT(&width
, INDENT
);
1062 if (bl
->data
.Bl
.width
)
1063 a2width(bl
->data
.Bl
.width
, &width
);
1066 for (i
= 0; bl
->args
&& i
< (int)bl
->args
->argc
; i
++)
1067 switch (bl
->args
->argv
[i
].arg
) {
1069 wp
= i
; /* Save for later. */
1075 /* Override width in some cases. */
1085 SCALE_HS_INIT(&width
, 0);
1088 if (0 == width
.scale
)
1089 SCALE_HS_INIT(&width
, INDENT
);
1093 if (LIST_column
== type
&& MDOC_BODY
== n
->type
) {
1094 nn
= n
->parent
->child
;
1095 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
)
1096 if (MDOC_BODY
== nn
->type
)
1098 if (i
< (int)bl
->args
->argv
[wp
].sz
)
1099 a2width(bl
->args
->argv
[wp
].value
[i
], &width
);
1102 if (MDOC_HEAD
== n
->type
)
1103 return(mdoc_it_head_pre(m
, n
, h
, type
, &width
));
1104 else if (MDOC_BODY
== n
->type
)
1105 return(mdoc_it_body_pre(m
, n
, h
, type
, &width
));
1107 return(mdoc_it_block_pre(m
, n
, h
, type
, comp
, &offs
, &width
));
1113 mdoc_bl_pre(MDOC_ARGS
)
1117 if (MDOC_HEAD
== n
->type
)
1119 if (MDOC_BLOCK
!= n
->type
)
1121 if (LIST_enum
!= n
->data
.Bl
.type
)
1124 ord
= malloc(sizeof(struct ord
));
1131 ord
->next
= h
->ords
.head
;
1139 mdoc_bl_post(MDOC_ARGS
)
1143 if (MDOC_BLOCK
!= n
->type
)
1145 if (LIST_enum
!= n
->data
.Bl
.type
)
1150 h
->ords
.head
= ord
->next
;
1157 mdoc_ex_pre(MDOC_ARGS
)
1159 const struct mdoc_node
*nn
;
1161 struct htmlpair tag
;
1163 PAIR_CLASS_INIT(&tag
, "utility");
1165 print_text(h
, "The");
1166 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1167 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1168 print_text(h
, nn
->string
);
1171 h
->flags
|= HTML_NOSPACE
;
1173 if (nn
->next
&& NULL
== nn
->next
->next
)
1174 print_text(h
, ", and");
1178 h
->flags
&= ~HTML_NOSPACE
;
1181 if (n
->child
&& n
->child
->next
)
1182 print_text(h
, "utilities exit");
1184 print_text(h
, "utility exits");
1186 print_text(h
, "0 on success, and >0 if an error occurs.");
1193 mdoc_dq_pre(MDOC_ARGS
)
1196 if (MDOC_BODY
!= n
->type
)
1198 print_text(h
, "\\(lq");
1199 h
->flags
|= HTML_NOSPACE
;
1206 mdoc_dq_post(MDOC_ARGS
)
1209 if (MDOC_BODY
!= n
->type
)
1211 h
->flags
|= HTML_NOSPACE
;
1212 print_text(h
, "\\(rq");
1218 mdoc_pq_pre(MDOC_ARGS
)
1221 if (MDOC_BODY
!= n
->type
)
1223 print_text(h
, "\\&(");
1224 h
->flags
|= HTML_NOSPACE
;
1231 mdoc_pq_post(MDOC_ARGS
)
1234 if (MDOC_BODY
!= n
->type
)
1242 mdoc_sq_pre(MDOC_ARGS
)
1245 if (MDOC_BODY
!= n
->type
)
1247 print_text(h
, "\\(oq");
1248 h
->flags
|= HTML_NOSPACE
;
1255 mdoc_sq_post(MDOC_ARGS
)
1258 if (MDOC_BODY
!= n
->type
)
1260 h
->flags
|= HTML_NOSPACE
;
1261 print_text(h
, "\\(aq");
1267 mdoc_em_pre(MDOC_ARGS
)
1269 struct htmlpair tag
;
1271 PAIR_CLASS_INIT(&tag
, "emph");
1272 print_otag(h
, TAG_SPAN
, 1, &tag
);
1279 mdoc_d1_pre(MDOC_ARGS
)
1281 struct htmlpair tag
[2];
1284 if (MDOC_BLOCK
!= n
->type
)
1287 /* FIXME: D1 shouldn't be literal. */
1289 SCALE_VS_INIT(&su
, INDENT
- 2);
1290 bufcat_su(h
, "margin-left", &su
);
1291 PAIR_CLASS_INIT(&tag
[0], "lit");
1292 PAIR_STYLE_INIT(&tag
[1], h
);
1293 print_otag(h
, TAG_DIV
, 2, tag
);
1300 mdoc_sx_pre(MDOC_ARGS
)
1302 struct htmlpair tag
[2];
1303 const struct mdoc_node
*nn
;
1306 strlcpy(buf
, "#", BUFSIZ
);
1307 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1308 html_idcat(buf
, nn
->string
, BUFSIZ
);
1310 html_idcat(buf
, " ", BUFSIZ
);
1313 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1314 PAIR_HREF_INIT(&tag
[1], buf
);
1316 print_otag(h
, TAG_A
, 2, tag
);
1323 mdoc_aq_pre(MDOC_ARGS
)
1326 if (MDOC_BODY
!= n
->type
)
1328 print_text(h
, "\\(la");
1329 h
->flags
|= HTML_NOSPACE
;
1336 mdoc_aq_post(MDOC_ARGS
)
1339 if (MDOC_BODY
!= n
->type
)
1341 h
->flags
|= HTML_NOSPACE
;
1342 print_text(h
, "\\(ra");
1348 mdoc_bd_pre(MDOC_ARGS
)
1350 struct htmlpair tag
[2];
1352 const struct mdoc_node
*nn
;
1355 if (MDOC_HEAD
== n
->type
)
1358 SCALE_VS_INIT(&su
, 0);
1360 if (n
->data
.Bd
.offs
)
1361 a2offs(n
->data
.Bd
.offs
, &su
);
1363 comp
= n
->data
.Bd
.comp
;
1365 /* FIXME: -centered, etc. formatting. */
1366 /* FIXME: does not respect -offset ??? */
1368 if (MDOC_BLOCK
== n
->type
) {
1369 bufcat_su(h
, "margin-left", &su
);
1370 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1371 if (MDOC_BLOCK
!= nn
->type
)
1373 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1379 PAIR_STYLE_INIT(&tag
[0], h
);
1380 print_otag(h
, TAG_DIV
, 1, tag
);
1383 SCALE_VS_INIT(&su
, 1);
1384 bufcat_su(h
, "margin-top", &su
);
1385 PAIR_STYLE_INIT(&tag
[0], h
);
1386 print_otag(h
, TAG_DIV
, 1, tag
);
1390 if (DISP_unfilled
!= n
->data
.Bd
.type
&&
1391 DISP_literal
!= n
->data
.Bd
.type
)
1394 PAIR_CLASS_INIT(&tag
[0], "lit");
1395 bufcat_style(h
, "white-space", "pre");
1396 PAIR_STYLE_INIT(&tag
[1], h
);
1397 print_otag(h
, TAG_DIV
, 2, tag
);
1399 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1400 h
->flags
|= HTML_NOSPACE
;
1401 print_mdoc_node(m
, nn
, h
);
1402 if (NULL
== nn
->next
)
1404 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1405 print_text(h
, "\n");
1406 else if (NULL
== nn
->prev
)
1407 print_text(h
, "\n");
1416 mdoc_pa_pre(MDOC_ARGS
)
1418 struct htmlpair tag
;
1420 PAIR_CLASS_INIT(&tag
, "file");
1421 print_otag(h
, TAG_SPAN
, 1, &tag
);
1428 mdoc_ad_pre(MDOC_ARGS
)
1430 struct htmlpair tag
;
1432 PAIR_CLASS_INIT(&tag
, "addr");
1433 print_otag(h
, TAG_SPAN
, 1, &tag
);
1440 mdoc_an_pre(MDOC_ARGS
)
1442 struct htmlpair tag
;
1444 /* TODO: -split and -nosplit (see termp_an_pre()). */
1446 PAIR_CLASS_INIT(&tag
, "author");
1447 print_otag(h
, TAG_SPAN
, 1, &tag
);
1454 mdoc_cd_pre(MDOC_ARGS
)
1456 struct htmlpair tag
;
1459 PAIR_CLASS_INIT(&tag
, "config");
1460 print_otag(h
, TAG_SPAN
, 1, &tag
);
1467 mdoc_dv_pre(MDOC_ARGS
)
1469 struct htmlpair tag
;
1471 PAIR_CLASS_INIT(&tag
, "define");
1472 print_otag(h
, TAG_SPAN
, 1, &tag
);
1479 mdoc_ev_pre(MDOC_ARGS
)
1481 struct htmlpair tag
;
1483 PAIR_CLASS_INIT(&tag
, "env");
1484 print_otag(h
, TAG_SPAN
, 1, &tag
);
1491 mdoc_er_pre(MDOC_ARGS
)
1493 struct htmlpair tag
;
1495 PAIR_CLASS_INIT(&tag
, "errno");
1496 print_otag(h
, TAG_SPAN
, 1, &tag
);
1503 mdoc_fa_pre(MDOC_ARGS
)
1505 const struct mdoc_node
*nn
;
1506 struct htmlpair tag
;
1509 PAIR_CLASS_INIT(&tag
, "farg");
1510 if (n
->parent
->tok
!= MDOC_Fo
) {
1511 print_otag(h
, TAG_SPAN
, 1, &tag
);
1515 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1516 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1517 print_text(h
, nn
->string
);
1523 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1532 mdoc_fd_pre(MDOC_ARGS
)
1534 struct htmlpair tag
;
1538 PAIR_CLASS_INIT(&tag
, "macro");
1539 print_otag(h
, TAG_SPAN
, 1, &tag
);
1546 mdoc_vt_pre(MDOC_ARGS
)
1548 struct htmlpair tag
;
1550 if (MDOC_BLOCK
== n
->type
) {
1553 } else if (MDOC_ELEM
== n
->type
) {
1555 } else if (MDOC_HEAD
== n
->type
)
1558 PAIR_CLASS_INIT(&tag
, "type");
1559 print_otag(h
, TAG_SPAN
, 1, &tag
);
1566 mdoc_ft_pre(MDOC_ARGS
)
1568 struct htmlpair tag
;
1571 PAIR_CLASS_INIT(&tag
, "ftype");
1572 print_otag(h
, TAG_SPAN
, 1, &tag
);
1579 mdoc_fn_pre(MDOC_ARGS
)
1582 struct htmlpair tag
[2];
1583 const struct mdoc_node
*nn
;
1585 const char *sp
, *ep
;
1590 /* Split apart into type and name. */
1591 assert(n
->child
->string
);
1592 sp
= n
->child
->string
;
1594 ep
= strchr(sp
, ' ');
1596 PAIR_CLASS_INIT(&tag
[0], "ftype");
1597 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1600 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1601 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1603 print_text(h
, nbuf
);
1605 ep
= strchr(sp
, ' ');
1610 PAIR_CLASS_INIT(&tag
[0], "fname");
1613 * FIXME: only refer to IDs that we know exist.
1617 if (MDOC_SYNPRETTY
& n
->flags
) {
1619 html_idcat(nbuf
, sp
, BUFSIZ
);
1620 PAIR_ID_INIT(&tag
[1], nbuf
);
1622 strlcpy(nbuf
, "#", BUFSIZ
);
1623 html_idcat(nbuf
, sp
, BUFSIZ
);
1624 PAIR_HREF_INIT(&tag
[1], nbuf
);
1628 t
= print_otag(h
, TAG_SPAN
, 1, tag
);
1631 strlcpy(nbuf
, sp
, BUFSIZ
);
1632 print_text(h
, nbuf
);
1637 h
->flags
|= HTML_NOSPACE
;
1641 PAIR_CLASS_INIT(&tag
[0], "farg");
1642 bufcat_style(h
, "white-space", "nowrap");
1643 PAIR_STYLE_INIT(&tag
[1], h
);
1645 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1647 if (MDOC_SYNPRETTY
& n
->flags
)
1649 t
= print_otag(h
, TAG_SPAN
, i
, tag
);
1650 print_text(h
, nn
->string
);
1657 if (MDOC_SYNPRETTY
& n
->flags
)
1666 mdoc_sp_pre(MDOC_ARGS
)
1669 struct htmlpair tag
;
1674 /* FIXME: can this have a scaling indicator? */
1675 len
= n
->child
? atoi(n
->child
->string
) : 1;
1685 SCALE_VS_INIT(&su
, len
);
1686 bufcat_su(h
, "height", &su
);
1687 PAIR_STYLE_INIT(&tag
, h
);
1688 print_otag(h
, TAG_DIV
, 1, &tag
);
1689 /* So the div isn't empty: */
1690 print_text(h
, "\\~");
1699 mdoc_brq_pre(MDOC_ARGS
)
1702 if (MDOC_BODY
!= n
->type
)
1704 print_text(h
, "\\(lC");
1705 h
->flags
|= HTML_NOSPACE
;
1712 mdoc_brq_post(MDOC_ARGS
)
1715 if (MDOC_BODY
!= n
->type
)
1717 h
->flags
|= HTML_NOSPACE
;
1718 print_text(h
, "\\(rC");
1724 mdoc_lk_pre(MDOC_ARGS
)
1726 const struct mdoc_node
*nn
;
1727 struct htmlpair tag
[2];
1731 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1732 PAIR_HREF_INIT(&tag
[1], nn
->string
);
1733 print_otag(h
, TAG_A
, 2, tag
);
1735 if (NULL
== nn
->next
)
1738 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
1739 print_text(h
, nn
->string
);
1747 mdoc_mt_pre(MDOC_ARGS
)
1749 struct htmlpair tag
[2];
1751 const struct mdoc_node
*nn
;
1753 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1755 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1757 bufcat(h
, "mailto:");
1758 bufcat(h
, nn
->string
);
1759 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1760 t
= print_otag(h
, TAG_A
, 2, tag
);
1761 print_text(h
, nn
->string
);
1771 mdoc_fo_pre(MDOC_ARGS
)
1773 struct htmlpair tag
;
1776 if (MDOC_BODY
== n
->type
) {
1777 h
->flags
|= HTML_NOSPACE
;
1779 h
->flags
|= HTML_NOSPACE
;
1781 } else if (MDOC_BLOCK
== n
->type
) {
1786 /* XXX: we drop non-initial arguments as per groff. */
1789 assert(n
->child
->string
);
1791 PAIR_CLASS_INIT(&tag
, "fname");
1792 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1793 print_text(h
, n
->child
->string
);
1801 mdoc_fo_post(MDOC_ARGS
)
1804 if (MDOC_BODY
!= n
->type
)
1806 h
->flags
|= HTML_NOSPACE
;
1808 h
->flags
|= HTML_NOSPACE
;
1815 mdoc_in_pre(MDOC_ARGS
)
1817 const struct mdoc_node
*nn
;
1819 struct htmlpair tag
[2];
1824 PAIR_CLASS_INIT(&tag
[0], "includes");
1825 print_otag(h
, TAG_SPAN
, 1, tag
);
1827 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1828 print_text(h
, "#include");
1831 h
->flags
|= HTML_NOSPACE
;
1833 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1834 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1837 if (h
->base_includes
) {
1838 buffmt_includes(h
, nn
->string
);
1839 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1842 t
= print_otag(h
, TAG_A
, i
, tag
);
1843 print_mdoc_node(m
, nn
, h
);
1847 h
->flags
|= HTML_NOSPACE
;
1856 mdoc_ic_pre(MDOC_ARGS
)
1858 struct htmlpair tag
;
1860 PAIR_CLASS_INIT(&tag
, "cmd");
1861 print_otag(h
, TAG_SPAN
, 1, &tag
);
1868 mdoc_rv_pre(MDOC_ARGS
)
1870 const struct mdoc_node
*nn
;
1871 struct htmlpair tag
;
1874 print_otag(h
, TAG_DIV
, 0, NULL
);
1875 print_text(h
, "The");
1877 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1878 PAIR_CLASS_INIT(&tag
, "fname");
1879 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1880 print_text(h
, nn
->string
);
1883 h
->flags
|= HTML_NOSPACE
;
1884 if (nn
->next
&& NULL
== nn
->next
->next
)
1885 print_text(h
, "(), and");
1887 print_text(h
, "(),");
1889 print_text(h
, "()");
1892 if (n
->child
&& n
->child
->next
)
1893 print_text(h
, "functions return");
1895 print_text(h
, "function returns");
1897 print_text(h
, "the value 0 if successful; otherwise the value "
1898 "-1 is returned and the global variable");
1900 PAIR_CLASS_INIT(&tag
, "var");
1901 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1902 print_text(h
, "errno");
1904 print_text(h
, "is set to indicate the error.");
1911 mdoc_va_pre(MDOC_ARGS
)
1913 struct htmlpair tag
;
1915 PAIR_CLASS_INIT(&tag
, "var");
1916 print_otag(h
, TAG_SPAN
, 1, &tag
);
1923 mdoc_bq_pre(MDOC_ARGS
)
1926 if (MDOC_BODY
!= n
->type
)
1928 print_text(h
, "\\(lB");
1929 h
->flags
|= HTML_NOSPACE
;
1936 mdoc_bq_post(MDOC_ARGS
)
1939 if (MDOC_BODY
!= n
->type
)
1941 h
->flags
|= HTML_NOSPACE
;
1942 print_text(h
, "\\(rB");
1948 mdoc_ap_pre(MDOC_ARGS
)
1951 h
->flags
|= HTML_NOSPACE
;
1952 print_text(h
, "\\(aq");
1953 h
->flags
|= HTML_NOSPACE
;
1960 mdoc_bf_pre(MDOC_ARGS
)
1963 struct htmlpair tag
[2];
1966 if (MDOC_HEAD
== n
->type
)
1968 else if (MDOC_BLOCK
!= n
->type
)
1971 PAIR_CLASS_INIT(&tag
[0], "lit");
1973 if (n
->head
->child
) {
1974 if ( ! strcmp("Em", n
->head
->child
->string
))
1975 PAIR_CLASS_INIT(&tag
[0], "emph");
1976 else if ( ! strcmp("Sy", n
->head
->child
->string
))
1977 PAIR_CLASS_INIT(&tag
[0], "symb");
1978 else if ( ! strcmp("Li", n
->head
->child
->string
))
1979 PAIR_CLASS_INIT(&tag
[0], "lit");
1981 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++)
1982 switch (n
->args
->argv
[i
].arg
) {
1983 case (MDOC_Symbolic
):
1984 PAIR_CLASS_INIT(&tag
[0], "symb");
1986 case (MDOC_Literal
):
1987 PAIR_CLASS_INIT(&tag
[0], "lit");
1989 case (MDOC_Emphasis
):
1990 PAIR_CLASS_INIT(&tag
[0], "emph");
1997 /* FIXME: div's have spaces stripped--we want them. */
1999 bufcat_style(h
, "display", "inline");
2000 SCALE_HS_INIT(&su
, 1);
2001 bufcat_su(h
, "margin-right", &su
);
2002 PAIR_STYLE_INIT(&tag
[1], h
);
2003 print_otag(h
, TAG_DIV
, 2, tag
);
2010 mdoc_ms_pre(MDOC_ARGS
)
2012 struct htmlpair tag
;
2014 PAIR_CLASS_INIT(&tag
, "symb");
2015 print_otag(h
, TAG_SPAN
, 1, &tag
);
2022 mdoc_pf_pre(MDOC_ARGS
)
2025 h
->flags
|= HTML_IGNDELIM
;
2032 mdoc_pf_post(MDOC_ARGS
)
2035 h
->flags
&= ~HTML_IGNDELIM
;
2036 h
->flags
|= HTML_NOSPACE
;
2042 mdoc_rs_pre(MDOC_ARGS
)
2044 struct htmlpair tag
;
2047 if (MDOC_BLOCK
!= n
->type
)
2050 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
) {
2051 SCALE_VS_INIT(&su
, 1);
2052 bufcat_su(h
, "margin-top", &su
);
2053 PAIR_STYLE_INIT(&tag
, h
);
2054 print_otag(h
, TAG_DIV
, 1, &tag
);
2057 PAIR_CLASS_INIT(&tag
, "ref");
2058 print_otag(h
, TAG_SPAN
, 1, &tag
);
2066 mdoc_li_pre(MDOC_ARGS
)
2068 struct htmlpair tag
;
2070 PAIR_CLASS_INIT(&tag
, "lit");
2071 print_otag(h
, TAG_SPAN
, 1, &tag
);
2078 mdoc_sy_pre(MDOC_ARGS
)
2080 struct htmlpair tag
;
2082 PAIR_CLASS_INIT(&tag
, "symb");
2083 print_otag(h
, TAG_SPAN
, 1, &tag
);
2090 mdoc_bt_pre(MDOC_ARGS
)
2093 print_text(h
, "is currently in beta test.");
2100 mdoc_ud_pre(MDOC_ARGS
)
2103 print_text(h
, "currently under development.");
2110 mdoc_lb_pre(MDOC_ARGS
)
2112 struct htmlpair tag
;
2114 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
2115 print_otag(h
, TAG_DIV
, 0, NULL
);
2116 PAIR_CLASS_INIT(&tag
, "lib");
2117 print_otag(h
, TAG_SPAN
, 1, &tag
);
2124 mdoc__x_pre(MDOC_ARGS
)
2126 struct htmlpair tag
[2];
2130 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2133 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2136 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2139 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2142 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2145 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2148 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2151 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2154 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2157 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2160 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2163 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2166 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2169 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2176 if (MDOC__U
!= n
->tok
) {
2177 print_otag(h
, TAG_SPAN
, 1, tag
);
2181 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2182 print_otag(h
, TAG_A
, 2, tag
);
2189 mdoc__x_post(MDOC_ARGS
)
2194 h
->flags
|= HTML_NOSPACE
;
2195 print_text(h
, n
->next
? "," : ".");