]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.234 2015/09/26 00:22:07 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015 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 AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
38 #define MDOC_ARGS const struct roff_meta *meta, \
39 struct roff_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static void print_mdoc_head(MDOC_ARGS
);
52 static void print_mdoc_node(MDOC_ARGS
);
53 static void print_mdoc_nodelist(MDOC_ARGS
);
54 static void synopsis_pre(struct html
*,
55 const struct roff_node
*);
57 static void a2width(const char *, struct roffsu
*);
59 static void mdoc_root_post(MDOC_ARGS
);
60 static int mdoc_root_pre(MDOC_ARGS
);
62 static void mdoc__x_post(MDOC_ARGS
);
63 static int mdoc__x_pre(MDOC_ARGS
);
64 static int mdoc_ad_pre(MDOC_ARGS
);
65 static int mdoc_an_pre(MDOC_ARGS
);
66 static int mdoc_ap_pre(MDOC_ARGS
);
67 static int mdoc_ar_pre(MDOC_ARGS
);
68 static int mdoc_bd_pre(MDOC_ARGS
);
69 static int mdoc_bf_pre(MDOC_ARGS
);
70 static void mdoc_bk_post(MDOC_ARGS
);
71 static int mdoc_bk_pre(MDOC_ARGS
);
72 static int mdoc_bl_pre(MDOC_ARGS
);
73 static int mdoc_bt_pre(MDOC_ARGS
);
74 static int mdoc_bx_pre(MDOC_ARGS
);
75 static int mdoc_cd_pre(MDOC_ARGS
);
76 static int mdoc_d1_pre(MDOC_ARGS
);
77 static int mdoc_dv_pre(MDOC_ARGS
);
78 static int mdoc_fa_pre(MDOC_ARGS
);
79 static int mdoc_fd_pre(MDOC_ARGS
);
80 static int mdoc_fl_pre(MDOC_ARGS
);
81 static int mdoc_fn_pre(MDOC_ARGS
);
82 static int mdoc_ft_pre(MDOC_ARGS
);
83 static int mdoc_em_pre(MDOC_ARGS
);
84 static void mdoc_eo_post(MDOC_ARGS
);
85 static int mdoc_eo_pre(MDOC_ARGS
);
86 static int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_igndelim_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_pre(MDOC_ARGS
);
95 static int mdoc_lb_pre(MDOC_ARGS
);
96 static int mdoc_li_pre(MDOC_ARGS
);
97 static int mdoc_lk_pre(MDOC_ARGS
);
98 static int mdoc_mt_pre(MDOC_ARGS
);
99 static int mdoc_ms_pre(MDOC_ARGS
);
100 static int mdoc_nd_pre(MDOC_ARGS
);
101 static int mdoc_nm_pre(MDOC_ARGS
);
102 static int mdoc_no_pre(MDOC_ARGS
);
103 static int mdoc_ns_pre(MDOC_ARGS
);
104 static int mdoc_pa_pre(MDOC_ARGS
);
105 static void mdoc_pf_post(MDOC_ARGS
);
106 static int mdoc_pp_pre(MDOC_ARGS
);
107 static void mdoc_quote_post(MDOC_ARGS
);
108 static int mdoc_quote_pre(MDOC_ARGS
);
109 static int mdoc_rs_pre(MDOC_ARGS
);
110 static int mdoc_rv_pre(MDOC_ARGS
);
111 static int mdoc_sh_pre(MDOC_ARGS
);
112 static int mdoc_skip_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 {mdoc_ft_pre
, 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 {mdoc_skip_pre
, 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_eo_pre
, mdoc_eo_post
}, /* Eo */
195 {mdoc_xx_pre
, NULL
}, /* Fx */
196 {mdoc_ms_pre
, NULL
}, /* Ms */
197 {mdoc_no_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 {mdoc_em_pre
, 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 {mdoc_skip_pre
, NULL
}, /* Es */
240 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
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_skip_pre
, NULL
}, /* ll */
250 static const char * const lists
[LIST_MAX
] = {
267 * Calculate the scaling unit passed in a `-width' argument. This uses
268 * either a native scaling unit (e.g., 1i, 2m) or the string length of
272 a2width(const char *p
, struct roffsu
*su
)
275 if (a2roffsu(p
, su
, SCALE_MAX
) < 2) {
277 su
->scale
= html_strlen(p
);
278 } else if (su
->scale
< 0.0)
283 * See the same function in mdoc_term.c for documentation.
286 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
289 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
292 if (n
->prev
->tok
== n
->tok
&&
296 print_otag(h
, TAG_BR
, 0, NULL
);
300 switch (n
->prev
->tok
) {
313 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
319 print_otag(h
, TAG_BR
, 0, NULL
);
325 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
331 PAIR_CLASS_INIT(&tag
, "mandoc");
332 h
= (struct html
*)arg
;
334 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
336 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
337 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
338 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
340 print_otag(h
, TAG_BODY
, 0, NULL
);
341 print_otag(h
, TAG_DIV
, 1, &tag
);
343 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
345 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
346 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
347 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
353 print_mdoc_head(MDOC_ARGS
)
358 bufcat(h
, meta
->title
);
360 bufcat_fmt(h
, "(%s)", meta
->msec
);
362 bufcat_fmt(h
, " (%s)", meta
->arch
);
364 print_otag(h
, TAG_TITLE
, 0, NULL
);
365 print_text(h
, h
->buf
);
369 print_mdoc_nodelist(MDOC_ARGS
)
373 print_mdoc_node(meta
, n
, h
);
379 print_mdoc_node(MDOC_ARGS
)
386 n
->flags
&= ~MDOC_ENDED
;
390 /* No tables in this mode... */
391 assert(NULL
== h
->tblt
);
394 * Make sure that if we're in a literal mode already
395 * (i.e., within a <PRE>) don't print the newline.
397 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
398 if ( ! (HTML_LITERAL
& h
->flags
))
399 print_otag(h
, TAG_BR
, 0, NULL
);
400 if (MDOC_DELIMC
& n
->flags
)
401 h
->flags
|= HTML_NOSPACE
;
402 print_text(h
, n
->string
);
403 if (MDOC_DELIMO
& n
->flags
)
404 h
->flags
|= HTML_NOSPACE
;
407 if (n
->flags
& MDOC_LINE
)
409 print_eqn(h
, n
->eqn
);
413 * This will take care of initialising all of the table
414 * state data for the first table, then tearing it down
417 print_tbl(h
, n
->span
);
421 * Close out the current table, if it's open, and unset
422 * the "meta" table state. This will be reopened on the
423 * next table element.
425 if (h
->tblt
!= NULL
) {
429 assert(h
->tblt
== NULL
);
430 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
431 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
435 if (h
->flags
& HTML_KEEP
&& n
->flags
& MDOC_LINE
) {
436 h
->flags
&= ~HTML_KEEP
;
437 h
->flags
|= HTML_PREKEEP
;
440 if (child
&& n
->child
)
441 print_mdoc_nodelist(meta
, n
->child
, h
);
449 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
451 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
452 if (n
->end
!= ENDBODY_NOT
)
453 n
->body
->flags
|= MDOC_ENDED
;
454 if (n
->end
== ENDBODY_NOSPACE
)
455 h
->flags
|= HTML_NOSPACE
;
461 mdoc_root_post(MDOC_ARGS
)
466 PAIR_CLASS_INIT(&tag
, "foot");
467 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
469 print_otag(h
, TAG_TBODY
, 0, NULL
);
471 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
473 PAIR_CLASS_INIT(&tag
, "foot-date");
474 print_otag(h
, TAG_TD
, 1, &tag
);
475 print_text(h
, meta
->date
);
478 PAIR_CLASS_INIT(&tag
, "foot-os");
479 print_otag(h
, TAG_TD
, 1, &tag
);
480 print_text(h
, meta
->os
);
485 mdoc_root_pre(MDOC_ARGS
)
489 char *volume
, *title
;
491 if (NULL
== meta
->arch
)
492 volume
= mandoc_strdup(meta
->vol
);
494 mandoc_asprintf(&volume
, "%s (%s)",
495 meta
->vol
, meta
->arch
);
497 if (NULL
== meta
->msec
)
498 title
= mandoc_strdup(meta
->title
);
500 mandoc_asprintf(&title
, "%s(%s)",
501 meta
->title
, meta
->msec
);
503 PAIR_CLASS_INIT(&tag
, "head");
504 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
506 print_otag(h
, TAG_TBODY
, 0, NULL
);
508 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
510 PAIR_CLASS_INIT(&tag
, "head-ltitle");
511 print_otag(h
, TAG_TD
, 1, &tag
);
512 print_text(h
, title
);
515 PAIR_CLASS_INIT(&tag
, "head-vol");
516 print_otag(h
, TAG_TD
, 1, &tag
);
517 print_text(h
, volume
);
520 PAIR_CLASS_INIT(&tag
, "head-rtitle");
521 print_otag(h
, TAG_TD
, 1, &tag
);
522 print_text(h
, title
);
531 mdoc_sh_pre(MDOC_ARGS
)
537 PAIR_CLASS_INIT(&tag
, "section");
538 print_otag(h
, TAG_DIV
, 1, &tag
);
541 if (n
->sec
== SEC_AUTHORS
)
542 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
551 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
552 bufcat_id(h
, n
->string
);
553 if (NULL
!= (n
= n
->next
))
558 PAIR_ID_INIT(&tag
, h
->buf
);
559 print_otag(h
, TAG_H1
, 1, &tag
);
561 print_otag(h
, TAG_H1
, 0, NULL
);
567 mdoc_ss_pre(MDOC_ARGS
)
571 if (n
->type
== ROFFT_BLOCK
) {
572 PAIR_CLASS_INIT(&tag
, "subsection");
573 print_otag(h
, TAG_DIV
, 1, &tag
);
575 } else if (n
->type
== ROFFT_BODY
)
581 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
582 bufcat_id(h
, n
->string
);
583 if (NULL
!= (n
= n
->next
))
588 PAIR_ID_INIT(&tag
, h
->buf
);
589 print_otag(h
, TAG_H2
, 1, &tag
);
591 print_otag(h
, TAG_H2
, 0, NULL
);
597 mdoc_fl_pre(MDOC_ARGS
)
601 PAIR_CLASS_INIT(&tag
, "flag");
602 print_otag(h
, TAG_B
, 1, &tag
);
604 /* `Cm' has no leading hyphen. */
606 if (MDOC_Cm
== n
->tok
)
609 print_text(h
, "\\-");
611 if ( ! (n
->nchild
== 0 &&
613 n
->next
->type
== ROFFT_TEXT
||
614 n
->next
->flags
& MDOC_LINE
)))
615 h
->flags
|= HTML_NOSPACE
;
621 mdoc_nd_pre(MDOC_ARGS
)
625 if (n
->type
!= ROFFT_BODY
)
628 /* XXX: this tag in theory can contain block elements. */
630 print_text(h
, "\\(em");
631 PAIR_CLASS_INIT(&tag
, "desc");
632 print_otag(h
, TAG_SPAN
, 1, &tag
);
637 mdoc_nm_pre(MDOC_ARGS
)
645 PAIR_CLASS_INIT(&tag
, "name");
646 print_otag(h
, TAG_B
, 1, &tag
);
647 if (NULL
== n
->child
&& meta
->name
)
648 print_text(h
, meta
->name
);
651 print_otag(h
, TAG_TD
, 0, NULL
);
652 PAIR_CLASS_INIT(&tag
, "name");
653 print_otag(h
, TAG_B
, 1, &tag
);
654 if (NULL
== n
->child
&& meta
->name
)
655 print_text(h
, meta
->name
);
658 print_otag(h
, TAG_TD
, 0, NULL
);
665 PAIR_CLASS_INIT(&tag
, "synopsis");
666 print_otag(h
, TAG_TABLE
, 1, &tag
);
668 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
669 if (n
->type
== ROFFT_TEXT
)
670 len
+= html_strlen(n
->string
);
672 if (0 == len
&& meta
->name
)
673 len
= html_strlen(meta
->name
);
675 SCALE_HS_INIT(&su
, len
);
677 bufcat_su(h
, "width", &su
);
678 PAIR_STYLE_INIT(&tag
, h
);
679 print_otag(h
, TAG_COL
, 1, &tag
);
680 print_otag(h
, TAG_COL
, 0, NULL
);
681 print_otag(h
, TAG_TBODY
, 0, NULL
);
682 print_otag(h
, TAG_TR
, 0, NULL
);
687 mdoc_xr_pre(MDOC_ARGS
)
689 struct htmlpair tag
[2];
691 if (NULL
== n
->child
)
694 PAIR_CLASS_INIT(&tag
[0], "link-man");
697 buffmt_man(h
, n
->child
->string
,
699 n
->child
->next
->string
: NULL
);
700 PAIR_HREF_INIT(&tag
[1], h
->buf
);
701 print_otag(h
, TAG_A
, 2, tag
);
703 print_otag(h
, TAG_A
, 1, tag
);
706 print_text(h
, n
->string
);
708 if (NULL
== (n
= n
->next
))
711 h
->flags
|= HTML_NOSPACE
;
713 h
->flags
|= HTML_NOSPACE
;
714 print_text(h
, n
->string
);
715 h
->flags
|= HTML_NOSPACE
;
721 mdoc_ns_pre(MDOC_ARGS
)
724 if ( ! (MDOC_LINE
& n
->flags
))
725 h
->flags
|= HTML_NOSPACE
;
730 mdoc_ar_pre(MDOC_ARGS
)
734 PAIR_CLASS_INIT(&tag
, "arg");
735 print_otag(h
, TAG_I
, 1, &tag
);
740 mdoc_xx_pre(MDOC_ARGS
)
769 PAIR_CLASS_INIT(&tag
, "unix");
770 print_otag(h
, TAG_SPAN
, 1, &tag
);
775 h
->flags
|= HTML_KEEP
;
776 print_text(h
, n
->child
->string
);
783 mdoc_bx_pre(MDOC_ARGS
)
787 PAIR_CLASS_INIT(&tag
, "unix");
788 print_otag(h
, TAG_SPAN
, 1, &tag
);
790 if (NULL
!= (n
= n
->child
)) {
791 print_text(h
, n
->string
);
792 h
->flags
|= HTML_NOSPACE
;
793 print_text(h
, "BSD");
795 print_text(h
, "BSD");
799 if (NULL
!= (n
= n
->next
)) {
800 h
->flags
|= HTML_NOSPACE
;
802 h
->flags
|= HTML_NOSPACE
;
803 print_text(h
, n
->string
);
810 mdoc_it_pre(MDOC_ARGS
)
814 struct htmlpair tag
[2];
815 const struct roff_node
*bl
;
818 while (bl
&& MDOC_Bl
!= bl
->tok
)
823 type
= bl
->norm
->Bl
.type
;
826 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
830 if (n
->type
== ROFFT_HEAD
) {
851 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
852 bufcat_su(h
, "margin-top", &su
);
853 PAIR_STYLE_INIT(&tag
[1], h
);
854 print_otag(h
, TAG_DT
, 2, tag
);
855 if (LIST_diag
!= type
)
857 PAIR_CLASS_INIT(&tag
[0], "diag");
858 print_otag(h
, TAG_B
, 1, tag
);
865 } else if (n
->type
== ROFFT_BODY
) {
876 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
877 bufcat_su(h
, "margin-top", &su
);
878 PAIR_STYLE_INIT(&tag
[1], h
);
879 print_otag(h
, TAG_LI
, 2, tag
);
890 if (NULL
== bl
->norm
->Bl
.width
) {
891 print_otag(h
, TAG_DD
, 1, tag
);
894 a2width(bl
->norm
->Bl
.width
, &su
);
895 bufcat_su(h
, "margin-left", &su
);
896 PAIR_STYLE_INIT(&tag
[1], h
);
897 print_otag(h
, TAG_DD
, 2, tag
);
900 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
901 bufcat_su(h
, "margin-top", &su
);
902 PAIR_STYLE_INIT(&tag
[1], h
);
903 print_otag(h
, TAG_TD
, 2, tag
);
911 print_otag(h
, TAG_TR
, 1, tag
);
922 mdoc_bl_pre(MDOC_ARGS
)
925 struct htmlpair tag
[3];
929 if (n
->type
== ROFFT_BODY
) {
930 if (LIST_column
== n
->norm
->Bl
.type
)
931 print_otag(h
, TAG_TBODY
, 0, NULL
);
935 if (n
->type
== ROFFT_HEAD
) {
936 if (LIST_column
!= n
->norm
->Bl
.type
)
940 * For each column, print out the <COL> tag with our
941 * suggested width. The last column gets min-width, as
942 * in terminal mode it auto-sizes to the width of the
943 * screen and we want to preserve that behaviour.
946 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
948 a2width(n
->norm
->Bl
.cols
[i
], &su
);
949 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
950 bufcat_su(h
, "width", &su
);
952 bufcat_su(h
, "min-width", &su
);
953 PAIR_STYLE_INIT(&tag
[0], h
);
954 print_otag(h
, TAG_COL
, 1, tag
);
960 SCALE_VS_INIT(&su
, 0);
962 bufcat_su(h
, "margin-top", &su
);
963 bufcat_su(h
, "margin-bottom", &su
);
964 PAIR_STYLE_INIT(&tag
[0], h
);
966 assert(lists
[n
->norm
->Bl
.type
]);
967 (void)strlcpy(buf
, "list ", BUFSIZ
);
968 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
969 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
971 /* Set the block's left-hand margin. */
973 if (n
->norm
->Bl
.offs
) {
974 a2width(n
->norm
->Bl
.offs
, &su
);
975 bufcat_su(h
, "margin-left", &su
);
978 switch (n
->norm
->Bl
.type
) {
986 print_otag(h
, TAG_UL
, 2, tag
);
989 print_otag(h
, TAG_OL
, 2, tag
);
1000 print_otag(h
, TAG_DL
, 2, tag
);
1003 print_otag(h
, TAG_TABLE
, 2, tag
);
1014 mdoc_ex_pre(MDOC_ARGS
)
1017 struct htmlpair tag
;
1021 print_otag(h
, TAG_BR
, 0, NULL
);
1023 PAIR_CLASS_INIT(&tag
, "utility");
1025 print_text(h
, "The");
1028 for (n
= n
->child
; n
; n
= n
->next
) {
1029 assert(n
->type
== ROFFT_TEXT
);
1031 t
= print_otag(h
, TAG_B
, 1, &tag
);
1032 print_text(h
, n
->string
);
1035 if (nchild
> 2 && n
->next
) {
1036 h
->flags
|= HTML_NOSPACE
;
1040 if (n
->next
&& NULL
== n
->next
->next
)
1041 print_text(h
, "and");
1045 print_text(h
, "utilities exit\\~0");
1047 print_text(h
, "utility exits\\~0");
1049 print_text(h
, "on success, and\\~>0 if an error occurs.");
1054 mdoc_em_pre(MDOC_ARGS
)
1056 struct htmlpair tag
;
1058 PAIR_CLASS_INIT(&tag
, "emph");
1059 print_otag(h
, TAG_SPAN
, 1, &tag
);
1064 mdoc_d1_pre(MDOC_ARGS
)
1066 struct htmlpair tag
[2];
1069 if (n
->type
!= ROFFT_BLOCK
)
1072 SCALE_VS_INIT(&su
, 0);
1074 bufcat_su(h
, "margin-top", &su
);
1075 bufcat_su(h
, "margin-bottom", &su
);
1076 PAIR_STYLE_INIT(&tag
[0], h
);
1077 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1079 /* BLOCKQUOTE needs a block body. */
1081 PAIR_CLASS_INIT(&tag
[0], "display");
1082 print_otag(h
, TAG_DIV
, 1, tag
);
1084 if (MDOC_Dl
== n
->tok
) {
1085 PAIR_CLASS_INIT(&tag
[0], "lit");
1086 print_otag(h
, TAG_CODE
, 1, tag
);
1093 mdoc_sx_pre(MDOC_ARGS
)
1095 struct htmlpair tag
[2];
1100 for (n
= n
->child
; n
; ) {
1101 bufcat_id(h
, n
->string
);
1102 if (NULL
!= (n
= n
->next
))
1106 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1107 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1109 print_otag(h
, TAG_I
, 1, tag
);
1110 print_otag(h
, TAG_A
, 2, tag
);
1115 mdoc_bd_pre(MDOC_ARGS
)
1117 struct htmlpair tag
[2];
1119 struct roff_node
*nn
;
1122 if (n
->type
== ROFFT_HEAD
)
1125 if (n
->type
== ROFFT_BLOCK
) {
1126 comp
= n
->norm
->Bd
.comp
;
1127 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1128 if (nn
->type
!= ROFFT_BLOCK
)
1130 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1140 /* Handle the -offset argument. */
1142 if (n
->norm
->Bd
.offs
== NULL
||
1143 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1144 SCALE_HS_INIT(&su
, 0);
1145 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1146 SCALE_HS_INIT(&su
, INDENT
);
1147 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1148 SCALE_HS_INIT(&su
, INDENT
* 2);
1150 a2width(n
->norm
->Bd
.offs
, &su
);
1153 bufcat_su(h
, "margin-left", &su
);
1154 PAIR_STYLE_INIT(&tag
[0], h
);
1156 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1157 DISP_literal
!= n
->norm
->Bd
.type
) {
1158 PAIR_CLASS_INIT(&tag
[1], "display");
1159 print_otag(h
, TAG_DIV
, 2, tag
);
1163 PAIR_CLASS_INIT(&tag
[1], "lit display");
1164 print_otag(h
, TAG_PRE
, 2, tag
);
1166 /* This can be recursive: save & set our literal state. */
1168 sv
= h
->flags
& HTML_LITERAL
;
1169 h
->flags
|= HTML_LITERAL
;
1171 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1172 print_mdoc_node(meta
, nn
, h
);
1174 * If the printed node flushes its own line, then we
1175 * needn't do it here as well. This is hacky, but the
1176 * notion of selective eoln whitespace is pretty dumb
1177 * anyway, so don't sweat it.
1199 if (h
->flags
& HTML_NONEWLINE
||
1200 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1203 print_text(h
, "\n");
1205 h
->flags
|= HTML_NOSPACE
;
1209 h
->flags
&= ~HTML_LITERAL
;
1215 mdoc_pa_pre(MDOC_ARGS
)
1217 struct htmlpair tag
;
1219 PAIR_CLASS_INIT(&tag
, "file");
1220 print_otag(h
, TAG_I
, 1, &tag
);
1225 mdoc_ad_pre(MDOC_ARGS
)
1227 struct htmlpair tag
;
1229 PAIR_CLASS_INIT(&tag
, "addr");
1230 print_otag(h
, TAG_I
, 1, &tag
);
1235 mdoc_an_pre(MDOC_ARGS
)
1237 struct htmlpair tag
;
1239 if (n
->norm
->An
.auth
== AUTH_split
) {
1240 h
->flags
&= ~HTML_NOSPLIT
;
1241 h
->flags
|= HTML_SPLIT
;
1244 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1245 h
->flags
&= ~HTML_SPLIT
;
1246 h
->flags
|= HTML_NOSPLIT
;
1250 if (h
->flags
& HTML_SPLIT
)
1251 print_otag(h
, TAG_BR
, 0, NULL
);
1253 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1254 h
->flags
|= HTML_SPLIT
;
1256 PAIR_CLASS_INIT(&tag
, "author");
1257 print_otag(h
, TAG_SPAN
, 1, &tag
);
1262 mdoc_cd_pre(MDOC_ARGS
)
1264 struct htmlpair tag
;
1267 PAIR_CLASS_INIT(&tag
, "config");
1268 print_otag(h
, TAG_B
, 1, &tag
);
1273 mdoc_dv_pre(MDOC_ARGS
)
1275 struct htmlpair tag
;
1277 PAIR_CLASS_INIT(&tag
, "define");
1278 print_otag(h
, TAG_SPAN
, 1, &tag
);
1283 mdoc_ev_pre(MDOC_ARGS
)
1285 struct htmlpair tag
;
1287 PAIR_CLASS_INIT(&tag
, "env");
1288 print_otag(h
, TAG_SPAN
, 1, &tag
);
1293 mdoc_er_pre(MDOC_ARGS
)
1295 struct htmlpair tag
;
1297 PAIR_CLASS_INIT(&tag
, "errno");
1298 print_otag(h
, TAG_SPAN
, 1, &tag
);
1303 mdoc_fa_pre(MDOC_ARGS
)
1305 const struct roff_node
*nn
;
1306 struct htmlpair tag
;
1309 PAIR_CLASS_INIT(&tag
, "farg");
1310 if (n
->parent
->tok
!= MDOC_Fo
) {
1311 print_otag(h
, TAG_I
, 1, &tag
);
1315 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1316 t
= print_otag(h
, TAG_I
, 1, &tag
);
1317 print_text(h
, nn
->string
);
1320 h
->flags
|= HTML_NOSPACE
;
1325 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1326 h
->flags
|= HTML_NOSPACE
;
1334 mdoc_fd_pre(MDOC_ARGS
)
1336 struct htmlpair tag
[2];
1344 if (NULL
== (n
= n
->child
))
1347 assert(n
->type
== ROFFT_TEXT
);
1349 if (strcmp(n
->string
, "#include")) {
1350 PAIR_CLASS_INIT(&tag
[0], "macro");
1351 print_otag(h
, TAG_B
, 1, tag
);
1355 PAIR_CLASS_INIT(&tag
[0], "includes");
1356 print_otag(h
, TAG_B
, 1, tag
);
1357 print_text(h
, n
->string
);
1359 if (NULL
!= (n
= n
->next
)) {
1360 assert(n
->type
== ROFFT_TEXT
);
1363 * XXX This is broken and not easy to fix.
1364 * When using -Oincludes, truncation may occur.
1365 * Dynamic allocation wouldn't help because
1366 * passing long strings to buffmt_includes()
1367 * does not work either.
1370 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1371 n
->string
+ 1 : n
->string
, BUFSIZ
);
1374 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1377 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1380 if (h
->base_includes
) {
1381 buffmt_includes(h
, buf
);
1382 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1386 t
= print_otag(h
, TAG_A
, i
, tag
);
1387 print_text(h
, n
->string
);
1393 for ( ; n
; n
= n
->next
) {
1394 assert(n
->type
== ROFFT_TEXT
);
1395 print_text(h
, n
->string
);
1402 mdoc_vt_pre(MDOC_ARGS
)
1404 struct htmlpair tag
;
1406 if (n
->type
== ROFFT_BLOCK
) {
1409 } else if (n
->type
== ROFFT_ELEM
) {
1411 } else if (n
->type
== ROFFT_HEAD
)
1414 PAIR_CLASS_INIT(&tag
, "type");
1415 print_otag(h
, TAG_SPAN
, 1, &tag
);
1420 mdoc_ft_pre(MDOC_ARGS
)
1422 struct htmlpair tag
;
1425 PAIR_CLASS_INIT(&tag
, "ftype");
1426 print_otag(h
, TAG_I
, 1, &tag
);
1431 mdoc_fn_pre(MDOC_ARGS
)
1434 struct htmlpair tag
[2];
1436 const char *sp
, *ep
;
1439 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1442 /* Split apart into type and name. */
1443 assert(n
->child
->string
);
1444 sp
= n
->child
->string
;
1446 ep
= strchr(sp
, ' ');
1448 PAIR_CLASS_INIT(&tag
[0], "ftype");
1449 t
= print_otag(h
, TAG_I
, 1, tag
);
1452 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1453 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1455 print_text(h
, nbuf
);
1457 ep
= strchr(sp
, ' ');
1462 PAIR_CLASS_INIT(&tag
[0], "fname");
1465 * FIXME: only refer to IDs that we know exist.
1469 if (MDOC_SYNPRETTY
& n
->flags
) {
1471 html_idcat(nbuf
, sp
, BUFSIZ
);
1472 PAIR_ID_INIT(&tag
[1], nbuf
);
1474 strlcpy(nbuf
, "#", BUFSIZ
);
1475 html_idcat(nbuf
, sp
, BUFSIZ
);
1476 PAIR_HREF_INIT(&tag
[1], nbuf
);
1480 t
= print_otag(h
, TAG_B
, 1, tag
);
1487 h
->flags
|= HTML_NOSPACE
;
1489 h
->flags
|= HTML_NOSPACE
;
1491 PAIR_CLASS_INIT(&tag
[0], "farg");
1493 bufcat_style(h
, "white-space", "nowrap");
1494 PAIR_STYLE_INIT(&tag
[1], h
);
1496 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1498 if (MDOC_SYNPRETTY
& n
->flags
)
1500 t
= print_otag(h
, TAG_I
, i
, tag
);
1501 print_text(h
, n
->string
);
1504 h
->flags
|= HTML_NOSPACE
;
1509 h
->flags
|= HTML_NOSPACE
;
1513 h
->flags
|= HTML_NOSPACE
;
1521 mdoc_sm_pre(MDOC_ARGS
)
1524 if (NULL
== n
->child
)
1525 h
->flags
^= HTML_NONOSPACE
;
1526 else if (0 == strcmp("on", n
->child
->string
))
1527 h
->flags
&= ~HTML_NONOSPACE
;
1529 h
->flags
|= HTML_NONOSPACE
;
1531 if ( ! (HTML_NONOSPACE
& h
->flags
))
1532 h
->flags
&= ~HTML_NOSPACE
;
1538 mdoc_skip_pre(MDOC_ARGS
)
1545 mdoc_pp_pre(MDOC_ARGS
)
1553 mdoc_sp_pre(MDOC_ARGS
)
1556 struct htmlpair tag
;
1558 SCALE_VS_INIT(&su
, 1);
1560 if (MDOC_sp
== n
->tok
) {
1561 if (NULL
!= (n
= n
->child
)) {
1562 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1564 else if (su
.scale
< 0.0)
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(n
->type
== ROFFT_TEXT
);
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(n
->type
== ROFFT_TEXT
);
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 (n
->type
== ROFFT_BODY
) {
1637 h
->flags
|= HTML_NOSPACE
;
1639 h
->flags
|= HTML_NOSPACE
;
1641 } else if (n
->type
== ROFFT_BLOCK
) {
1646 if (n
->child
== NULL
)
1649 assert(n
->child
->string
);
1650 PAIR_CLASS_INIT(&tag
, "fname");
1651 t
= print_otag(h
, TAG_B
, 1, &tag
);
1652 print_text(h
, n
->child
->string
);
1658 mdoc_fo_post(MDOC_ARGS
)
1661 if (n
->type
!= ROFFT_BODY
)
1663 h
->flags
|= HTML_NOSPACE
;
1665 h
->flags
|= HTML_NOSPACE
;
1670 mdoc_in_pre(MDOC_ARGS
)
1673 struct htmlpair tag
[2];
1678 PAIR_CLASS_INIT(&tag
[0], "includes");
1679 print_otag(h
, TAG_B
, 1, tag
);
1682 * The first argument of the `In' gets special treatment as
1683 * being a linked value. Subsequent values are printed
1684 * afterward. groff does similarly. This also handles the case
1688 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1689 print_text(h
, "#include");
1692 h
->flags
|= HTML_NOSPACE
;
1694 if (NULL
!= (n
= n
->child
)) {
1695 assert(n
->type
== ROFFT_TEXT
);
1697 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1700 if (h
->base_includes
) {
1701 buffmt_includes(h
, n
->string
);
1702 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1706 t
= print_otag(h
, TAG_A
, i
, tag
);
1707 print_text(h
, n
->string
);
1713 h
->flags
|= HTML_NOSPACE
;
1716 for ( ; n
; n
= n
->next
) {
1717 assert(n
->type
== ROFFT_TEXT
);
1718 print_text(h
, n
->string
);
1725 mdoc_ic_pre(MDOC_ARGS
)
1727 struct htmlpair tag
;
1729 PAIR_CLASS_INIT(&tag
, "cmd");
1730 print_otag(h
, TAG_B
, 1, &tag
);
1735 mdoc_rv_pre(MDOC_ARGS
)
1737 struct htmlpair tag
;
1742 print_otag(h
, TAG_BR
, 0, NULL
);
1744 PAIR_CLASS_INIT(&tag
, "fname");
1748 print_text(h
, "The");
1750 for (n
= n
->child
; n
; n
= n
->next
) {
1751 t
= print_otag(h
, TAG_B
, 1, &tag
);
1752 print_text(h
, n
->string
);
1755 h
->flags
|= HTML_NOSPACE
;
1756 print_text(h
, "()");
1758 if (n
->next
== NULL
)
1762 h
->flags
|= HTML_NOSPACE
;
1765 if (n
->next
->next
== NULL
)
1766 print_text(h
, "and");
1770 print_text(h
, "functions return");
1772 print_text(h
, "function returns");
1774 print_text(h
, "the value\\~0 if successful;");
1776 print_text(h
, "Upon successful completion,"
1777 " the value\\~0 is returned;");
1779 print_text(h
, "otherwise the value\\~\\-1 is returned"
1780 " and the global variable");
1782 PAIR_CLASS_INIT(&tag
, "var");
1783 t
= print_otag(h
, TAG_B
, 1, &tag
);
1784 print_text(h
, "errno");
1786 print_text(h
, "is set to indicate the error.");
1791 mdoc_va_pre(MDOC_ARGS
)
1793 struct htmlpair tag
;
1795 PAIR_CLASS_INIT(&tag
, "var");
1796 print_otag(h
, TAG_B
, 1, &tag
);
1801 mdoc_ap_pre(MDOC_ARGS
)
1804 h
->flags
|= HTML_NOSPACE
;
1805 print_text(h
, "\\(aq");
1806 h
->flags
|= HTML_NOSPACE
;
1811 mdoc_bf_pre(MDOC_ARGS
)
1813 struct htmlpair tag
[2];
1816 if (n
->type
== ROFFT_HEAD
)
1818 else if (n
->type
!= ROFFT_BODY
)
1821 if (FONT_Em
== n
->norm
->Bf
.font
)
1822 PAIR_CLASS_INIT(&tag
[0], "emph");
1823 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1824 PAIR_CLASS_INIT(&tag
[0], "symb");
1825 else if (FONT_Li
== n
->norm
->Bf
.font
)
1826 PAIR_CLASS_INIT(&tag
[0], "lit");
1828 PAIR_CLASS_INIT(&tag
[0], "none");
1831 * We want this to be inline-formatted, but needs to be div to
1832 * accept block children.
1835 bufcat_style(h
, "display", "inline");
1836 SCALE_HS_INIT(&su
, 1);
1837 /* Needs a left-margin for spacing. */
1838 bufcat_su(h
, "margin-left", &su
);
1839 PAIR_STYLE_INIT(&tag
[1], h
);
1840 print_otag(h
, TAG_DIV
, 2, tag
);
1845 mdoc_ms_pre(MDOC_ARGS
)
1847 struct htmlpair tag
;
1849 PAIR_CLASS_INIT(&tag
, "symb");
1850 print_otag(h
, TAG_SPAN
, 1, &tag
);
1855 mdoc_igndelim_pre(MDOC_ARGS
)
1858 h
->flags
|= HTML_IGNDELIM
;
1863 mdoc_pf_post(MDOC_ARGS
)
1866 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1867 h
->flags
|= HTML_NOSPACE
;
1871 mdoc_rs_pre(MDOC_ARGS
)
1873 struct htmlpair tag
;
1875 if (n
->type
!= ROFFT_BLOCK
)
1878 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1881 PAIR_CLASS_INIT(&tag
, "ref");
1882 print_otag(h
, TAG_SPAN
, 1, &tag
);
1887 mdoc_no_pre(MDOC_ARGS
)
1889 struct htmlpair tag
;
1891 PAIR_CLASS_INIT(&tag
, "none");
1892 print_otag(h
, TAG_CODE
, 1, &tag
);
1897 mdoc_li_pre(MDOC_ARGS
)
1899 struct htmlpair tag
;
1901 PAIR_CLASS_INIT(&tag
, "lit");
1902 print_otag(h
, TAG_CODE
, 1, &tag
);
1907 mdoc_sy_pre(MDOC_ARGS
)
1909 struct htmlpair tag
;
1911 PAIR_CLASS_INIT(&tag
, "symb");
1912 print_otag(h
, TAG_SPAN
, 1, &tag
);
1917 mdoc_bt_pre(MDOC_ARGS
)
1920 print_text(h
, "is currently in beta test.");
1925 mdoc_ud_pre(MDOC_ARGS
)
1928 print_text(h
, "currently under development.");
1933 mdoc_lb_pre(MDOC_ARGS
)
1935 struct htmlpair tag
;
1937 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1938 print_otag(h
, TAG_BR
, 0, NULL
);
1940 PAIR_CLASS_INIT(&tag
, "lib");
1941 print_otag(h
, TAG_SPAN
, 1, &tag
);
1946 mdoc__x_pre(MDOC_ARGS
)
1948 struct htmlpair tag
[2];
1955 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1956 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1957 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1958 print_text(h
, "and");
1961 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1965 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1968 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1971 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1982 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1985 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1988 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1991 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1994 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1997 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2000 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2007 if (MDOC__U
!= n
->tok
) {
2008 print_otag(h
, t
, 1, tag
);
2012 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2013 print_otag(h
, TAG_A
, 2, tag
);
2019 mdoc__x_post(MDOC_ARGS
)
2022 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2023 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2024 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2029 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2032 h
->flags
|= HTML_NOSPACE
;
2033 print_text(h
, n
->next
? "," : ".");
2037 mdoc_bk_pre(MDOC_ARGS
)
2046 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2047 h
->flags
|= HTML_PREKEEP
;
2058 mdoc_bk_post(MDOC_ARGS
)
2061 if (n
->type
== ROFFT_BODY
)
2062 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2066 mdoc_quote_pre(MDOC_ARGS
)
2068 struct htmlpair tag
;
2070 if (n
->type
!= ROFFT_BODY
)
2077 print_text(h
, n
->nchild
== 1 &&
2078 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2083 print_text(h
, "\\(lC");
2088 print_text(h
, "\\(lB");
2093 print_text(h
, "\\(lB");
2094 h
->flags
|= HTML_NOSPACE
;
2095 PAIR_CLASS_INIT(&tag
, "opt");
2096 print_otag(h
, TAG_SPAN
, 1, &tag
);
2099 if (NULL
== n
->norm
->Es
||
2100 NULL
== n
->norm
->Es
->child
)
2102 print_text(h
, n
->norm
->Es
->child
->string
);
2111 print_text(h
, "\\(lq");
2119 print_text(h
, "\\(oq");
2120 h
->flags
|= HTML_NOSPACE
;
2121 PAIR_CLASS_INIT(&tag
, "lit");
2122 print_otag(h
, TAG_CODE
, 1, &tag
);
2127 print_text(h
, "\\(oq");
2134 h
->flags
|= HTML_NOSPACE
;
2139 mdoc_quote_post(MDOC_ARGS
)
2142 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
2145 h
->flags
|= HTML_NOSPACE
;
2151 print_text(h
, n
->nchild
== 1 &&
2152 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2157 print_text(h
, "\\(rC");
2166 print_text(h
, "\\(rB");
2169 if (n
->norm
->Es
== NULL
||
2170 n
->norm
->Es
->child
== NULL
||
2171 n
->norm
->Es
->child
->next
== NULL
)
2172 h
->flags
&= ~HTML_NOSPACE
;
2174 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2183 print_text(h
, "\\(rq");
2195 print_text(h
, "\\(cq");
2204 mdoc_eo_pre(MDOC_ARGS
)
2207 if (n
->type
!= ROFFT_BODY
)
2210 if (n
->end
== ENDBODY_NOT
&&
2211 n
->parent
->head
->child
== NULL
&&
2213 n
->child
->end
!= ENDBODY_NOT
)
2214 print_text(h
, "\\&");
2215 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2216 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2217 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2218 h
->flags
|= HTML_NOSPACE
;
2223 mdoc_eo_post(MDOC_ARGS
)
2227 if (n
->type
!= ROFFT_BODY
)
2230 if (n
->end
!= ENDBODY_NOT
) {
2231 h
->flags
&= ~HTML_NOSPACE
;
2235 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2236 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2239 h
->flags
|= HTML_NOSPACE
;
2241 h
->flags
&= ~HTML_NOSPACE
;