]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.187 2014/03/30 19:47:48 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>
39 #define MDOC_ARGS const struct mdoc_meta *meta, \
40 const struct mdoc_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static void print_mdoc(MDOC_ARGS
);
53 static void print_mdoc_head(MDOC_ARGS
);
54 static void print_mdoc_node(MDOC_ARGS
);
55 static void print_mdoc_nodelist(MDOC_ARGS
);
56 static void synopsis_pre(struct html
*,
57 const struct mdoc_node
*);
59 static void a2width(const char *, struct roffsu
*);
60 static void a2offs(const char *, struct roffsu
*);
62 static void mdoc_root_post(MDOC_ARGS
);
63 static int mdoc_root_pre(MDOC_ARGS
);
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static int mdoc_bt_pre(MDOC_ARGS
);
77 static int mdoc_bx_pre(MDOC_ARGS
);
78 static int mdoc_cd_pre(MDOC_ARGS
);
79 static int mdoc_d1_pre(MDOC_ARGS
);
80 static int mdoc_dv_pre(MDOC_ARGS
);
81 static int mdoc_fa_pre(MDOC_ARGS
);
82 static int mdoc_fd_pre(MDOC_ARGS
);
83 static int mdoc_fl_pre(MDOC_ARGS
);
84 static int mdoc_fn_pre(MDOC_ARGS
);
85 static int mdoc_ft_pre(MDOC_ARGS
);
86 static int mdoc_em_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_ll_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_sm_pre(MDOC_ARGS
);
114 static int mdoc_sp_pre(MDOC_ARGS
);
115 static int mdoc_ss_pre(MDOC_ARGS
);
116 static int mdoc_sx_pre(MDOC_ARGS
);
117 static int mdoc_sy_pre(MDOC_ARGS
);
118 static int mdoc_ud_pre(MDOC_ARGS
);
119 static int mdoc_va_pre(MDOC_ARGS
);
120 static int mdoc_vt_pre(MDOC_ARGS
);
121 static int mdoc_xr_pre(MDOC_ARGS
);
122 static int mdoc_xx_pre(MDOC_ARGS
);
124 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
125 {mdoc_ap_pre
, NULL
}, /* Ap */
126 {NULL
, NULL
}, /* Dd */
127 {NULL
, NULL
}, /* Dt */
128 {NULL
, NULL
}, /* Os */
129 {mdoc_sh_pre
, NULL
}, /* Sh */
130 {mdoc_ss_pre
, NULL
}, /* Ss */
131 {mdoc_pp_pre
, NULL
}, /* Pp */
132 {mdoc_d1_pre
, NULL
}, /* D1 */
133 {mdoc_d1_pre
, NULL
}, /* Dl */
134 {mdoc_bd_pre
, NULL
}, /* Bd */
135 {NULL
, NULL
}, /* Ed */
136 {mdoc_bl_pre
, NULL
}, /* Bl */
137 {NULL
, NULL
}, /* El */
138 {mdoc_it_pre
, NULL
}, /* It */
139 {mdoc_ad_pre
, NULL
}, /* Ad */
140 {mdoc_an_pre
, NULL
}, /* An */
141 {mdoc_ar_pre
, NULL
}, /* Ar */
142 {mdoc_cd_pre
, NULL
}, /* Cd */
143 {mdoc_fl_pre
, NULL
}, /* Cm */
144 {mdoc_dv_pre
, NULL
}, /* Dv */
145 {mdoc_er_pre
, NULL
}, /* Er */
146 {mdoc_ev_pre
, NULL
}, /* Ev */
147 {mdoc_ex_pre
, NULL
}, /* Ex */
148 {mdoc_fa_pre
, NULL
}, /* Fa */
149 {mdoc_fd_pre
, NULL
}, /* Fd */
150 {mdoc_fl_pre
, NULL
}, /* Fl */
151 {mdoc_fn_pre
, NULL
}, /* Fn */
152 {mdoc_ft_pre
, NULL
}, /* Ft */
153 {mdoc_ic_pre
, NULL
}, /* Ic */
154 {mdoc_in_pre
, NULL
}, /* In */
155 {mdoc_li_pre
, NULL
}, /* Li */
156 {mdoc_nd_pre
, NULL
}, /* Nd */
157 {mdoc_nm_pre
, NULL
}, /* Nm */
158 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
159 {NULL
, NULL
}, /* Ot */
160 {mdoc_pa_pre
, NULL
}, /* Pa */
161 {mdoc_rv_pre
, NULL
}, /* Rv */
162 {NULL
, NULL
}, /* St */
163 {mdoc_va_pre
, NULL
}, /* Va */
164 {mdoc_vt_pre
, NULL
}, /* Vt */
165 {mdoc_xr_pre
, NULL
}, /* Xr */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
177 {NULL
, NULL
}, /* Ac */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
180 {NULL
, NULL
}, /* At */
181 {NULL
, NULL
}, /* Bc */
182 {mdoc_bf_pre
, NULL
}, /* Bf */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
185 {mdoc_xx_pre
, NULL
}, /* Bsx */
186 {mdoc_bx_pre
, NULL
}, /* Bx */
187 {NULL
, NULL
}, /* Db */
188 {NULL
, NULL
}, /* Dc */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
191 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
192 {NULL
, NULL
}, /* Ef */
193 {mdoc_em_pre
, NULL
}, /* Em */
194 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
195 {mdoc_xx_pre
, NULL
}, /* Fx */
196 {mdoc_ms_pre
, NULL
}, /* Ms */
197 {mdoc_igndelim_pre
, NULL
}, /* No */
198 {mdoc_ns_pre
, NULL
}, /* Ns */
199 {mdoc_xx_pre
, NULL
}, /* Nx */
200 {mdoc_xx_pre
, NULL
}, /* Ox */
201 {NULL
, NULL
}, /* Pc */
202 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
205 {NULL
, NULL
}, /* Qc */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
209 {NULL
, NULL
}, /* Re */
210 {mdoc_rs_pre
, NULL
}, /* Rs */
211 {NULL
, NULL
}, /* Sc */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
214 {mdoc_sm_pre
, NULL
}, /* Sm */
215 {mdoc_sx_pre
, NULL
}, /* Sx */
216 {mdoc_sy_pre
, NULL
}, /* Sy */
217 {NULL
, NULL
}, /* Tn */
218 {mdoc_xx_pre
, NULL
}, /* Ux */
219 {NULL
, NULL
}, /* Xc */
220 {NULL
, NULL
}, /* Xo */
221 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
222 {NULL
, NULL
}, /* Fc */
223 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
224 {NULL
, NULL
}, /* Oc */
225 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
226 {NULL
, NULL
}, /* Ek */
227 {mdoc_bt_pre
, NULL
}, /* Bt */
228 {NULL
, NULL
}, /* Hf */
229 {NULL
, NULL
}, /* Fr */
230 {mdoc_ud_pre
, NULL
}, /* Ud */
231 {mdoc_lb_pre
, NULL
}, /* Lb */
232 {mdoc_pp_pre
, NULL
}, /* Lp */
233 {mdoc_lk_pre
, NULL
}, /* Lk */
234 {mdoc_mt_pre
, NULL
}, /* Mt */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
237 {NULL
, NULL
}, /* Brc */
238 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
239 {NULL
, NULL
}, /* Es */ /* TODO */
240 {NULL
, NULL
}, /* En */ /* TODO */
241 {mdoc_xx_pre
, NULL
}, /* Dx */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
243 {mdoc_sp_pre
, NULL
}, /* br */
244 {mdoc_sp_pre
, NULL
}, /* sp */
245 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
246 {NULL
, NULL
}, /* Ta */
247 {mdoc_ll_pre
, NULL
}, /* ll */
250 static const char * const lists
[LIST_MAX
] = {
266 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
269 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
276 * Calculate the scaling unit passed in a `-width' argument. This uses
277 * either a native scaling unit (e.g., 1i, 2m) or the string length of
281 a2width(const char *p
, struct roffsu
*su
)
284 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
286 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
);
335 * Calculate the scaling unit passed in an `-offset' argument. This
336 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
337 * predefined strings (indent, etc.), or the string length of the value.
340 a2offs(const char *p
, struct roffsu
*su
)
343 /* FIXME: "right"? */
345 if (0 == strcmp(p
, "left"))
346 SCALE_HS_INIT(su
, 0);
347 else if (0 == strcmp(p
, "indent"))
348 SCALE_HS_INIT(su
, INDENT
);
349 else if (0 == strcmp(p
, "indent-two"))
350 SCALE_HS_INIT(su
, INDENT
* 2);
351 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
352 SCALE_HS_INIT(su
, html_strlen(p
));
357 print_mdoc(MDOC_ARGS
)
362 PAIR_CLASS_INIT(&tag
, "mandoc");
364 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
366 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
367 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
368 print_mdoc_head(meta
, n
, h
);
370 print_otag(h
, TAG_BODY
, 0, NULL
);
371 print_otag(h
, TAG_DIV
, 1, &tag
);
373 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
375 print_mdoc_nodelist(meta
, n
, h
);
382 print_mdoc_head(MDOC_ARGS
)
387 bufcat_fmt(h
, "%s(%s)", meta
->title
, meta
->msec
);
390 bufcat_fmt(h
, " (%s)", meta
->arch
);
392 print_otag(h
, TAG_TITLE
, 0, NULL
);
393 print_text(h
, h
->buf
);
398 print_mdoc_nodelist(MDOC_ARGS
)
401 print_mdoc_node(meta
, n
, h
);
403 print_mdoc_nodelist(meta
, n
->next
, h
);
408 print_mdoc_node(MDOC_ARGS
)
418 child
= mdoc_root_pre(meta
, n
, h
);
421 /* No tables in this mode... */
422 assert(NULL
== h
->tblt
);
425 * Make sure that if we're in a literal mode already
426 * (i.e., within a <PRE>) don't print the newline.
428 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
429 if ( ! (HTML_LITERAL
& h
->flags
))
430 print_otag(h
, TAG_BR
, 0, NULL
);
431 if (MDOC_DELIMC
& n
->flags
)
432 h
->flags
|= HTML_NOSPACE
;
433 print_text(h
, n
->string
);
434 if (MDOC_DELIMO
& n
->flags
)
435 h
->flags
|= HTML_NOSPACE
;
438 print_eqn(h
, n
->eqn
);
442 * This will take care of initialising all of the table
443 * state data for the first table, then tearing it down
446 print_tbl(h
, n
->span
);
450 * Close out the current table, if it's open, and unset
451 * the "meta" table state. This will be reopened on the
452 * next table element.
459 assert(NULL
== h
->tblt
);
460 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
461 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
465 if (HTML_KEEP
& h
->flags
) {
466 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
467 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
468 h
->flags
&= ~HTML_KEEP
;
469 h
->flags
|= HTML_PREKEEP
;
473 if (child
&& n
->child
)
474 print_mdoc_nodelist(meta
, n
->child
, h
);
480 mdoc_root_post(meta
, n
, h
);
485 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
486 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
493 mdoc_root_post(MDOC_ARGS
)
495 struct htmlpair tag
[3];
498 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
499 PAIR_CLASS_INIT(&tag
[1], "foot");
500 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
501 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
502 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
503 print_otag(h
, TAG_COL
, 1, tag
);
504 print_otag(h
, TAG_COL
, 1, tag
);
506 print_otag(h
, TAG_TBODY
, 0, NULL
);
508 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
510 PAIR_CLASS_INIT(&tag
[0], "foot-date");
511 print_otag(h
, TAG_TD
, 1, tag
);
512 print_text(h
, meta
->date
);
515 PAIR_CLASS_INIT(&tag
[0], "foot-os");
516 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
517 print_otag(h
, TAG_TD
, 2, tag
);
518 print_text(h
, meta
->os
);
525 mdoc_root_pre(MDOC_ARGS
)
527 struct htmlpair tag
[3];
529 char b
[BUFSIZ
], title
[BUFSIZ
];
531 strlcpy(b
, meta
->vol
, BUFSIZ
);
534 strlcat(b
, " (", BUFSIZ
);
535 strlcat(b
, meta
->arch
, BUFSIZ
);
536 strlcat(b
, ")", BUFSIZ
);
539 snprintf(title
, BUFSIZ
- 1, "%s(%s)", meta
->title
, meta
->msec
);
541 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
542 PAIR_CLASS_INIT(&tag
[1], "head");
543 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
544 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
545 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
546 print_otag(h
, TAG_COL
, 1, tag
);
547 print_otag(h
, TAG_COL
, 1, tag
);
548 print_otag(h
, TAG_COL
, 1, tag
);
550 print_otag(h
, TAG_TBODY
, 0, NULL
);
552 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
554 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
555 print_otag(h
, TAG_TD
, 1, tag
);
556 print_text(h
, title
);
559 PAIR_CLASS_INIT(&tag
[0], "head-vol");
560 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
561 print_otag(h
, TAG_TD
, 2, tag
);
565 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
566 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
567 print_otag(h
, TAG_TD
, 2, tag
);
568 print_text(h
, title
);
576 mdoc_sh_pre(MDOC_ARGS
)
580 if (MDOC_BLOCK
== n
->type
) {
581 PAIR_CLASS_INIT(&tag
, "section");
582 print_otag(h
, TAG_DIV
, 1, &tag
);
584 } else if (MDOC_BODY
== n
->type
)
590 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
591 bufcat_id(h
, n
->string
);
592 if (NULL
!= (n
= n
->next
))
597 PAIR_ID_INIT(&tag
, h
->buf
);
598 print_otag(h
, TAG_H1
, 1, &tag
);
600 print_otag(h
, TAG_H1
, 0, NULL
);
607 mdoc_ss_pre(MDOC_ARGS
)
611 if (MDOC_BLOCK
== n
->type
) {
612 PAIR_CLASS_INIT(&tag
, "subsection");
613 print_otag(h
, TAG_DIV
, 1, &tag
);
615 } else if (MDOC_BODY
== n
->type
)
621 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
622 bufcat_id(h
, n
->string
);
623 if (NULL
!= (n
= n
->next
))
628 PAIR_ID_INIT(&tag
, h
->buf
);
629 print_otag(h
, TAG_H2
, 1, &tag
);
631 print_otag(h
, TAG_H2
, 0, NULL
);
639 mdoc_fl_pre(MDOC_ARGS
)
643 PAIR_CLASS_INIT(&tag
, "flag");
644 print_otag(h
, TAG_B
, 1, &tag
);
646 /* `Cm' has no leading hyphen. */
648 if (MDOC_Cm
== n
->tok
)
651 print_text(h
, "\\-");
654 h
->flags
|= HTML_NOSPACE
;
655 else if (n
->next
&& n
->next
->line
== n
->line
)
656 h
->flags
|= HTML_NOSPACE
;
664 mdoc_nd_pre(MDOC_ARGS
)
668 if (MDOC_BODY
!= n
->type
)
671 /* XXX: this tag in theory can contain block elements. */
673 print_text(h
, "\\(em");
674 PAIR_CLASS_INIT(&tag
, "desc");
675 print_otag(h
, TAG_SPAN
, 1, &tag
);
681 mdoc_nm_pre(MDOC_ARGS
)
690 PAIR_CLASS_INIT(&tag
, "name");
691 print_otag(h
, TAG_B
, 1, &tag
);
692 if (NULL
== n
->child
&& meta
->name
)
693 print_text(h
, meta
->name
);
696 print_otag(h
, TAG_TD
, 0, NULL
);
697 if (NULL
== n
->child
&& meta
->name
)
698 print_text(h
, meta
->name
);
701 print_otag(h
, TAG_TD
, 0, NULL
);
708 PAIR_CLASS_INIT(&tag
, "synopsis");
709 print_otag(h
, TAG_TABLE
, 1, &tag
);
711 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
712 if (MDOC_TEXT
== n
->type
)
713 len
+= html_strlen(n
->string
);
715 if (0 == len
&& meta
->name
)
716 len
= html_strlen(meta
->name
);
718 SCALE_HS_INIT(&su
, (double)len
);
720 bufcat_su(h
, "width", &su
);
721 PAIR_STYLE_INIT(&tag
, h
);
722 print_otag(h
, TAG_COL
, 1, &tag
);
723 print_otag(h
, TAG_COL
, 0, NULL
);
724 print_otag(h
, TAG_TBODY
, 0, NULL
);
725 print_otag(h
, TAG_TR
, 0, NULL
);
732 mdoc_xr_pre(MDOC_ARGS
)
734 struct htmlpair tag
[2];
736 if (NULL
== n
->child
)
739 PAIR_CLASS_INIT(&tag
[0], "link-man");
742 buffmt_man(h
, n
->child
->string
,
744 n
->child
->next
->string
: NULL
);
745 PAIR_HREF_INIT(&tag
[1], h
->buf
);
746 print_otag(h
, TAG_A
, 2, tag
);
748 print_otag(h
, TAG_A
, 1, tag
);
751 print_text(h
, n
->string
);
753 if (NULL
== (n
= n
->next
))
756 h
->flags
|= HTML_NOSPACE
;
758 h
->flags
|= HTML_NOSPACE
;
759 print_text(h
, n
->string
);
760 h
->flags
|= HTML_NOSPACE
;
768 mdoc_ns_pre(MDOC_ARGS
)
771 if ( ! (MDOC_LINE
& n
->flags
))
772 h
->flags
|= HTML_NOSPACE
;
779 mdoc_ar_pre(MDOC_ARGS
)
783 PAIR_CLASS_INIT(&tag
, "arg");
784 print_otag(h
, TAG_I
, 1, &tag
);
791 mdoc_xx_pre(MDOC_ARGS
)
820 PAIR_CLASS_INIT(&tag
, "unix");
821 print_otag(h
, TAG_SPAN
, 1, &tag
);
826 h
->flags
|= HTML_KEEP
;
827 print_text(h
, n
->child
->string
);
836 mdoc_bx_pre(MDOC_ARGS
)
840 PAIR_CLASS_INIT(&tag
, "unix");
841 print_otag(h
, TAG_SPAN
, 1, &tag
);
843 if (NULL
!= (n
= n
->child
)) {
844 print_text(h
, n
->string
);
845 h
->flags
|= HTML_NOSPACE
;
846 print_text(h
, "BSD");
848 print_text(h
, "BSD");
852 if (NULL
!= (n
= n
->next
)) {
853 h
->flags
|= HTML_NOSPACE
;
855 h
->flags
|= HTML_NOSPACE
;
856 print_text(h
, n
->string
);
864 mdoc_it_pre(MDOC_ARGS
)
868 struct htmlpair tag
[2];
869 const struct mdoc_node
*bl
;
872 while (bl
&& MDOC_Bl
!= bl
->tok
)
877 type
= bl
->norm
->Bl
.type
;
880 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
884 if (MDOC_HEAD
== n
->type
) {
905 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
906 bufcat_su(h
, "margin-top", &su
);
907 PAIR_STYLE_INIT(&tag
[1], h
);
908 print_otag(h
, TAG_DT
, 2, tag
);
909 if (LIST_diag
!= type
)
911 PAIR_CLASS_INIT(&tag
[0], "diag");
912 print_otag(h
, TAG_B
, 1, tag
);
919 } else if (MDOC_BODY
== n
->type
) {
930 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
931 bufcat_su(h
, "margin-top", &su
);
932 PAIR_STYLE_INIT(&tag
[1], h
);
933 print_otag(h
, TAG_LI
, 2, tag
);
944 if (NULL
== bl
->norm
->Bl
.width
) {
945 print_otag(h
, TAG_DD
, 1, tag
);
948 a2width(bl
->norm
->Bl
.width
, &su
);
949 bufcat_su(h
, "margin-left", &su
);
950 PAIR_STYLE_INIT(&tag
[1], h
);
951 print_otag(h
, TAG_DD
, 2, tag
);
954 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
955 bufcat_su(h
, "margin-top", &su
);
956 PAIR_STYLE_INIT(&tag
[1], h
);
957 print_otag(h
, TAG_TD
, 2, tag
);
965 print_otag(h
, TAG_TR
, 1, tag
);
977 mdoc_bl_pre(MDOC_ARGS
)
980 struct htmlpair tag
[3];
984 if (MDOC_BODY
== n
->type
) {
985 if (LIST_column
== n
->norm
->Bl
.type
)
986 print_otag(h
, TAG_TBODY
, 0, NULL
);
990 if (MDOC_HEAD
== n
->type
) {
991 if (LIST_column
!= n
->norm
->Bl
.type
)
995 * For each column, print out the <COL> tag with our
996 * suggested width. The last column gets min-width, as
997 * in terminal mode it auto-sizes to the width of the
998 * screen and we want to preserve that behaviour.
1001 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1003 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1004 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1005 bufcat_su(h
, "width", &su
);
1007 bufcat_su(h
, "min-width", &su
);
1008 PAIR_STYLE_INIT(&tag
[0], h
);
1009 print_otag(h
, TAG_COL
, 1, tag
);
1015 SCALE_VS_INIT(&su
, 0);
1017 bufcat_su(h
, "margin-top", &su
);
1018 bufcat_su(h
, "margin-bottom", &su
);
1019 PAIR_STYLE_INIT(&tag
[0], h
);
1021 assert(lists
[n
->norm
->Bl
.type
]);
1022 strlcpy(buf
, "list ", BUFSIZ
);
1023 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1024 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1026 /* Set the block's left-hand margin. */
1028 if (n
->norm
->Bl
.offs
) {
1029 a2offs(n
->norm
->Bl
.offs
, &su
);
1030 bufcat_su(h
, "margin-left", &su
);
1033 switch (n
->norm
->Bl
.type
) {
1041 print_otag(h
, TAG_UL
, 2, tag
);
1044 print_otag(h
, TAG_OL
, 2, tag
);
1055 print_otag(h
, TAG_DL
, 2, tag
);
1058 print_otag(h
, TAG_TABLE
, 2, tag
);
1070 mdoc_ex_pre(MDOC_ARGS
)
1073 struct htmlpair tag
;
1077 print_otag(h
, TAG_BR
, 0, NULL
);
1079 PAIR_CLASS_INIT(&tag
, "utility");
1081 print_text(h
, "The");
1084 for (n
= n
->child
; n
; n
= n
->next
) {
1085 assert(MDOC_TEXT
== n
->type
);
1087 t
= print_otag(h
, TAG_B
, 1, &tag
);
1088 print_text(h
, n
->string
);
1091 if (nchild
> 2 && n
->next
) {
1092 h
->flags
|= HTML_NOSPACE
;
1096 if (n
->next
&& NULL
== n
->next
->next
)
1097 print_text(h
, "and");
1101 print_text(h
, "utilities exit");
1103 print_text(h
, "utility exits");
1105 print_text(h
, "0 on success, and >0 if an error occurs.");
1112 mdoc_em_pre(MDOC_ARGS
)
1114 struct htmlpair tag
;
1116 PAIR_CLASS_INIT(&tag
, "emph");
1117 print_otag(h
, TAG_SPAN
, 1, &tag
);
1124 mdoc_d1_pre(MDOC_ARGS
)
1126 struct htmlpair tag
[2];
1129 if (MDOC_BLOCK
!= n
->type
)
1132 SCALE_VS_INIT(&su
, 0);
1134 bufcat_su(h
, "margin-top", &su
);
1135 bufcat_su(h
, "margin-bottom", &su
);
1136 PAIR_STYLE_INIT(&tag
[0], h
);
1137 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1139 /* BLOCKQUOTE needs a block body. */
1141 PAIR_CLASS_INIT(&tag
[0], "display");
1142 print_otag(h
, TAG_DIV
, 1, tag
);
1144 if (MDOC_Dl
== n
->tok
) {
1145 PAIR_CLASS_INIT(&tag
[0], "lit");
1146 print_otag(h
, TAG_CODE
, 1, tag
);
1155 mdoc_sx_pre(MDOC_ARGS
)
1157 struct htmlpair tag
[2];
1162 for (n
= n
->child
; n
; ) {
1163 bufcat_id(h
, n
->string
);
1164 if (NULL
!= (n
= n
->next
))
1168 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1169 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1171 print_otag(h
, TAG_I
, 1, tag
);
1172 print_otag(h
, TAG_A
, 2, tag
);
1179 mdoc_bd_pre(MDOC_ARGS
)
1181 struct htmlpair tag
[2];
1183 const struct mdoc_node
*nn
;
1186 if (MDOC_HEAD
== n
->type
)
1189 if (MDOC_BLOCK
== n
->type
) {
1190 comp
= n
->norm
->Bd
.comp
;
1191 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1192 if (MDOC_BLOCK
!= nn
->type
)
1194 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1200 print_otag(h
, TAG_P
, 0, NULL
);
1204 SCALE_HS_INIT(&su
, 0);
1205 if (n
->norm
->Bd
.offs
)
1206 a2offs(n
->norm
->Bd
.offs
, &su
);
1209 bufcat_su(h
, "margin-left", &su
);
1210 PAIR_STYLE_INIT(&tag
[0], h
);
1212 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1213 DISP_literal
!= n
->norm
->Bd
.type
) {
1214 PAIR_CLASS_INIT(&tag
[1], "display");
1215 print_otag(h
, TAG_DIV
, 2, tag
);
1219 PAIR_CLASS_INIT(&tag
[1], "lit display");
1220 print_otag(h
, TAG_PRE
, 2, tag
);
1222 /* This can be recursive: save & set our literal state. */
1224 sv
= h
->flags
& HTML_LITERAL
;
1225 h
->flags
|= HTML_LITERAL
;
1227 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1228 print_mdoc_node(meta
, nn
, h
);
1230 * If the printed node flushes its own line, then we
1231 * needn't do it here as well. This is hacky, but the
1232 * notion of selective eoln whitespace is pretty dumb
1233 * anyway, so don't sweat it.
1255 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1258 print_text(h
, "\n");
1260 h
->flags
|= HTML_NOSPACE
;
1264 h
->flags
&= ~HTML_LITERAL
;
1272 mdoc_pa_pre(MDOC_ARGS
)
1274 struct htmlpair tag
;
1276 PAIR_CLASS_INIT(&tag
, "file");
1277 print_otag(h
, TAG_I
, 1, &tag
);
1284 mdoc_ad_pre(MDOC_ARGS
)
1286 struct htmlpair tag
;
1288 PAIR_CLASS_INIT(&tag
, "addr");
1289 print_otag(h
, TAG_I
, 1, &tag
);
1296 mdoc_an_pre(MDOC_ARGS
)
1298 struct htmlpair tag
;
1300 /* TODO: -split and -nosplit (see termp_an_pre()). */
1302 PAIR_CLASS_INIT(&tag
, "author");
1303 print_otag(h
, TAG_SPAN
, 1, &tag
);
1310 mdoc_cd_pre(MDOC_ARGS
)
1312 struct htmlpair tag
;
1315 PAIR_CLASS_INIT(&tag
, "config");
1316 print_otag(h
, TAG_B
, 1, &tag
);
1323 mdoc_dv_pre(MDOC_ARGS
)
1325 struct htmlpair tag
;
1327 PAIR_CLASS_INIT(&tag
, "define");
1328 print_otag(h
, TAG_SPAN
, 1, &tag
);
1335 mdoc_ev_pre(MDOC_ARGS
)
1337 struct htmlpair tag
;
1339 PAIR_CLASS_INIT(&tag
, "env");
1340 print_otag(h
, TAG_SPAN
, 1, &tag
);
1347 mdoc_er_pre(MDOC_ARGS
)
1349 struct htmlpair tag
;
1351 PAIR_CLASS_INIT(&tag
, "errno");
1352 print_otag(h
, TAG_SPAN
, 1, &tag
);
1359 mdoc_fa_pre(MDOC_ARGS
)
1361 const struct mdoc_node
*nn
;
1362 struct htmlpair tag
;
1365 PAIR_CLASS_INIT(&tag
, "farg");
1366 if (n
->parent
->tok
!= MDOC_Fo
) {
1367 print_otag(h
, TAG_I
, 1, &tag
);
1371 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1372 t
= print_otag(h
, TAG_I
, 1, &tag
);
1373 print_text(h
, nn
->string
);
1376 h
->flags
|= HTML_NOSPACE
;
1381 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1382 h
->flags
|= HTML_NOSPACE
;
1392 mdoc_fd_pre(MDOC_ARGS
)
1394 struct htmlpair tag
[2];
1402 if (NULL
== (n
= n
->child
))
1405 assert(MDOC_TEXT
== n
->type
);
1407 if (strcmp(n
->string
, "#include")) {
1408 PAIR_CLASS_INIT(&tag
[0], "macro");
1409 print_otag(h
, TAG_B
, 1, tag
);
1413 PAIR_CLASS_INIT(&tag
[0], "includes");
1414 print_otag(h
, TAG_B
, 1, tag
);
1415 print_text(h
, n
->string
);
1417 if (NULL
!= (n
= n
->next
)) {
1418 assert(MDOC_TEXT
== n
->type
);
1419 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1420 n
->string
+ 1 : n
->string
, BUFSIZ
);
1423 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1426 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1429 if (h
->base_includes
) {
1430 buffmt_includes(h
, buf
);
1431 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1435 t
= print_otag(h
, TAG_A
, i
, tag
);
1436 print_text(h
, n
->string
);
1442 for ( ; n
; n
= n
->next
) {
1443 assert(MDOC_TEXT
== n
->type
);
1444 print_text(h
, n
->string
);
1453 mdoc_vt_pre(MDOC_ARGS
)
1455 struct htmlpair tag
;
1457 if (MDOC_BLOCK
== n
->type
) {
1460 } else if (MDOC_ELEM
== n
->type
) {
1462 } else if (MDOC_HEAD
== n
->type
)
1465 PAIR_CLASS_INIT(&tag
, "type");
1466 print_otag(h
, TAG_SPAN
, 1, &tag
);
1473 mdoc_ft_pre(MDOC_ARGS
)
1475 struct htmlpair tag
;
1478 PAIR_CLASS_INIT(&tag
, "ftype");
1479 print_otag(h
, TAG_I
, 1, &tag
);
1486 mdoc_fn_pre(MDOC_ARGS
)
1489 struct htmlpair tag
[2];
1491 const char *sp
, *ep
;
1494 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1497 /* Split apart into type and name. */
1498 assert(n
->child
->string
);
1499 sp
= n
->child
->string
;
1501 ep
= strchr(sp
, ' ');
1503 PAIR_CLASS_INIT(&tag
[0], "ftype");
1504 t
= print_otag(h
, TAG_I
, 1, tag
);
1507 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1508 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1510 print_text(h
, nbuf
);
1512 ep
= strchr(sp
, ' ');
1517 PAIR_CLASS_INIT(&tag
[0], "fname");
1520 * FIXME: only refer to IDs that we know exist.
1524 if (MDOC_SYNPRETTY
& n
->flags
) {
1526 html_idcat(nbuf
, sp
, BUFSIZ
);
1527 PAIR_ID_INIT(&tag
[1], nbuf
);
1529 strlcpy(nbuf
, "#", BUFSIZ
);
1530 html_idcat(nbuf
, sp
, BUFSIZ
);
1531 PAIR_HREF_INIT(&tag
[1], nbuf
);
1535 t
= print_otag(h
, TAG_B
, 1, tag
);
1538 strlcpy(nbuf
, sp
, BUFSIZ
);
1539 print_text(h
, nbuf
);
1544 h
->flags
|= HTML_NOSPACE
;
1546 h
->flags
|= HTML_NOSPACE
;
1548 PAIR_CLASS_INIT(&tag
[0], "farg");
1550 bufcat_style(h
, "white-space", "nowrap");
1551 PAIR_STYLE_INIT(&tag
[1], h
);
1553 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1555 if (MDOC_SYNPRETTY
& n
->flags
)
1557 t
= print_otag(h
, TAG_I
, i
, tag
);
1558 print_text(h
, n
->string
);
1561 h
->flags
|= HTML_NOSPACE
;
1566 h
->flags
|= HTML_NOSPACE
;
1570 h
->flags
|= HTML_NOSPACE
;
1580 mdoc_sm_pre(MDOC_ARGS
)
1583 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1584 if (0 == strcmp("on", n
->child
->string
)) {
1586 * FIXME: no p->col to check. Thus, if we have
1593 * the "3" is preceded by a space.
1595 h
->flags
&= ~HTML_NOSPACE
;
1596 h
->flags
&= ~HTML_NONOSPACE
;
1598 h
->flags
|= HTML_NONOSPACE
;
1605 mdoc_ll_pre(MDOC_ARGS
)
1613 mdoc_pp_pre(MDOC_ARGS
)
1616 print_otag(h
, TAG_P
, 0, NULL
);
1622 mdoc_sp_pre(MDOC_ARGS
)
1625 struct htmlpair tag
;
1627 SCALE_VS_INIT(&su
, 1);
1629 if (MDOC_sp
== n
->tok
) {
1630 if (NULL
!= (n
= n
->child
))
1631 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1632 SCALE_VS_INIT(&su
, atoi(n
->string
));
1637 bufcat_su(h
, "height", &su
);
1638 PAIR_STYLE_INIT(&tag
, h
);
1639 print_otag(h
, TAG_DIV
, 1, &tag
);
1641 /* So the div isn't empty: */
1642 print_text(h
, "\\~");
1650 mdoc_lk_pre(MDOC_ARGS
)
1652 struct htmlpair tag
[2];
1654 if (NULL
== (n
= n
->child
))
1657 assert(MDOC_TEXT
== n
->type
);
1659 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1660 PAIR_HREF_INIT(&tag
[1], n
->string
);
1662 print_otag(h
, TAG_A
, 2, tag
);
1664 if (NULL
== n
->next
)
1665 print_text(h
, n
->string
);
1667 for (n
= n
->next
; n
; n
= n
->next
)
1668 print_text(h
, n
->string
);
1676 mdoc_mt_pre(MDOC_ARGS
)
1678 struct htmlpair tag
[2];
1681 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1683 for (n
= n
->child
; n
; n
= n
->next
) {
1684 assert(MDOC_TEXT
== n
->type
);
1687 bufcat(h
, "mailto:");
1688 bufcat(h
, n
->string
);
1690 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1691 t
= print_otag(h
, TAG_A
, 2, tag
);
1692 print_text(h
, n
->string
);
1702 mdoc_fo_pre(MDOC_ARGS
)
1704 struct htmlpair tag
;
1707 if (MDOC_BODY
== n
->type
) {
1708 h
->flags
|= HTML_NOSPACE
;
1710 h
->flags
|= HTML_NOSPACE
;
1712 } else if (MDOC_BLOCK
== n
->type
) {
1717 /* XXX: we drop non-initial arguments as per groff. */
1720 assert(n
->child
->string
);
1722 PAIR_CLASS_INIT(&tag
, "fname");
1723 t
= print_otag(h
, TAG_B
, 1, &tag
);
1724 print_text(h
, n
->child
->string
);
1732 mdoc_fo_post(MDOC_ARGS
)
1735 if (MDOC_BODY
!= n
->type
)
1737 h
->flags
|= HTML_NOSPACE
;
1739 h
->flags
|= HTML_NOSPACE
;
1746 mdoc_in_pre(MDOC_ARGS
)
1749 struct htmlpair tag
[2];
1754 PAIR_CLASS_INIT(&tag
[0], "includes");
1755 print_otag(h
, TAG_B
, 1, tag
);
1758 * The first argument of the `In' gets special treatment as
1759 * being a linked value. Subsequent values are printed
1760 * afterward. groff does similarly. This also handles the case
1764 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1765 print_text(h
, "#include");
1768 h
->flags
|= HTML_NOSPACE
;
1770 if (NULL
!= (n
= n
->child
)) {
1771 assert(MDOC_TEXT
== n
->type
);
1773 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1776 if (h
->base_includes
) {
1777 buffmt_includes(h
, n
->string
);
1778 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1782 t
= print_otag(h
, TAG_A
, i
, tag
);
1783 print_text(h
, n
->string
);
1789 h
->flags
|= HTML_NOSPACE
;
1792 for ( ; n
; n
= n
->next
) {
1793 assert(MDOC_TEXT
== n
->type
);
1794 print_text(h
, n
->string
);
1803 mdoc_ic_pre(MDOC_ARGS
)
1805 struct htmlpair tag
;
1807 PAIR_CLASS_INIT(&tag
, "cmd");
1808 print_otag(h
, TAG_B
, 1, &tag
);
1815 mdoc_rv_pre(MDOC_ARGS
)
1817 struct htmlpair tag
;
1822 print_otag(h
, TAG_BR
, 0, NULL
);
1824 PAIR_CLASS_INIT(&tag
, "fname");
1826 print_text(h
, "The");
1829 for (n
= n
->child
; n
; n
= n
->next
) {
1830 assert(MDOC_TEXT
== n
->type
);
1832 t
= print_otag(h
, TAG_B
, 1, &tag
);
1833 print_text(h
, n
->string
);
1836 h
->flags
|= HTML_NOSPACE
;
1837 print_text(h
, "()");
1839 if (nchild
> 2 && n
->next
) {
1840 h
->flags
|= HTML_NOSPACE
;
1844 if (n
->next
&& NULL
== n
->next
->next
)
1845 print_text(h
, "and");
1849 print_text(h
, "functions return");
1851 print_text(h
, "function returns");
1853 print_text(h
, "the value 0 if successful; otherwise the value "
1854 "-1 is returned and the global variable");
1856 PAIR_CLASS_INIT(&tag
, "var");
1857 t
= print_otag(h
, TAG_B
, 1, &tag
);
1858 print_text(h
, "errno");
1860 print_text(h
, "is set to indicate the error.");
1867 mdoc_va_pre(MDOC_ARGS
)
1869 struct htmlpair tag
;
1871 PAIR_CLASS_INIT(&tag
, "var");
1872 print_otag(h
, TAG_B
, 1, &tag
);
1879 mdoc_ap_pre(MDOC_ARGS
)
1882 h
->flags
|= HTML_NOSPACE
;
1883 print_text(h
, "\\(aq");
1884 h
->flags
|= HTML_NOSPACE
;
1891 mdoc_bf_pre(MDOC_ARGS
)
1893 struct htmlpair tag
[2];
1896 if (MDOC_HEAD
== n
->type
)
1898 else if (MDOC_BODY
!= n
->type
)
1901 if (FONT_Em
== n
->norm
->Bf
.font
)
1902 PAIR_CLASS_INIT(&tag
[0], "emph");
1903 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1904 PAIR_CLASS_INIT(&tag
[0], "symb");
1905 else if (FONT_Li
== n
->norm
->Bf
.font
)
1906 PAIR_CLASS_INIT(&tag
[0], "lit");
1908 PAIR_CLASS_INIT(&tag
[0], "none");
1911 * We want this to be inline-formatted, but needs to be div to
1912 * accept block children.
1915 bufcat_style(h
, "display", "inline");
1916 SCALE_HS_INIT(&su
, 1);
1917 /* Needs a left-margin for spacing. */
1918 bufcat_su(h
, "margin-left", &su
);
1919 PAIR_STYLE_INIT(&tag
[1], h
);
1920 print_otag(h
, TAG_DIV
, 2, tag
);
1927 mdoc_ms_pre(MDOC_ARGS
)
1929 struct htmlpair tag
;
1931 PAIR_CLASS_INIT(&tag
, "symb");
1932 print_otag(h
, TAG_SPAN
, 1, &tag
);
1939 mdoc_igndelim_pre(MDOC_ARGS
)
1942 h
->flags
|= HTML_IGNDELIM
;
1949 mdoc_pf_post(MDOC_ARGS
)
1952 h
->flags
|= HTML_NOSPACE
;
1958 mdoc_rs_pre(MDOC_ARGS
)
1960 struct htmlpair tag
;
1962 if (MDOC_BLOCK
!= n
->type
)
1965 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1966 print_otag(h
, TAG_P
, 0, NULL
);
1968 PAIR_CLASS_INIT(&tag
, "ref");
1969 print_otag(h
, TAG_SPAN
, 1, &tag
);
1977 mdoc_li_pre(MDOC_ARGS
)
1979 struct htmlpair tag
;
1981 PAIR_CLASS_INIT(&tag
, "lit");
1982 print_otag(h
, TAG_CODE
, 1, &tag
);
1989 mdoc_sy_pre(MDOC_ARGS
)
1991 struct htmlpair tag
;
1993 PAIR_CLASS_INIT(&tag
, "symb");
1994 print_otag(h
, TAG_SPAN
, 1, &tag
);
2001 mdoc_bt_pre(MDOC_ARGS
)
2004 print_text(h
, "is currently in beta test.");
2011 mdoc_ud_pre(MDOC_ARGS
)
2014 print_text(h
, "currently under development.");
2021 mdoc_lb_pre(MDOC_ARGS
)
2023 struct htmlpair tag
;
2025 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2026 print_otag(h
, TAG_BR
, 0, NULL
);
2028 PAIR_CLASS_INIT(&tag
, "lib");
2029 print_otag(h
, TAG_SPAN
, 1, &tag
);
2036 mdoc__x_pre(MDOC_ARGS
)
2038 struct htmlpair tag
[2];
2045 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2046 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2047 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2048 print_text(h
, "and");
2051 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2055 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2058 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2061 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2065 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2069 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2072 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2075 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2078 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2081 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2084 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2087 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2090 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2097 if (MDOC__U
!= n
->tok
) {
2098 print_otag(h
, t
, 1, tag
);
2102 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2103 print_otag(h
, TAG_A
, 2, tag
);
2111 mdoc__x_post(MDOC_ARGS
)
2114 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2115 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2116 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2121 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2124 h
->flags
|= HTML_NOSPACE
;
2125 print_text(h
, n
->next
? "," : ".");
2131 mdoc_bk_pre(MDOC_ARGS
)
2140 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2141 h
->flags
|= HTML_PREKEEP
;
2154 mdoc_bk_post(MDOC_ARGS
)
2157 if (MDOC_BODY
== n
->type
)
2158 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2164 mdoc_quote_pre(MDOC_ARGS
)
2166 struct htmlpair tag
;
2168 if (MDOC_BODY
!= n
->type
)
2175 print_text(h
, "\\(la");
2180 print_text(h
, "\\(lC");
2185 print_text(h
, "\\(lB");
2190 print_text(h
, "\\(lB");
2191 h
->flags
|= HTML_NOSPACE
;
2192 PAIR_CLASS_INIT(&tag
, "opt");
2193 print_otag(h
, TAG_SPAN
, 1, &tag
);
2204 print_text(h
, "\\(lq");
2212 print_text(h
, "\\(oq");
2213 h
->flags
|= HTML_NOSPACE
;
2214 PAIR_CLASS_INIT(&tag
, "lit");
2215 print_otag(h
, TAG_CODE
, 1, &tag
);
2220 print_text(h
, "\\(oq");
2227 h
->flags
|= HTML_NOSPACE
;
2234 mdoc_quote_post(MDOC_ARGS
)
2237 if (MDOC_BODY
!= n
->type
)
2240 h
->flags
|= HTML_NOSPACE
;
2246 print_text(h
, "\\(ra");
2251 print_text(h
, "\\(rC");
2260 print_text(h
, "\\(rB");
2271 print_text(h
, "\\(rq");
2283 print_text(h
, "\\(cq");