]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.202 2014/09/27 09:05:57 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014 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>
30 #include "mandoc_aux.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_skip_pre(MDOC_ARGS
);
112 static int mdoc_sm_pre(MDOC_ARGS
);
113 static int mdoc_sp_pre(MDOC_ARGS
);
114 static int mdoc_ss_pre(MDOC_ARGS
);
115 static int mdoc_sx_pre(MDOC_ARGS
);
116 static int mdoc_sy_pre(MDOC_ARGS
);
117 static int mdoc_ud_pre(MDOC_ARGS
);
118 static int mdoc_va_pre(MDOC_ARGS
);
119 static int mdoc_vt_pre(MDOC_ARGS
);
120 static int mdoc_xr_pre(MDOC_ARGS
);
121 static int mdoc_xx_pre(MDOC_ARGS
);
123 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
124 {mdoc_ap_pre
, NULL
}, /* Ap */
125 {NULL
, NULL
}, /* Dd */
126 {NULL
, NULL
}, /* Dt */
127 {NULL
, NULL
}, /* Os */
128 {mdoc_sh_pre
, NULL
}, /* Sh */
129 {mdoc_ss_pre
, NULL
}, /* Ss */
130 {mdoc_pp_pre
, NULL
}, /* Pp */
131 {mdoc_d1_pre
, NULL
}, /* D1 */
132 {mdoc_d1_pre
, NULL
}, /* Dl */
133 {mdoc_bd_pre
, NULL
}, /* Bd */
134 {NULL
, NULL
}, /* Ed */
135 {mdoc_bl_pre
, NULL
}, /* Bl */
136 {NULL
, NULL
}, /* El */
137 {mdoc_it_pre
, NULL
}, /* It */
138 {mdoc_ad_pre
, NULL
}, /* Ad */
139 {mdoc_an_pre
, NULL
}, /* An */
140 {mdoc_ar_pre
, NULL
}, /* Ar */
141 {mdoc_cd_pre
, NULL
}, /* Cd */
142 {mdoc_fl_pre
, NULL
}, /* Cm */
143 {mdoc_dv_pre
, NULL
}, /* Dv */
144 {mdoc_er_pre
, NULL
}, /* Er */
145 {mdoc_ev_pre
, NULL
}, /* Ev */
146 {mdoc_ex_pre
, NULL
}, /* Ex */
147 {mdoc_fa_pre
, NULL
}, /* Fa */
148 {mdoc_fd_pre
, NULL
}, /* Fd */
149 {mdoc_fl_pre
, NULL
}, /* Fl */
150 {mdoc_fn_pre
, NULL
}, /* Fn */
151 {mdoc_ft_pre
, NULL
}, /* Ft */
152 {mdoc_ic_pre
, NULL
}, /* Ic */
153 {mdoc_in_pre
, NULL
}, /* In */
154 {mdoc_li_pre
, NULL
}, /* Li */
155 {mdoc_nd_pre
, NULL
}, /* Nd */
156 {mdoc_nm_pre
, NULL
}, /* Nm */
157 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
158 {mdoc_ft_pre
, NULL
}, /* Ot */
159 {mdoc_pa_pre
, NULL
}, /* Pa */
160 {mdoc_rv_pre
, NULL
}, /* Rv */
161 {NULL
, NULL
}, /* St */
162 {mdoc_va_pre
, NULL
}, /* Va */
163 {mdoc_vt_pre
, NULL
}, /* Vt */
164 {mdoc_xr_pre
, NULL
}, /* Xr */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
176 {NULL
, NULL
}, /* Ac */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
179 {NULL
, NULL
}, /* At */
180 {NULL
, NULL
}, /* Bc */
181 {mdoc_bf_pre
, NULL
}, /* Bf */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
184 {mdoc_xx_pre
, NULL
}, /* Bsx */
185 {mdoc_bx_pre
, NULL
}, /* Bx */
186 {NULL
, NULL
}, /* Db */
187 {NULL
, NULL
}, /* Dc */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
190 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 {NULL
, NULL
}, /* Ef */
192 {mdoc_em_pre
, NULL
}, /* Em */
193 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
194 {mdoc_xx_pre
, NULL
}, /* Fx */
195 {mdoc_ms_pre
, NULL
}, /* Ms */
196 {mdoc_igndelim_pre
, NULL
}, /* No */
197 {mdoc_ns_pre
, NULL
}, /* Ns */
198 {mdoc_xx_pre
, NULL
}, /* Nx */
199 {mdoc_xx_pre
, NULL
}, /* Ox */
200 {NULL
, NULL
}, /* Pc */
201 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
204 {NULL
, NULL
}, /* Qc */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
208 {NULL
, NULL
}, /* Re */
209 {mdoc_rs_pre
, NULL
}, /* Rs */
210 {NULL
, NULL
}, /* Sc */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
213 {mdoc_sm_pre
, NULL
}, /* Sm */
214 {mdoc_sx_pre
, NULL
}, /* Sx */
215 {mdoc_sy_pre
, NULL
}, /* Sy */
216 {NULL
, NULL
}, /* Tn */
217 {mdoc_xx_pre
, NULL
}, /* Ux */
218 {NULL
, NULL
}, /* Xc */
219 {NULL
, NULL
}, /* Xo */
220 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
221 {NULL
, NULL
}, /* Fc */
222 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
223 {NULL
, NULL
}, /* Oc */
224 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
225 {NULL
, NULL
}, /* Ek */
226 {mdoc_bt_pre
, NULL
}, /* Bt */
227 {NULL
, NULL
}, /* Hf */
228 {mdoc_em_pre
, NULL
}, /* Fr */
229 {mdoc_ud_pre
, NULL
}, /* Ud */
230 {mdoc_lb_pre
, NULL
}, /* Lb */
231 {mdoc_pp_pre
, NULL
}, /* Lp */
232 {mdoc_lk_pre
, NULL
}, /* Lk */
233 {mdoc_mt_pre
, NULL
}, /* Mt */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
236 {NULL
, NULL
}, /* Brc */
237 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
238 {mdoc_skip_pre
, NULL
}, /* Es */
239 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
240 {mdoc_xx_pre
, NULL
}, /* Dx */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
242 {mdoc_sp_pre
, NULL
}, /* br */
243 {mdoc_sp_pre
, NULL
}, /* sp */
244 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
245 {NULL
, NULL
}, /* Ta */
246 {mdoc_skip_pre
, NULL
}, /* ll */
249 static const char * const lists
[LIST_MAX
] = {
266 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
269 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
275 * Calculate the scaling unit passed in a `-width' argument. This uses
276 * either a native scaling unit (e.g., 1i, 2m) or the string length of
280 a2width(const char *p
, struct roffsu
*su
)
283 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
285 su
->scale
= html_strlen(p
);
290 * See the same function in mdoc_term.c for documentation.
293 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
296 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
299 if (n
->prev
->tok
== n
->tok
&&
303 print_otag(h
, TAG_BR
, 0, NULL
);
307 switch (n
->prev
->tok
) {
317 print_otag(h
, TAG_P
, 0, NULL
);
320 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
321 print_otag(h
, TAG_P
, 0, NULL
);
326 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
));
353 print_mdoc(MDOC_ARGS
)
358 PAIR_CLASS_INIT(&tag
, "mandoc");
360 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
362 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
363 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
364 print_mdoc_head(meta
, n
, h
);
366 print_otag(h
, TAG_BODY
, 0, NULL
);
367 print_otag(h
, TAG_DIV
, 1, &tag
);
369 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
371 print_mdoc_nodelist(meta
, n
, h
);
376 print_mdoc_head(MDOC_ARGS
)
381 bufcat(h
, meta
->title
);
383 bufcat_fmt(h
, "(%s)", meta
->msec
);
385 bufcat_fmt(h
, " (%s)", meta
->arch
);
387 print_otag(h
, TAG_TITLE
, 0, NULL
);
388 print_text(h
, h
->buf
);
392 print_mdoc_nodelist(MDOC_ARGS
)
395 print_mdoc_node(meta
, n
, h
);
397 print_mdoc_nodelist(meta
, n
->next
, h
);
401 print_mdoc_node(MDOC_ARGS
)
411 child
= mdoc_root_pre(meta
, n
, h
);
414 /* No tables in this mode... */
415 assert(NULL
== h
->tblt
);
418 * Make sure that if we're in a literal mode already
419 * (i.e., within a <PRE>) don't print the newline.
421 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
422 if ( ! (HTML_LITERAL
& h
->flags
))
423 print_otag(h
, TAG_BR
, 0, NULL
);
424 if (MDOC_DELIMC
& n
->flags
)
425 h
->flags
|= HTML_NOSPACE
;
426 print_text(h
, n
->string
);
427 if (MDOC_DELIMO
& n
->flags
)
428 h
->flags
|= HTML_NOSPACE
;
431 print_eqn(h
, n
->eqn
);
435 * This will take care of initialising all of the table
436 * state data for the first table, then tearing it down
439 print_tbl(h
, n
->span
);
443 * Close out the current table, if it's open, and unset
444 * the "meta" table state. This will be reopened on the
445 * next table element.
452 assert(NULL
== h
->tblt
);
453 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
454 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
458 if (HTML_KEEP
& h
->flags
) {
459 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
460 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
461 h
->flags
&= ~HTML_KEEP
;
462 h
->flags
|= HTML_PREKEEP
;
466 if (child
&& n
->child
)
467 print_mdoc_nodelist(meta
, n
->child
, h
);
473 mdoc_root_post(meta
, n
, h
);
478 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
479 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
485 mdoc_root_post(MDOC_ARGS
)
487 struct htmlpair tag
[2];
490 PAIR_CLASS_INIT(&tag
[0], "foot");
491 t
= print_otag(h
, TAG_TABLE
, 1, tag
);
492 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
493 print_otag(h
, TAG_COL
, 1, tag
);
494 print_otag(h
, TAG_COL
, 1, tag
);
496 print_otag(h
, TAG_TBODY
, 0, NULL
);
498 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
500 PAIR_CLASS_INIT(&tag
[0], "foot-date");
501 print_otag(h
, TAG_TD
, 1, tag
);
502 print_text(h
, meta
->date
);
505 PAIR_CLASS_INIT(&tag
[0], "foot-os");
506 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
507 print_otag(h
, TAG_TD
, 2, tag
);
508 print_text(h
, meta
->os
);
513 mdoc_root_pre(MDOC_ARGS
)
515 struct htmlpair tag
[2];
517 char *volume
, *title
;
519 if (NULL
== meta
->arch
)
520 volume
= mandoc_strdup(meta
->vol
);
522 mandoc_asprintf(&volume
, "%s (%s)",
523 meta
->vol
, meta
->arch
);
525 if (NULL
== meta
->msec
)
526 title
= mandoc_strdup(meta
->title
);
528 mandoc_asprintf(&title
, "%s(%s)",
529 meta
->title
, meta
->msec
);
531 PAIR_CLASS_INIT(&tag
[0], "head");
532 t
= print_otag(h
, TAG_TABLE
, 1, tag
);
533 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
534 print_otag(h
, TAG_COL
, 1, tag
);
535 print_otag(h
, TAG_COL
, 1, tag
);
536 print_otag(h
, TAG_COL
, 1, tag
);
538 print_otag(h
, TAG_TBODY
, 0, NULL
);
540 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
542 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
543 print_otag(h
, TAG_TD
, 1, tag
);
544 print_text(h
, title
);
547 PAIR_CLASS_INIT(&tag
[0], "head-vol");
548 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
549 print_otag(h
, TAG_TD
, 2, tag
);
550 print_text(h
, volume
);
553 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
554 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
555 print_otag(h
, TAG_TD
, 2, tag
);
556 print_text(h
, title
);
565 mdoc_sh_pre(MDOC_ARGS
)
571 PAIR_CLASS_INIT(&tag
, "section");
572 print_otag(h
, TAG_DIV
, 1, &tag
);
575 if (n
->sec
== SEC_AUTHORS
)
576 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
585 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
586 bufcat_id(h
, n
->string
);
587 if (NULL
!= (n
= n
->next
))
592 PAIR_ID_INIT(&tag
, h
->buf
);
593 print_otag(h
, TAG_H1
, 1, &tag
);
595 print_otag(h
, TAG_H1
, 0, NULL
);
601 mdoc_ss_pre(MDOC_ARGS
)
605 if (MDOC_BLOCK
== n
->type
) {
606 PAIR_CLASS_INIT(&tag
, "subsection");
607 print_otag(h
, TAG_DIV
, 1, &tag
);
609 } else if (MDOC_BODY
== n
->type
)
615 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
616 bufcat_id(h
, n
->string
);
617 if (NULL
!= (n
= n
->next
))
622 PAIR_ID_INIT(&tag
, h
->buf
);
623 print_otag(h
, TAG_H2
, 1, &tag
);
625 print_otag(h
, TAG_H2
, 0, NULL
);
631 mdoc_fl_pre(MDOC_ARGS
)
635 PAIR_CLASS_INIT(&tag
, "flag");
636 print_otag(h
, TAG_B
, 1, &tag
);
638 /* `Cm' has no leading hyphen. */
640 if (MDOC_Cm
== n
->tok
)
643 print_text(h
, "\\-");
645 if ( ! (n
->nchild
== 0 &&
647 n
->next
->type
== MDOC_TEXT
||
648 n
->next
->flags
& MDOC_LINE
)))
649 h
->flags
|= HTML_NOSPACE
;
655 mdoc_nd_pre(MDOC_ARGS
)
659 if (MDOC_BODY
!= n
->type
)
662 /* XXX: this tag in theory can contain block elements. */
664 print_text(h
, "\\(em");
665 PAIR_CLASS_INIT(&tag
, "desc");
666 print_otag(h
, TAG_SPAN
, 1, &tag
);
671 mdoc_nm_pre(MDOC_ARGS
)
680 PAIR_CLASS_INIT(&tag
, "name");
681 print_otag(h
, TAG_B
, 1, &tag
);
682 if (NULL
== n
->child
&& meta
->name
)
683 print_text(h
, meta
->name
);
686 print_otag(h
, TAG_TD
, 0, NULL
);
687 if (NULL
== n
->child
&& meta
->name
)
688 print_text(h
, meta
->name
);
691 print_otag(h
, TAG_TD
, 0, NULL
);
698 PAIR_CLASS_INIT(&tag
, "synopsis");
699 print_otag(h
, TAG_TABLE
, 1, &tag
);
701 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
702 if (MDOC_TEXT
== n
->type
)
703 len
+= html_strlen(n
->string
);
705 if (0 == len
&& meta
->name
)
706 len
= html_strlen(meta
->name
);
708 SCALE_HS_INIT(&su
, len
);
710 bufcat_su(h
, "width", &su
);
711 PAIR_STYLE_INIT(&tag
, h
);
712 print_otag(h
, TAG_COL
, 1, &tag
);
713 print_otag(h
, TAG_COL
, 0, NULL
);
714 print_otag(h
, TAG_TBODY
, 0, NULL
);
715 print_otag(h
, TAG_TR
, 0, NULL
);
720 mdoc_xr_pre(MDOC_ARGS
)
722 struct htmlpair tag
[2];
724 if (NULL
== n
->child
)
727 PAIR_CLASS_INIT(&tag
[0], "link-man");
730 buffmt_man(h
, n
->child
->string
,
732 n
->child
->next
->string
: NULL
);
733 PAIR_HREF_INIT(&tag
[1], h
->buf
);
734 print_otag(h
, TAG_A
, 2, tag
);
736 print_otag(h
, TAG_A
, 1, tag
);
739 print_text(h
, n
->string
);
741 if (NULL
== (n
= n
->next
))
744 h
->flags
|= HTML_NOSPACE
;
746 h
->flags
|= HTML_NOSPACE
;
747 print_text(h
, n
->string
);
748 h
->flags
|= HTML_NOSPACE
;
754 mdoc_ns_pre(MDOC_ARGS
)
757 if ( ! (MDOC_LINE
& n
->flags
))
758 h
->flags
|= HTML_NOSPACE
;
763 mdoc_ar_pre(MDOC_ARGS
)
767 PAIR_CLASS_INIT(&tag
, "arg");
768 print_otag(h
, TAG_I
, 1, &tag
);
773 mdoc_xx_pre(MDOC_ARGS
)
802 PAIR_CLASS_INIT(&tag
, "unix");
803 print_otag(h
, TAG_SPAN
, 1, &tag
);
808 h
->flags
|= HTML_KEEP
;
809 print_text(h
, n
->child
->string
);
816 mdoc_bx_pre(MDOC_ARGS
)
820 PAIR_CLASS_INIT(&tag
, "unix");
821 print_otag(h
, TAG_SPAN
, 1, &tag
);
823 if (NULL
!= (n
= n
->child
)) {
824 print_text(h
, n
->string
);
825 h
->flags
|= HTML_NOSPACE
;
826 print_text(h
, "BSD");
828 print_text(h
, "BSD");
832 if (NULL
!= (n
= n
->next
)) {
833 h
->flags
|= HTML_NOSPACE
;
835 h
->flags
|= HTML_NOSPACE
;
836 print_text(h
, n
->string
);
843 mdoc_it_pre(MDOC_ARGS
)
847 struct htmlpair tag
[2];
848 const struct mdoc_node
*bl
;
851 while (bl
&& MDOC_Bl
!= bl
->tok
)
856 type
= bl
->norm
->Bl
.type
;
859 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
863 if (MDOC_HEAD
== n
->type
) {
884 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
885 bufcat_su(h
, "margin-top", &su
);
886 PAIR_STYLE_INIT(&tag
[1], h
);
887 print_otag(h
, TAG_DT
, 2, tag
);
888 if (LIST_diag
!= type
)
890 PAIR_CLASS_INIT(&tag
[0], "diag");
891 print_otag(h
, TAG_B
, 1, tag
);
898 } else if (MDOC_BODY
== n
->type
) {
909 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
910 bufcat_su(h
, "margin-top", &su
);
911 PAIR_STYLE_INIT(&tag
[1], h
);
912 print_otag(h
, TAG_LI
, 2, tag
);
923 if (NULL
== bl
->norm
->Bl
.width
) {
924 print_otag(h
, TAG_DD
, 1, tag
);
927 a2width(bl
->norm
->Bl
.width
, &su
);
928 bufcat_su(h
, "margin-left", &su
);
929 PAIR_STYLE_INIT(&tag
[1], h
);
930 print_otag(h
, TAG_DD
, 2, tag
);
933 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
934 bufcat_su(h
, "margin-top", &su
);
935 PAIR_STYLE_INIT(&tag
[1], h
);
936 print_otag(h
, TAG_TD
, 2, tag
);
944 print_otag(h
, TAG_TR
, 1, tag
);
955 mdoc_bl_pre(MDOC_ARGS
)
958 struct htmlpair tag
[3];
962 if (MDOC_BODY
== n
->type
) {
963 if (LIST_column
== n
->norm
->Bl
.type
)
964 print_otag(h
, TAG_TBODY
, 0, NULL
);
968 if (MDOC_HEAD
== n
->type
) {
969 if (LIST_column
!= n
->norm
->Bl
.type
)
973 * For each column, print out the <COL> tag with our
974 * suggested width. The last column gets min-width, as
975 * in terminal mode it auto-sizes to the width of the
976 * screen and we want to preserve that behaviour.
979 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
981 a2width(n
->norm
->Bl
.cols
[i
], &su
);
982 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
983 bufcat_su(h
, "width", &su
);
985 bufcat_su(h
, "min-width", &su
);
986 PAIR_STYLE_INIT(&tag
[0], h
);
987 print_otag(h
, TAG_COL
, 1, tag
);
993 SCALE_VS_INIT(&su
, 0);
995 bufcat_su(h
, "margin-top", &su
);
996 bufcat_su(h
, "margin-bottom", &su
);
997 PAIR_STYLE_INIT(&tag
[0], h
);
999 assert(lists
[n
->norm
->Bl
.type
]);
1000 (void)strlcpy(buf
, "list ", BUFSIZ
);
1001 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1002 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1004 /* Set the block's left-hand margin. */
1006 if (n
->norm
->Bl
.offs
) {
1007 a2offs(n
->norm
->Bl
.offs
, &su
);
1008 bufcat_su(h
, "margin-left", &su
);
1011 switch (n
->norm
->Bl
.type
) {
1019 print_otag(h
, TAG_UL
, 2, tag
);
1022 print_otag(h
, TAG_OL
, 2, tag
);
1033 print_otag(h
, TAG_DL
, 2, tag
);
1036 print_otag(h
, TAG_TABLE
, 2, tag
);
1047 mdoc_ex_pre(MDOC_ARGS
)
1050 struct htmlpair tag
;
1054 print_otag(h
, TAG_BR
, 0, NULL
);
1056 PAIR_CLASS_INIT(&tag
, "utility");
1058 print_text(h
, "The");
1061 for (n
= n
->child
; n
; n
= n
->next
) {
1062 assert(MDOC_TEXT
== n
->type
);
1064 t
= print_otag(h
, TAG_B
, 1, &tag
);
1065 print_text(h
, n
->string
);
1068 if (nchild
> 2 && n
->next
) {
1069 h
->flags
|= HTML_NOSPACE
;
1073 if (n
->next
&& NULL
== n
->next
->next
)
1074 print_text(h
, "and");
1078 print_text(h
, "utilities exit\\~0");
1080 print_text(h
, "utility exits\\~0");
1082 print_text(h
, "on success, and\\~>0 if an error occurs.");
1087 mdoc_em_pre(MDOC_ARGS
)
1089 struct htmlpair tag
;
1091 PAIR_CLASS_INIT(&tag
, "emph");
1092 print_otag(h
, TAG_SPAN
, 1, &tag
);
1097 mdoc_d1_pre(MDOC_ARGS
)
1099 struct htmlpair tag
[2];
1102 if (MDOC_BLOCK
!= n
->type
)
1105 SCALE_VS_INIT(&su
, 0);
1107 bufcat_su(h
, "margin-top", &su
);
1108 bufcat_su(h
, "margin-bottom", &su
);
1109 PAIR_STYLE_INIT(&tag
[0], h
);
1110 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1112 /* BLOCKQUOTE needs a block body. */
1114 PAIR_CLASS_INIT(&tag
[0], "display");
1115 print_otag(h
, TAG_DIV
, 1, tag
);
1117 if (MDOC_Dl
== n
->tok
) {
1118 PAIR_CLASS_INIT(&tag
[0], "lit");
1119 print_otag(h
, TAG_CODE
, 1, tag
);
1126 mdoc_sx_pre(MDOC_ARGS
)
1128 struct htmlpair tag
[2];
1133 for (n
= n
->child
; n
; ) {
1134 bufcat_id(h
, n
->string
);
1135 if (NULL
!= (n
= n
->next
))
1139 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1140 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1142 print_otag(h
, TAG_I
, 1, tag
);
1143 print_otag(h
, TAG_A
, 2, tag
);
1148 mdoc_bd_pre(MDOC_ARGS
)
1150 struct htmlpair tag
[2];
1152 const struct mdoc_node
*nn
;
1155 if (MDOC_HEAD
== n
->type
)
1158 if (MDOC_BLOCK
== n
->type
) {
1159 comp
= n
->norm
->Bd
.comp
;
1160 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1161 if (MDOC_BLOCK
!= nn
->type
)
1163 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1169 print_otag(h
, TAG_P
, 0, NULL
);
1173 SCALE_HS_INIT(&su
, 0);
1174 if (n
->norm
->Bd
.offs
)
1175 a2offs(n
->norm
->Bd
.offs
, &su
);
1178 bufcat_su(h
, "margin-left", &su
);
1179 PAIR_STYLE_INIT(&tag
[0], h
);
1181 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1182 DISP_literal
!= n
->norm
->Bd
.type
) {
1183 PAIR_CLASS_INIT(&tag
[1], "display");
1184 print_otag(h
, TAG_DIV
, 2, tag
);
1188 PAIR_CLASS_INIT(&tag
[1], "lit display");
1189 print_otag(h
, TAG_PRE
, 2, tag
);
1191 /* This can be recursive: save & set our literal state. */
1193 sv
= h
->flags
& HTML_LITERAL
;
1194 h
->flags
|= HTML_LITERAL
;
1196 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1197 print_mdoc_node(meta
, nn
, h
);
1199 * If the printed node flushes its own line, then we
1200 * needn't do it here as well. This is hacky, but the
1201 * notion of selective eoln whitespace is pretty dumb
1202 * anyway, so don't sweat it.
1224 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1227 print_text(h
, "\n");
1229 h
->flags
|= HTML_NOSPACE
;
1233 h
->flags
&= ~HTML_LITERAL
;
1239 mdoc_pa_pre(MDOC_ARGS
)
1241 struct htmlpair tag
;
1243 PAIR_CLASS_INIT(&tag
, "file");
1244 print_otag(h
, TAG_I
, 1, &tag
);
1249 mdoc_ad_pre(MDOC_ARGS
)
1251 struct htmlpair tag
;
1253 PAIR_CLASS_INIT(&tag
, "addr");
1254 print_otag(h
, TAG_I
, 1, &tag
);
1259 mdoc_an_pre(MDOC_ARGS
)
1261 struct htmlpair tag
;
1263 if (n
->norm
->An
.auth
== AUTH_split
) {
1264 h
->flags
&= ~HTML_NOSPLIT
;
1265 h
->flags
|= HTML_SPLIT
;
1268 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1269 h
->flags
&= ~HTML_SPLIT
;
1270 h
->flags
|= HTML_NOSPLIT
;
1274 if (n
->child
== NULL
)
1277 if (h
->flags
& HTML_SPLIT
)
1278 print_otag(h
, TAG_BR
, 0, NULL
);
1280 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1281 h
->flags
|= HTML_SPLIT
;
1283 PAIR_CLASS_INIT(&tag
, "author");
1284 print_otag(h
, TAG_SPAN
, 1, &tag
);
1289 mdoc_cd_pre(MDOC_ARGS
)
1291 struct htmlpair tag
;
1294 PAIR_CLASS_INIT(&tag
, "config");
1295 print_otag(h
, TAG_B
, 1, &tag
);
1300 mdoc_dv_pre(MDOC_ARGS
)
1302 struct htmlpair tag
;
1304 PAIR_CLASS_INIT(&tag
, "define");
1305 print_otag(h
, TAG_SPAN
, 1, &tag
);
1310 mdoc_ev_pre(MDOC_ARGS
)
1312 struct htmlpair tag
;
1314 PAIR_CLASS_INIT(&tag
, "env");
1315 print_otag(h
, TAG_SPAN
, 1, &tag
);
1320 mdoc_er_pre(MDOC_ARGS
)
1322 struct htmlpair tag
;
1324 PAIR_CLASS_INIT(&tag
, "errno");
1325 print_otag(h
, TAG_SPAN
, 1, &tag
);
1330 mdoc_fa_pre(MDOC_ARGS
)
1332 const struct mdoc_node
*nn
;
1333 struct htmlpair tag
;
1336 PAIR_CLASS_INIT(&tag
, "farg");
1337 if (n
->parent
->tok
!= MDOC_Fo
) {
1338 print_otag(h
, TAG_I
, 1, &tag
);
1342 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1343 t
= print_otag(h
, TAG_I
, 1, &tag
);
1344 print_text(h
, nn
->string
);
1347 h
->flags
|= HTML_NOSPACE
;
1352 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1353 h
->flags
|= HTML_NOSPACE
;
1361 mdoc_fd_pre(MDOC_ARGS
)
1363 struct htmlpair tag
[2];
1371 if (NULL
== (n
= n
->child
))
1374 assert(MDOC_TEXT
== n
->type
);
1376 if (strcmp(n
->string
, "#include")) {
1377 PAIR_CLASS_INIT(&tag
[0], "macro");
1378 print_otag(h
, TAG_B
, 1, tag
);
1382 PAIR_CLASS_INIT(&tag
[0], "includes");
1383 print_otag(h
, TAG_B
, 1, tag
);
1384 print_text(h
, n
->string
);
1386 if (NULL
!= (n
= n
->next
)) {
1387 assert(MDOC_TEXT
== n
->type
);
1390 * XXX This is broken and not easy to fix.
1391 * When using -Oincludes, truncation may occur.
1392 * Dynamic allocation wouldn't help because
1393 * passing long strings to buffmt_includes()
1394 * does not work either.
1397 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1398 n
->string
+ 1 : n
->string
, BUFSIZ
);
1401 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1404 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1407 if (h
->base_includes
) {
1408 buffmt_includes(h
, buf
);
1409 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1413 t
= print_otag(h
, TAG_A
, i
, tag
);
1414 print_text(h
, n
->string
);
1420 for ( ; n
; n
= n
->next
) {
1421 assert(MDOC_TEXT
== n
->type
);
1422 print_text(h
, n
->string
);
1429 mdoc_vt_pre(MDOC_ARGS
)
1431 struct htmlpair tag
;
1433 if (MDOC_BLOCK
== n
->type
) {
1436 } else if (MDOC_ELEM
== n
->type
) {
1438 } else if (MDOC_HEAD
== n
->type
)
1441 PAIR_CLASS_INIT(&tag
, "type");
1442 print_otag(h
, TAG_SPAN
, 1, &tag
);
1447 mdoc_ft_pre(MDOC_ARGS
)
1449 struct htmlpair tag
;
1452 PAIR_CLASS_INIT(&tag
, "ftype");
1453 print_otag(h
, TAG_I
, 1, &tag
);
1458 mdoc_fn_pre(MDOC_ARGS
)
1461 struct htmlpair tag
[2];
1463 const char *sp
, *ep
;
1466 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1469 /* Split apart into type and name. */
1470 assert(n
->child
->string
);
1471 sp
= n
->child
->string
;
1473 ep
= strchr(sp
, ' ');
1475 PAIR_CLASS_INIT(&tag
[0], "ftype");
1476 t
= print_otag(h
, TAG_I
, 1, tag
);
1479 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1480 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1482 print_text(h
, nbuf
);
1484 ep
= strchr(sp
, ' ');
1489 PAIR_CLASS_INIT(&tag
[0], "fname");
1492 * FIXME: only refer to IDs that we know exist.
1496 if (MDOC_SYNPRETTY
& n
->flags
) {
1498 html_idcat(nbuf
, sp
, BUFSIZ
);
1499 PAIR_ID_INIT(&tag
[1], nbuf
);
1501 strlcpy(nbuf
, "#", BUFSIZ
);
1502 html_idcat(nbuf
, sp
, BUFSIZ
);
1503 PAIR_HREF_INIT(&tag
[1], nbuf
);
1507 t
= print_otag(h
, TAG_B
, 1, tag
);
1514 h
->flags
|= HTML_NOSPACE
;
1516 h
->flags
|= HTML_NOSPACE
;
1518 PAIR_CLASS_INIT(&tag
[0], "farg");
1520 bufcat_style(h
, "white-space", "nowrap");
1521 PAIR_STYLE_INIT(&tag
[1], h
);
1523 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1525 if (MDOC_SYNPRETTY
& n
->flags
)
1527 t
= print_otag(h
, TAG_I
, i
, tag
);
1528 print_text(h
, n
->string
);
1531 h
->flags
|= HTML_NOSPACE
;
1536 h
->flags
|= HTML_NOSPACE
;
1540 h
->flags
|= HTML_NOSPACE
;
1548 mdoc_sm_pre(MDOC_ARGS
)
1551 if (NULL
== n
->child
)
1552 h
->flags
^= HTML_NONOSPACE
;
1553 else if (0 == strcmp("on", n
->child
->string
))
1554 h
->flags
&= ~HTML_NONOSPACE
;
1556 h
->flags
|= HTML_NONOSPACE
;
1558 if ( ! (HTML_NONOSPACE
& h
->flags
))
1559 h
->flags
&= ~HTML_NOSPACE
;
1565 mdoc_skip_pre(MDOC_ARGS
)
1572 mdoc_pp_pre(MDOC_ARGS
)
1575 print_otag(h
, TAG_P
, 0, NULL
);
1580 mdoc_sp_pre(MDOC_ARGS
)
1583 struct htmlpair tag
;
1585 SCALE_VS_INIT(&su
, 1);
1587 if (MDOC_sp
== n
->tok
) {
1588 if (NULL
!= (n
= n
->child
))
1589 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1590 SCALE_VS_INIT(&su
, atoi(n
->string
));
1595 bufcat_su(h
, "height", &su
);
1596 PAIR_STYLE_INIT(&tag
, h
);
1597 print_otag(h
, TAG_DIV
, 1, &tag
);
1599 /* So the div isn't empty: */
1600 print_text(h
, "\\~");
1607 mdoc_lk_pre(MDOC_ARGS
)
1609 struct htmlpair tag
[2];
1611 if (NULL
== (n
= n
->child
))
1614 assert(MDOC_TEXT
== n
->type
);
1616 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1617 PAIR_HREF_INIT(&tag
[1], n
->string
);
1619 print_otag(h
, TAG_A
, 2, tag
);
1621 if (NULL
== n
->next
)
1622 print_text(h
, n
->string
);
1624 for (n
= n
->next
; n
; n
= n
->next
)
1625 print_text(h
, n
->string
);
1631 mdoc_mt_pre(MDOC_ARGS
)
1633 struct htmlpair tag
[2];
1636 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1638 for (n
= n
->child
; n
; n
= n
->next
) {
1639 assert(MDOC_TEXT
== n
->type
);
1642 bufcat(h
, "mailto:");
1643 bufcat(h
, n
->string
);
1645 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1646 t
= print_otag(h
, TAG_A
, 2, tag
);
1647 print_text(h
, n
->string
);
1655 mdoc_fo_pre(MDOC_ARGS
)
1657 struct htmlpair tag
;
1660 if (MDOC_BODY
== n
->type
) {
1661 h
->flags
|= HTML_NOSPACE
;
1663 h
->flags
|= HTML_NOSPACE
;
1665 } else if (MDOC_BLOCK
== n
->type
) {
1670 /* XXX: we drop non-initial arguments as per groff. */
1673 assert(n
->child
->string
);
1675 PAIR_CLASS_INIT(&tag
, "fname");
1676 t
= print_otag(h
, TAG_B
, 1, &tag
);
1677 print_text(h
, n
->child
->string
);
1683 mdoc_fo_post(MDOC_ARGS
)
1686 if (MDOC_BODY
!= n
->type
)
1688 h
->flags
|= HTML_NOSPACE
;
1690 h
->flags
|= HTML_NOSPACE
;
1695 mdoc_in_pre(MDOC_ARGS
)
1698 struct htmlpair tag
[2];
1703 PAIR_CLASS_INIT(&tag
[0], "includes");
1704 print_otag(h
, TAG_B
, 1, tag
);
1707 * The first argument of the `In' gets special treatment as
1708 * being a linked value. Subsequent values are printed
1709 * afterward. groff does similarly. This also handles the case
1713 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1714 print_text(h
, "#include");
1717 h
->flags
|= HTML_NOSPACE
;
1719 if (NULL
!= (n
= n
->child
)) {
1720 assert(MDOC_TEXT
== n
->type
);
1722 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1725 if (h
->base_includes
) {
1726 buffmt_includes(h
, n
->string
);
1727 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1731 t
= print_otag(h
, TAG_A
, i
, tag
);
1732 print_text(h
, n
->string
);
1738 h
->flags
|= HTML_NOSPACE
;
1741 for ( ; n
; n
= n
->next
) {
1742 assert(MDOC_TEXT
== n
->type
);
1743 print_text(h
, n
->string
);
1750 mdoc_ic_pre(MDOC_ARGS
)
1752 struct htmlpair tag
;
1754 PAIR_CLASS_INIT(&tag
, "cmd");
1755 print_otag(h
, TAG_B
, 1, &tag
);
1760 mdoc_rv_pre(MDOC_ARGS
)
1762 struct htmlpair tag
;
1767 print_otag(h
, TAG_BR
, 0, NULL
);
1769 PAIR_CLASS_INIT(&tag
, "fname");
1773 print_text(h
, "The");
1775 for (n
= n
->child
; n
; n
= n
->next
) {
1776 t
= print_otag(h
, TAG_B
, 1, &tag
);
1777 print_text(h
, n
->string
);
1780 h
->flags
|= HTML_NOSPACE
;
1781 print_text(h
, "()");
1783 if (n
->next
== NULL
)
1787 h
->flags
|= HTML_NOSPACE
;
1790 if (n
->next
->next
== NULL
)
1791 print_text(h
, "and");
1795 print_text(h
, "functions return");
1797 print_text(h
, "function returns");
1799 print_text(h
, "the value\\~0 if successful;");
1801 print_text(h
, "Upon successful completion,"
1802 " the value\\~0 is returned;");
1804 print_text(h
, "otherwise the value\\~\\-1 is returned"
1805 " and the global variable");
1807 PAIR_CLASS_INIT(&tag
, "var");
1808 t
= print_otag(h
, TAG_B
, 1, &tag
);
1809 print_text(h
, "errno");
1811 print_text(h
, "is set to indicate the error.");
1816 mdoc_va_pre(MDOC_ARGS
)
1818 struct htmlpair tag
;
1820 PAIR_CLASS_INIT(&tag
, "var");
1821 print_otag(h
, TAG_B
, 1, &tag
);
1826 mdoc_ap_pre(MDOC_ARGS
)
1829 h
->flags
|= HTML_NOSPACE
;
1830 print_text(h
, "\\(aq");
1831 h
->flags
|= HTML_NOSPACE
;
1836 mdoc_bf_pre(MDOC_ARGS
)
1838 struct htmlpair tag
[2];
1841 if (MDOC_HEAD
== n
->type
)
1843 else if (MDOC_BODY
!= n
->type
)
1846 if (FONT_Em
== n
->norm
->Bf
.font
)
1847 PAIR_CLASS_INIT(&tag
[0], "emph");
1848 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1849 PAIR_CLASS_INIT(&tag
[0], "symb");
1850 else if (FONT_Li
== n
->norm
->Bf
.font
)
1851 PAIR_CLASS_INIT(&tag
[0], "lit");
1853 PAIR_CLASS_INIT(&tag
[0], "none");
1856 * We want this to be inline-formatted, but needs to be div to
1857 * accept block children.
1860 bufcat_style(h
, "display", "inline");
1861 SCALE_HS_INIT(&su
, 1);
1862 /* Needs a left-margin for spacing. */
1863 bufcat_su(h
, "margin-left", &su
);
1864 PAIR_STYLE_INIT(&tag
[1], h
);
1865 print_otag(h
, TAG_DIV
, 2, tag
);
1870 mdoc_ms_pre(MDOC_ARGS
)
1872 struct htmlpair tag
;
1874 PAIR_CLASS_INIT(&tag
, "symb");
1875 print_otag(h
, TAG_SPAN
, 1, &tag
);
1880 mdoc_igndelim_pre(MDOC_ARGS
)
1883 h
->flags
|= HTML_IGNDELIM
;
1888 mdoc_pf_post(MDOC_ARGS
)
1891 h
->flags
|= HTML_NOSPACE
;
1895 mdoc_rs_pre(MDOC_ARGS
)
1897 struct htmlpair tag
;
1899 if (MDOC_BLOCK
!= n
->type
)
1902 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1903 print_otag(h
, TAG_P
, 0, NULL
);
1905 PAIR_CLASS_INIT(&tag
, "ref");
1906 print_otag(h
, TAG_SPAN
, 1, &tag
);
1911 mdoc_li_pre(MDOC_ARGS
)
1913 struct htmlpair tag
;
1915 PAIR_CLASS_INIT(&tag
, "lit");
1916 print_otag(h
, TAG_CODE
, 1, &tag
);
1921 mdoc_sy_pre(MDOC_ARGS
)
1923 struct htmlpair tag
;
1925 PAIR_CLASS_INIT(&tag
, "symb");
1926 print_otag(h
, TAG_SPAN
, 1, &tag
);
1931 mdoc_bt_pre(MDOC_ARGS
)
1934 print_text(h
, "is currently in beta test.");
1939 mdoc_ud_pre(MDOC_ARGS
)
1942 print_text(h
, "currently under development.");
1947 mdoc_lb_pre(MDOC_ARGS
)
1949 struct htmlpair tag
;
1951 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1952 print_otag(h
, TAG_BR
, 0, NULL
);
1954 PAIR_CLASS_INIT(&tag
, "lib");
1955 print_otag(h
, TAG_SPAN
, 1, &tag
);
1960 mdoc__x_pre(MDOC_ARGS
)
1962 struct htmlpair tag
[2];
1969 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1970 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1971 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1972 print_text(h
, "and");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1982 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1985 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1989 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1993 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1996 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1999 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2002 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2005 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2008 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2011 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2014 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2021 if (MDOC__U
!= n
->tok
) {
2022 print_otag(h
, t
, 1, tag
);
2026 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2027 print_otag(h
, TAG_A
, 2, tag
);
2033 mdoc__x_post(MDOC_ARGS
)
2036 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2037 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2038 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2043 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2046 h
->flags
|= HTML_NOSPACE
;
2047 print_text(h
, n
->next
? "," : ".");
2051 mdoc_bk_pre(MDOC_ARGS
)
2060 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2061 h
->flags
|= HTML_PREKEEP
;
2072 mdoc_bk_post(MDOC_ARGS
)
2075 if (MDOC_BODY
== n
->type
)
2076 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2080 mdoc_quote_pre(MDOC_ARGS
)
2082 struct htmlpair tag
;
2084 if (MDOC_BODY
!= n
->type
)
2091 print_text(h
, "\\(la");
2096 print_text(h
, "\\(lC");
2101 print_text(h
, "\\(lB");
2106 print_text(h
, "\\(lB");
2107 h
->flags
|= HTML_NOSPACE
;
2108 PAIR_CLASS_INIT(&tag
, "opt");
2109 print_otag(h
, TAG_SPAN
, 1, &tag
);
2112 if (NULL
== n
->norm
->Es
||
2113 NULL
== n
->norm
->Es
->child
)
2115 print_text(h
, n
->norm
->Es
->child
->string
);
2126 print_text(h
, "\\(lq");
2134 print_text(h
, "\\(oq");
2135 h
->flags
|= HTML_NOSPACE
;
2136 PAIR_CLASS_INIT(&tag
, "lit");
2137 print_otag(h
, TAG_CODE
, 1, &tag
);
2142 print_text(h
, "\\(oq");
2149 h
->flags
|= HTML_NOSPACE
;
2154 mdoc_quote_post(MDOC_ARGS
)
2157 if (MDOC_BODY
!= n
->type
)
2160 if (MDOC_En
!= n
->tok
)
2161 h
->flags
|= HTML_NOSPACE
;
2167 print_text(h
, "\\(ra");
2172 print_text(h
, "\\(rC");
2181 print_text(h
, "\\(rB");
2184 if (NULL
!= n
->norm
->Es
&&
2185 NULL
!= n
->norm
->Es
->child
&&
2186 NULL
!= n
->norm
->Es
->child
->next
) {
2187 h
->flags
|= HTML_NOSPACE
;
2188 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2200 print_text(h
, "\\(rq");
2212 print_text(h
, "\\(cq");