]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.237 2015/10/06 18:32:19 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 print_otag(h
, TAG_TD
, 0, NULL
);
648 PAIR_CLASS_INIT(&tag
, "name");
649 print_otag(h
, TAG_B
, 1, &tag
);
650 if (n
->child
== NULL
&& meta
->name
!= NULL
)
651 print_text(h
, meta
->name
);
654 print_otag(h
, TAG_TD
, 0, NULL
);
661 PAIR_CLASS_INIT(&tag
, "synopsis");
662 print_otag(h
, TAG_TABLE
, 1, &tag
);
664 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
665 if (n
->type
== ROFFT_TEXT
)
666 len
+= html_strlen(n
->string
);
668 if (len
== 0 && meta
->name
!= NULL
)
669 len
= html_strlen(meta
->name
);
671 SCALE_HS_INIT(&su
, len
);
673 bufcat_su(h
, "width", &su
);
674 PAIR_STYLE_INIT(&tag
, h
);
675 print_otag(h
, TAG_COL
, 1, &tag
);
676 print_otag(h
, TAG_COL
, 0, NULL
);
677 print_otag(h
, TAG_TBODY
, 0, NULL
);
678 print_otag(h
, TAG_TR
, 0, NULL
);
683 mdoc_xr_pre(MDOC_ARGS
)
685 struct htmlpair tag
[2];
687 if (NULL
== n
->child
)
690 PAIR_CLASS_INIT(&tag
[0], "link-man");
693 buffmt_man(h
, n
->child
->string
,
695 n
->child
->next
->string
: NULL
);
696 PAIR_HREF_INIT(&tag
[1], h
->buf
);
697 print_otag(h
, TAG_A
, 2, tag
);
699 print_otag(h
, TAG_A
, 1, tag
);
702 print_text(h
, n
->string
);
704 if (NULL
== (n
= n
->next
))
707 h
->flags
|= HTML_NOSPACE
;
709 h
->flags
|= HTML_NOSPACE
;
710 print_text(h
, n
->string
);
711 h
->flags
|= HTML_NOSPACE
;
717 mdoc_ns_pre(MDOC_ARGS
)
720 if ( ! (MDOC_LINE
& n
->flags
))
721 h
->flags
|= HTML_NOSPACE
;
726 mdoc_ar_pre(MDOC_ARGS
)
730 PAIR_CLASS_INIT(&tag
, "arg");
731 print_otag(h
, TAG_I
, 1, &tag
);
736 mdoc_xx_pre(MDOC_ARGS
)
765 PAIR_CLASS_INIT(&tag
, "unix");
766 print_otag(h
, TAG_SPAN
, 1, &tag
);
771 h
->flags
|= HTML_KEEP
;
772 print_text(h
, n
->child
->string
);
779 mdoc_bx_pre(MDOC_ARGS
)
783 PAIR_CLASS_INIT(&tag
, "unix");
784 print_otag(h
, TAG_SPAN
, 1, &tag
);
786 if (NULL
!= (n
= n
->child
)) {
787 print_text(h
, n
->string
);
788 h
->flags
|= HTML_NOSPACE
;
789 print_text(h
, "BSD");
791 print_text(h
, "BSD");
795 if (NULL
!= (n
= n
->next
)) {
796 h
->flags
|= HTML_NOSPACE
;
798 h
->flags
|= HTML_NOSPACE
;
799 print_text(h
, n
->string
);
806 mdoc_it_pre(MDOC_ARGS
)
810 struct htmlpair tag
[2];
811 const struct roff_node
*bl
;
814 while (bl
&& MDOC_Bl
!= bl
->tok
)
819 type
= bl
->norm
->Bl
.type
;
822 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
826 if (n
->type
== ROFFT_HEAD
) {
847 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
848 bufcat_su(h
, "margin-top", &su
);
849 PAIR_STYLE_INIT(&tag
[1], h
);
850 print_otag(h
, TAG_DT
, 2, tag
);
851 if (LIST_diag
!= type
)
853 PAIR_CLASS_INIT(&tag
[0], "diag");
854 print_otag(h
, TAG_B
, 1, tag
);
861 } else if (n
->type
== ROFFT_BODY
) {
872 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
873 bufcat_su(h
, "margin-top", &su
);
874 PAIR_STYLE_INIT(&tag
[1], h
);
875 print_otag(h
, TAG_LI
, 2, tag
);
886 if (NULL
== bl
->norm
->Bl
.width
) {
887 print_otag(h
, TAG_DD
, 1, tag
);
890 a2width(bl
->norm
->Bl
.width
, &su
);
891 bufcat_su(h
, "margin-left", &su
);
892 PAIR_STYLE_INIT(&tag
[1], h
);
893 print_otag(h
, TAG_DD
, 2, tag
);
896 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
897 bufcat_su(h
, "margin-top", &su
);
898 PAIR_STYLE_INIT(&tag
[1], h
);
899 print_otag(h
, TAG_TD
, 2, tag
);
907 print_otag(h
, TAG_TR
, 1, tag
);
918 mdoc_bl_pre(MDOC_ARGS
)
921 struct htmlpair tag
[3];
925 if (n
->type
== ROFFT_BODY
) {
926 if (LIST_column
== n
->norm
->Bl
.type
)
927 print_otag(h
, TAG_TBODY
, 0, NULL
);
931 if (n
->type
== ROFFT_HEAD
) {
932 if (LIST_column
!= n
->norm
->Bl
.type
)
936 * For each column, print out the <COL> tag with our
937 * suggested width. The last column gets min-width, as
938 * in terminal mode it auto-sizes to the width of the
939 * screen and we want to preserve that behaviour.
942 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
944 a2width(n
->norm
->Bl
.cols
[i
], &su
);
945 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
946 bufcat_su(h
, "width", &su
);
948 bufcat_su(h
, "min-width", &su
);
949 PAIR_STYLE_INIT(&tag
[0], h
);
950 print_otag(h
, TAG_COL
, 1, tag
);
956 SCALE_VS_INIT(&su
, 0);
958 bufcat_su(h
, "margin-top", &su
);
959 bufcat_su(h
, "margin-bottom", &su
);
960 PAIR_STYLE_INIT(&tag
[0], h
);
962 assert(lists
[n
->norm
->Bl
.type
]);
963 (void)strlcpy(buf
, "list ", BUFSIZ
);
964 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
965 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
967 /* Set the block's left-hand margin. */
969 if (n
->norm
->Bl
.offs
) {
970 a2width(n
->norm
->Bl
.offs
, &su
);
971 bufcat_su(h
, "margin-left", &su
);
974 switch (n
->norm
->Bl
.type
) {
982 print_otag(h
, TAG_UL
, 2, tag
);
985 print_otag(h
, TAG_OL
, 2, tag
);
996 print_otag(h
, TAG_DL
, 2, tag
);
999 print_otag(h
, TAG_TABLE
, 2, tag
);
1009 mdoc_ex_pre(MDOC_ARGS
)
1012 struct htmlpair tag
;
1016 print_otag(h
, TAG_BR
, 0, NULL
);
1018 PAIR_CLASS_INIT(&tag
, "utility");
1020 print_text(h
, "The");
1023 for (n
= n
->child
; n
; n
= n
->next
) {
1024 assert(n
->type
== ROFFT_TEXT
);
1026 t
= print_otag(h
, TAG_B
, 1, &tag
);
1027 print_text(h
, n
->string
);
1030 if (nchild
> 2 && n
->next
) {
1031 h
->flags
|= HTML_NOSPACE
;
1035 if (n
->next
&& NULL
== n
->next
->next
)
1036 print_text(h
, "and");
1040 print_text(h
, "utilities exit\\~0");
1042 print_text(h
, "utility exits\\~0");
1044 print_text(h
, "on success, and\\~>0 if an error occurs.");
1049 mdoc_em_pre(MDOC_ARGS
)
1051 struct htmlpair tag
;
1053 PAIR_CLASS_INIT(&tag
, "emph");
1054 print_otag(h
, TAG_SPAN
, 1, &tag
);
1059 mdoc_d1_pre(MDOC_ARGS
)
1061 struct htmlpair tag
[2];
1064 if (n
->type
!= ROFFT_BLOCK
)
1067 SCALE_VS_INIT(&su
, 0);
1069 bufcat_su(h
, "margin-top", &su
);
1070 bufcat_su(h
, "margin-bottom", &su
);
1071 PAIR_STYLE_INIT(&tag
[0], h
);
1072 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1074 /* BLOCKQUOTE needs a block body. */
1076 PAIR_CLASS_INIT(&tag
[0], "display");
1077 print_otag(h
, TAG_DIV
, 1, tag
);
1079 if (MDOC_Dl
== n
->tok
) {
1080 PAIR_CLASS_INIT(&tag
[0], "lit");
1081 print_otag(h
, TAG_CODE
, 1, tag
);
1088 mdoc_sx_pre(MDOC_ARGS
)
1090 struct htmlpair tag
[2];
1095 for (n
= n
->child
; n
; ) {
1096 bufcat_id(h
, n
->string
);
1097 if (NULL
!= (n
= n
->next
))
1101 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1102 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1104 print_otag(h
, TAG_I
, 1, tag
);
1105 print_otag(h
, TAG_A
, 2, tag
);
1110 mdoc_bd_pre(MDOC_ARGS
)
1112 struct htmlpair tag
[2];
1114 struct roff_node
*nn
;
1117 if (n
->type
== ROFFT_HEAD
)
1120 if (n
->type
== ROFFT_BLOCK
) {
1121 comp
= n
->norm
->Bd
.comp
;
1122 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1123 if (nn
->type
!= ROFFT_BLOCK
)
1125 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1135 /* Handle the -offset argument. */
1137 if (n
->norm
->Bd
.offs
== NULL
||
1138 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1139 SCALE_HS_INIT(&su
, 0);
1140 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1141 SCALE_HS_INIT(&su
, INDENT
);
1142 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1143 SCALE_HS_INIT(&su
, INDENT
* 2);
1145 a2width(n
->norm
->Bd
.offs
, &su
);
1148 bufcat_su(h
, "margin-left", &su
);
1149 PAIR_STYLE_INIT(&tag
[0], h
);
1151 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1152 DISP_literal
!= n
->norm
->Bd
.type
) {
1153 PAIR_CLASS_INIT(&tag
[1], "display");
1154 print_otag(h
, TAG_DIV
, 2, tag
);
1158 PAIR_CLASS_INIT(&tag
[1], "lit display");
1159 print_otag(h
, TAG_PRE
, 2, tag
);
1161 /* This can be recursive: save & set our literal state. */
1163 sv
= h
->flags
& HTML_LITERAL
;
1164 h
->flags
|= HTML_LITERAL
;
1166 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1167 print_mdoc_node(meta
, nn
, h
);
1169 * If the printed node flushes its own line, then we
1170 * needn't do it here as well. This is hacky, but the
1171 * notion of selective eoln whitespace is pretty dumb
1172 * anyway, so don't sweat it.
1194 if (h
->flags
& HTML_NONEWLINE
||
1195 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1198 print_text(h
, "\n");
1200 h
->flags
|= HTML_NOSPACE
;
1204 h
->flags
&= ~HTML_LITERAL
;
1210 mdoc_pa_pre(MDOC_ARGS
)
1212 struct htmlpair tag
;
1214 PAIR_CLASS_INIT(&tag
, "file");
1215 print_otag(h
, TAG_I
, 1, &tag
);
1220 mdoc_ad_pre(MDOC_ARGS
)
1222 struct htmlpair tag
;
1224 PAIR_CLASS_INIT(&tag
, "addr");
1225 print_otag(h
, TAG_I
, 1, &tag
);
1230 mdoc_an_pre(MDOC_ARGS
)
1232 struct htmlpair tag
;
1234 if (n
->norm
->An
.auth
== AUTH_split
) {
1235 h
->flags
&= ~HTML_NOSPLIT
;
1236 h
->flags
|= HTML_SPLIT
;
1239 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1240 h
->flags
&= ~HTML_SPLIT
;
1241 h
->flags
|= HTML_NOSPLIT
;
1245 if (h
->flags
& HTML_SPLIT
)
1246 print_otag(h
, TAG_BR
, 0, NULL
);
1248 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1249 h
->flags
|= HTML_SPLIT
;
1251 PAIR_CLASS_INIT(&tag
, "author");
1252 print_otag(h
, TAG_SPAN
, 1, &tag
);
1257 mdoc_cd_pre(MDOC_ARGS
)
1259 struct htmlpair tag
;
1262 PAIR_CLASS_INIT(&tag
, "config");
1263 print_otag(h
, TAG_B
, 1, &tag
);
1268 mdoc_dv_pre(MDOC_ARGS
)
1270 struct htmlpair tag
;
1272 PAIR_CLASS_INIT(&tag
, "define");
1273 print_otag(h
, TAG_SPAN
, 1, &tag
);
1278 mdoc_ev_pre(MDOC_ARGS
)
1280 struct htmlpair tag
;
1282 PAIR_CLASS_INIT(&tag
, "env");
1283 print_otag(h
, TAG_SPAN
, 1, &tag
);
1288 mdoc_er_pre(MDOC_ARGS
)
1290 struct htmlpair tag
;
1292 PAIR_CLASS_INIT(&tag
, "errno");
1293 print_otag(h
, TAG_SPAN
, 1, &tag
);
1298 mdoc_fa_pre(MDOC_ARGS
)
1300 const struct roff_node
*nn
;
1301 struct htmlpair tag
;
1304 PAIR_CLASS_INIT(&tag
, "farg");
1305 if (n
->parent
->tok
!= MDOC_Fo
) {
1306 print_otag(h
, TAG_I
, 1, &tag
);
1310 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1311 t
= print_otag(h
, TAG_I
, 1, &tag
);
1312 print_text(h
, nn
->string
);
1315 h
->flags
|= HTML_NOSPACE
;
1320 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1321 h
->flags
|= HTML_NOSPACE
;
1329 mdoc_fd_pre(MDOC_ARGS
)
1331 struct htmlpair tag
[2];
1339 if (NULL
== (n
= n
->child
))
1342 assert(n
->type
== ROFFT_TEXT
);
1344 if (strcmp(n
->string
, "#include")) {
1345 PAIR_CLASS_INIT(&tag
[0], "macro");
1346 print_otag(h
, TAG_B
, 1, tag
);
1350 PAIR_CLASS_INIT(&tag
[0], "includes");
1351 print_otag(h
, TAG_B
, 1, tag
);
1352 print_text(h
, n
->string
);
1354 if (NULL
!= (n
= n
->next
)) {
1355 assert(n
->type
== ROFFT_TEXT
);
1358 * XXX This is broken and not easy to fix.
1359 * When using -Oincludes, truncation may occur.
1360 * Dynamic allocation wouldn't help because
1361 * passing long strings to buffmt_includes()
1362 * does not work either.
1365 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1366 n
->string
+ 1 : n
->string
, BUFSIZ
);
1369 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1372 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1375 if (h
->base_includes
) {
1376 buffmt_includes(h
, buf
);
1377 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1381 t
= print_otag(h
, TAG_A
, i
, tag
);
1382 print_text(h
, n
->string
);
1388 for ( ; n
; n
= n
->next
) {
1389 assert(n
->type
== ROFFT_TEXT
);
1390 print_text(h
, n
->string
);
1397 mdoc_vt_pre(MDOC_ARGS
)
1399 struct htmlpair tag
;
1401 if (n
->type
== ROFFT_BLOCK
) {
1404 } else if (n
->type
== ROFFT_ELEM
) {
1406 } else if (n
->type
== ROFFT_HEAD
)
1409 PAIR_CLASS_INIT(&tag
, "type");
1410 print_otag(h
, TAG_SPAN
, 1, &tag
);
1415 mdoc_ft_pre(MDOC_ARGS
)
1417 struct htmlpair tag
;
1420 PAIR_CLASS_INIT(&tag
, "ftype");
1421 print_otag(h
, TAG_I
, 1, &tag
);
1426 mdoc_fn_pre(MDOC_ARGS
)
1429 struct htmlpair tag
[2];
1431 const char *sp
, *ep
;
1434 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1437 /* Split apart into type and name. */
1438 assert(n
->child
->string
);
1439 sp
= n
->child
->string
;
1441 ep
= strchr(sp
, ' ');
1443 PAIR_CLASS_INIT(&tag
[0], "ftype");
1444 t
= print_otag(h
, TAG_I
, 1, tag
);
1447 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1448 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1450 print_text(h
, nbuf
);
1452 ep
= strchr(sp
, ' ');
1457 PAIR_CLASS_INIT(&tag
[0], "fname");
1460 * FIXME: only refer to IDs that we know exist.
1464 if (MDOC_SYNPRETTY
& n
->flags
) {
1466 html_idcat(nbuf
, sp
, BUFSIZ
);
1467 PAIR_ID_INIT(&tag
[1], nbuf
);
1469 strlcpy(nbuf
, "#", BUFSIZ
);
1470 html_idcat(nbuf
, sp
, BUFSIZ
);
1471 PAIR_HREF_INIT(&tag
[1], nbuf
);
1475 t
= print_otag(h
, TAG_B
, 1, tag
);
1482 h
->flags
|= HTML_NOSPACE
;
1484 h
->flags
|= HTML_NOSPACE
;
1486 PAIR_CLASS_INIT(&tag
[0], "farg");
1488 bufcat_style(h
, "white-space", "nowrap");
1489 PAIR_STYLE_INIT(&tag
[1], h
);
1491 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1493 if (MDOC_SYNPRETTY
& n
->flags
)
1495 t
= print_otag(h
, TAG_I
, i
, tag
);
1496 print_text(h
, n
->string
);
1499 h
->flags
|= HTML_NOSPACE
;
1504 h
->flags
|= HTML_NOSPACE
;
1508 h
->flags
|= HTML_NOSPACE
;
1516 mdoc_sm_pre(MDOC_ARGS
)
1519 if (NULL
== n
->child
)
1520 h
->flags
^= HTML_NONOSPACE
;
1521 else if (0 == strcmp("on", n
->child
->string
))
1522 h
->flags
&= ~HTML_NONOSPACE
;
1524 h
->flags
|= HTML_NONOSPACE
;
1526 if ( ! (HTML_NONOSPACE
& h
->flags
))
1527 h
->flags
&= ~HTML_NOSPACE
;
1533 mdoc_skip_pre(MDOC_ARGS
)
1540 mdoc_pp_pre(MDOC_ARGS
)
1548 mdoc_sp_pre(MDOC_ARGS
)
1551 struct htmlpair tag
;
1553 SCALE_VS_INIT(&su
, 1);
1555 if (MDOC_sp
== n
->tok
) {
1556 if (NULL
!= (n
= n
->child
)) {
1557 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1559 else if (su
.scale
< 0.0)
1566 bufcat_su(h
, "height", &su
);
1567 PAIR_STYLE_INIT(&tag
, h
);
1568 print_otag(h
, TAG_DIV
, 1, &tag
);
1570 /* So the div isn't empty: */
1571 print_text(h
, "\\~");
1578 mdoc_lk_pre(MDOC_ARGS
)
1580 struct htmlpair tag
[2];
1582 if (NULL
== (n
= n
->child
))
1585 assert(n
->type
== ROFFT_TEXT
);
1587 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1588 PAIR_HREF_INIT(&tag
[1], n
->string
);
1590 print_otag(h
, TAG_A
, 2, tag
);
1592 if (NULL
== n
->next
)
1593 print_text(h
, n
->string
);
1595 for (n
= n
->next
; n
; n
= n
->next
)
1596 print_text(h
, n
->string
);
1602 mdoc_mt_pre(MDOC_ARGS
)
1604 struct htmlpair tag
[2];
1607 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1609 for (n
= n
->child
; n
; n
= n
->next
) {
1610 assert(n
->type
== ROFFT_TEXT
);
1613 bufcat(h
, "mailto:");
1614 bufcat(h
, n
->string
);
1616 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1617 t
= print_otag(h
, TAG_A
, 2, tag
);
1618 print_text(h
, n
->string
);
1626 mdoc_fo_pre(MDOC_ARGS
)
1628 struct htmlpair tag
;
1631 if (n
->type
== ROFFT_BODY
) {
1632 h
->flags
|= HTML_NOSPACE
;
1634 h
->flags
|= HTML_NOSPACE
;
1636 } else if (n
->type
== ROFFT_BLOCK
) {
1641 if (n
->child
== NULL
)
1644 assert(n
->child
->string
);
1645 PAIR_CLASS_INIT(&tag
, "fname");
1646 t
= print_otag(h
, TAG_B
, 1, &tag
);
1647 print_text(h
, n
->child
->string
);
1653 mdoc_fo_post(MDOC_ARGS
)
1656 if (n
->type
!= ROFFT_BODY
)
1658 h
->flags
|= HTML_NOSPACE
;
1660 h
->flags
|= HTML_NOSPACE
;
1665 mdoc_in_pre(MDOC_ARGS
)
1668 struct htmlpair tag
[2];
1673 PAIR_CLASS_INIT(&tag
[0], "includes");
1674 print_otag(h
, TAG_B
, 1, tag
);
1677 * The first argument of the `In' gets special treatment as
1678 * being a linked value. Subsequent values are printed
1679 * afterward. groff does similarly. This also handles the case
1683 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1684 print_text(h
, "#include");
1687 h
->flags
|= HTML_NOSPACE
;
1689 if (NULL
!= (n
= n
->child
)) {
1690 assert(n
->type
== ROFFT_TEXT
);
1692 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1695 if (h
->base_includes
) {
1696 buffmt_includes(h
, n
->string
);
1697 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1701 t
= print_otag(h
, TAG_A
, i
, tag
);
1702 print_text(h
, n
->string
);
1708 h
->flags
|= HTML_NOSPACE
;
1711 for ( ; n
; n
= n
->next
) {
1712 assert(n
->type
== ROFFT_TEXT
);
1713 print_text(h
, n
->string
);
1720 mdoc_ic_pre(MDOC_ARGS
)
1722 struct htmlpair tag
;
1724 PAIR_CLASS_INIT(&tag
, "cmd");
1725 print_otag(h
, TAG_B
, 1, &tag
);
1730 mdoc_rv_pre(MDOC_ARGS
)
1732 struct htmlpair tag
;
1737 print_otag(h
, TAG_BR
, 0, NULL
);
1739 PAIR_CLASS_INIT(&tag
, "fname");
1743 print_text(h
, "The");
1745 for (n
= n
->child
; n
; n
= n
->next
) {
1746 t
= print_otag(h
, TAG_B
, 1, &tag
);
1747 print_text(h
, n
->string
);
1750 h
->flags
|= HTML_NOSPACE
;
1751 print_text(h
, "()");
1753 if (n
->next
== NULL
)
1757 h
->flags
|= HTML_NOSPACE
;
1760 if (n
->next
->next
== NULL
)
1761 print_text(h
, "and");
1765 print_text(h
, "functions return");
1767 print_text(h
, "function returns");
1769 print_text(h
, "the value\\~0 if successful;");
1771 print_text(h
, "Upon successful completion,"
1772 " the value\\~0 is returned;");
1774 print_text(h
, "otherwise the value\\~\\-1 is returned"
1775 " and the global variable");
1777 PAIR_CLASS_INIT(&tag
, "var");
1778 t
= print_otag(h
, TAG_B
, 1, &tag
);
1779 print_text(h
, "errno");
1781 print_text(h
, "is set to indicate the error.");
1786 mdoc_va_pre(MDOC_ARGS
)
1788 struct htmlpair tag
;
1790 PAIR_CLASS_INIT(&tag
, "var");
1791 print_otag(h
, TAG_B
, 1, &tag
);
1796 mdoc_ap_pre(MDOC_ARGS
)
1799 h
->flags
|= HTML_NOSPACE
;
1800 print_text(h
, "\\(aq");
1801 h
->flags
|= HTML_NOSPACE
;
1806 mdoc_bf_pre(MDOC_ARGS
)
1808 struct htmlpair tag
[2];
1811 if (n
->type
== ROFFT_HEAD
)
1813 else if (n
->type
!= ROFFT_BODY
)
1816 if (FONT_Em
== n
->norm
->Bf
.font
)
1817 PAIR_CLASS_INIT(&tag
[0], "emph");
1818 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1819 PAIR_CLASS_INIT(&tag
[0], "symb");
1820 else if (FONT_Li
== n
->norm
->Bf
.font
)
1821 PAIR_CLASS_INIT(&tag
[0], "lit");
1823 PAIR_CLASS_INIT(&tag
[0], "none");
1826 * We want this to be inline-formatted, but needs to be div to
1827 * accept block children.
1830 bufcat_style(h
, "display", "inline");
1831 SCALE_HS_INIT(&su
, 1);
1832 /* Needs a left-margin for spacing. */
1833 bufcat_su(h
, "margin-left", &su
);
1834 PAIR_STYLE_INIT(&tag
[1], h
);
1835 print_otag(h
, TAG_DIV
, 2, tag
);
1840 mdoc_ms_pre(MDOC_ARGS
)
1842 struct htmlpair tag
;
1844 PAIR_CLASS_INIT(&tag
, "symb");
1845 print_otag(h
, TAG_SPAN
, 1, &tag
);
1850 mdoc_igndelim_pre(MDOC_ARGS
)
1853 h
->flags
|= HTML_IGNDELIM
;
1858 mdoc_pf_post(MDOC_ARGS
)
1861 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1862 h
->flags
|= HTML_NOSPACE
;
1866 mdoc_rs_pre(MDOC_ARGS
)
1868 struct htmlpair tag
;
1870 if (n
->type
!= ROFFT_BLOCK
)
1873 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1876 PAIR_CLASS_INIT(&tag
, "ref");
1877 print_otag(h
, TAG_SPAN
, 1, &tag
);
1882 mdoc_no_pre(MDOC_ARGS
)
1884 struct htmlpair tag
;
1886 PAIR_CLASS_INIT(&tag
, "none");
1887 print_otag(h
, TAG_CODE
, 1, &tag
);
1892 mdoc_li_pre(MDOC_ARGS
)
1894 struct htmlpair tag
;
1896 PAIR_CLASS_INIT(&tag
, "lit");
1897 print_otag(h
, TAG_CODE
, 1, &tag
);
1902 mdoc_sy_pre(MDOC_ARGS
)
1904 struct htmlpair tag
;
1906 PAIR_CLASS_INIT(&tag
, "symb");
1907 print_otag(h
, TAG_SPAN
, 1, &tag
);
1912 mdoc_bt_pre(MDOC_ARGS
)
1915 print_text(h
, "is currently in beta test.");
1920 mdoc_ud_pre(MDOC_ARGS
)
1923 print_text(h
, "currently under development.");
1928 mdoc_lb_pre(MDOC_ARGS
)
1930 struct htmlpair tag
;
1932 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1933 print_otag(h
, TAG_BR
, 0, NULL
);
1935 PAIR_CLASS_INIT(&tag
, "lib");
1936 print_otag(h
, TAG_SPAN
, 1, &tag
);
1941 mdoc__x_pre(MDOC_ARGS
)
1943 struct htmlpair tag
[2];
1950 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1951 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1952 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1953 print_text(h
, "and");
1956 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1960 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1963 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1966 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1970 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1974 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1977 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1980 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1983 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1986 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1989 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1992 PAIR_CLASS_INIT(&tag
[0], "link-ref");
1995 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2001 if (MDOC__U
!= n
->tok
) {
2002 print_otag(h
, t
, 1, tag
);
2006 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2007 print_otag(h
, TAG_A
, 2, tag
);
2013 mdoc__x_post(MDOC_ARGS
)
2016 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2017 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2018 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2023 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2026 h
->flags
|= HTML_NOSPACE
;
2027 print_text(h
, n
->next
? "," : ".");
2031 mdoc_bk_pre(MDOC_ARGS
)
2040 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2041 h
->flags
|= HTML_PREKEEP
;
2051 mdoc_bk_post(MDOC_ARGS
)
2054 if (n
->type
== ROFFT_BODY
)
2055 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2059 mdoc_quote_pre(MDOC_ARGS
)
2061 struct htmlpair tag
;
2063 if (n
->type
!= ROFFT_BODY
)
2070 print_text(h
, n
->nchild
== 1 &&
2071 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2076 print_text(h
, "\\(lC");
2081 print_text(h
, "\\(lB");
2086 print_text(h
, "\\(lB");
2087 h
->flags
|= HTML_NOSPACE
;
2088 PAIR_CLASS_INIT(&tag
, "opt");
2089 print_otag(h
, TAG_SPAN
, 1, &tag
);
2092 if (NULL
== n
->norm
->Es
||
2093 NULL
== n
->norm
->Es
->child
)
2095 print_text(h
, n
->norm
->Es
->child
->string
);
2104 print_text(h
, "\\(lq");
2112 print_text(h
, "\\(oq");
2113 h
->flags
|= HTML_NOSPACE
;
2114 PAIR_CLASS_INIT(&tag
, "lit");
2115 print_otag(h
, TAG_CODE
, 1, &tag
);
2120 print_text(h
, "\\(oq");
2126 h
->flags
|= HTML_NOSPACE
;
2131 mdoc_quote_post(MDOC_ARGS
)
2134 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
2137 h
->flags
|= HTML_NOSPACE
;
2143 print_text(h
, n
->nchild
== 1 &&
2144 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2149 print_text(h
, "\\(rC");
2158 print_text(h
, "\\(rB");
2161 if (n
->norm
->Es
== NULL
||
2162 n
->norm
->Es
->child
== NULL
||
2163 n
->norm
->Es
->child
->next
== NULL
)
2164 h
->flags
&= ~HTML_NOSPACE
;
2166 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2175 print_text(h
, "\\(rq");
2187 print_text(h
, "\\(cq");
2195 mdoc_eo_pre(MDOC_ARGS
)
2198 if (n
->type
!= ROFFT_BODY
)
2201 if (n
->end
== ENDBODY_NOT
&&
2202 n
->parent
->head
->child
== NULL
&&
2204 n
->child
->end
!= ENDBODY_NOT
)
2205 print_text(h
, "\\&");
2206 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2207 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2208 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2209 h
->flags
|= HTML_NOSPACE
;
2214 mdoc_eo_post(MDOC_ARGS
)
2218 if (n
->type
!= ROFFT_BODY
)
2221 if (n
->end
!= ENDBODY_NOT
) {
2222 h
->flags
&= ~HTML_NOSPACE
;
2226 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2227 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2230 h
->flags
|= HTML_NOSPACE
;
2232 h
->flags
&= ~HTML_NOSPACE
;