]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.184 2012/11/17 00:26:33 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
38 #define MDOC_ARGS const struct mdoc_meta *meta, \
39 const struct mdoc_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 mdoc_node
*);
58 static void a2width(const char *, struct roffsu
*);
59 static void a2offs(const char *, struct roffsu
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static int mdoc_ar_pre(MDOC_ARGS
);
70 static int mdoc_bd_pre(MDOC_ARGS
);
71 static int mdoc_bf_pre(MDOC_ARGS
);
72 static void mdoc_bk_post(MDOC_ARGS
);
73 static int mdoc_bk_pre(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static int mdoc_bt_pre(MDOC_ARGS
);
76 static int mdoc_bx_pre(MDOC_ARGS
);
77 static int mdoc_cd_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_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_ns_pre(MDOC_ARGS
);
103 static int mdoc_pa_pre(MDOC_ARGS
);
104 static void mdoc_pf_post(MDOC_ARGS
);
105 static int mdoc_pp_pre(MDOC_ARGS
);
106 static void mdoc_quote_post(MDOC_ARGS
);
107 static int mdoc_quote_pre(MDOC_ARGS
);
108 static int mdoc_rs_pre(MDOC_ARGS
);
109 static int mdoc_rv_pre(MDOC_ARGS
);
110 static int mdoc_sh_pre(MDOC_ARGS
);
111 static int mdoc_sm_pre(MDOC_ARGS
);
112 static int mdoc_sp_pre(MDOC_ARGS
);
113 static int mdoc_ss_pre(MDOC_ARGS
);
114 static int mdoc_sx_pre(MDOC_ARGS
);
115 static int mdoc_sy_pre(MDOC_ARGS
);
116 static int mdoc_ud_pre(MDOC_ARGS
);
117 static int mdoc_va_pre(MDOC_ARGS
);
118 static int mdoc_vt_pre(MDOC_ARGS
);
119 static int mdoc_xr_pre(MDOC_ARGS
);
120 static int mdoc_xx_pre(MDOC_ARGS
);
122 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
123 {mdoc_ap_pre
, NULL
}, /* Ap */
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ar_pre
, NULL
}, /* Ar */
140 {mdoc_cd_pre
, NULL
}, /* Cd */
141 {mdoc_fl_pre
, NULL
}, /* Cm */
142 {mdoc_dv_pre
, NULL
}, /* Dv */
143 {mdoc_er_pre
, NULL
}, /* Er */
144 {mdoc_ev_pre
, NULL
}, /* Ev */
145 {mdoc_ex_pre
, NULL
}, /* Ex */
146 {mdoc_fa_pre
, NULL
}, /* Fa */
147 {mdoc_fd_pre
, NULL
}, /* Fd */
148 {mdoc_fl_pre
, NULL
}, /* Fl */
149 {mdoc_fn_pre
, NULL
}, /* Fn */
150 {mdoc_ft_pre
, NULL
}, /* Ft */
151 {mdoc_ic_pre
, NULL
}, /* Ic */
152 {mdoc_in_pre
, NULL
}, /* In */
153 {mdoc_li_pre
, NULL
}, /* Li */
154 {mdoc_nd_pre
, NULL
}, /* Nd */
155 {mdoc_nm_pre
, NULL
}, /* Nm */
156 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
157 {NULL
, NULL
}, /* Ot */
158 {mdoc_pa_pre
, NULL
}, /* Pa */
159 {mdoc_rv_pre
, NULL
}, /* Rv */
160 {NULL
, NULL
}, /* St */
161 {mdoc_va_pre
, NULL
}, /* Va */
162 {mdoc_vt_pre
, NULL
}, /* Vt */
163 {mdoc_xr_pre
, NULL
}, /* Xr */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
175 {NULL
, NULL
}, /* Ac */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
178 {NULL
, NULL
}, /* At */
179 {NULL
, NULL
}, /* Bc */
180 {mdoc_bf_pre
, NULL
}, /* Bf */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
183 {mdoc_xx_pre
, NULL
}, /* Bsx */
184 {mdoc_bx_pre
, NULL
}, /* Bx */
185 {NULL
, NULL
}, /* Db */
186 {NULL
, NULL
}, /* Dc */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
189 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
190 {NULL
, NULL
}, /* Ef */
191 {mdoc_em_pre
, NULL
}, /* Em */
192 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
193 {mdoc_xx_pre
, NULL
}, /* Fx */
194 {mdoc_ms_pre
, NULL
}, /* Ms */
195 {mdoc_igndelim_pre
, NULL
}, /* No */
196 {mdoc_ns_pre
, NULL
}, /* Ns */
197 {mdoc_xx_pre
, NULL
}, /* Nx */
198 {mdoc_xx_pre
, NULL
}, /* Ox */
199 {NULL
, NULL
}, /* Pc */
200 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
203 {NULL
, NULL
}, /* Qc */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
207 {NULL
, NULL
}, /* Re */
208 {mdoc_rs_pre
, NULL
}, /* Rs */
209 {NULL
, NULL
}, /* Sc */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
212 {mdoc_sm_pre
, NULL
}, /* Sm */
213 {mdoc_sx_pre
, NULL
}, /* Sx */
214 {mdoc_sy_pre
, NULL
}, /* Sy */
215 {NULL
, NULL
}, /* Tn */
216 {mdoc_xx_pre
, NULL
}, /* Ux */
217 {NULL
, NULL
}, /* Xc */
218 {NULL
, NULL
}, /* Xo */
219 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
220 {NULL
, NULL
}, /* Fc */
221 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
222 {NULL
, NULL
}, /* Oc */
223 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
224 {NULL
, NULL
}, /* Ek */
225 {mdoc_bt_pre
, NULL
}, /* Bt */
226 {NULL
, NULL
}, /* Hf */
227 {NULL
, NULL
}, /* Fr */
228 {mdoc_ud_pre
, NULL
}, /* Ud */
229 {mdoc_lb_pre
, NULL
}, /* Lb */
230 {mdoc_pp_pre
, NULL
}, /* Lp */
231 {mdoc_lk_pre
, NULL
}, /* Lk */
232 {mdoc_mt_pre
, NULL
}, /* Mt */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
235 {NULL
, NULL
}, /* Brc */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
237 {NULL
, NULL
}, /* Es */ /* TODO */
238 {NULL
, NULL
}, /* En */ /* TODO */
239 {mdoc_xx_pre
, NULL
}, /* Dx */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
241 {mdoc_sp_pre
, NULL
}, /* br */
242 {mdoc_sp_pre
, NULL
}, /* sp */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
247 static const char * const lists
[LIST_MAX
] = {
263 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
266 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
273 * Calculate the scaling unit passed in a `-width' argument. This uses
274 * either a native scaling unit (e.g., 1i, 2m) or the string length of
278 a2width(const char *p
, struct roffsu
*su
)
281 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
283 su
->scale
= html_strlen(p
);
289 * See the same function in mdoc_term.c for documentation.
292 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
295 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
298 if (n
->prev
->tok
== n
->tok
&&
302 print_otag(h
, TAG_BR
, 0, NULL
);
306 switch (n
->prev
->tok
) {
316 print_otag(h
, TAG_P
, 0, NULL
);
319 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
320 print_otag(h
, TAG_P
, 0, NULL
);
325 print_otag(h
, TAG_BR
, 0, NULL
);
332 * Calculate the scaling unit passed in an `-offset' argument. This
333 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
334 * predefined strings (indent, etc.), or the string length of the value.
337 a2offs(const char *p
, struct roffsu
*su
)
340 /* FIXME: "right"? */
342 if (0 == strcmp(p
, "left"))
343 SCALE_HS_INIT(su
, 0);
344 else if (0 == strcmp(p
, "indent"))
345 SCALE_HS_INIT(su
, INDENT
);
346 else if (0 == strcmp(p
, "indent-two"))
347 SCALE_HS_INIT(su
, INDENT
* 2);
348 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
349 SCALE_HS_INIT(su
, html_strlen(p
));
354 print_mdoc(MDOC_ARGS
)
359 PAIR_CLASS_INIT(&tag
, "mandoc");
361 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
363 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
364 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
365 print_mdoc_head(meta
, n
, h
);
367 print_otag(h
, TAG_BODY
, 0, NULL
);
368 print_otag(h
, TAG_DIV
, 1, &tag
);
370 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
372 print_mdoc_nodelist(meta
, n
, h
);
379 print_mdoc_head(MDOC_ARGS
)
384 bufcat_fmt(h
, "%s(%s)", meta
->title
, meta
->msec
);
387 bufcat_fmt(h
, " (%s)", meta
->arch
);
389 print_otag(h
, TAG_TITLE
, 0, NULL
);
390 print_text(h
, h
->buf
);
395 print_mdoc_nodelist(MDOC_ARGS
)
398 print_mdoc_node(meta
, n
, h
);
400 print_mdoc_nodelist(meta
, n
->next
, h
);
405 print_mdoc_node(MDOC_ARGS
)
415 child
= mdoc_root_pre(meta
, n
, h
);
418 /* No tables in this mode... */
419 assert(NULL
== h
->tblt
);
422 * Make sure that if we're in a literal mode already
423 * (i.e., within a <PRE>) don't print the newline.
425 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
426 if ( ! (HTML_LITERAL
& h
->flags
))
427 print_otag(h
, TAG_BR
, 0, NULL
);
428 if (MDOC_DELIMC
& n
->flags
)
429 h
->flags
|= HTML_NOSPACE
;
430 print_text(h
, n
->string
);
431 if (MDOC_DELIMO
& n
->flags
)
432 h
->flags
|= HTML_NOSPACE
;
435 print_eqn(h
, n
->eqn
);
439 * This will take care of initialising all of the table
440 * state data for the first table, then tearing it down
443 print_tbl(h
, n
->span
);
447 * Close out the current table, if it's open, and unset
448 * the "meta" table state. This will be reopened on the
449 * next table element.
456 assert(NULL
== h
->tblt
);
457 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
458 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
462 if (HTML_KEEP
& h
->flags
) {
463 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
464 h
->flags
&= ~HTML_KEEP
;
465 h
->flags
|= HTML_PREKEEP
;
466 } else if (NULL
== n
->prev
) {
467 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
468 h
->flags
&= ~HTML_KEEP
;
469 h
->flags
|= HTML_PREKEEP
;
474 if (child
&& n
->child
)
475 print_mdoc_nodelist(meta
, n
->child
, h
);
481 mdoc_root_post(meta
, n
, h
);
486 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
487 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
494 mdoc_root_post(MDOC_ARGS
)
496 struct htmlpair tag
[3];
499 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
500 PAIR_CLASS_INIT(&tag
[1], "foot");
501 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
502 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
503 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
504 print_otag(h
, TAG_COL
, 1, tag
);
505 print_otag(h
, TAG_COL
, 1, tag
);
507 print_otag(h
, TAG_TBODY
, 0, NULL
);
509 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
511 PAIR_CLASS_INIT(&tag
[0], "foot-date");
512 print_otag(h
, TAG_TD
, 1, tag
);
513 print_text(h
, meta
->date
);
516 PAIR_CLASS_INIT(&tag
[0], "foot-os");
517 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
518 print_otag(h
, TAG_TD
, 2, tag
);
519 print_text(h
, meta
->os
);
526 mdoc_root_pre(MDOC_ARGS
)
528 struct htmlpair tag
[3];
530 char b
[BUFSIZ
], title
[BUFSIZ
];
532 strlcpy(b
, meta
->vol
, BUFSIZ
);
535 strlcat(b
, " (", BUFSIZ
);
536 strlcat(b
, meta
->arch
, BUFSIZ
);
537 strlcat(b
, ")", BUFSIZ
);
540 snprintf(title
, BUFSIZ
- 1, "%s(%s)", meta
->title
, meta
->msec
);
542 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
543 PAIR_CLASS_INIT(&tag
[1], "head");
544 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
545 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
546 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
547 print_otag(h
, TAG_COL
, 1, tag
);
548 print_otag(h
, TAG_COL
, 1, tag
);
549 print_otag(h
, TAG_COL
, 1, tag
);
551 print_otag(h
, TAG_TBODY
, 0, NULL
);
553 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
555 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
556 print_otag(h
, TAG_TD
, 1, tag
);
557 print_text(h
, title
);
560 PAIR_CLASS_INIT(&tag
[0], "head-vol");
561 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
562 print_otag(h
, TAG_TD
, 2, tag
);
566 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
567 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
568 print_otag(h
, TAG_TD
, 2, tag
);
569 print_text(h
, title
);
577 mdoc_sh_pre(MDOC_ARGS
)
581 if (MDOC_BLOCK
== n
->type
) {
582 PAIR_CLASS_INIT(&tag
, "section");
583 print_otag(h
, TAG_DIV
, 1, &tag
);
585 } else if (MDOC_BODY
== n
->type
)
591 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
592 bufcat_id(h
, n
->string
);
593 if (NULL
!= (n
= n
->next
))
598 PAIR_ID_INIT(&tag
, h
->buf
);
599 print_otag(h
, TAG_H1
, 1, &tag
);
601 print_otag(h
, TAG_H1
, 0, NULL
);
608 mdoc_ss_pre(MDOC_ARGS
)
612 if (MDOC_BLOCK
== n
->type
) {
613 PAIR_CLASS_INIT(&tag
, "subsection");
614 print_otag(h
, TAG_DIV
, 1, &tag
);
616 } else if (MDOC_BODY
== n
->type
)
622 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
623 bufcat_id(h
, n
->string
);
624 if (NULL
!= (n
= n
->next
))
629 PAIR_ID_INIT(&tag
, h
->buf
);
630 print_otag(h
, TAG_H2
, 1, &tag
);
632 print_otag(h
, TAG_H2
, 0, NULL
);
640 mdoc_fl_pre(MDOC_ARGS
)
644 PAIR_CLASS_INIT(&tag
, "flag");
645 print_otag(h
, TAG_B
, 1, &tag
);
647 /* `Cm' has no leading hyphen. */
649 if (MDOC_Cm
== n
->tok
)
652 print_text(h
, "\\-");
655 h
->flags
|= HTML_NOSPACE
;
656 else if (n
->next
&& n
->next
->line
== n
->line
)
657 h
->flags
|= HTML_NOSPACE
;
665 mdoc_nd_pre(MDOC_ARGS
)
669 if (MDOC_BODY
!= n
->type
)
672 /* XXX: this tag in theory can contain block elements. */
674 print_text(h
, "\\(em");
675 PAIR_CLASS_INIT(&tag
, "desc");
676 print_otag(h
, TAG_SPAN
, 1, &tag
);
682 mdoc_nm_pre(MDOC_ARGS
)
691 PAIR_CLASS_INIT(&tag
, "name");
692 print_otag(h
, TAG_B
, 1, &tag
);
693 if (NULL
== n
->child
&& meta
->name
)
694 print_text(h
, meta
->name
);
697 print_otag(h
, TAG_TD
, 0, NULL
);
698 if (NULL
== n
->child
&& meta
->name
)
699 print_text(h
, meta
->name
);
702 print_otag(h
, TAG_TD
, 0, NULL
);
709 PAIR_CLASS_INIT(&tag
, "synopsis");
710 print_otag(h
, TAG_TABLE
, 1, &tag
);
712 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
713 if (MDOC_TEXT
== n
->type
)
714 len
+= html_strlen(n
->string
);
716 if (0 == len
&& meta
->name
)
717 len
= html_strlen(meta
->name
);
719 SCALE_HS_INIT(&su
, (double)len
);
721 bufcat_su(h
, "width", &su
);
722 PAIR_STYLE_INIT(&tag
, h
);
723 print_otag(h
, TAG_COL
, 1, &tag
);
724 print_otag(h
, TAG_COL
, 0, NULL
);
725 print_otag(h
, TAG_TBODY
, 0, NULL
);
726 print_otag(h
, TAG_TR
, 0, NULL
);
733 mdoc_xr_pre(MDOC_ARGS
)
735 struct htmlpair tag
[2];
737 if (NULL
== n
->child
)
740 PAIR_CLASS_INIT(&tag
[0], "link-man");
743 buffmt_man(h
, n
->child
->string
,
745 n
->child
->next
->string
: NULL
);
746 PAIR_HREF_INIT(&tag
[1], h
->buf
);
747 print_otag(h
, TAG_A
, 2, tag
);
749 print_otag(h
, TAG_A
, 1, tag
);
752 print_text(h
, n
->string
);
754 if (NULL
== (n
= n
->next
))
757 h
->flags
|= HTML_NOSPACE
;
759 h
->flags
|= HTML_NOSPACE
;
760 print_text(h
, n
->string
);
761 h
->flags
|= HTML_NOSPACE
;
769 mdoc_ns_pre(MDOC_ARGS
)
772 if ( ! (MDOC_LINE
& n
->flags
))
773 h
->flags
|= HTML_NOSPACE
;
780 mdoc_ar_pre(MDOC_ARGS
)
784 PAIR_CLASS_INIT(&tag
, "arg");
785 print_otag(h
, TAG_I
, 1, &tag
);
792 mdoc_xx_pre(MDOC_ARGS
)
821 PAIR_CLASS_INIT(&tag
, "unix");
822 print_otag(h
, TAG_SPAN
, 1, &tag
);
827 h
->flags
|= HTML_KEEP
;
828 print_text(h
, n
->child
->string
);
837 mdoc_bx_pre(MDOC_ARGS
)
841 PAIR_CLASS_INIT(&tag
, "unix");
842 print_otag(h
, TAG_SPAN
, 1, &tag
);
844 if (NULL
!= (n
= n
->child
)) {
845 print_text(h
, n
->string
);
846 h
->flags
|= HTML_NOSPACE
;
847 print_text(h
, "BSD");
849 print_text(h
, "BSD");
853 if (NULL
!= (n
= n
->next
)) {
854 h
->flags
|= HTML_NOSPACE
;
856 h
->flags
|= HTML_NOSPACE
;
857 print_text(h
, n
->string
);
865 mdoc_it_pre(MDOC_ARGS
)
869 struct htmlpair tag
[2];
870 const struct mdoc_node
*bl
;
873 while (bl
&& MDOC_Bl
!= bl
->tok
)
878 type
= bl
->norm
->Bl
.type
;
881 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
885 if (MDOC_HEAD
== n
->type
) {
906 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
907 bufcat_su(h
, "margin-top", &su
);
908 PAIR_STYLE_INIT(&tag
[1], h
);
909 print_otag(h
, TAG_DT
, 2, tag
);
910 if (LIST_diag
!= type
)
912 PAIR_CLASS_INIT(&tag
[0], "diag");
913 print_otag(h
, TAG_B
, 1, tag
);
920 } else if (MDOC_BODY
== n
->type
) {
931 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
932 bufcat_su(h
, "margin-top", &su
);
933 PAIR_STYLE_INIT(&tag
[1], h
);
934 print_otag(h
, TAG_LI
, 2, tag
);
945 if (NULL
== bl
->norm
->Bl
.width
) {
946 print_otag(h
, TAG_DD
, 1, tag
);
949 a2width(bl
->norm
->Bl
.width
, &su
);
950 bufcat_su(h
, "margin-left", &su
);
951 PAIR_STYLE_INIT(&tag
[1], h
);
952 print_otag(h
, TAG_DD
, 2, tag
);
955 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
956 bufcat_su(h
, "margin-top", &su
);
957 PAIR_STYLE_INIT(&tag
[1], h
);
958 print_otag(h
, TAG_TD
, 2, tag
);
966 print_otag(h
, TAG_TR
, 1, tag
);
978 mdoc_bl_pre(MDOC_ARGS
)
981 struct htmlpair tag
[3];
985 if (MDOC_BODY
== n
->type
) {
986 if (LIST_column
== n
->norm
->Bl
.type
)
987 print_otag(h
, TAG_TBODY
, 0, NULL
);
991 if (MDOC_HEAD
== n
->type
) {
992 if (LIST_column
!= n
->norm
->Bl
.type
)
996 * For each column, print out the <COL> tag with our
997 * suggested width. The last column gets min-width, as
998 * in terminal mode it auto-sizes to the width of the
999 * screen and we want to preserve that behaviour.
1002 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1004 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1005 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1006 bufcat_su(h
, "width", &su
);
1008 bufcat_su(h
, "min-width", &su
);
1009 PAIR_STYLE_INIT(&tag
[0], h
);
1010 print_otag(h
, TAG_COL
, 1, tag
);
1016 SCALE_VS_INIT(&su
, 0);
1018 bufcat_su(h
, "margin-top", &su
);
1019 bufcat_su(h
, "margin-bottom", &su
);
1020 PAIR_STYLE_INIT(&tag
[0], h
);
1022 assert(lists
[n
->norm
->Bl
.type
]);
1023 strlcpy(buf
, "list ", BUFSIZ
);
1024 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1025 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1027 /* Set the block's left-hand margin. */
1029 if (n
->norm
->Bl
.offs
) {
1030 a2offs(n
->norm
->Bl
.offs
, &su
);
1031 bufcat_su(h
, "margin-left", &su
);
1034 switch (n
->norm
->Bl
.type
) {
1042 print_otag(h
, TAG_UL
, 2, tag
);
1045 print_otag(h
, TAG_OL
, 2, tag
);
1056 print_otag(h
, TAG_DL
, 2, tag
);
1059 print_otag(h
, TAG_TABLE
, 2, tag
);
1071 mdoc_ex_pre(MDOC_ARGS
)
1074 struct htmlpair tag
;
1078 print_otag(h
, TAG_BR
, 0, NULL
);
1080 PAIR_CLASS_INIT(&tag
, "utility");
1082 print_text(h
, "The");
1085 for (n
= n
->child
; n
; n
= n
->next
) {
1086 assert(MDOC_TEXT
== n
->type
);
1088 t
= print_otag(h
, TAG_B
, 1, &tag
);
1089 print_text(h
, n
->string
);
1092 if (nchild
> 2 && n
->next
) {
1093 h
->flags
|= HTML_NOSPACE
;
1097 if (n
->next
&& NULL
== n
->next
->next
)
1098 print_text(h
, "and");
1102 print_text(h
, "utilities exit");
1104 print_text(h
, "utility exits");
1106 print_text(h
, "0 on success, and >0 if an error occurs.");
1113 mdoc_em_pre(MDOC_ARGS
)
1115 struct htmlpair tag
;
1117 PAIR_CLASS_INIT(&tag
, "emph");
1118 print_otag(h
, TAG_SPAN
, 1, &tag
);
1125 mdoc_d1_pre(MDOC_ARGS
)
1127 struct htmlpair tag
[2];
1130 if (MDOC_BLOCK
!= n
->type
)
1133 SCALE_VS_INIT(&su
, 0);
1135 bufcat_su(h
, "margin-top", &su
);
1136 bufcat_su(h
, "margin-bottom", &su
);
1137 PAIR_STYLE_INIT(&tag
[0], h
);
1138 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1140 /* BLOCKQUOTE needs a block body. */
1142 PAIR_CLASS_INIT(&tag
[0], "display");
1143 print_otag(h
, TAG_DIV
, 1, tag
);
1145 if (MDOC_Dl
== n
->tok
) {
1146 PAIR_CLASS_INIT(&tag
[0], "lit");
1147 print_otag(h
, TAG_CODE
, 1, tag
);
1156 mdoc_sx_pre(MDOC_ARGS
)
1158 struct htmlpair tag
[2];
1163 for (n
= n
->child
; n
; ) {
1164 bufcat_id(h
, n
->string
);
1165 if (NULL
!= (n
= n
->next
))
1169 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1170 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1172 print_otag(h
, TAG_I
, 1, tag
);
1173 print_otag(h
, TAG_A
, 2, tag
);
1180 mdoc_bd_pre(MDOC_ARGS
)
1182 struct htmlpair tag
[2];
1184 const struct mdoc_node
*nn
;
1187 if (MDOC_HEAD
== n
->type
)
1190 if (MDOC_BLOCK
== n
->type
) {
1191 comp
= n
->norm
->Bd
.comp
;
1192 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1193 if (MDOC_BLOCK
!= nn
->type
)
1195 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1201 print_otag(h
, TAG_P
, 0, NULL
);
1205 SCALE_HS_INIT(&su
, 0);
1206 if (n
->norm
->Bd
.offs
)
1207 a2offs(n
->norm
->Bd
.offs
, &su
);
1210 bufcat_su(h
, "margin-left", &su
);
1211 PAIR_STYLE_INIT(&tag
[0], h
);
1213 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1214 DISP_literal
!= n
->norm
->Bd
.type
) {
1215 PAIR_CLASS_INIT(&tag
[1], "display");
1216 print_otag(h
, TAG_DIV
, 2, tag
);
1220 PAIR_CLASS_INIT(&tag
[1], "lit display");
1221 print_otag(h
, TAG_PRE
, 2, tag
);
1223 /* This can be recursive: save & set our literal state. */
1225 sv
= h
->flags
& HTML_LITERAL
;
1226 h
->flags
|= HTML_LITERAL
;
1228 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1229 print_mdoc_node(meta
, nn
, h
);
1231 * If the printed node flushes its own line, then we
1232 * needn't do it here as well. This is hacky, but the
1233 * notion of selective eoln whitespace is pretty dumb
1234 * anyway, so don't sweat it.
1256 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1259 print_text(h
, "\n");
1261 h
->flags
|= HTML_NOSPACE
;
1265 h
->flags
&= ~HTML_LITERAL
;
1273 mdoc_pa_pre(MDOC_ARGS
)
1275 struct htmlpair tag
;
1277 PAIR_CLASS_INIT(&tag
, "file");
1278 print_otag(h
, TAG_I
, 1, &tag
);
1285 mdoc_ad_pre(MDOC_ARGS
)
1287 struct htmlpair tag
;
1289 PAIR_CLASS_INIT(&tag
, "addr");
1290 print_otag(h
, TAG_I
, 1, &tag
);
1297 mdoc_an_pre(MDOC_ARGS
)
1299 struct htmlpair tag
;
1301 /* TODO: -split and -nosplit (see termp_an_pre()). */
1303 PAIR_CLASS_INIT(&tag
, "author");
1304 print_otag(h
, TAG_SPAN
, 1, &tag
);
1311 mdoc_cd_pre(MDOC_ARGS
)
1313 struct htmlpair tag
;
1316 PAIR_CLASS_INIT(&tag
, "config");
1317 print_otag(h
, TAG_B
, 1, &tag
);
1324 mdoc_dv_pre(MDOC_ARGS
)
1326 struct htmlpair tag
;
1328 PAIR_CLASS_INIT(&tag
, "define");
1329 print_otag(h
, TAG_SPAN
, 1, &tag
);
1336 mdoc_ev_pre(MDOC_ARGS
)
1338 struct htmlpair tag
;
1340 PAIR_CLASS_INIT(&tag
, "env");
1341 print_otag(h
, TAG_SPAN
, 1, &tag
);
1348 mdoc_er_pre(MDOC_ARGS
)
1350 struct htmlpair tag
;
1352 PAIR_CLASS_INIT(&tag
, "errno");
1353 print_otag(h
, TAG_SPAN
, 1, &tag
);
1360 mdoc_fa_pre(MDOC_ARGS
)
1362 const struct mdoc_node
*nn
;
1363 struct htmlpair tag
;
1366 PAIR_CLASS_INIT(&tag
, "farg");
1367 if (n
->parent
->tok
!= MDOC_Fo
) {
1368 print_otag(h
, TAG_I
, 1, &tag
);
1372 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1373 t
= print_otag(h
, TAG_I
, 1, &tag
);
1374 print_text(h
, nn
->string
);
1377 h
->flags
|= HTML_NOSPACE
;
1382 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1383 h
->flags
|= HTML_NOSPACE
;
1393 mdoc_fd_pre(MDOC_ARGS
)
1395 struct htmlpair tag
[2];
1403 if (NULL
== (n
= n
->child
))
1406 assert(MDOC_TEXT
== n
->type
);
1408 if (strcmp(n
->string
, "#include")) {
1409 PAIR_CLASS_INIT(&tag
[0], "macro");
1410 print_otag(h
, TAG_B
, 1, tag
);
1414 PAIR_CLASS_INIT(&tag
[0], "includes");
1415 print_otag(h
, TAG_B
, 1, tag
);
1416 print_text(h
, n
->string
);
1418 if (NULL
!= (n
= n
->next
)) {
1419 assert(MDOC_TEXT
== n
->type
);
1420 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1421 n
->string
+ 1 : n
->string
, BUFSIZ
);
1424 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1427 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1430 if (h
->base_includes
) {
1431 buffmt_includes(h
, buf
);
1432 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1436 t
= print_otag(h
, TAG_A
, i
, tag
);
1437 print_text(h
, n
->string
);
1443 for ( ; n
; n
= n
->next
) {
1444 assert(MDOC_TEXT
== n
->type
);
1445 print_text(h
, n
->string
);
1454 mdoc_vt_pre(MDOC_ARGS
)
1456 struct htmlpair tag
;
1458 if (MDOC_BLOCK
== n
->type
) {
1461 } else if (MDOC_ELEM
== n
->type
) {
1463 } else if (MDOC_HEAD
== n
->type
)
1466 PAIR_CLASS_INIT(&tag
, "type");
1467 print_otag(h
, TAG_SPAN
, 1, &tag
);
1474 mdoc_ft_pre(MDOC_ARGS
)
1476 struct htmlpair tag
;
1479 PAIR_CLASS_INIT(&tag
, "ftype");
1480 print_otag(h
, TAG_I
, 1, &tag
);
1487 mdoc_fn_pre(MDOC_ARGS
)
1490 struct htmlpair tag
[2];
1492 const char *sp
, *ep
;
1495 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1498 /* Split apart into type and name. */
1499 assert(n
->child
->string
);
1500 sp
= n
->child
->string
;
1502 ep
= strchr(sp
, ' ');
1504 PAIR_CLASS_INIT(&tag
[0], "ftype");
1505 t
= print_otag(h
, TAG_I
, 1, tag
);
1508 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1509 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1511 print_text(h
, nbuf
);
1513 ep
= strchr(sp
, ' ');
1518 PAIR_CLASS_INIT(&tag
[0], "fname");
1521 * FIXME: only refer to IDs that we know exist.
1525 if (MDOC_SYNPRETTY
& n
->flags
) {
1527 html_idcat(nbuf
, sp
, BUFSIZ
);
1528 PAIR_ID_INIT(&tag
[1], nbuf
);
1530 strlcpy(nbuf
, "#", BUFSIZ
);
1531 html_idcat(nbuf
, sp
, BUFSIZ
);
1532 PAIR_HREF_INIT(&tag
[1], nbuf
);
1536 t
= print_otag(h
, TAG_B
, 1, tag
);
1539 strlcpy(nbuf
, sp
, BUFSIZ
);
1540 print_text(h
, nbuf
);
1545 h
->flags
|= HTML_NOSPACE
;
1547 h
->flags
|= HTML_NOSPACE
;
1549 PAIR_CLASS_INIT(&tag
[0], "farg");
1551 bufcat_style(h
, "white-space", "nowrap");
1552 PAIR_STYLE_INIT(&tag
[1], h
);
1554 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1556 if (MDOC_SYNPRETTY
& n
->flags
)
1558 t
= print_otag(h
, TAG_I
, i
, tag
);
1559 print_text(h
, n
->string
);
1562 h
->flags
|= HTML_NOSPACE
;
1567 h
->flags
|= HTML_NOSPACE
;
1571 h
->flags
|= HTML_NOSPACE
;
1581 mdoc_sm_pre(MDOC_ARGS
)
1584 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1585 if (0 == strcmp("on", n
->child
->string
)) {
1587 * FIXME: no p->col to check. Thus, if we have
1594 * the "3" is preceded by a space.
1596 h
->flags
&= ~HTML_NOSPACE
;
1597 h
->flags
&= ~HTML_NONOSPACE
;
1599 h
->flags
|= HTML_NONOSPACE
;
1606 mdoc_pp_pre(MDOC_ARGS
)
1609 print_otag(h
, TAG_P
, 0, NULL
);
1616 mdoc_sp_pre(MDOC_ARGS
)
1619 struct htmlpair tag
;
1621 SCALE_VS_INIT(&su
, 1);
1623 if (MDOC_sp
== n
->tok
) {
1624 if (NULL
!= (n
= n
->child
))
1625 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1626 SCALE_VS_INIT(&su
, atoi(n
->string
));
1631 bufcat_su(h
, "height", &su
);
1632 PAIR_STYLE_INIT(&tag
, h
);
1633 print_otag(h
, TAG_DIV
, 1, &tag
);
1635 /* So the div isn't empty: */
1636 print_text(h
, "\\~");
1644 mdoc_lk_pre(MDOC_ARGS
)
1646 struct htmlpair tag
[2];
1648 if (NULL
== (n
= n
->child
))
1651 assert(MDOC_TEXT
== n
->type
);
1653 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1654 PAIR_HREF_INIT(&tag
[1], n
->string
);
1656 print_otag(h
, TAG_A
, 2, tag
);
1658 if (NULL
== n
->next
)
1659 print_text(h
, n
->string
);
1661 for (n
= n
->next
; n
; n
= n
->next
)
1662 print_text(h
, n
->string
);
1670 mdoc_mt_pre(MDOC_ARGS
)
1672 struct htmlpair tag
[2];
1675 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1677 for (n
= n
->child
; n
; n
= n
->next
) {
1678 assert(MDOC_TEXT
== n
->type
);
1681 bufcat(h
, "mailto:");
1682 bufcat(h
, n
->string
);
1684 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1685 t
= print_otag(h
, TAG_A
, 2, tag
);
1686 print_text(h
, n
->string
);
1696 mdoc_fo_pre(MDOC_ARGS
)
1698 struct htmlpair tag
;
1701 if (MDOC_BODY
== n
->type
) {
1702 h
->flags
|= HTML_NOSPACE
;
1704 h
->flags
|= HTML_NOSPACE
;
1706 } else if (MDOC_BLOCK
== n
->type
) {
1711 /* XXX: we drop non-initial arguments as per groff. */
1714 assert(n
->child
->string
);
1716 PAIR_CLASS_INIT(&tag
, "fname");
1717 t
= print_otag(h
, TAG_B
, 1, &tag
);
1718 print_text(h
, n
->child
->string
);
1726 mdoc_fo_post(MDOC_ARGS
)
1729 if (MDOC_BODY
!= n
->type
)
1731 h
->flags
|= HTML_NOSPACE
;
1733 h
->flags
|= HTML_NOSPACE
;
1740 mdoc_in_pre(MDOC_ARGS
)
1743 struct htmlpair tag
[2];
1748 PAIR_CLASS_INIT(&tag
[0], "includes");
1749 print_otag(h
, TAG_B
, 1, tag
);
1752 * The first argument of the `In' gets special treatment as
1753 * being a linked value. Subsequent values are printed
1754 * afterward. groff does similarly. This also handles the case
1758 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1759 print_text(h
, "#include");
1762 h
->flags
|= HTML_NOSPACE
;
1764 if (NULL
!= (n
= n
->child
)) {
1765 assert(MDOC_TEXT
== n
->type
);
1767 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1770 if (h
->base_includes
) {
1771 buffmt_includes(h
, n
->string
);
1772 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1776 t
= print_otag(h
, TAG_A
, i
, tag
);
1777 print_text(h
, n
->string
);
1783 h
->flags
|= HTML_NOSPACE
;
1786 for ( ; n
; n
= n
->next
) {
1787 assert(MDOC_TEXT
== n
->type
);
1788 print_text(h
, n
->string
);
1797 mdoc_ic_pre(MDOC_ARGS
)
1799 struct htmlpair tag
;
1801 PAIR_CLASS_INIT(&tag
, "cmd");
1802 print_otag(h
, TAG_B
, 1, &tag
);
1809 mdoc_rv_pre(MDOC_ARGS
)
1811 struct htmlpair tag
;
1816 print_otag(h
, TAG_BR
, 0, NULL
);
1818 PAIR_CLASS_INIT(&tag
, "fname");
1820 print_text(h
, "The");
1823 for (n
= n
->child
; n
; n
= n
->next
) {
1824 assert(MDOC_TEXT
== n
->type
);
1826 t
= print_otag(h
, TAG_B
, 1, &tag
);
1827 print_text(h
, n
->string
);
1830 h
->flags
|= HTML_NOSPACE
;
1831 print_text(h
, "()");
1833 if (nchild
> 2 && n
->next
) {
1834 h
->flags
|= HTML_NOSPACE
;
1838 if (n
->next
&& NULL
== n
->next
->next
)
1839 print_text(h
, "and");
1843 print_text(h
, "functions return");
1845 print_text(h
, "function returns");
1847 print_text(h
, "the value 0 if successful; otherwise the value "
1848 "-1 is returned and the global variable");
1850 PAIR_CLASS_INIT(&tag
, "var");
1851 t
= print_otag(h
, TAG_B
, 1, &tag
);
1852 print_text(h
, "errno");
1854 print_text(h
, "is set to indicate the error.");
1861 mdoc_va_pre(MDOC_ARGS
)
1863 struct htmlpair tag
;
1865 PAIR_CLASS_INIT(&tag
, "var");
1866 print_otag(h
, TAG_B
, 1, &tag
);
1873 mdoc_ap_pre(MDOC_ARGS
)
1876 h
->flags
|= HTML_NOSPACE
;
1877 print_text(h
, "\\(aq");
1878 h
->flags
|= HTML_NOSPACE
;
1885 mdoc_bf_pre(MDOC_ARGS
)
1887 struct htmlpair tag
[2];
1890 if (MDOC_HEAD
== n
->type
)
1892 else if (MDOC_BODY
!= n
->type
)
1895 if (FONT_Em
== n
->norm
->Bf
.font
)
1896 PAIR_CLASS_INIT(&tag
[0], "emph");
1897 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1898 PAIR_CLASS_INIT(&tag
[0], "symb");
1899 else if (FONT_Li
== n
->norm
->Bf
.font
)
1900 PAIR_CLASS_INIT(&tag
[0], "lit");
1902 PAIR_CLASS_INIT(&tag
[0], "none");
1905 * We want this to be inline-formatted, but needs to be div to
1906 * accept block children.
1909 bufcat_style(h
, "display", "inline");
1910 SCALE_HS_INIT(&su
, 1);
1911 /* Needs a left-margin for spacing. */
1912 bufcat_su(h
, "margin-left", &su
);
1913 PAIR_STYLE_INIT(&tag
[1], h
);
1914 print_otag(h
, TAG_DIV
, 2, tag
);
1921 mdoc_ms_pre(MDOC_ARGS
)
1923 struct htmlpair tag
;
1925 PAIR_CLASS_INIT(&tag
, "symb");
1926 print_otag(h
, TAG_SPAN
, 1, &tag
);
1933 mdoc_igndelim_pre(MDOC_ARGS
)
1936 h
->flags
|= HTML_IGNDELIM
;
1943 mdoc_pf_post(MDOC_ARGS
)
1946 h
->flags
|= HTML_NOSPACE
;
1952 mdoc_rs_pre(MDOC_ARGS
)
1954 struct htmlpair tag
;
1956 if (MDOC_BLOCK
!= n
->type
)
1959 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1960 print_otag(h
, TAG_P
, 0, NULL
);
1962 PAIR_CLASS_INIT(&tag
, "ref");
1963 print_otag(h
, TAG_SPAN
, 1, &tag
);
1971 mdoc_li_pre(MDOC_ARGS
)
1973 struct htmlpair tag
;
1975 PAIR_CLASS_INIT(&tag
, "lit");
1976 print_otag(h
, TAG_CODE
, 1, &tag
);
1983 mdoc_sy_pre(MDOC_ARGS
)
1985 struct htmlpair tag
;
1987 PAIR_CLASS_INIT(&tag
, "symb");
1988 print_otag(h
, TAG_SPAN
, 1, &tag
);
1995 mdoc_bt_pre(MDOC_ARGS
)
1998 print_text(h
, "is currently in beta test.");
2005 mdoc_ud_pre(MDOC_ARGS
)
2008 print_text(h
, "currently under development.");
2015 mdoc_lb_pre(MDOC_ARGS
)
2017 struct htmlpair tag
;
2019 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2020 print_otag(h
, TAG_BR
, 0, NULL
);
2022 PAIR_CLASS_INIT(&tag
, "lib");
2023 print_otag(h
, TAG_SPAN
, 1, &tag
);
2030 mdoc__x_pre(MDOC_ARGS
)
2032 struct htmlpair tag
[2];
2039 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2040 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2041 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2042 print_text(h
, "and");
2045 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2049 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2052 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2055 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2059 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2063 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2066 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2069 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2072 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2075 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2078 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2081 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2084 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2091 if (MDOC__U
!= n
->tok
) {
2092 print_otag(h
, t
, 1, tag
);
2096 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2097 print_otag(h
, TAG_A
, 2, tag
);
2105 mdoc__x_post(MDOC_ARGS
)
2108 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2109 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2110 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2115 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2118 h
->flags
|= HTML_NOSPACE
;
2119 print_text(h
, n
->next
? "," : ".");
2125 mdoc_bk_pre(MDOC_ARGS
)
2134 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2135 h
->flags
|= HTML_PREKEEP
;
2148 mdoc_bk_post(MDOC_ARGS
)
2151 if (MDOC_BODY
== n
->type
)
2152 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2158 mdoc_quote_pre(MDOC_ARGS
)
2160 struct htmlpair tag
;
2162 if (MDOC_BODY
!= n
->type
)
2169 print_text(h
, "\\(la");
2174 print_text(h
, "\\(lC");
2179 print_text(h
, "\\(lB");
2184 print_text(h
, "\\(lB");
2185 h
->flags
|= HTML_NOSPACE
;
2186 PAIR_CLASS_INIT(&tag
, "opt");
2187 print_otag(h
, TAG_SPAN
, 1, &tag
);
2198 print_text(h
, "\\(lq");
2206 print_text(h
, "\\(oq");
2207 h
->flags
|= HTML_NOSPACE
;
2208 PAIR_CLASS_INIT(&tag
, "lit");
2209 print_otag(h
, TAG_CODE
, 1, &tag
);
2214 print_text(h
, "\\(oq");
2221 h
->flags
|= HTML_NOSPACE
;
2228 mdoc_quote_post(MDOC_ARGS
)
2231 if (MDOC_BODY
!= n
->type
)
2234 h
->flags
|= HTML_NOSPACE
;
2240 print_text(h
, "\\(ra");
2245 print_text(h
, "\\(rC");
2254 print_text(h
, "\\(rB");
2265 print_text(h
, "\\(rq");
2277 print_text(h
, "\\(cq");