]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.193 2014/07/30 00:19:16 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/types.h>
32 #include "mandoc_aux.h"
40 #define MDOC_ARGS const struct mdoc_meta *meta, \
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 int mdoc_ar_pre(MDOC_ARGS
);
72 static int mdoc_bd_pre(MDOC_ARGS
);
73 static int mdoc_bf_pre(MDOC_ARGS
);
74 static void mdoc_bk_post(MDOC_ARGS
);
75 static int mdoc_bk_pre(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_pre(MDOC_ARGS
);
97 static int mdoc_lb_pre(MDOC_ARGS
);
98 static int mdoc_li_pre(MDOC_ARGS
);
99 static int mdoc_lk_pre(MDOC_ARGS
);
100 static int mdoc_mt_pre(MDOC_ARGS
);
101 static int mdoc_ms_pre(MDOC_ARGS
);
102 static int mdoc_nd_pre(MDOC_ARGS
);
103 static int mdoc_nm_pre(MDOC_ARGS
);
104 static int mdoc_ns_pre(MDOC_ARGS
);
105 static int mdoc_pa_pre(MDOC_ARGS
);
106 static void mdoc_pf_post(MDOC_ARGS
);
107 static int mdoc_pp_pre(MDOC_ARGS
);
108 static void mdoc_quote_post(MDOC_ARGS
);
109 static int mdoc_quote_pre(MDOC_ARGS
);
110 static int mdoc_rs_pre(MDOC_ARGS
);
111 static int mdoc_rv_pre(MDOC_ARGS
);
112 static int mdoc_sh_pre(MDOC_ARGS
);
113 static int mdoc_skip_pre(MDOC_ARGS
);
114 static int mdoc_sm_pre(MDOC_ARGS
);
115 static int mdoc_sp_pre(MDOC_ARGS
);
116 static int mdoc_ss_pre(MDOC_ARGS
);
117 static int mdoc_sx_pre(MDOC_ARGS
);
118 static int mdoc_sy_pre(MDOC_ARGS
);
119 static int mdoc_ud_pre(MDOC_ARGS
);
120 static int mdoc_va_pre(MDOC_ARGS
);
121 static int mdoc_vt_pre(MDOC_ARGS
);
122 static int mdoc_xr_pre(MDOC_ARGS
);
123 static int mdoc_xx_pre(MDOC_ARGS
);
125 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
126 {mdoc_ap_pre
, NULL
}, /* Ap */
127 {NULL
, NULL
}, /* Dd */
128 {NULL
, NULL
}, /* Dt */
129 {NULL
, NULL
}, /* Os */
130 {mdoc_sh_pre
, NULL
}, /* Sh */
131 {mdoc_ss_pre
, NULL
}, /* Ss */
132 {mdoc_pp_pre
, NULL
}, /* Pp */
133 {mdoc_d1_pre
, NULL
}, /* D1 */
134 {mdoc_d1_pre
, NULL
}, /* Dl */
135 {mdoc_bd_pre
, NULL
}, /* Bd */
136 {NULL
, NULL
}, /* Ed */
137 {mdoc_bl_pre
, NULL
}, /* Bl */
138 {NULL
, NULL
}, /* El */
139 {mdoc_it_pre
, NULL
}, /* It */
140 {mdoc_ad_pre
, NULL
}, /* Ad */
141 {mdoc_an_pre
, NULL
}, /* An */
142 {mdoc_ar_pre
, NULL
}, /* Ar */
143 {mdoc_cd_pre
, NULL
}, /* Cd */
144 {mdoc_fl_pre
, NULL
}, /* Cm */
145 {mdoc_dv_pre
, NULL
}, /* Dv */
146 {mdoc_er_pre
, NULL
}, /* Er */
147 {mdoc_ev_pre
, NULL
}, /* Ev */
148 {mdoc_ex_pre
, NULL
}, /* Ex */
149 {mdoc_fa_pre
, NULL
}, /* Fa */
150 {mdoc_fd_pre
, NULL
}, /* Fd */
151 {mdoc_fl_pre
, NULL
}, /* Fl */
152 {mdoc_fn_pre
, NULL
}, /* Fn */
153 {mdoc_ft_pre
, NULL
}, /* Ft */
154 {mdoc_ic_pre
, NULL
}, /* Ic */
155 {mdoc_in_pre
, NULL
}, /* In */
156 {mdoc_li_pre
, NULL
}, /* Li */
157 {mdoc_nd_pre
, NULL
}, /* Nd */
158 {mdoc_nm_pre
, NULL
}, /* Nm */
159 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
160 {mdoc_ft_pre
, NULL
}, /* Ot */
161 {mdoc_pa_pre
, NULL
}, /* Pa */
162 {mdoc_rv_pre
, NULL
}, /* Rv */
163 {NULL
, NULL
}, /* St */
164 {mdoc_va_pre
, NULL
}, /* Va */
165 {mdoc_vt_pre
, NULL
}, /* Vt */
166 {mdoc_xr_pre
, NULL
}, /* Xr */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
177 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
178 {NULL
, NULL
}, /* Ac */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
180 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
181 {NULL
, NULL
}, /* At */
182 {NULL
, NULL
}, /* Bc */
183 {mdoc_bf_pre
, NULL
}, /* Bf */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
185 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
186 {mdoc_xx_pre
, NULL
}, /* Bsx */
187 {mdoc_bx_pre
, NULL
}, /* Bx */
188 {NULL
, NULL
}, /* Db */
189 {NULL
, NULL
}, /* Dc */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
191 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
192 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
193 {NULL
, NULL
}, /* Ef */
194 {mdoc_em_pre
, NULL
}, /* Em */
195 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
196 {mdoc_xx_pre
, NULL
}, /* Fx */
197 {mdoc_ms_pre
, NULL
}, /* Ms */
198 {mdoc_igndelim_pre
, NULL
}, /* No */
199 {mdoc_ns_pre
, NULL
}, /* Ns */
200 {mdoc_xx_pre
, NULL
}, /* Nx */
201 {mdoc_xx_pre
, NULL
}, /* Ox */
202 {NULL
, NULL
}, /* Pc */
203 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
206 {NULL
, NULL
}, /* Qc */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
209 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
210 {NULL
, NULL
}, /* Re */
211 {mdoc_rs_pre
, NULL
}, /* Rs */
212 {NULL
, NULL
}, /* Sc */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
214 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
215 {mdoc_sm_pre
, NULL
}, /* Sm */
216 {mdoc_sx_pre
, NULL
}, /* Sx */
217 {mdoc_sy_pre
, NULL
}, /* Sy */
218 {NULL
, NULL
}, /* Tn */
219 {mdoc_xx_pre
, NULL
}, /* Ux */
220 {NULL
, NULL
}, /* Xc */
221 {NULL
, NULL
}, /* Xo */
222 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
223 {NULL
, NULL
}, /* Fc */
224 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
225 {NULL
, NULL
}, /* Oc */
226 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
227 {NULL
, NULL
}, /* Ek */
228 {mdoc_bt_pre
, NULL
}, /* Bt */
229 {NULL
, NULL
}, /* Hf */
230 {mdoc_em_pre
, NULL
}, /* Fr */
231 {mdoc_ud_pre
, NULL
}, /* Ud */
232 {mdoc_lb_pre
, NULL
}, /* Lb */
233 {mdoc_pp_pre
, NULL
}, /* Lp */
234 {mdoc_lk_pre
, NULL
}, /* Lk */
235 {mdoc_mt_pre
, NULL
}, /* Mt */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
237 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
238 {NULL
, NULL
}, /* Brc */
239 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
240 {mdoc_skip_pre
, NULL
}, /* Es */
241 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
242 {mdoc_xx_pre
, NULL
}, /* Dx */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
244 {mdoc_sp_pre
, NULL
}, /* br */
245 {mdoc_sp_pre
, NULL
}, /* sp */
246 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
247 {NULL
, NULL
}, /* Ta */
248 {mdoc_skip_pre
, NULL
}, /* ll */
251 static const char * const lists
[LIST_MAX
] = {
268 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
271 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
277 * Calculate the scaling unit passed in a `-width' argument. This uses
278 * either a native scaling unit (e.g., 1i, 2m) or the string length of
282 a2width(const char *p
, struct roffsu
*su
)
285 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
287 su
->scale
= html_strlen(p
);
292 * See the same function in mdoc_term.c for documentation.
295 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
298 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
301 if (n
->prev
->tok
== n
->tok
&&
305 print_otag(h
, TAG_BR
, 0, NULL
);
309 switch (n
->prev
->tok
) {
319 print_otag(h
, TAG_P
, 0, NULL
);
322 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
323 print_otag(h
, TAG_P
, 0, NULL
);
328 print_otag(h
, TAG_BR
, 0, NULL
);
334 * Calculate the scaling unit passed in an `-offset' argument. This
335 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
336 * predefined strings (indent, etc.), or the string length of the value.
339 a2offs(const char *p
, struct roffsu
*su
)
342 /* FIXME: "right"? */
344 if (0 == strcmp(p
, "left"))
345 SCALE_HS_INIT(su
, 0);
346 else if (0 == strcmp(p
, "indent"))
347 SCALE_HS_INIT(su
, INDENT
);
348 else if (0 == strcmp(p
, "indent-two"))
349 SCALE_HS_INIT(su
, INDENT
* 2);
350 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
351 SCALE_HS_INIT(su
, html_strlen(p
));
355 print_mdoc(MDOC_ARGS
)
360 PAIR_CLASS_INIT(&tag
, "mandoc");
362 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
364 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
365 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
366 print_mdoc_head(meta
, n
, h
);
368 print_otag(h
, TAG_BODY
, 0, NULL
);
369 print_otag(h
, TAG_DIV
, 1, &tag
);
371 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
373 print_mdoc_nodelist(meta
, n
, h
);
378 print_mdoc_head(MDOC_ARGS
)
383 bufcat_fmt(h
, "%s(%s)", meta
->title
, meta
->msec
);
386 bufcat_fmt(h
, " (%s)", meta
->arch
);
388 print_otag(h
, TAG_TITLE
, 0, NULL
);
389 print_text(h
, h
->buf
);
393 print_mdoc_nodelist(MDOC_ARGS
)
396 print_mdoc_node(meta
, n
, h
);
398 print_mdoc_nodelist(meta
, n
->next
, h
);
402 print_mdoc_node(MDOC_ARGS
)
412 child
= mdoc_root_pre(meta
, n
, h
);
415 /* No tables in this mode... */
416 assert(NULL
== h
->tblt
);
419 * Make sure that if we're in a literal mode already
420 * (i.e., within a <PRE>) don't print the newline.
422 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
423 if ( ! (HTML_LITERAL
& h
->flags
))
424 print_otag(h
, TAG_BR
, 0, NULL
);
425 if (MDOC_DELIMC
& n
->flags
)
426 h
->flags
|= HTML_NOSPACE
;
427 print_text(h
, n
->string
);
428 if (MDOC_DELIMO
& n
->flags
)
429 h
->flags
|= HTML_NOSPACE
;
432 print_eqn(h
, n
->eqn
);
436 * This will take care of initialising all of the table
437 * state data for the first table, then tearing it down
440 print_tbl(h
, n
->span
);
444 * Close out the current table, if it's open, and unset
445 * the "meta" table state. This will be reopened on the
446 * next table element.
453 assert(NULL
== h
->tblt
);
454 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
455 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
459 if (HTML_KEEP
& h
->flags
) {
460 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
461 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
462 h
->flags
&= ~HTML_KEEP
;
463 h
->flags
|= HTML_PREKEEP
;
467 if (child
&& n
->child
)
468 print_mdoc_nodelist(meta
, n
->child
, h
);
474 mdoc_root_post(meta
, n
, h
);
479 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
480 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
486 mdoc_root_post(MDOC_ARGS
)
488 struct htmlpair tag
[3];
491 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
492 PAIR_CLASS_INIT(&tag
[1], "foot");
493 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
494 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
495 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
496 print_otag(h
, TAG_COL
, 1, tag
);
497 print_otag(h
, TAG_COL
, 1, tag
);
499 print_otag(h
, TAG_TBODY
, 0, NULL
);
501 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
503 PAIR_CLASS_INIT(&tag
[0], "foot-date");
504 print_otag(h
, TAG_TD
, 1, tag
);
505 print_text(h
, meta
->date
);
508 PAIR_CLASS_INIT(&tag
[0], "foot-os");
509 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
510 print_otag(h
, TAG_TD
, 2, tag
);
511 print_text(h
, meta
->os
);
516 mdoc_root_pre(MDOC_ARGS
)
518 struct htmlpair tag
[3];
520 char *volume
, *title
;
522 if (NULL
== meta
->arch
)
523 volume
= mandoc_strdup(meta
->vol
);
525 mandoc_asprintf(&volume
, "%s (%s)",
526 meta
->vol
, meta
->arch
);
528 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
530 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
531 PAIR_CLASS_INIT(&tag
[1], "head");
532 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
533 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
534 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
535 print_otag(h
, TAG_COL
, 1, tag
);
536 print_otag(h
, TAG_COL
, 1, tag
);
537 print_otag(h
, TAG_COL
, 1, tag
);
539 print_otag(h
, TAG_TBODY
, 0, NULL
);
541 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
543 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
544 print_otag(h
, TAG_TD
, 1, tag
);
545 print_text(h
, title
);
548 PAIR_CLASS_INIT(&tag
[0], "head-vol");
549 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
550 print_otag(h
, TAG_TD
, 2, tag
);
551 print_text(h
, volume
);
554 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
555 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
556 print_otag(h
, TAG_TD
, 2, tag
);
557 print_text(h
, title
);
566 mdoc_sh_pre(MDOC_ARGS
)
570 if (MDOC_BLOCK
== n
->type
) {
571 PAIR_CLASS_INIT(&tag
, "section");
572 print_otag(h
, TAG_DIV
, 1, &tag
);
574 } else if (MDOC_BODY
== n
->type
)
580 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
581 bufcat_id(h
, n
->string
);
582 if (NULL
!= (n
= n
->next
))
587 PAIR_ID_INIT(&tag
, h
->buf
);
588 print_otag(h
, TAG_H1
, 1, &tag
);
590 print_otag(h
, TAG_H1
, 0, NULL
);
596 mdoc_ss_pre(MDOC_ARGS
)
600 if (MDOC_BLOCK
== n
->type
) {
601 PAIR_CLASS_INIT(&tag
, "subsection");
602 print_otag(h
, TAG_DIV
, 1, &tag
);
604 } else if (MDOC_BODY
== n
->type
)
610 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
611 bufcat_id(h
, n
->string
);
612 if (NULL
!= (n
= n
->next
))
617 PAIR_ID_INIT(&tag
, h
->buf
);
618 print_otag(h
, TAG_H2
, 1, &tag
);
620 print_otag(h
, TAG_H2
, 0, NULL
);
626 mdoc_fl_pre(MDOC_ARGS
)
630 PAIR_CLASS_INIT(&tag
, "flag");
631 print_otag(h
, TAG_B
, 1, &tag
);
633 /* `Cm' has no leading hyphen. */
635 if (MDOC_Cm
== n
->tok
)
638 print_text(h
, "\\-");
641 h
->flags
|= HTML_NOSPACE
;
642 else if (n
->next
&& n
->next
->line
== n
->line
)
643 h
->flags
|= HTML_NOSPACE
;
649 mdoc_nd_pre(MDOC_ARGS
)
653 if (MDOC_BODY
!= n
->type
)
656 /* XXX: this tag in theory can contain block elements. */
658 print_text(h
, "\\(em");
659 PAIR_CLASS_INIT(&tag
, "desc");
660 print_otag(h
, TAG_SPAN
, 1, &tag
);
665 mdoc_nm_pre(MDOC_ARGS
)
674 PAIR_CLASS_INIT(&tag
, "name");
675 print_otag(h
, TAG_B
, 1, &tag
);
676 if (NULL
== n
->child
&& meta
->name
)
677 print_text(h
, meta
->name
);
680 print_otag(h
, TAG_TD
, 0, NULL
);
681 if (NULL
== n
->child
&& meta
->name
)
682 print_text(h
, meta
->name
);
685 print_otag(h
, TAG_TD
, 0, NULL
);
692 PAIR_CLASS_INIT(&tag
, "synopsis");
693 print_otag(h
, TAG_TABLE
, 1, &tag
);
695 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
696 if (MDOC_TEXT
== n
->type
)
697 len
+= html_strlen(n
->string
);
699 if (0 == len
&& meta
->name
)
700 len
= html_strlen(meta
->name
);
702 SCALE_HS_INIT(&su
, (double)len
);
704 bufcat_su(h
, "width", &su
);
705 PAIR_STYLE_INIT(&tag
, h
);
706 print_otag(h
, TAG_COL
, 1, &tag
);
707 print_otag(h
, TAG_COL
, 0, NULL
);
708 print_otag(h
, TAG_TBODY
, 0, NULL
);
709 print_otag(h
, TAG_TR
, 0, NULL
);
714 mdoc_xr_pre(MDOC_ARGS
)
716 struct htmlpair tag
[2];
718 if (NULL
== n
->child
)
721 PAIR_CLASS_INIT(&tag
[0], "link-man");
724 buffmt_man(h
, n
->child
->string
,
726 n
->child
->next
->string
: NULL
);
727 PAIR_HREF_INIT(&tag
[1], h
->buf
);
728 print_otag(h
, TAG_A
, 2, tag
);
730 print_otag(h
, TAG_A
, 1, tag
);
733 print_text(h
, n
->string
);
735 if (NULL
== (n
= n
->next
))
738 h
->flags
|= HTML_NOSPACE
;
740 h
->flags
|= HTML_NOSPACE
;
741 print_text(h
, n
->string
);
742 h
->flags
|= HTML_NOSPACE
;
748 mdoc_ns_pre(MDOC_ARGS
)
751 if ( ! (MDOC_LINE
& n
->flags
))
752 h
->flags
|= HTML_NOSPACE
;
757 mdoc_ar_pre(MDOC_ARGS
)
761 PAIR_CLASS_INIT(&tag
, "arg");
762 print_otag(h
, TAG_I
, 1, &tag
);
767 mdoc_xx_pre(MDOC_ARGS
)
796 PAIR_CLASS_INIT(&tag
, "unix");
797 print_otag(h
, TAG_SPAN
, 1, &tag
);
802 h
->flags
|= HTML_KEEP
;
803 print_text(h
, n
->child
->string
);
810 mdoc_bx_pre(MDOC_ARGS
)
814 PAIR_CLASS_INIT(&tag
, "unix");
815 print_otag(h
, TAG_SPAN
, 1, &tag
);
817 if (NULL
!= (n
= n
->child
)) {
818 print_text(h
, n
->string
);
819 h
->flags
|= HTML_NOSPACE
;
820 print_text(h
, "BSD");
822 print_text(h
, "BSD");
826 if (NULL
!= (n
= n
->next
)) {
827 h
->flags
|= HTML_NOSPACE
;
829 h
->flags
|= HTML_NOSPACE
;
830 print_text(h
, n
->string
);
837 mdoc_it_pre(MDOC_ARGS
)
841 struct htmlpair tag
[2];
842 const struct mdoc_node
*bl
;
845 while (bl
&& MDOC_Bl
!= bl
->tok
)
850 type
= bl
->norm
->Bl
.type
;
853 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
857 if (MDOC_HEAD
== n
->type
) {
878 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
879 bufcat_su(h
, "margin-top", &su
);
880 PAIR_STYLE_INIT(&tag
[1], h
);
881 print_otag(h
, TAG_DT
, 2, tag
);
882 if (LIST_diag
!= type
)
884 PAIR_CLASS_INIT(&tag
[0], "diag");
885 print_otag(h
, TAG_B
, 1, tag
);
892 } else if (MDOC_BODY
== n
->type
) {
903 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
904 bufcat_su(h
, "margin-top", &su
);
905 PAIR_STYLE_INIT(&tag
[1], h
);
906 print_otag(h
, TAG_LI
, 2, tag
);
917 if (NULL
== bl
->norm
->Bl
.width
) {
918 print_otag(h
, TAG_DD
, 1, tag
);
921 a2width(bl
->norm
->Bl
.width
, &su
);
922 bufcat_su(h
, "margin-left", &su
);
923 PAIR_STYLE_INIT(&tag
[1], h
);
924 print_otag(h
, TAG_DD
, 2, tag
);
927 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
928 bufcat_su(h
, "margin-top", &su
);
929 PAIR_STYLE_INIT(&tag
[1], h
);
930 print_otag(h
, TAG_TD
, 2, tag
);
938 print_otag(h
, TAG_TR
, 1, tag
);
949 mdoc_bl_pre(MDOC_ARGS
)
952 struct htmlpair tag
[3];
956 if (MDOC_BODY
== n
->type
) {
957 if (LIST_column
== n
->norm
->Bl
.type
)
958 print_otag(h
, TAG_TBODY
, 0, NULL
);
962 if (MDOC_HEAD
== n
->type
) {
963 if (LIST_column
!= n
->norm
->Bl
.type
)
967 * For each column, print out the <COL> tag with our
968 * suggested width. The last column gets min-width, as
969 * in terminal mode it auto-sizes to the width of the
970 * screen and we want to preserve that behaviour.
973 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
975 a2width(n
->norm
->Bl
.cols
[i
], &su
);
976 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
977 bufcat_su(h
, "width", &su
);
979 bufcat_su(h
, "min-width", &su
);
980 PAIR_STYLE_INIT(&tag
[0], h
);
981 print_otag(h
, TAG_COL
, 1, tag
);
987 SCALE_VS_INIT(&su
, 0);
989 bufcat_su(h
, "margin-top", &su
);
990 bufcat_su(h
, "margin-bottom", &su
);
991 PAIR_STYLE_INIT(&tag
[0], h
);
993 assert(lists
[n
->norm
->Bl
.type
]);
994 (void)strlcpy(buf
, "list ", BUFSIZ
);
995 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
996 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
998 /* Set the block's left-hand margin. */
1000 if (n
->norm
->Bl
.offs
) {
1001 a2offs(n
->norm
->Bl
.offs
, &su
);
1002 bufcat_su(h
, "margin-left", &su
);
1005 switch (n
->norm
->Bl
.type
) {
1013 print_otag(h
, TAG_UL
, 2, tag
);
1016 print_otag(h
, TAG_OL
, 2, tag
);
1027 print_otag(h
, TAG_DL
, 2, tag
);
1030 print_otag(h
, TAG_TABLE
, 2, tag
);
1041 mdoc_ex_pre(MDOC_ARGS
)
1044 struct htmlpair tag
;
1048 print_otag(h
, TAG_BR
, 0, NULL
);
1050 PAIR_CLASS_INIT(&tag
, "utility");
1052 print_text(h
, "The");
1055 for (n
= n
->child
; n
; n
= n
->next
) {
1056 assert(MDOC_TEXT
== n
->type
);
1058 t
= print_otag(h
, TAG_B
, 1, &tag
);
1059 print_text(h
, n
->string
);
1062 if (nchild
> 2 && n
->next
) {
1063 h
->flags
|= HTML_NOSPACE
;
1067 if (n
->next
&& NULL
== n
->next
->next
)
1068 print_text(h
, "and");
1072 print_text(h
, "utilities exit\\~0");
1074 print_text(h
, "utility exits\\~0");
1076 print_text(h
, "on success, and\\~>0 if an error occurs.");
1081 mdoc_em_pre(MDOC_ARGS
)
1083 struct htmlpair tag
;
1085 PAIR_CLASS_INIT(&tag
, "emph");
1086 print_otag(h
, TAG_SPAN
, 1, &tag
);
1091 mdoc_d1_pre(MDOC_ARGS
)
1093 struct htmlpair tag
[2];
1096 if (MDOC_BLOCK
!= n
->type
)
1099 SCALE_VS_INIT(&su
, 0);
1101 bufcat_su(h
, "margin-top", &su
);
1102 bufcat_su(h
, "margin-bottom", &su
);
1103 PAIR_STYLE_INIT(&tag
[0], h
);
1104 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1106 /* BLOCKQUOTE needs a block body. */
1108 PAIR_CLASS_INIT(&tag
[0], "display");
1109 print_otag(h
, TAG_DIV
, 1, tag
);
1111 if (MDOC_Dl
== n
->tok
) {
1112 PAIR_CLASS_INIT(&tag
[0], "lit");
1113 print_otag(h
, TAG_CODE
, 1, tag
);
1120 mdoc_sx_pre(MDOC_ARGS
)
1122 struct htmlpair tag
[2];
1127 for (n
= n
->child
; n
; ) {
1128 bufcat_id(h
, n
->string
);
1129 if (NULL
!= (n
= n
->next
))
1133 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1134 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1136 print_otag(h
, TAG_I
, 1, tag
);
1137 print_otag(h
, TAG_A
, 2, tag
);
1142 mdoc_bd_pre(MDOC_ARGS
)
1144 struct htmlpair tag
[2];
1146 const struct mdoc_node
*nn
;
1149 if (MDOC_HEAD
== n
->type
)
1152 if (MDOC_BLOCK
== n
->type
) {
1153 comp
= n
->norm
->Bd
.comp
;
1154 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1155 if (MDOC_BLOCK
!= nn
->type
)
1157 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1163 print_otag(h
, TAG_P
, 0, NULL
);
1167 SCALE_HS_INIT(&su
, 0);
1168 if (n
->norm
->Bd
.offs
)
1169 a2offs(n
->norm
->Bd
.offs
, &su
);
1172 bufcat_su(h
, "margin-left", &su
);
1173 PAIR_STYLE_INIT(&tag
[0], h
);
1175 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1176 DISP_literal
!= n
->norm
->Bd
.type
) {
1177 PAIR_CLASS_INIT(&tag
[1], "display");
1178 print_otag(h
, TAG_DIV
, 2, tag
);
1182 PAIR_CLASS_INIT(&tag
[1], "lit display");
1183 print_otag(h
, TAG_PRE
, 2, tag
);
1185 /* This can be recursive: save & set our literal state. */
1187 sv
= h
->flags
& HTML_LITERAL
;
1188 h
->flags
|= HTML_LITERAL
;
1190 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1191 print_mdoc_node(meta
, nn
, h
);
1193 * If the printed node flushes its own line, then we
1194 * needn't do it here as well. This is hacky, but the
1195 * notion of selective eoln whitespace is pretty dumb
1196 * anyway, so don't sweat it.
1218 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1221 print_text(h
, "\n");
1223 h
->flags
|= HTML_NOSPACE
;
1227 h
->flags
&= ~HTML_LITERAL
;
1233 mdoc_pa_pre(MDOC_ARGS
)
1235 struct htmlpair tag
;
1237 PAIR_CLASS_INIT(&tag
, "file");
1238 print_otag(h
, TAG_I
, 1, &tag
);
1243 mdoc_ad_pre(MDOC_ARGS
)
1245 struct htmlpair tag
;
1247 PAIR_CLASS_INIT(&tag
, "addr");
1248 print_otag(h
, TAG_I
, 1, &tag
);
1253 mdoc_an_pre(MDOC_ARGS
)
1255 struct htmlpair tag
;
1257 /* TODO: -split and -nosplit (see termp_an_pre()). */
1259 PAIR_CLASS_INIT(&tag
, "author");
1260 print_otag(h
, TAG_SPAN
, 1, &tag
);
1265 mdoc_cd_pre(MDOC_ARGS
)
1267 struct htmlpair tag
;
1270 PAIR_CLASS_INIT(&tag
, "config");
1271 print_otag(h
, TAG_B
, 1, &tag
);
1276 mdoc_dv_pre(MDOC_ARGS
)
1278 struct htmlpair tag
;
1280 PAIR_CLASS_INIT(&tag
, "define");
1281 print_otag(h
, TAG_SPAN
, 1, &tag
);
1286 mdoc_ev_pre(MDOC_ARGS
)
1288 struct htmlpair tag
;
1290 PAIR_CLASS_INIT(&tag
, "env");
1291 print_otag(h
, TAG_SPAN
, 1, &tag
);
1296 mdoc_er_pre(MDOC_ARGS
)
1298 struct htmlpair tag
;
1300 PAIR_CLASS_INIT(&tag
, "errno");
1301 print_otag(h
, TAG_SPAN
, 1, &tag
);
1306 mdoc_fa_pre(MDOC_ARGS
)
1308 const struct mdoc_node
*nn
;
1309 struct htmlpair tag
;
1312 PAIR_CLASS_INIT(&tag
, "farg");
1313 if (n
->parent
->tok
!= MDOC_Fo
) {
1314 print_otag(h
, TAG_I
, 1, &tag
);
1318 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1319 t
= print_otag(h
, TAG_I
, 1, &tag
);
1320 print_text(h
, nn
->string
);
1323 h
->flags
|= HTML_NOSPACE
;
1328 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1329 h
->flags
|= HTML_NOSPACE
;
1337 mdoc_fd_pre(MDOC_ARGS
)
1339 struct htmlpair tag
[2];
1347 if (NULL
== (n
= n
->child
))
1350 assert(MDOC_TEXT
== n
->type
);
1352 if (strcmp(n
->string
, "#include")) {
1353 PAIR_CLASS_INIT(&tag
[0], "macro");
1354 print_otag(h
, TAG_B
, 1, tag
);
1358 PAIR_CLASS_INIT(&tag
[0], "includes");
1359 print_otag(h
, TAG_B
, 1, tag
);
1360 print_text(h
, n
->string
);
1362 if (NULL
!= (n
= n
->next
)) {
1363 assert(MDOC_TEXT
== n
->type
);
1366 * XXX This is broken and not easy to fix.
1367 * When using -Oincludes, truncation may occur.
1368 * Dynamic allocation wouldn't help because
1369 * passing long strings to buffmt_includes()
1370 * does not work either.
1373 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1374 n
->string
+ 1 : n
->string
, BUFSIZ
);
1377 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1380 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1383 if (h
->base_includes
) {
1384 buffmt_includes(h
, buf
);
1385 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1389 t
= print_otag(h
, TAG_A
, i
, tag
);
1390 print_text(h
, n
->string
);
1396 for ( ; n
; n
= n
->next
) {
1397 assert(MDOC_TEXT
== n
->type
);
1398 print_text(h
, n
->string
);
1405 mdoc_vt_pre(MDOC_ARGS
)
1407 struct htmlpair tag
;
1409 if (MDOC_BLOCK
== n
->type
) {
1412 } else if (MDOC_ELEM
== n
->type
) {
1414 } else if (MDOC_HEAD
== n
->type
)
1417 PAIR_CLASS_INIT(&tag
, "type");
1418 print_otag(h
, TAG_SPAN
, 1, &tag
);
1423 mdoc_ft_pre(MDOC_ARGS
)
1425 struct htmlpair tag
;
1428 PAIR_CLASS_INIT(&tag
, "ftype");
1429 print_otag(h
, TAG_I
, 1, &tag
);
1434 mdoc_fn_pre(MDOC_ARGS
)
1437 struct htmlpair tag
[2];
1439 const char *sp
, *ep
;
1442 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1445 /* Split apart into type and name. */
1446 assert(n
->child
->string
);
1447 sp
= n
->child
->string
;
1449 ep
= strchr(sp
, ' ');
1451 PAIR_CLASS_INIT(&tag
[0], "ftype");
1452 t
= print_otag(h
, TAG_I
, 1, tag
);
1455 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1456 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1458 print_text(h
, nbuf
);
1460 ep
= strchr(sp
, ' ');
1465 PAIR_CLASS_INIT(&tag
[0], "fname");
1468 * FIXME: only refer to IDs that we know exist.
1472 if (MDOC_SYNPRETTY
& n
->flags
) {
1474 html_idcat(nbuf
, sp
, BUFSIZ
);
1475 PAIR_ID_INIT(&tag
[1], nbuf
);
1477 strlcpy(nbuf
, "#", BUFSIZ
);
1478 html_idcat(nbuf
, sp
, BUFSIZ
);
1479 PAIR_HREF_INIT(&tag
[1], nbuf
);
1483 t
= print_otag(h
, TAG_B
, 1, tag
);
1490 h
->flags
|= HTML_NOSPACE
;
1492 h
->flags
|= HTML_NOSPACE
;
1494 PAIR_CLASS_INIT(&tag
[0], "farg");
1496 bufcat_style(h
, "white-space", "nowrap");
1497 PAIR_STYLE_INIT(&tag
[1], h
);
1499 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1501 if (MDOC_SYNPRETTY
& n
->flags
)
1503 t
= print_otag(h
, TAG_I
, i
, tag
);
1504 print_text(h
, n
->string
);
1507 h
->flags
|= HTML_NOSPACE
;
1512 h
->flags
|= HTML_NOSPACE
;
1516 h
->flags
|= HTML_NOSPACE
;
1524 mdoc_sm_pre(MDOC_ARGS
)
1527 if (NULL
== n
->child
)
1528 h
->flags
^= HTML_NONOSPACE
;
1529 else if (0 == strcmp("on", n
->child
->string
))
1530 h
->flags
&= ~HTML_NONOSPACE
;
1532 h
->flags
|= HTML_NONOSPACE
;
1534 if ( ! (HTML_NONOSPACE
& h
->flags
))
1535 h
->flags
&= ~HTML_NOSPACE
;
1541 mdoc_skip_pre(MDOC_ARGS
)
1548 mdoc_pp_pre(MDOC_ARGS
)
1551 print_otag(h
, TAG_P
, 0, NULL
);
1556 mdoc_sp_pre(MDOC_ARGS
)
1559 struct htmlpair tag
;
1561 SCALE_VS_INIT(&su
, 1);
1563 if (MDOC_sp
== n
->tok
) {
1564 if (NULL
!= (n
= n
->child
))
1565 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1566 SCALE_VS_INIT(&su
, atoi(n
->string
));
1571 bufcat_su(h
, "height", &su
);
1572 PAIR_STYLE_INIT(&tag
, h
);
1573 print_otag(h
, TAG_DIV
, 1, &tag
);
1575 /* So the div isn't empty: */
1576 print_text(h
, "\\~");
1583 mdoc_lk_pre(MDOC_ARGS
)
1585 struct htmlpair tag
[2];
1587 if (NULL
== (n
= n
->child
))
1590 assert(MDOC_TEXT
== n
->type
);
1592 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1593 PAIR_HREF_INIT(&tag
[1], n
->string
);
1595 print_otag(h
, TAG_A
, 2, tag
);
1597 if (NULL
== n
->next
)
1598 print_text(h
, n
->string
);
1600 for (n
= n
->next
; n
; n
= n
->next
)
1601 print_text(h
, n
->string
);
1607 mdoc_mt_pre(MDOC_ARGS
)
1609 struct htmlpair tag
[2];
1612 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1614 for (n
= n
->child
; n
; n
= n
->next
) {
1615 assert(MDOC_TEXT
== n
->type
);
1618 bufcat(h
, "mailto:");
1619 bufcat(h
, n
->string
);
1621 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1622 t
= print_otag(h
, TAG_A
, 2, tag
);
1623 print_text(h
, n
->string
);
1631 mdoc_fo_pre(MDOC_ARGS
)
1633 struct htmlpair tag
;
1636 if (MDOC_BODY
== n
->type
) {
1637 h
->flags
|= HTML_NOSPACE
;
1639 h
->flags
|= HTML_NOSPACE
;
1641 } else if (MDOC_BLOCK
== n
->type
) {
1646 /* XXX: we drop non-initial arguments as per groff. */
1649 assert(n
->child
->string
);
1651 PAIR_CLASS_INIT(&tag
, "fname");
1652 t
= print_otag(h
, TAG_B
, 1, &tag
);
1653 print_text(h
, n
->child
->string
);
1659 mdoc_fo_post(MDOC_ARGS
)
1662 if (MDOC_BODY
!= n
->type
)
1664 h
->flags
|= HTML_NOSPACE
;
1666 h
->flags
|= HTML_NOSPACE
;
1671 mdoc_in_pre(MDOC_ARGS
)
1674 struct htmlpair tag
[2];
1679 PAIR_CLASS_INIT(&tag
[0], "includes");
1680 print_otag(h
, TAG_B
, 1, tag
);
1683 * The first argument of the `In' gets special treatment as
1684 * being a linked value. Subsequent values are printed
1685 * afterward. groff does similarly. This also handles the case
1689 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1690 print_text(h
, "#include");
1693 h
->flags
|= HTML_NOSPACE
;
1695 if (NULL
!= (n
= n
->child
)) {
1696 assert(MDOC_TEXT
== n
->type
);
1698 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1701 if (h
->base_includes
) {
1702 buffmt_includes(h
, n
->string
);
1703 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1707 t
= print_otag(h
, TAG_A
, i
, tag
);
1708 print_text(h
, n
->string
);
1714 h
->flags
|= HTML_NOSPACE
;
1717 for ( ; n
; n
= n
->next
) {
1718 assert(MDOC_TEXT
== n
->type
);
1719 print_text(h
, n
->string
);
1726 mdoc_ic_pre(MDOC_ARGS
)
1728 struct htmlpair tag
;
1730 PAIR_CLASS_INIT(&tag
, "cmd");
1731 print_otag(h
, TAG_B
, 1, &tag
);
1736 mdoc_rv_pre(MDOC_ARGS
)
1738 struct htmlpair tag
;
1743 print_otag(h
, TAG_BR
, 0, NULL
);
1745 PAIR_CLASS_INIT(&tag
, "fname");
1749 print_text(h
, "The");
1751 for (n
= n
->child
; n
; n
= n
->next
) {
1752 t
= print_otag(h
, TAG_B
, 1, &tag
);
1753 print_text(h
, n
->string
);
1756 h
->flags
|= HTML_NOSPACE
;
1757 print_text(h
, "()");
1759 if (n
->next
== NULL
)
1763 h
->flags
|= HTML_NOSPACE
;
1766 if (n
->next
->next
== NULL
)
1767 print_text(h
, "and");
1771 print_text(h
, "functions return");
1773 print_text(h
, "function returns");
1775 print_text(h
, "the value\\~0 if successful;");
1777 print_text(h
, "Upon successful completion,"
1778 " the value\\~0 is returned;");
1780 print_text(h
, "otherwise the value\\~\\-1 is returned"
1781 " and the global variable");
1783 PAIR_CLASS_INIT(&tag
, "var");
1784 t
= print_otag(h
, TAG_B
, 1, &tag
);
1785 print_text(h
, "errno");
1787 print_text(h
, "is set to indicate the error.");
1792 mdoc_va_pre(MDOC_ARGS
)
1794 struct htmlpair tag
;
1796 PAIR_CLASS_INIT(&tag
, "var");
1797 print_otag(h
, TAG_B
, 1, &tag
);
1802 mdoc_ap_pre(MDOC_ARGS
)
1805 h
->flags
|= HTML_NOSPACE
;
1806 print_text(h
, "\\(aq");
1807 h
->flags
|= HTML_NOSPACE
;
1812 mdoc_bf_pre(MDOC_ARGS
)
1814 struct htmlpair tag
[2];
1817 if (MDOC_HEAD
== n
->type
)
1819 else if (MDOC_BODY
!= n
->type
)
1822 if (FONT_Em
== n
->norm
->Bf
.font
)
1823 PAIR_CLASS_INIT(&tag
[0], "emph");
1824 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1825 PAIR_CLASS_INIT(&tag
[0], "symb");
1826 else if (FONT_Li
== n
->norm
->Bf
.font
)
1827 PAIR_CLASS_INIT(&tag
[0], "lit");
1829 PAIR_CLASS_INIT(&tag
[0], "none");
1832 * We want this to be inline-formatted, but needs to be div to
1833 * accept block children.
1836 bufcat_style(h
, "display", "inline");
1837 SCALE_HS_INIT(&su
, 1);
1838 /* Needs a left-margin for spacing. */
1839 bufcat_su(h
, "margin-left", &su
);
1840 PAIR_STYLE_INIT(&tag
[1], h
);
1841 print_otag(h
, TAG_DIV
, 2, tag
);
1846 mdoc_ms_pre(MDOC_ARGS
)
1848 struct htmlpair tag
;
1850 PAIR_CLASS_INIT(&tag
, "symb");
1851 print_otag(h
, TAG_SPAN
, 1, &tag
);
1856 mdoc_igndelim_pre(MDOC_ARGS
)
1859 h
->flags
|= HTML_IGNDELIM
;
1864 mdoc_pf_post(MDOC_ARGS
)
1867 h
->flags
|= HTML_NOSPACE
;
1871 mdoc_rs_pre(MDOC_ARGS
)
1873 struct htmlpair tag
;
1875 if (MDOC_BLOCK
!= n
->type
)
1878 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1879 print_otag(h
, TAG_P
, 0, NULL
);
1881 PAIR_CLASS_INIT(&tag
, "ref");
1882 print_otag(h
, TAG_SPAN
, 1, &tag
);
1887 mdoc_li_pre(MDOC_ARGS
)
1889 struct htmlpair tag
;
1891 PAIR_CLASS_INIT(&tag
, "lit");
1892 print_otag(h
, TAG_CODE
, 1, &tag
);
1897 mdoc_sy_pre(MDOC_ARGS
)
1899 struct htmlpair tag
;
1901 PAIR_CLASS_INIT(&tag
, "symb");
1902 print_otag(h
, TAG_SPAN
, 1, &tag
);
1907 mdoc_bt_pre(MDOC_ARGS
)
1910 print_text(h
, "is currently in beta test.");
1915 mdoc_ud_pre(MDOC_ARGS
)
1918 print_text(h
, "currently under development.");
1923 mdoc_lb_pre(MDOC_ARGS
)
1925 struct htmlpair tag
;
1927 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1928 print_otag(h
, TAG_BR
, 0, NULL
);
1930 PAIR_CLASS_INIT(&tag
, "lib");
1931 print_otag(h
, TAG_SPAN
, 1, &tag
);
1936 mdoc__x_pre(MDOC_ARGS
)
1938 struct htmlpair tag
[2];
1945 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1946 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1947 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1948 print_text(h
, "and");
1951 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1955 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1958 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1961 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1965 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1969 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1978 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1981 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1984 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1987 PAIR_CLASS_INIT(&tag
[0], "link-ref");
1990 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
1997 if (MDOC__U
!= n
->tok
) {
1998 print_otag(h
, t
, 1, tag
);
2002 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2003 print_otag(h
, TAG_A
, 2, tag
);
2009 mdoc__x_post(MDOC_ARGS
)
2012 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2013 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2014 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2019 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2022 h
->flags
|= HTML_NOSPACE
;
2023 print_text(h
, n
->next
? "," : ".");
2027 mdoc_bk_pre(MDOC_ARGS
)
2036 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2037 h
->flags
|= HTML_PREKEEP
;
2048 mdoc_bk_post(MDOC_ARGS
)
2051 if (MDOC_BODY
== n
->type
)
2052 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2056 mdoc_quote_pre(MDOC_ARGS
)
2058 struct htmlpair tag
;
2060 if (MDOC_BODY
!= n
->type
)
2067 print_text(h
, "\\(la");
2072 print_text(h
, "\\(lC");
2077 print_text(h
, "\\(lB");
2082 print_text(h
, "\\(lB");
2083 h
->flags
|= HTML_NOSPACE
;
2084 PAIR_CLASS_INIT(&tag
, "opt");
2085 print_otag(h
, TAG_SPAN
, 1, &tag
);
2088 if (NULL
== n
->norm
->Es
||
2089 NULL
== n
->norm
->Es
->child
)
2091 print_text(h
, n
->norm
->Es
->child
->string
);
2102 print_text(h
, "\\(lq");
2110 print_text(h
, "\\(oq");
2111 h
->flags
|= HTML_NOSPACE
;
2112 PAIR_CLASS_INIT(&tag
, "lit");
2113 print_otag(h
, TAG_CODE
, 1, &tag
);
2118 print_text(h
, "\\(oq");
2125 h
->flags
|= HTML_NOSPACE
;
2130 mdoc_quote_post(MDOC_ARGS
)
2133 if (MDOC_BODY
!= n
->type
)
2136 if (MDOC_En
!= n
->tok
)
2137 h
->flags
|= HTML_NOSPACE
;
2143 print_text(h
, "\\(ra");
2148 print_text(h
, "\\(rC");
2157 print_text(h
, "\\(rB");
2160 if (NULL
!= n
->norm
->Es
&&
2161 NULL
!= n
->norm
->Es
->child
&&
2162 NULL
!= n
->norm
->Es
->child
->next
) {
2163 h
->flags
|= HTML_NOSPACE
;
2164 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2176 print_text(h
, "\\(rq");
2188 print_text(h
, "\\(cq");