]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.228 2015/04/02 22:48:17 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 mdoc_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(MDOC_ARGS
);
52 static void print_mdoc_head(MDOC_ARGS
);
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
55 static void synopsis_pre(struct html
*,
56 const struct roff_node
*);
58 static void a2width(const char *, struct roffsu
*);
60 static void mdoc_root_post(MDOC_ARGS
);
61 static int mdoc_root_pre(MDOC_ARGS
);
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_ad_pre(MDOC_ARGS
);
66 static int mdoc_an_pre(MDOC_ARGS
);
67 static int mdoc_ap_pre(MDOC_ARGS
);
68 static int mdoc_ar_pre(MDOC_ARGS
);
69 static int mdoc_bd_pre(MDOC_ARGS
);
70 static int mdoc_bf_pre(MDOC_ARGS
);
71 static void mdoc_bk_post(MDOC_ARGS
);
72 static int mdoc_bk_pre(MDOC_ARGS
);
73 static int mdoc_bl_pre(MDOC_ARGS
);
74 static int mdoc_bt_pre(MDOC_ARGS
);
75 static int mdoc_bx_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static int mdoc_dv_pre(MDOC_ARGS
);
79 static int mdoc_fa_pre(MDOC_ARGS
);
80 static int mdoc_fd_pre(MDOC_ARGS
);
81 static int mdoc_fl_pre(MDOC_ARGS
);
82 static int mdoc_fn_pre(MDOC_ARGS
);
83 static int mdoc_ft_pre(MDOC_ARGS
);
84 static int mdoc_em_pre(MDOC_ARGS
);
85 static void mdoc_eo_post(MDOC_ARGS
);
86 static int mdoc_eo_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_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_no_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 {mdoc_skip_pre
, 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_eo_pre
, mdoc_eo_post
}, /* Eo */
196 {mdoc_xx_pre
, NULL
}, /* Fx */
197 {mdoc_ms_pre
, NULL
}, /* Ms */
198 {mdoc_no_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
)->child
,
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
) < 2) {
287 su
->scale
= html_strlen(p
);
288 } else if (su
->scale
< 0.0)
293 * See the same function in mdoc_term.c for documentation.
296 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
299 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
302 if (n
->prev
->tok
== n
->tok
&&
306 print_otag(h
, TAG_BR
, 0, NULL
);
310 switch (n
->prev
->tok
) {
323 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
329 print_otag(h
, TAG_BR
, 0, NULL
);
335 print_mdoc(MDOC_ARGS
)
340 PAIR_CLASS_INIT(&tag
, "mandoc");
342 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
344 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
345 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
346 print_mdoc_head(meta
, n
, h
);
348 print_otag(h
, TAG_BODY
, 0, NULL
);
349 print_otag(h
, TAG_DIV
, 1, &tag
);
351 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
353 print_mdoc_nodelist(meta
, n
, h
);
358 print_mdoc_head(MDOC_ARGS
)
363 bufcat(h
, meta
->title
);
365 bufcat_fmt(h
, "(%s)", meta
->msec
);
367 bufcat_fmt(h
, " (%s)", meta
->arch
);
369 print_otag(h
, TAG_TITLE
, 0, NULL
);
370 print_text(h
, h
->buf
);
374 print_mdoc_nodelist(MDOC_ARGS
)
378 print_mdoc_node(meta
, n
, h
);
384 print_mdoc_node(MDOC_ARGS
)
391 n
->flags
&= ~MDOC_ENDED
;
395 child
= mdoc_root_pre(meta
, n
, h
);
398 /* No tables in this mode... */
399 assert(NULL
== h
->tblt
);
402 * Make sure that if we're in a literal mode already
403 * (i.e., within a <PRE>) don't print the newline.
405 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
406 if ( ! (HTML_LITERAL
& h
->flags
))
407 print_otag(h
, TAG_BR
, 0, NULL
);
408 if (MDOC_DELIMC
& n
->flags
)
409 h
->flags
|= HTML_NOSPACE
;
410 print_text(h
, n
->string
);
411 if (MDOC_DELIMO
& n
->flags
)
412 h
->flags
|= HTML_NOSPACE
;
415 if (n
->flags
& MDOC_LINE
)
417 print_eqn(h
, n
->eqn
);
421 * This will take care of initialising all of the table
422 * state data for the first table, then tearing it down
425 print_tbl(h
, n
->span
);
429 * Close out the current table, if it's open, and unset
430 * the "meta" table state. This will be reopened on the
431 * next table element.
433 if (h
->tblt
!= NULL
) {
437 assert(h
->tblt
== NULL
);
438 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
439 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
443 if (h
->flags
& HTML_KEEP
&& n
->flags
& MDOC_LINE
) {
444 h
->flags
&= ~HTML_KEEP
;
445 h
->flags
|= HTML_PREKEEP
;
448 if (child
&& n
->child
)
449 print_mdoc_nodelist(meta
, n
->child
, h
);
455 mdoc_root_post(meta
, n
, h
);
460 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
462 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
463 if (n
->end
!= ENDBODY_NOT
)
464 n
->body
->flags
|= MDOC_ENDED
;
465 if (n
->end
== ENDBODY_NOSPACE
)
466 h
->flags
|= HTML_NOSPACE
;
472 mdoc_root_post(MDOC_ARGS
)
477 PAIR_CLASS_INIT(&tag
, "foot");
478 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
480 print_otag(h
, TAG_TBODY
, 0, NULL
);
482 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
484 PAIR_CLASS_INIT(&tag
, "foot-date");
485 print_otag(h
, TAG_TD
, 1, &tag
);
486 print_text(h
, meta
->date
);
489 PAIR_CLASS_INIT(&tag
, "foot-os");
490 print_otag(h
, TAG_TD
, 1, &tag
);
491 print_text(h
, meta
->os
);
496 mdoc_root_pre(MDOC_ARGS
)
500 char *volume
, *title
;
502 if (NULL
== meta
->arch
)
503 volume
= mandoc_strdup(meta
->vol
);
505 mandoc_asprintf(&volume
, "%s (%s)",
506 meta
->vol
, meta
->arch
);
508 if (NULL
== meta
->msec
)
509 title
= mandoc_strdup(meta
->title
);
511 mandoc_asprintf(&title
, "%s(%s)",
512 meta
->title
, meta
->msec
);
514 PAIR_CLASS_INIT(&tag
, "head");
515 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
517 print_otag(h
, TAG_TBODY
, 0, NULL
);
519 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
521 PAIR_CLASS_INIT(&tag
, "head-ltitle");
522 print_otag(h
, TAG_TD
, 1, &tag
);
523 print_text(h
, title
);
526 PAIR_CLASS_INIT(&tag
, "head-vol");
527 print_otag(h
, TAG_TD
, 1, &tag
);
528 print_text(h
, volume
);
531 PAIR_CLASS_INIT(&tag
, "head-rtitle");
532 print_otag(h
, TAG_TD
, 1, &tag
);
533 print_text(h
, title
);
542 mdoc_sh_pre(MDOC_ARGS
)
548 PAIR_CLASS_INIT(&tag
, "section");
549 print_otag(h
, TAG_DIV
, 1, &tag
);
552 if (n
->sec
== SEC_AUTHORS
)
553 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
562 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
563 bufcat_id(h
, n
->string
);
564 if (NULL
!= (n
= n
->next
))
569 PAIR_ID_INIT(&tag
, h
->buf
);
570 print_otag(h
, TAG_H1
, 1, &tag
);
572 print_otag(h
, TAG_H1
, 0, NULL
);
578 mdoc_ss_pre(MDOC_ARGS
)
582 if (n
->type
== ROFFT_BLOCK
) {
583 PAIR_CLASS_INIT(&tag
, "subsection");
584 print_otag(h
, TAG_DIV
, 1, &tag
);
586 } else if (n
->type
== ROFFT_BODY
)
592 for (n
= n
->child
; n
!= NULL
&& n
->type
== ROFFT_TEXT
; ) {
593 bufcat_id(h
, n
->string
);
594 if (NULL
!= (n
= n
->next
))
599 PAIR_ID_INIT(&tag
, h
->buf
);
600 print_otag(h
, TAG_H2
, 1, &tag
);
602 print_otag(h
, TAG_H2
, 0, NULL
);
608 mdoc_fl_pre(MDOC_ARGS
)
612 PAIR_CLASS_INIT(&tag
, "flag");
613 print_otag(h
, TAG_B
, 1, &tag
);
615 /* `Cm' has no leading hyphen. */
617 if (MDOC_Cm
== n
->tok
)
620 print_text(h
, "\\-");
622 if ( ! (n
->nchild
== 0 &&
624 n
->next
->type
== ROFFT_TEXT
||
625 n
->next
->flags
& MDOC_LINE
)))
626 h
->flags
|= HTML_NOSPACE
;
632 mdoc_nd_pre(MDOC_ARGS
)
636 if (n
->type
!= ROFFT_BODY
)
639 /* XXX: this tag in theory can contain block elements. */
641 print_text(h
, "\\(em");
642 PAIR_CLASS_INIT(&tag
, "desc");
643 print_otag(h
, TAG_SPAN
, 1, &tag
);
648 mdoc_nm_pre(MDOC_ARGS
)
657 PAIR_CLASS_INIT(&tag
, "name");
658 print_otag(h
, TAG_B
, 1, &tag
);
659 if (NULL
== n
->child
&& meta
->name
)
660 print_text(h
, meta
->name
);
663 print_otag(h
, TAG_TD
, 0, NULL
);
664 if (NULL
== n
->child
&& meta
->name
)
665 print_text(h
, meta
->name
);
668 print_otag(h
, TAG_TD
, 0, NULL
);
675 PAIR_CLASS_INIT(&tag
, "synopsis");
676 print_otag(h
, TAG_TABLE
, 1, &tag
);
678 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
679 if (n
->type
== ROFFT_TEXT
)
680 len
+= html_strlen(n
->string
);
682 if (0 == len
&& meta
->name
)
683 len
= html_strlen(meta
->name
);
685 SCALE_HS_INIT(&su
, len
);
687 bufcat_su(h
, "width", &su
);
688 PAIR_STYLE_INIT(&tag
, h
);
689 print_otag(h
, TAG_COL
, 1, &tag
);
690 print_otag(h
, TAG_COL
, 0, NULL
);
691 print_otag(h
, TAG_TBODY
, 0, NULL
);
692 print_otag(h
, TAG_TR
, 0, NULL
);
697 mdoc_xr_pre(MDOC_ARGS
)
699 struct htmlpair tag
[2];
701 if (NULL
== n
->child
)
704 PAIR_CLASS_INIT(&tag
[0], "link-man");
707 buffmt_man(h
, n
->child
->string
,
709 n
->child
->next
->string
: NULL
);
710 PAIR_HREF_INIT(&tag
[1], h
->buf
);
711 print_otag(h
, TAG_A
, 2, tag
);
713 print_otag(h
, TAG_A
, 1, tag
);
716 print_text(h
, n
->string
);
718 if (NULL
== (n
= n
->next
))
721 h
->flags
|= HTML_NOSPACE
;
723 h
->flags
|= HTML_NOSPACE
;
724 print_text(h
, n
->string
);
725 h
->flags
|= HTML_NOSPACE
;
731 mdoc_ns_pre(MDOC_ARGS
)
734 if ( ! (MDOC_LINE
& n
->flags
))
735 h
->flags
|= HTML_NOSPACE
;
740 mdoc_ar_pre(MDOC_ARGS
)
744 PAIR_CLASS_INIT(&tag
, "arg");
745 print_otag(h
, TAG_I
, 1, &tag
);
750 mdoc_xx_pre(MDOC_ARGS
)
779 PAIR_CLASS_INIT(&tag
, "unix");
780 print_otag(h
, TAG_SPAN
, 1, &tag
);
785 h
->flags
|= HTML_KEEP
;
786 print_text(h
, n
->child
->string
);
793 mdoc_bx_pre(MDOC_ARGS
)
797 PAIR_CLASS_INIT(&tag
, "unix");
798 print_otag(h
, TAG_SPAN
, 1, &tag
);
800 if (NULL
!= (n
= n
->child
)) {
801 print_text(h
, n
->string
);
802 h
->flags
|= HTML_NOSPACE
;
803 print_text(h
, "BSD");
805 print_text(h
, "BSD");
809 if (NULL
!= (n
= n
->next
)) {
810 h
->flags
|= HTML_NOSPACE
;
812 h
->flags
|= HTML_NOSPACE
;
813 print_text(h
, n
->string
);
820 mdoc_it_pre(MDOC_ARGS
)
824 struct htmlpair tag
[2];
825 const struct roff_node
*bl
;
828 while (bl
&& MDOC_Bl
!= bl
->tok
)
833 type
= bl
->norm
->Bl
.type
;
836 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
840 if (n
->type
== ROFFT_HEAD
) {
861 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
862 bufcat_su(h
, "margin-top", &su
);
863 PAIR_STYLE_INIT(&tag
[1], h
);
864 print_otag(h
, TAG_DT
, 2, tag
);
865 if (LIST_diag
!= type
)
867 PAIR_CLASS_INIT(&tag
[0], "diag");
868 print_otag(h
, TAG_B
, 1, tag
);
875 } else if (n
->type
== ROFFT_BODY
) {
886 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
887 bufcat_su(h
, "margin-top", &su
);
888 PAIR_STYLE_INIT(&tag
[1], h
);
889 print_otag(h
, TAG_LI
, 2, tag
);
900 if (NULL
== bl
->norm
->Bl
.width
) {
901 print_otag(h
, TAG_DD
, 1, tag
);
904 a2width(bl
->norm
->Bl
.width
, &su
);
905 bufcat_su(h
, "margin-left", &su
);
906 PAIR_STYLE_INIT(&tag
[1], h
);
907 print_otag(h
, TAG_DD
, 2, tag
);
910 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
911 bufcat_su(h
, "margin-top", &su
);
912 PAIR_STYLE_INIT(&tag
[1], h
);
913 print_otag(h
, TAG_TD
, 2, tag
);
921 print_otag(h
, TAG_TR
, 1, tag
);
932 mdoc_bl_pre(MDOC_ARGS
)
935 struct htmlpair tag
[3];
939 if (n
->type
== ROFFT_BODY
) {
940 if (LIST_column
== n
->norm
->Bl
.type
)
941 print_otag(h
, TAG_TBODY
, 0, NULL
);
945 if (n
->type
== ROFFT_HEAD
) {
946 if (LIST_column
!= n
->norm
->Bl
.type
)
950 * For each column, print out the <COL> tag with our
951 * suggested width. The last column gets min-width, as
952 * in terminal mode it auto-sizes to the width of the
953 * screen and we want to preserve that behaviour.
956 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
958 a2width(n
->norm
->Bl
.cols
[i
], &su
);
959 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
960 bufcat_su(h
, "width", &su
);
962 bufcat_su(h
, "min-width", &su
);
963 PAIR_STYLE_INIT(&tag
[0], h
);
964 print_otag(h
, TAG_COL
, 1, tag
);
970 SCALE_VS_INIT(&su
, 0);
972 bufcat_su(h
, "margin-top", &su
);
973 bufcat_su(h
, "margin-bottom", &su
);
974 PAIR_STYLE_INIT(&tag
[0], h
);
976 assert(lists
[n
->norm
->Bl
.type
]);
977 (void)strlcpy(buf
, "list ", BUFSIZ
);
978 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
979 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
981 /* Set the block's left-hand margin. */
983 if (n
->norm
->Bl
.offs
) {
984 a2width(n
->norm
->Bl
.offs
, &su
);
985 bufcat_su(h
, "margin-left", &su
);
988 switch (n
->norm
->Bl
.type
) {
996 print_otag(h
, TAG_UL
, 2, tag
);
999 print_otag(h
, TAG_OL
, 2, tag
);
1010 print_otag(h
, TAG_DL
, 2, tag
);
1013 print_otag(h
, TAG_TABLE
, 2, tag
);
1024 mdoc_ex_pre(MDOC_ARGS
)
1027 struct htmlpair tag
;
1031 print_otag(h
, TAG_BR
, 0, NULL
);
1033 PAIR_CLASS_INIT(&tag
, "utility");
1035 print_text(h
, "The");
1038 for (n
= n
->child
; n
; n
= n
->next
) {
1039 assert(n
->type
== ROFFT_TEXT
);
1041 t
= print_otag(h
, TAG_B
, 1, &tag
);
1042 print_text(h
, n
->string
);
1045 if (nchild
> 2 && n
->next
) {
1046 h
->flags
|= HTML_NOSPACE
;
1050 if (n
->next
&& NULL
== n
->next
->next
)
1051 print_text(h
, "and");
1055 print_text(h
, "utilities exit\\~0");
1057 print_text(h
, "utility exits\\~0");
1059 print_text(h
, "on success, and\\~>0 if an error occurs.");
1064 mdoc_em_pre(MDOC_ARGS
)
1066 struct htmlpair tag
;
1068 PAIR_CLASS_INIT(&tag
, "emph");
1069 print_otag(h
, TAG_SPAN
, 1, &tag
);
1074 mdoc_d1_pre(MDOC_ARGS
)
1076 struct htmlpair tag
[2];
1079 if (n
->type
!= ROFFT_BLOCK
)
1082 SCALE_VS_INIT(&su
, 0);
1084 bufcat_su(h
, "margin-top", &su
);
1085 bufcat_su(h
, "margin-bottom", &su
);
1086 PAIR_STYLE_INIT(&tag
[0], h
);
1087 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1089 /* BLOCKQUOTE needs a block body. */
1091 PAIR_CLASS_INIT(&tag
[0], "display");
1092 print_otag(h
, TAG_DIV
, 1, tag
);
1094 if (MDOC_Dl
== n
->tok
) {
1095 PAIR_CLASS_INIT(&tag
[0], "lit");
1096 print_otag(h
, TAG_CODE
, 1, tag
);
1103 mdoc_sx_pre(MDOC_ARGS
)
1105 struct htmlpair tag
[2];
1110 for (n
= n
->child
; n
; ) {
1111 bufcat_id(h
, n
->string
);
1112 if (NULL
!= (n
= n
->next
))
1116 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1117 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1119 print_otag(h
, TAG_I
, 1, tag
);
1120 print_otag(h
, TAG_A
, 2, tag
);
1125 mdoc_bd_pre(MDOC_ARGS
)
1127 struct htmlpair tag
[2];
1129 struct roff_node
*nn
;
1132 if (n
->type
== ROFFT_HEAD
)
1135 if (n
->type
== ROFFT_BLOCK
) {
1136 comp
= n
->norm
->Bd
.comp
;
1137 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1138 if (nn
->type
!= ROFFT_BLOCK
)
1140 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1150 /* Handle the -offset argument. */
1152 if (n
->norm
->Bd
.offs
== NULL
||
1153 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1154 SCALE_HS_INIT(&su
, 0);
1155 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1156 SCALE_HS_INIT(&su
, INDENT
);
1157 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1158 SCALE_HS_INIT(&su
, INDENT
* 2);
1160 a2width(n
->norm
->Bd
.offs
, &su
);
1163 bufcat_su(h
, "margin-left", &su
);
1164 PAIR_STYLE_INIT(&tag
[0], h
);
1166 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1167 DISP_literal
!= n
->norm
->Bd
.type
) {
1168 PAIR_CLASS_INIT(&tag
[1], "display");
1169 print_otag(h
, TAG_DIV
, 2, tag
);
1173 PAIR_CLASS_INIT(&tag
[1], "lit display");
1174 print_otag(h
, TAG_PRE
, 2, tag
);
1176 /* This can be recursive: save & set our literal state. */
1178 sv
= h
->flags
& HTML_LITERAL
;
1179 h
->flags
|= HTML_LITERAL
;
1181 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1182 print_mdoc_node(meta
, nn
, h
);
1184 * If the printed node flushes its own line, then we
1185 * needn't do it here as well. This is hacky, but the
1186 * notion of selective eoln whitespace is pretty dumb
1187 * anyway, so don't sweat it.
1209 if (h
->flags
& HTML_NONEWLINE
||
1210 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1213 print_text(h
, "\n");
1215 h
->flags
|= HTML_NOSPACE
;
1219 h
->flags
&= ~HTML_LITERAL
;
1225 mdoc_pa_pre(MDOC_ARGS
)
1227 struct htmlpair tag
;
1229 PAIR_CLASS_INIT(&tag
, "file");
1230 print_otag(h
, TAG_I
, 1, &tag
);
1235 mdoc_ad_pre(MDOC_ARGS
)
1237 struct htmlpair tag
;
1239 PAIR_CLASS_INIT(&tag
, "addr");
1240 print_otag(h
, TAG_I
, 1, &tag
);
1245 mdoc_an_pre(MDOC_ARGS
)
1247 struct htmlpair tag
;
1249 if (n
->norm
->An
.auth
== AUTH_split
) {
1250 h
->flags
&= ~HTML_NOSPLIT
;
1251 h
->flags
|= HTML_SPLIT
;
1254 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1255 h
->flags
&= ~HTML_SPLIT
;
1256 h
->flags
|= HTML_NOSPLIT
;
1260 if (h
->flags
& HTML_SPLIT
)
1261 print_otag(h
, TAG_BR
, 0, NULL
);
1263 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1264 h
->flags
|= HTML_SPLIT
;
1266 PAIR_CLASS_INIT(&tag
, "author");
1267 print_otag(h
, TAG_SPAN
, 1, &tag
);
1272 mdoc_cd_pre(MDOC_ARGS
)
1274 struct htmlpair tag
;
1277 PAIR_CLASS_INIT(&tag
, "config");
1278 print_otag(h
, TAG_B
, 1, &tag
);
1283 mdoc_dv_pre(MDOC_ARGS
)
1285 struct htmlpair tag
;
1287 PAIR_CLASS_INIT(&tag
, "define");
1288 print_otag(h
, TAG_SPAN
, 1, &tag
);
1293 mdoc_ev_pre(MDOC_ARGS
)
1295 struct htmlpair tag
;
1297 PAIR_CLASS_INIT(&tag
, "env");
1298 print_otag(h
, TAG_SPAN
, 1, &tag
);
1303 mdoc_er_pre(MDOC_ARGS
)
1305 struct htmlpair tag
;
1307 PAIR_CLASS_INIT(&tag
, "errno");
1308 print_otag(h
, TAG_SPAN
, 1, &tag
);
1313 mdoc_fa_pre(MDOC_ARGS
)
1315 const struct roff_node
*nn
;
1316 struct htmlpair tag
;
1319 PAIR_CLASS_INIT(&tag
, "farg");
1320 if (n
->parent
->tok
!= MDOC_Fo
) {
1321 print_otag(h
, TAG_I
, 1, &tag
);
1325 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1326 t
= print_otag(h
, TAG_I
, 1, &tag
);
1327 print_text(h
, nn
->string
);
1330 h
->flags
|= HTML_NOSPACE
;
1335 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1336 h
->flags
|= HTML_NOSPACE
;
1344 mdoc_fd_pre(MDOC_ARGS
)
1346 struct htmlpair tag
[2];
1354 if (NULL
== (n
= n
->child
))
1357 assert(n
->type
== ROFFT_TEXT
);
1359 if (strcmp(n
->string
, "#include")) {
1360 PAIR_CLASS_INIT(&tag
[0], "macro");
1361 print_otag(h
, TAG_B
, 1, tag
);
1365 PAIR_CLASS_INIT(&tag
[0], "includes");
1366 print_otag(h
, TAG_B
, 1, tag
);
1367 print_text(h
, n
->string
);
1369 if (NULL
!= (n
= n
->next
)) {
1370 assert(n
->type
== ROFFT_TEXT
);
1373 * XXX This is broken and not easy to fix.
1374 * When using -Oincludes, truncation may occur.
1375 * Dynamic allocation wouldn't help because
1376 * passing long strings to buffmt_includes()
1377 * does not work either.
1380 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1381 n
->string
+ 1 : n
->string
, BUFSIZ
);
1384 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1387 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1390 if (h
->base_includes
) {
1391 buffmt_includes(h
, buf
);
1392 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1396 t
= print_otag(h
, TAG_A
, i
, tag
);
1397 print_text(h
, n
->string
);
1403 for ( ; n
; n
= n
->next
) {
1404 assert(n
->type
== ROFFT_TEXT
);
1405 print_text(h
, n
->string
);
1412 mdoc_vt_pre(MDOC_ARGS
)
1414 struct htmlpair tag
;
1416 if (n
->type
== ROFFT_BLOCK
) {
1419 } else if (n
->type
== ROFFT_ELEM
) {
1421 } else if (n
->type
== ROFFT_HEAD
)
1424 PAIR_CLASS_INIT(&tag
, "type");
1425 print_otag(h
, TAG_SPAN
, 1, &tag
);
1430 mdoc_ft_pre(MDOC_ARGS
)
1432 struct htmlpair tag
;
1435 PAIR_CLASS_INIT(&tag
, "ftype");
1436 print_otag(h
, TAG_I
, 1, &tag
);
1441 mdoc_fn_pre(MDOC_ARGS
)
1444 struct htmlpair tag
[2];
1446 const char *sp
, *ep
;
1449 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1452 /* Split apart into type and name. */
1453 assert(n
->child
->string
);
1454 sp
= n
->child
->string
;
1456 ep
= strchr(sp
, ' ');
1458 PAIR_CLASS_INIT(&tag
[0], "ftype");
1459 t
= print_otag(h
, TAG_I
, 1, tag
);
1462 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1463 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1465 print_text(h
, nbuf
);
1467 ep
= strchr(sp
, ' ');
1472 PAIR_CLASS_INIT(&tag
[0], "fname");
1475 * FIXME: only refer to IDs that we know exist.
1479 if (MDOC_SYNPRETTY
& n
->flags
) {
1481 html_idcat(nbuf
, sp
, BUFSIZ
);
1482 PAIR_ID_INIT(&tag
[1], nbuf
);
1484 strlcpy(nbuf
, "#", BUFSIZ
);
1485 html_idcat(nbuf
, sp
, BUFSIZ
);
1486 PAIR_HREF_INIT(&tag
[1], nbuf
);
1490 t
= print_otag(h
, TAG_B
, 1, tag
);
1497 h
->flags
|= HTML_NOSPACE
;
1499 h
->flags
|= HTML_NOSPACE
;
1501 PAIR_CLASS_INIT(&tag
[0], "farg");
1503 bufcat_style(h
, "white-space", "nowrap");
1504 PAIR_STYLE_INIT(&tag
[1], h
);
1506 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1508 if (MDOC_SYNPRETTY
& n
->flags
)
1510 t
= print_otag(h
, TAG_I
, i
, tag
);
1511 print_text(h
, n
->string
);
1514 h
->flags
|= HTML_NOSPACE
;
1519 h
->flags
|= HTML_NOSPACE
;
1523 h
->flags
|= HTML_NOSPACE
;
1531 mdoc_sm_pre(MDOC_ARGS
)
1534 if (NULL
== n
->child
)
1535 h
->flags
^= HTML_NONOSPACE
;
1536 else if (0 == strcmp("on", n
->child
->string
))
1537 h
->flags
&= ~HTML_NONOSPACE
;
1539 h
->flags
|= HTML_NONOSPACE
;
1541 if ( ! (HTML_NONOSPACE
& h
->flags
))
1542 h
->flags
&= ~HTML_NOSPACE
;
1548 mdoc_skip_pre(MDOC_ARGS
)
1555 mdoc_pp_pre(MDOC_ARGS
)
1563 mdoc_sp_pre(MDOC_ARGS
)
1566 struct htmlpair tag
;
1568 SCALE_VS_INIT(&su
, 1);
1570 if (MDOC_sp
== n
->tok
) {
1571 if (NULL
!= (n
= n
->child
)) {
1572 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1574 else if (su
.scale
< 0.0)
1581 bufcat_su(h
, "height", &su
);
1582 PAIR_STYLE_INIT(&tag
, h
);
1583 print_otag(h
, TAG_DIV
, 1, &tag
);
1585 /* So the div isn't empty: */
1586 print_text(h
, "\\~");
1593 mdoc_lk_pre(MDOC_ARGS
)
1595 struct htmlpair tag
[2];
1597 if (NULL
== (n
= n
->child
))
1600 assert(n
->type
== ROFFT_TEXT
);
1602 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1603 PAIR_HREF_INIT(&tag
[1], n
->string
);
1605 print_otag(h
, TAG_A
, 2, tag
);
1607 if (NULL
== n
->next
)
1608 print_text(h
, n
->string
);
1610 for (n
= n
->next
; n
; n
= n
->next
)
1611 print_text(h
, n
->string
);
1617 mdoc_mt_pre(MDOC_ARGS
)
1619 struct htmlpair tag
[2];
1622 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1624 for (n
= n
->child
; n
; n
= n
->next
) {
1625 assert(n
->type
== ROFFT_TEXT
);
1628 bufcat(h
, "mailto:");
1629 bufcat(h
, n
->string
);
1631 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1632 t
= print_otag(h
, TAG_A
, 2, tag
);
1633 print_text(h
, n
->string
);
1641 mdoc_fo_pre(MDOC_ARGS
)
1643 struct htmlpair tag
;
1646 if (n
->type
== ROFFT_BODY
) {
1647 h
->flags
|= HTML_NOSPACE
;
1649 h
->flags
|= HTML_NOSPACE
;
1651 } else if (n
->type
== ROFFT_BLOCK
) {
1656 /* XXX: we drop non-initial arguments as per groff. */
1659 assert(n
->child
->string
);
1661 PAIR_CLASS_INIT(&tag
, "fname");
1662 t
= print_otag(h
, TAG_B
, 1, &tag
);
1663 print_text(h
, n
->child
->string
);
1669 mdoc_fo_post(MDOC_ARGS
)
1672 if (n
->type
!= ROFFT_BODY
)
1674 h
->flags
|= HTML_NOSPACE
;
1676 h
->flags
|= HTML_NOSPACE
;
1681 mdoc_in_pre(MDOC_ARGS
)
1684 struct htmlpair tag
[2];
1689 PAIR_CLASS_INIT(&tag
[0], "includes");
1690 print_otag(h
, TAG_B
, 1, tag
);
1693 * The first argument of the `In' gets special treatment as
1694 * being a linked value. Subsequent values are printed
1695 * afterward. groff does similarly. This also handles the case
1699 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1700 print_text(h
, "#include");
1703 h
->flags
|= HTML_NOSPACE
;
1705 if (NULL
!= (n
= n
->child
)) {
1706 assert(n
->type
== ROFFT_TEXT
);
1708 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1711 if (h
->base_includes
) {
1712 buffmt_includes(h
, n
->string
);
1713 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1717 t
= print_otag(h
, TAG_A
, i
, tag
);
1718 print_text(h
, n
->string
);
1724 h
->flags
|= HTML_NOSPACE
;
1727 for ( ; n
; n
= n
->next
) {
1728 assert(n
->type
== ROFFT_TEXT
);
1729 print_text(h
, n
->string
);
1736 mdoc_ic_pre(MDOC_ARGS
)
1738 struct htmlpair tag
;
1740 PAIR_CLASS_INIT(&tag
, "cmd");
1741 print_otag(h
, TAG_B
, 1, &tag
);
1746 mdoc_rv_pre(MDOC_ARGS
)
1748 struct htmlpair tag
;
1753 print_otag(h
, TAG_BR
, 0, NULL
);
1755 PAIR_CLASS_INIT(&tag
, "fname");
1759 print_text(h
, "The");
1761 for (n
= n
->child
; n
; n
= n
->next
) {
1762 t
= print_otag(h
, TAG_B
, 1, &tag
);
1763 print_text(h
, n
->string
);
1766 h
->flags
|= HTML_NOSPACE
;
1767 print_text(h
, "()");
1769 if (n
->next
== NULL
)
1773 h
->flags
|= HTML_NOSPACE
;
1776 if (n
->next
->next
== NULL
)
1777 print_text(h
, "and");
1781 print_text(h
, "functions return");
1783 print_text(h
, "function returns");
1785 print_text(h
, "the value\\~0 if successful;");
1787 print_text(h
, "Upon successful completion,"
1788 " the value\\~0 is returned;");
1790 print_text(h
, "otherwise the value\\~\\-1 is returned"
1791 " and the global variable");
1793 PAIR_CLASS_INIT(&tag
, "var");
1794 t
= print_otag(h
, TAG_B
, 1, &tag
);
1795 print_text(h
, "errno");
1797 print_text(h
, "is set to indicate the error.");
1802 mdoc_va_pre(MDOC_ARGS
)
1804 struct htmlpair tag
;
1806 PAIR_CLASS_INIT(&tag
, "var");
1807 print_otag(h
, TAG_B
, 1, &tag
);
1812 mdoc_ap_pre(MDOC_ARGS
)
1815 h
->flags
|= HTML_NOSPACE
;
1816 print_text(h
, "\\(aq");
1817 h
->flags
|= HTML_NOSPACE
;
1822 mdoc_bf_pre(MDOC_ARGS
)
1824 struct htmlpair tag
[2];
1827 if (n
->type
== ROFFT_HEAD
)
1829 else if (n
->type
!= ROFFT_BODY
)
1832 if (FONT_Em
== n
->norm
->Bf
.font
)
1833 PAIR_CLASS_INIT(&tag
[0], "emph");
1834 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1835 PAIR_CLASS_INIT(&tag
[0], "symb");
1836 else if (FONT_Li
== n
->norm
->Bf
.font
)
1837 PAIR_CLASS_INIT(&tag
[0], "lit");
1839 PAIR_CLASS_INIT(&tag
[0], "none");
1842 * We want this to be inline-formatted, but needs to be div to
1843 * accept block children.
1846 bufcat_style(h
, "display", "inline");
1847 SCALE_HS_INIT(&su
, 1);
1848 /* Needs a left-margin for spacing. */
1849 bufcat_su(h
, "margin-left", &su
);
1850 PAIR_STYLE_INIT(&tag
[1], h
);
1851 print_otag(h
, TAG_DIV
, 2, tag
);
1856 mdoc_ms_pre(MDOC_ARGS
)
1858 struct htmlpair tag
;
1860 PAIR_CLASS_INIT(&tag
, "symb");
1861 print_otag(h
, TAG_SPAN
, 1, &tag
);
1866 mdoc_igndelim_pre(MDOC_ARGS
)
1869 h
->flags
|= HTML_IGNDELIM
;
1874 mdoc_pf_post(MDOC_ARGS
)
1877 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1878 h
->flags
|= HTML_NOSPACE
;
1882 mdoc_rs_pre(MDOC_ARGS
)
1884 struct htmlpair tag
;
1886 if (n
->type
!= ROFFT_BLOCK
)
1889 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1892 PAIR_CLASS_INIT(&tag
, "ref");
1893 print_otag(h
, TAG_SPAN
, 1, &tag
);
1898 mdoc_no_pre(MDOC_ARGS
)
1900 struct htmlpair tag
;
1902 PAIR_CLASS_INIT(&tag
, "none");
1903 print_otag(h
, TAG_CODE
, 1, &tag
);
1908 mdoc_li_pre(MDOC_ARGS
)
1910 struct htmlpair tag
;
1912 PAIR_CLASS_INIT(&tag
, "lit");
1913 print_otag(h
, TAG_CODE
, 1, &tag
);
1918 mdoc_sy_pre(MDOC_ARGS
)
1920 struct htmlpair tag
;
1922 PAIR_CLASS_INIT(&tag
, "symb");
1923 print_otag(h
, TAG_SPAN
, 1, &tag
);
1928 mdoc_bt_pre(MDOC_ARGS
)
1931 print_text(h
, "is currently in beta test.");
1936 mdoc_ud_pre(MDOC_ARGS
)
1939 print_text(h
, "currently under development.");
1944 mdoc_lb_pre(MDOC_ARGS
)
1946 struct htmlpair tag
;
1948 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1949 print_otag(h
, TAG_BR
, 0, NULL
);
1951 PAIR_CLASS_INIT(&tag
, "lib");
1952 print_otag(h
, TAG_SPAN
, 1, &tag
);
1957 mdoc__x_pre(MDOC_ARGS
)
1959 struct htmlpair tag
[2];
1966 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1967 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1968 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1969 print_text(h
, "and");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1976 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1982 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1986 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1990 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1993 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1996 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1999 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2002 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2005 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2008 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2011 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2018 if (MDOC__U
!= n
->tok
) {
2019 print_otag(h
, t
, 1, tag
);
2023 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2024 print_otag(h
, TAG_A
, 2, tag
);
2030 mdoc__x_post(MDOC_ARGS
)
2033 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2034 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2035 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2040 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2043 h
->flags
|= HTML_NOSPACE
;
2044 print_text(h
, n
->next
? "," : ".");
2048 mdoc_bk_pre(MDOC_ARGS
)
2057 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2058 h
->flags
|= HTML_PREKEEP
;
2069 mdoc_bk_post(MDOC_ARGS
)
2072 if (n
->type
== ROFFT_BODY
)
2073 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2077 mdoc_quote_pre(MDOC_ARGS
)
2079 struct htmlpair tag
;
2081 if (n
->type
!= ROFFT_BODY
)
2088 print_text(h
, n
->nchild
== 1 &&
2089 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2094 print_text(h
, "\\(lC");
2099 print_text(h
, "\\(lB");
2104 print_text(h
, "\\(lB");
2105 h
->flags
|= HTML_NOSPACE
;
2106 PAIR_CLASS_INIT(&tag
, "opt");
2107 print_otag(h
, TAG_SPAN
, 1, &tag
);
2110 if (NULL
== n
->norm
->Es
||
2111 NULL
== n
->norm
->Es
->child
)
2113 print_text(h
, n
->norm
->Es
->child
->string
);
2122 print_text(h
, "\\(lq");
2130 print_text(h
, "\\(oq");
2131 h
->flags
|= HTML_NOSPACE
;
2132 PAIR_CLASS_INIT(&tag
, "lit");
2133 print_otag(h
, TAG_CODE
, 1, &tag
);
2138 print_text(h
, "\\(oq");
2145 h
->flags
|= HTML_NOSPACE
;
2150 mdoc_quote_post(MDOC_ARGS
)
2153 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
2156 h
->flags
|= HTML_NOSPACE
;
2162 print_text(h
, n
->nchild
== 1 &&
2163 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2168 print_text(h
, "\\(rC");
2177 print_text(h
, "\\(rB");
2180 if (n
->norm
->Es
== NULL
||
2181 n
->norm
->Es
->child
== NULL
||
2182 n
->norm
->Es
->child
->next
== NULL
)
2183 h
->flags
&= ~HTML_NOSPACE
;
2185 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2194 print_text(h
, "\\(rq");
2206 print_text(h
, "\\(cq");
2215 mdoc_eo_pre(MDOC_ARGS
)
2218 if (n
->type
!= ROFFT_BODY
)
2221 if (n
->end
== ENDBODY_NOT
&&
2222 n
->parent
->head
->child
== NULL
&&
2224 n
->child
->end
!= ENDBODY_NOT
)
2225 print_text(h
, "\\&");
2226 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2227 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2228 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2229 h
->flags
|= HTML_NOSPACE
;
2234 mdoc_eo_post(MDOC_ARGS
)
2238 if (n
->type
!= ROFFT_BODY
)
2241 if (n
->end
!= ENDBODY_NOT
) {
2242 h
->flags
&= ~HTML_NOSPACE
;
2246 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2247 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2250 h
->flags
|= HTML_NOSPACE
;
2252 h
->flags
&= ~HTML_NOSPACE
;