]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.225 2015/02/12 12:24:33 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 AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
37 #define MDOC_ARGS const struct mdoc_meta *meta, \
38 struct mdoc_node *n, \
42 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
46 int (*pre
)(MDOC_ARGS
);
47 void (*post
)(MDOC_ARGS
);
50 static void print_mdoc(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 mdoc_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 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
270 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
)->child
,
276 * Calculate the scaling unit passed in a `-width' argument. This uses
277 * either a native scaling unit (e.g., 1i, 2m) or the string length of
281 a2width(const char *p
, struct roffsu
*su
)
284 if (a2roffsu(p
, su
, SCALE_MAX
) < 2) {
286 su
->scale
= html_strlen(p
);
287 } else if (su
->scale
< 0.0)
292 * See the same function in mdoc_term.c for documentation.
295 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
298 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
301 if (n
->prev
->tok
== n
->tok
&&
305 print_otag(h
, TAG_BR
, 0, NULL
);
309 switch (n
->prev
->tok
) {
322 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
328 print_otag(h
, TAG_BR
, 0, NULL
);
334 print_mdoc(MDOC_ARGS
)
339 PAIR_CLASS_INIT(&tag
, "mandoc");
341 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
343 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
344 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
345 print_mdoc_head(meta
, n
, h
);
347 print_otag(h
, TAG_BODY
, 0, NULL
);
348 print_otag(h
, TAG_DIV
, 1, &tag
);
350 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
352 print_mdoc_nodelist(meta
, n
, h
);
357 print_mdoc_head(MDOC_ARGS
)
362 bufcat(h
, meta
->title
);
364 bufcat_fmt(h
, "(%s)", meta
->msec
);
366 bufcat_fmt(h
, " (%s)", meta
->arch
);
368 print_otag(h
, TAG_TITLE
, 0, NULL
);
369 print_text(h
, h
->buf
);
373 print_mdoc_nodelist(MDOC_ARGS
)
377 print_mdoc_node(meta
, n
, h
);
383 print_mdoc_node(MDOC_ARGS
)
390 n
->flags
&= ~MDOC_ENDED
;
394 child
= mdoc_root_pre(meta
, n
, h
);
397 /* No tables in this mode... */
398 assert(NULL
== h
->tblt
);
401 * Make sure that if we're in a literal mode already
402 * (i.e., within a <PRE>) don't print the newline.
404 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
405 if ( ! (HTML_LITERAL
& h
->flags
))
406 print_otag(h
, TAG_BR
, 0, NULL
);
407 if (MDOC_DELIMC
& n
->flags
)
408 h
->flags
|= HTML_NOSPACE
;
409 print_text(h
, n
->string
);
410 if (MDOC_DELIMO
& n
->flags
)
411 h
->flags
|= HTML_NOSPACE
;
414 print_eqn(h
, n
->eqn
);
418 * This will take care of initialising all of the table
419 * state data for the first table, then tearing it down
422 print_tbl(h
, n
->span
);
426 * Close out the current table, if it's open, and unset
427 * the "meta" table state. This will be reopened on the
428 * next table element.
430 if (h
->tblt
!= NULL
) {
434 assert(h
->tblt
== NULL
);
435 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
436 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
440 if (h
->flags
& HTML_KEEP
&& n
->flags
& MDOC_LINE
) {
441 h
->flags
&= ~HTML_KEEP
;
442 h
->flags
|= HTML_PREKEEP
;
445 if (child
&& n
->child
)
446 print_mdoc_nodelist(meta
, n
->child
, h
);
452 mdoc_root_post(meta
, n
, h
);
457 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
459 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
460 if (n
->end
!= ENDBODY_NOT
)
461 n
->body
->flags
|= MDOC_ENDED
;
462 if (n
->end
== ENDBODY_NOSPACE
)
463 h
->flags
|= HTML_NOSPACE
;
469 mdoc_root_post(MDOC_ARGS
)
474 PAIR_CLASS_INIT(&tag
, "foot");
475 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
477 print_otag(h
, TAG_TBODY
, 0, NULL
);
479 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
481 PAIR_CLASS_INIT(&tag
, "foot-date");
482 print_otag(h
, TAG_TD
, 1, &tag
);
483 print_text(h
, meta
->date
);
486 PAIR_CLASS_INIT(&tag
, "foot-os");
487 print_otag(h
, TAG_TD
, 1, &tag
);
488 print_text(h
, meta
->os
);
493 mdoc_root_pre(MDOC_ARGS
)
497 char *volume
, *title
;
499 if (NULL
== meta
->arch
)
500 volume
= mandoc_strdup(meta
->vol
);
502 mandoc_asprintf(&volume
, "%s (%s)",
503 meta
->vol
, meta
->arch
);
505 if (NULL
== meta
->msec
)
506 title
= mandoc_strdup(meta
->title
);
508 mandoc_asprintf(&title
, "%s(%s)",
509 meta
->title
, meta
->msec
);
511 PAIR_CLASS_INIT(&tag
, "head");
512 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
514 print_otag(h
, TAG_TBODY
, 0, NULL
);
516 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
518 PAIR_CLASS_INIT(&tag
, "head-ltitle");
519 print_otag(h
, TAG_TD
, 1, &tag
);
520 print_text(h
, title
);
523 PAIR_CLASS_INIT(&tag
, "head-vol");
524 print_otag(h
, TAG_TD
, 1, &tag
);
525 print_text(h
, volume
);
528 PAIR_CLASS_INIT(&tag
, "head-rtitle");
529 print_otag(h
, TAG_TD
, 1, &tag
);
530 print_text(h
, title
);
539 mdoc_sh_pre(MDOC_ARGS
)
545 PAIR_CLASS_INIT(&tag
, "section");
546 print_otag(h
, TAG_DIV
, 1, &tag
);
549 if (n
->sec
== SEC_AUTHORS
)
550 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
559 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
560 bufcat_id(h
, n
->string
);
561 if (NULL
!= (n
= n
->next
))
566 PAIR_ID_INIT(&tag
, h
->buf
);
567 print_otag(h
, TAG_H1
, 1, &tag
);
569 print_otag(h
, TAG_H1
, 0, NULL
);
575 mdoc_ss_pre(MDOC_ARGS
)
579 if (MDOC_BLOCK
== n
->type
) {
580 PAIR_CLASS_INIT(&tag
, "subsection");
581 print_otag(h
, TAG_DIV
, 1, &tag
);
583 } else if (MDOC_BODY
== n
->type
)
589 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
590 bufcat_id(h
, n
->string
);
591 if (NULL
!= (n
= n
->next
))
596 PAIR_ID_INIT(&tag
, h
->buf
);
597 print_otag(h
, TAG_H2
, 1, &tag
);
599 print_otag(h
, TAG_H2
, 0, NULL
);
605 mdoc_fl_pre(MDOC_ARGS
)
609 PAIR_CLASS_INIT(&tag
, "flag");
610 print_otag(h
, TAG_B
, 1, &tag
);
612 /* `Cm' has no leading hyphen. */
614 if (MDOC_Cm
== n
->tok
)
617 print_text(h
, "\\-");
619 if ( ! (n
->nchild
== 0 &&
621 n
->next
->type
== MDOC_TEXT
||
622 n
->next
->flags
& MDOC_LINE
)))
623 h
->flags
|= HTML_NOSPACE
;
629 mdoc_nd_pre(MDOC_ARGS
)
633 if (MDOC_BODY
!= n
->type
)
636 /* XXX: this tag in theory can contain block elements. */
638 print_text(h
, "\\(em");
639 PAIR_CLASS_INIT(&tag
, "desc");
640 print_otag(h
, TAG_SPAN
, 1, &tag
);
645 mdoc_nm_pre(MDOC_ARGS
)
654 PAIR_CLASS_INIT(&tag
, "name");
655 print_otag(h
, TAG_B
, 1, &tag
);
656 if (NULL
== n
->child
&& meta
->name
)
657 print_text(h
, meta
->name
);
660 print_otag(h
, TAG_TD
, 0, NULL
);
661 if (NULL
== n
->child
&& meta
->name
)
662 print_text(h
, meta
->name
);
665 print_otag(h
, TAG_TD
, 0, NULL
);
672 PAIR_CLASS_INIT(&tag
, "synopsis");
673 print_otag(h
, TAG_TABLE
, 1, &tag
);
675 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
676 if (MDOC_TEXT
== n
->type
)
677 len
+= html_strlen(n
->string
);
679 if (0 == len
&& meta
->name
)
680 len
= html_strlen(meta
->name
);
682 SCALE_HS_INIT(&su
, len
);
684 bufcat_su(h
, "width", &su
);
685 PAIR_STYLE_INIT(&tag
, h
);
686 print_otag(h
, TAG_COL
, 1, &tag
);
687 print_otag(h
, TAG_COL
, 0, NULL
);
688 print_otag(h
, TAG_TBODY
, 0, NULL
);
689 print_otag(h
, TAG_TR
, 0, NULL
);
694 mdoc_xr_pre(MDOC_ARGS
)
696 struct htmlpair tag
[2];
698 if (NULL
== n
->child
)
701 PAIR_CLASS_INIT(&tag
[0], "link-man");
704 buffmt_man(h
, n
->child
->string
,
706 n
->child
->next
->string
: NULL
);
707 PAIR_HREF_INIT(&tag
[1], h
->buf
);
708 print_otag(h
, TAG_A
, 2, tag
);
710 print_otag(h
, TAG_A
, 1, tag
);
713 print_text(h
, n
->string
);
715 if (NULL
== (n
= n
->next
))
718 h
->flags
|= HTML_NOSPACE
;
720 h
->flags
|= HTML_NOSPACE
;
721 print_text(h
, n
->string
);
722 h
->flags
|= HTML_NOSPACE
;
728 mdoc_ns_pre(MDOC_ARGS
)
731 if ( ! (MDOC_LINE
& n
->flags
))
732 h
->flags
|= HTML_NOSPACE
;
737 mdoc_ar_pre(MDOC_ARGS
)
741 PAIR_CLASS_INIT(&tag
, "arg");
742 print_otag(h
, TAG_I
, 1, &tag
);
747 mdoc_xx_pre(MDOC_ARGS
)
776 PAIR_CLASS_INIT(&tag
, "unix");
777 print_otag(h
, TAG_SPAN
, 1, &tag
);
782 h
->flags
|= HTML_KEEP
;
783 print_text(h
, n
->child
->string
);
790 mdoc_bx_pre(MDOC_ARGS
)
794 PAIR_CLASS_INIT(&tag
, "unix");
795 print_otag(h
, TAG_SPAN
, 1, &tag
);
797 if (NULL
!= (n
= n
->child
)) {
798 print_text(h
, n
->string
);
799 h
->flags
|= HTML_NOSPACE
;
800 print_text(h
, "BSD");
802 print_text(h
, "BSD");
806 if (NULL
!= (n
= n
->next
)) {
807 h
->flags
|= HTML_NOSPACE
;
809 h
->flags
|= HTML_NOSPACE
;
810 print_text(h
, n
->string
);
817 mdoc_it_pre(MDOC_ARGS
)
821 struct htmlpair tag
[2];
822 const struct mdoc_node
*bl
;
825 while (bl
&& MDOC_Bl
!= bl
->tok
)
830 type
= bl
->norm
->Bl
.type
;
833 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
837 if (MDOC_HEAD
== n
->type
) {
858 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
859 bufcat_su(h
, "margin-top", &su
);
860 PAIR_STYLE_INIT(&tag
[1], h
);
861 print_otag(h
, TAG_DT
, 2, tag
);
862 if (LIST_diag
!= type
)
864 PAIR_CLASS_INIT(&tag
[0], "diag");
865 print_otag(h
, TAG_B
, 1, tag
);
872 } else if (MDOC_BODY
== n
->type
) {
883 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
884 bufcat_su(h
, "margin-top", &su
);
885 PAIR_STYLE_INIT(&tag
[1], h
);
886 print_otag(h
, TAG_LI
, 2, tag
);
897 if (NULL
== bl
->norm
->Bl
.width
) {
898 print_otag(h
, TAG_DD
, 1, tag
);
901 a2width(bl
->norm
->Bl
.width
, &su
);
902 bufcat_su(h
, "margin-left", &su
);
903 PAIR_STYLE_INIT(&tag
[1], h
);
904 print_otag(h
, TAG_DD
, 2, tag
);
907 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
908 bufcat_su(h
, "margin-top", &su
);
909 PAIR_STYLE_INIT(&tag
[1], h
);
910 print_otag(h
, TAG_TD
, 2, tag
);
918 print_otag(h
, TAG_TR
, 1, tag
);
929 mdoc_bl_pre(MDOC_ARGS
)
932 struct htmlpair tag
[3];
936 if (MDOC_BODY
== n
->type
) {
937 if (LIST_column
== n
->norm
->Bl
.type
)
938 print_otag(h
, TAG_TBODY
, 0, NULL
);
942 if (MDOC_HEAD
== n
->type
) {
943 if (LIST_column
!= n
->norm
->Bl
.type
)
947 * For each column, print out the <COL> tag with our
948 * suggested width. The last column gets min-width, as
949 * in terminal mode it auto-sizes to the width of the
950 * screen and we want to preserve that behaviour.
953 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
955 a2width(n
->norm
->Bl
.cols
[i
], &su
);
956 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
957 bufcat_su(h
, "width", &su
);
959 bufcat_su(h
, "min-width", &su
);
960 PAIR_STYLE_INIT(&tag
[0], h
);
961 print_otag(h
, TAG_COL
, 1, tag
);
967 SCALE_VS_INIT(&su
, 0);
969 bufcat_su(h
, "margin-top", &su
);
970 bufcat_su(h
, "margin-bottom", &su
);
971 PAIR_STYLE_INIT(&tag
[0], h
);
973 assert(lists
[n
->norm
->Bl
.type
]);
974 (void)strlcpy(buf
, "list ", BUFSIZ
);
975 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
976 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
978 /* Set the block's left-hand margin. */
980 if (n
->norm
->Bl
.offs
) {
981 a2width(n
->norm
->Bl
.offs
, &su
);
982 bufcat_su(h
, "margin-left", &su
);
985 switch (n
->norm
->Bl
.type
) {
993 print_otag(h
, TAG_UL
, 2, tag
);
996 print_otag(h
, TAG_OL
, 2, tag
);
1007 print_otag(h
, TAG_DL
, 2, tag
);
1010 print_otag(h
, TAG_TABLE
, 2, tag
);
1021 mdoc_ex_pre(MDOC_ARGS
)
1024 struct htmlpair tag
;
1028 print_otag(h
, TAG_BR
, 0, NULL
);
1030 PAIR_CLASS_INIT(&tag
, "utility");
1032 print_text(h
, "The");
1035 for (n
= n
->child
; n
; n
= n
->next
) {
1036 assert(MDOC_TEXT
== n
->type
);
1038 t
= print_otag(h
, TAG_B
, 1, &tag
);
1039 print_text(h
, n
->string
);
1042 if (nchild
> 2 && n
->next
) {
1043 h
->flags
|= HTML_NOSPACE
;
1047 if (n
->next
&& NULL
== n
->next
->next
)
1048 print_text(h
, "and");
1052 print_text(h
, "utilities exit\\~0");
1054 print_text(h
, "utility exits\\~0");
1056 print_text(h
, "on success, and\\~>0 if an error occurs.");
1061 mdoc_em_pre(MDOC_ARGS
)
1063 struct htmlpair tag
;
1065 PAIR_CLASS_INIT(&tag
, "emph");
1066 print_otag(h
, TAG_SPAN
, 1, &tag
);
1071 mdoc_d1_pre(MDOC_ARGS
)
1073 struct htmlpair tag
[2];
1076 if (MDOC_BLOCK
!= n
->type
)
1079 SCALE_VS_INIT(&su
, 0);
1081 bufcat_su(h
, "margin-top", &su
);
1082 bufcat_su(h
, "margin-bottom", &su
);
1083 PAIR_STYLE_INIT(&tag
[0], h
);
1084 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1086 /* BLOCKQUOTE needs a block body. */
1088 PAIR_CLASS_INIT(&tag
[0], "display");
1089 print_otag(h
, TAG_DIV
, 1, tag
);
1091 if (MDOC_Dl
== n
->tok
) {
1092 PAIR_CLASS_INIT(&tag
[0], "lit");
1093 print_otag(h
, TAG_CODE
, 1, tag
);
1100 mdoc_sx_pre(MDOC_ARGS
)
1102 struct htmlpair tag
[2];
1107 for (n
= n
->child
; n
; ) {
1108 bufcat_id(h
, n
->string
);
1109 if (NULL
!= (n
= n
->next
))
1113 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1114 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1116 print_otag(h
, TAG_I
, 1, tag
);
1117 print_otag(h
, TAG_A
, 2, tag
);
1122 mdoc_bd_pre(MDOC_ARGS
)
1124 struct htmlpair tag
[2];
1126 struct mdoc_node
*nn
;
1129 if (MDOC_HEAD
== n
->type
)
1132 if (MDOC_BLOCK
== n
->type
) {
1133 comp
= n
->norm
->Bd
.comp
;
1134 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1135 if (MDOC_BLOCK
!= nn
->type
)
1137 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1147 /* Handle the -offset argument. */
1149 if (n
->norm
->Bd
.offs
== NULL
||
1150 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1151 SCALE_HS_INIT(&su
, 0);
1152 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1153 SCALE_HS_INIT(&su
, INDENT
);
1154 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1155 SCALE_HS_INIT(&su
, INDENT
* 2);
1157 a2width(n
->norm
->Bd
.offs
, &su
);
1160 bufcat_su(h
, "margin-left", &su
);
1161 PAIR_STYLE_INIT(&tag
[0], h
);
1163 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1164 DISP_literal
!= n
->norm
->Bd
.type
) {
1165 PAIR_CLASS_INIT(&tag
[1], "display");
1166 print_otag(h
, TAG_DIV
, 2, tag
);
1170 PAIR_CLASS_INIT(&tag
[1], "lit display");
1171 print_otag(h
, TAG_PRE
, 2, tag
);
1173 /* This can be recursive: save & set our literal state. */
1175 sv
= h
->flags
& HTML_LITERAL
;
1176 h
->flags
|= HTML_LITERAL
;
1178 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1179 print_mdoc_node(meta
, nn
, h
);
1181 * If the printed node flushes its own line, then we
1182 * needn't do it here as well. This is hacky, but the
1183 * notion of selective eoln whitespace is pretty dumb
1184 * anyway, so don't sweat it.
1206 if (h
->flags
& HTML_NONEWLINE
||
1207 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1210 print_text(h
, "\n");
1212 h
->flags
|= HTML_NOSPACE
;
1216 h
->flags
&= ~HTML_LITERAL
;
1222 mdoc_pa_pre(MDOC_ARGS
)
1224 struct htmlpair tag
;
1226 PAIR_CLASS_INIT(&tag
, "file");
1227 print_otag(h
, TAG_I
, 1, &tag
);
1232 mdoc_ad_pre(MDOC_ARGS
)
1234 struct htmlpair tag
;
1236 PAIR_CLASS_INIT(&tag
, "addr");
1237 print_otag(h
, TAG_I
, 1, &tag
);
1242 mdoc_an_pre(MDOC_ARGS
)
1244 struct htmlpair tag
;
1246 if (n
->norm
->An
.auth
== AUTH_split
) {
1247 h
->flags
&= ~HTML_NOSPLIT
;
1248 h
->flags
|= HTML_SPLIT
;
1251 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1252 h
->flags
&= ~HTML_SPLIT
;
1253 h
->flags
|= HTML_NOSPLIT
;
1257 if (h
->flags
& HTML_SPLIT
)
1258 print_otag(h
, TAG_BR
, 0, NULL
);
1260 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1261 h
->flags
|= HTML_SPLIT
;
1263 PAIR_CLASS_INIT(&tag
, "author");
1264 print_otag(h
, TAG_SPAN
, 1, &tag
);
1269 mdoc_cd_pre(MDOC_ARGS
)
1271 struct htmlpair tag
;
1274 PAIR_CLASS_INIT(&tag
, "config");
1275 print_otag(h
, TAG_B
, 1, &tag
);
1280 mdoc_dv_pre(MDOC_ARGS
)
1282 struct htmlpair tag
;
1284 PAIR_CLASS_INIT(&tag
, "define");
1285 print_otag(h
, TAG_SPAN
, 1, &tag
);
1290 mdoc_ev_pre(MDOC_ARGS
)
1292 struct htmlpair tag
;
1294 PAIR_CLASS_INIT(&tag
, "env");
1295 print_otag(h
, TAG_SPAN
, 1, &tag
);
1300 mdoc_er_pre(MDOC_ARGS
)
1302 struct htmlpair tag
;
1304 PAIR_CLASS_INIT(&tag
, "errno");
1305 print_otag(h
, TAG_SPAN
, 1, &tag
);
1310 mdoc_fa_pre(MDOC_ARGS
)
1312 const struct mdoc_node
*nn
;
1313 struct htmlpair tag
;
1316 PAIR_CLASS_INIT(&tag
, "farg");
1317 if (n
->parent
->tok
!= MDOC_Fo
) {
1318 print_otag(h
, TAG_I
, 1, &tag
);
1322 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1323 t
= print_otag(h
, TAG_I
, 1, &tag
);
1324 print_text(h
, nn
->string
);
1327 h
->flags
|= HTML_NOSPACE
;
1332 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1333 h
->flags
|= HTML_NOSPACE
;
1341 mdoc_fd_pre(MDOC_ARGS
)
1343 struct htmlpair tag
[2];
1351 if (NULL
== (n
= n
->child
))
1354 assert(MDOC_TEXT
== n
->type
);
1356 if (strcmp(n
->string
, "#include")) {
1357 PAIR_CLASS_INIT(&tag
[0], "macro");
1358 print_otag(h
, TAG_B
, 1, tag
);
1362 PAIR_CLASS_INIT(&tag
[0], "includes");
1363 print_otag(h
, TAG_B
, 1, tag
);
1364 print_text(h
, n
->string
);
1366 if (NULL
!= (n
= n
->next
)) {
1367 assert(MDOC_TEXT
== n
->type
);
1370 * XXX This is broken and not easy to fix.
1371 * When using -Oincludes, truncation may occur.
1372 * Dynamic allocation wouldn't help because
1373 * passing long strings to buffmt_includes()
1374 * does not work either.
1377 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1378 n
->string
+ 1 : n
->string
, BUFSIZ
);
1381 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1384 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1387 if (h
->base_includes
) {
1388 buffmt_includes(h
, buf
);
1389 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1393 t
= print_otag(h
, TAG_A
, i
, tag
);
1394 print_text(h
, n
->string
);
1400 for ( ; n
; n
= n
->next
) {
1401 assert(MDOC_TEXT
== n
->type
);
1402 print_text(h
, n
->string
);
1409 mdoc_vt_pre(MDOC_ARGS
)
1411 struct htmlpair tag
;
1413 if (MDOC_BLOCK
== n
->type
) {
1416 } else if (MDOC_ELEM
== n
->type
) {
1418 } else if (MDOC_HEAD
== n
->type
)
1421 PAIR_CLASS_INIT(&tag
, "type");
1422 print_otag(h
, TAG_SPAN
, 1, &tag
);
1427 mdoc_ft_pre(MDOC_ARGS
)
1429 struct htmlpair tag
;
1432 PAIR_CLASS_INIT(&tag
, "ftype");
1433 print_otag(h
, TAG_I
, 1, &tag
);
1438 mdoc_fn_pre(MDOC_ARGS
)
1441 struct htmlpair tag
[2];
1443 const char *sp
, *ep
;
1446 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1449 /* Split apart into type and name. */
1450 assert(n
->child
->string
);
1451 sp
= n
->child
->string
;
1453 ep
= strchr(sp
, ' ');
1455 PAIR_CLASS_INIT(&tag
[0], "ftype");
1456 t
= print_otag(h
, TAG_I
, 1, tag
);
1459 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1460 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1462 print_text(h
, nbuf
);
1464 ep
= strchr(sp
, ' ');
1469 PAIR_CLASS_INIT(&tag
[0], "fname");
1472 * FIXME: only refer to IDs that we know exist.
1476 if (MDOC_SYNPRETTY
& n
->flags
) {
1478 html_idcat(nbuf
, sp
, BUFSIZ
);
1479 PAIR_ID_INIT(&tag
[1], nbuf
);
1481 strlcpy(nbuf
, "#", BUFSIZ
);
1482 html_idcat(nbuf
, sp
, BUFSIZ
);
1483 PAIR_HREF_INIT(&tag
[1], nbuf
);
1487 t
= print_otag(h
, TAG_B
, 1, tag
);
1494 h
->flags
|= HTML_NOSPACE
;
1496 h
->flags
|= HTML_NOSPACE
;
1498 PAIR_CLASS_INIT(&tag
[0], "farg");
1500 bufcat_style(h
, "white-space", "nowrap");
1501 PAIR_STYLE_INIT(&tag
[1], h
);
1503 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1505 if (MDOC_SYNPRETTY
& n
->flags
)
1507 t
= print_otag(h
, TAG_I
, i
, tag
);
1508 print_text(h
, n
->string
);
1511 h
->flags
|= HTML_NOSPACE
;
1516 h
->flags
|= HTML_NOSPACE
;
1520 h
->flags
|= HTML_NOSPACE
;
1528 mdoc_sm_pre(MDOC_ARGS
)
1531 if (NULL
== n
->child
)
1532 h
->flags
^= HTML_NONOSPACE
;
1533 else if (0 == strcmp("on", n
->child
->string
))
1534 h
->flags
&= ~HTML_NONOSPACE
;
1536 h
->flags
|= HTML_NONOSPACE
;
1538 if ( ! (HTML_NONOSPACE
& h
->flags
))
1539 h
->flags
&= ~HTML_NOSPACE
;
1545 mdoc_skip_pre(MDOC_ARGS
)
1552 mdoc_pp_pre(MDOC_ARGS
)
1560 mdoc_sp_pre(MDOC_ARGS
)
1563 struct htmlpair tag
;
1565 SCALE_VS_INIT(&su
, 1);
1567 if (MDOC_sp
== n
->tok
) {
1568 if (NULL
!= (n
= n
->child
)) {
1569 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1571 else if (su
.scale
< 0.0)
1578 bufcat_su(h
, "height", &su
);
1579 PAIR_STYLE_INIT(&tag
, h
);
1580 print_otag(h
, TAG_DIV
, 1, &tag
);
1582 /* So the div isn't empty: */
1583 print_text(h
, "\\~");
1590 mdoc_lk_pre(MDOC_ARGS
)
1592 struct htmlpair tag
[2];
1594 if (NULL
== (n
= n
->child
))
1597 assert(MDOC_TEXT
== n
->type
);
1599 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1600 PAIR_HREF_INIT(&tag
[1], n
->string
);
1602 print_otag(h
, TAG_A
, 2, tag
);
1604 if (NULL
== n
->next
)
1605 print_text(h
, n
->string
);
1607 for (n
= n
->next
; n
; n
= n
->next
)
1608 print_text(h
, n
->string
);
1614 mdoc_mt_pre(MDOC_ARGS
)
1616 struct htmlpair tag
[2];
1619 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1621 for (n
= n
->child
; n
; n
= n
->next
) {
1622 assert(MDOC_TEXT
== n
->type
);
1625 bufcat(h
, "mailto:");
1626 bufcat(h
, n
->string
);
1628 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1629 t
= print_otag(h
, TAG_A
, 2, tag
);
1630 print_text(h
, n
->string
);
1638 mdoc_fo_pre(MDOC_ARGS
)
1640 struct htmlpair tag
;
1643 if (MDOC_BODY
== n
->type
) {
1644 h
->flags
|= HTML_NOSPACE
;
1646 h
->flags
|= HTML_NOSPACE
;
1648 } else if (MDOC_BLOCK
== n
->type
) {
1653 /* XXX: we drop non-initial arguments as per groff. */
1656 assert(n
->child
->string
);
1658 PAIR_CLASS_INIT(&tag
, "fname");
1659 t
= print_otag(h
, TAG_B
, 1, &tag
);
1660 print_text(h
, n
->child
->string
);
1666 mdoc_fo_post(MDOC_ARGS
)
1669 if (MDOC_BODY
!= n
->type
)
1671 h
->flags
|= HTML_NOSPACE
;
1673 h
->flags
|= HTML_NOSPACE
;
1678 mdoc_in_pre(MDOC_ARGS
)
1681 struct htmlpair tag
[2];
1686 PAIR_CLASS_INIT(&tag
[0], "includes");
1687 print_otag(h
, TAG_B
, 1, tag
);
1690 * The first argument of the `In' gets special treatment as
1691 * being a linked value. Subsequent values are printed
1692 * afterward. groff does similarly. This also handles the case
1696 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1697 print_text(h
, "#include");
1700 h
->flags
|= HTML_NOSPACE
;
1702 if (NULL
!= (n
= n
->child
)) {
1703 assert(MDOC_TEXT
== n
->type
);
1705 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1708 if (h
->base_includes
) {
1709 buffmt_includes(h
, n
->string
);
1710 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1714 t
= print_otag(h
, TAG_A
, i
, tag
);
1715 print_text(h
, n
->string
);
1721 h
->flags
|= HTML_NOSPACE
;
1724 for ( ; n
; n
= n
->next
) {
1725 assert(MDOC_TEXT
== n
->type
);
1726 print_text(h
, n
->string
);
1733 mdoc_ic_pre(MDOC_ARGS
)
1735 struct htmlpair tag
;
1737 PAIR_CLASS_INIT(&tag
, "cmd");
1738 print_otag(h
, TAG_B
, 1, &tag
);
1743 mdoc_rv_pre(MDOC_ARGS
)
1745 struct htmlpair tag
;
1750 print_otag(h
, TAG_BR
, 0, NULL
);
1752 PAIR_CLASS_INIT(&tag
, "fname");
1756 print_text(h
, "The");
1758 for (n
= n
->child
; n
; n
= n
->next
) {
1759 t
= print_otag(h
, TAG_B
, 1, &tag
);
1760 print_text(h
, n
->string
);
1763 h
->flags
|= HTML_NOSPACE
;
1764 print_text(h
, "()");
1766 if (n
->next
== NULL
)
1770 h
->flags
|= HTML_NOSPACE
;
1773 if (n
->next
->next
== NULL
)
1774 print_text(h
, "and");
1778 print_text(h
, "functions return");
1780 print_text(h
, "function returns");
1782 print_text(h
, "the value\\~0 if successful;");
1784 print_text(h
, "Upon successful completion,"
1785 " the value\\~0 is returned;");
1787 print_text(h
, "otherwise the value\\~\\-1 is returned"
1788 " and the global variable");
1790 PAIR_CLASS_INIT(&tag
, "var");
1791 t
= print_otag(h
, TAG_B
, 1, &tag
);
1792 print_text(h
, "errno");
1794 print_text(h
, "is set to indicate the error.");
1799 mdoc_va_pre(MDOC_ARGS
)
1801 struct htmlpair tag
;
1803 PAIR_CLASS_INIT(&tag
, "var");
1804 print_otag(h
, TAG_B
, 1, &tag
);
1809 mdoc_ap_pre(MDOC_ARGS
)
1812 h
->flags
|= HTML_NOSPACE
;
1813 print_text(h
, "\\(aq");
1814 h
->flags
|= HTML_NOSPACE
;
1819 mdoc_bf_pre(MDOC_ARGS
)
1821 struct htmlpair tag
[2];
1824 if (MDOC_HEAD
== n
->type
)
1826 else if (MDOC_BODY
!= n
->type
)
1829 if (FONT_Em
== n
->norm
->Bf
.font
)
1830 PAIR_CLASS_INIT(&tag
[0], "emph");
1831 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1832 PAIR_CLASS_INIT(&tag
[0], "symb");
1833 else if (FONT_Li
== n
->norm
->Bf
.font
)
1834 PAIR_CLASS_INIT(&tag
[0], "lit");
1836 PAIR_CLASS_INIT(&tag
[0], "none");
1839 * We want this to be inline-formatted, but needs to be div to
1840 * accept block children.
1843 bufcat_style(h
, "display", "inline");
1844 SCALE_HS_INIT(&su
, 1);
1845 /* Needs a left-margin for spacing. */
1846 bufcat_su(h
, "margin-left", &su
);
1847 PAIR_STYLE_INIT(&tag
[1], h
);
1848 print_otag(h
, TAG_DIV
, 2, tag
);
1853 mdoc_ms_pre(MDOC_ARGS
)
1855 struct htmlpair tag
;
1857 PAIR_CLASS_INIT(&tag
, "symb");
1858 print_otag(h
, TAG_SPAN
, 1, &tag
);
1863 mdoc_igndelim_pre(MDOC_ARGS
)
1866 h
->flags
|= HTML_IGNDELIM
;
1871 mdoc_pf_post(MDOC_ARGS
)
1874 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1875 h
->flags
|= HTML_NOSPACE
;
1879 mdoc_rs_pre(MDOC_ARGS
)
1881 struct htmlpair tag
;
1883 if (MDOC_BLOCK
!= n
->type
)
1886 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1889 PAIR_CLASS_INIT(&tag
, "ref");
1890 print_otag(h
, TAG_SPAN
, 1, &tag
);
1895 mdoc_no_pre(MDOC_ARGS
)
1897 struct htmlpair tag
;
1899 PAIR_CLASS_INIT(&tag
, "none");
1900 print_otag(h
, TAG_CODE
, 1, &tag
);
1905 mdoc_li_pre(MDOC_ARGS
)
1907 struct htmlpair tag
;
1909 PAIR_CLASS_INIT(&tag
, "lit");
1910 print_otag(h
, TAG_CODE
, 1, &tag
);
1915 mdoc_sy_pre(MDOC_ARGS
)
1917 struct htmlpair tag
;
1919 PAIR_CLASS_INIT(&tag
, "symb");
1920 print_otag(h
, TAG_SPAN
, 1, &tag
);
1925 mdoc_bt_pre(MDOC_ARGS
)
1928 print_text(h
, "is currently in beta test.");
1933 mdoc_ud_pre(MDOC_ARGS
)
1936 print_text(h
, "currently under development.");
1941 mdoc_lb_pre(MDOC_ARGS
)
1943 struct htmlpair tag
;
1945 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1946 print_otag(h
, TAG_BR
, 0, NULL
);
1948 PAIR_CLASS_INIT(&tag
, "lib");
1949 print_otag(h
, TAG_SPAN
, 1, &tag
);
1954 mdoc__x_pre(MDOC_ARGS
)
1956 struct htmlpair tag
[2];
1963 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1964 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1965 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1966 print_text(h
, "and");
1969 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1973 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1976 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1983 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1987 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1990 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1993 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1996 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1999 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2002 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2005 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2008 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2015 if (MDOC__U
!= n
->tok
) {
2016 print_otag(h
, t
, 1, tag
);
2020 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2021 print_otag(h
, TAG_A
, 2, tag
);
2027 mdoc__x_post(MDOC_ARGS
)
2030 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2031 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2032 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2037 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2040 h
->flags
|= HTML_NOSPACE
;
2041 print_text(h
, n
->next
? "," : ".");
2045 mdoc_bk_pre(MDOC_ARGS
)
2054 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2055 h
->flags
|= HTML_PREKEEP
;
2066 mdoc_bk_post(MDOC_ARGS
)
2069 if (MDOC_BODY
== n
->type
)
2070 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2074 mdoc_quote_pre(MDOC_ARGS
)
2076 struct htmlpair tag
;
2078 if (MDOC_BODY
!= n
->type
)
2085 print_text(h
, n
->nchild
== 1 &&
2086 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
2091 print_text(h
, "\\(lC");
2096 print_text(h
, "\\(lB");
2101 print_text(h
, "\\(lB");
2102 h
->flags
|= HTML_NOSPACE
;
2103 PAIR_CLASS_INIT(&tag
, "opt");
2104 print_otag(h
, TAG_SPAN
, 1, &tag
);
2107 if (NULL
== n
->norm
->Es
||
2108 NULL
== n
->norm
->Es
->child
)
2110 print_text(h
, n
->norm
->Es
->child
->string
);
2119 print_text(h
, "\\(lq");
2127 print_text(h
, "\\(oq");
2128 h
->flags
|= HTML_NOSPACE
;
2129 PAIR_CLASS_INIT(&tag
, "lit");
2130 print_otag(h
, TAG_CODE
, 1, &tag
);
2135 print_text(h
, "\\(oq");
2142 h
->flags
|= HTML_NOSPACE
;
2147 mdoc_quote_post(MDOC_ARGS
)
2150 if (n
->type
!= MDOC_BODY
&& n
->type
!= MDOC_ELEM
)
2153 h
->flags
|= HTML_NOSPACE
;
2159 print_text(h
, n
->nchild
== 1 &&
2160 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
2165 print_text(h
, "\\(rC");
2174 print_text(h
, "\\(rB");
2177 if (n
->norm
->Es
== NULL
||
2178 n
->norm
->Es
->child
== NULL
||
2179 n
->norm
->Es
->child
->next
== NULL
)
2180 h
->flags
&= ~HTML_NOSPACE
;
2182 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2191 print_text(h
, "\\(rq");
2203 print_text(h
, "\\(cq");
2212 mdoc_eo_pre(MDOC_ARGS
)
2215 if (n
->type
!= MDOC_BODY
)
2218 if (n
->end
== ENDBODY_NOT
&&
2219 n
->parent
->head
->child
== NULL
&&
2221 n
->child
->end
!= ENDBODY_NOT
)
2222 print_text(h
, "\\&");
2223 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
2224 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
2225 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
2226 h
->flags
|= HTML_NOSPACE
;
2231 mdoc_eo_post(MDOC_ARGS
)
2235 if (n
->type
!= MDOC_BODY
)
2238 if (n
->end
!= ENDBODY_NOT
) {
2239 h
->flags
&= ~HTML_NOSPACE
;
2243 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2244 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2247 h
->flags
|= HTML_NOSPACE
;
2249 h
->flags
&= ~HTML_NOSPACE
;