]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.174 2011/07/23 22:57:13 kristaps 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>
39 #define MDOC_ARGS const struct mdoc_meta *m, \
40 const struct mdoc_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static void print_mdoc(MDOC_ARGS
);
53 static void print_mdoc_head(MDOC_ARGS
);
54 static void print_mdoc_node(MDOC_ARGS
);
55 static void print_mdoc_nodelist(MDOC_ARGS
);
56 static void synopsis_pre(struct html
*,
57 const struct mdoc_node
*);
59 static void a2width(const char *, struct roffsu
*);
60 static void a2offs(const char *, struct roffsu
*);
62 static void mdoc_root_post(MDOC_ARGS
);
63 static int mdoc_root_pre(MDOC_ARGS
);
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static int mdoc_bt_pre(MDOC_ARGS
);
77 static int mdoc_bx_pre(MDOC_ARGS
);
78 static int mdoc_cd_pre(MDOC_ARGS
);
79 static int mdoc_d1_pre(MDOC_ARGS
);
80 static int mdoc_dv_pre(MDOC_ARGS
);
81 static int mdoc_fa_pre(MDOC_ARGS
);
82 static int mdoc_fd_pre(MDOC_ARGS
);
83 static int mdoc_fl_pre(MDOC_ARGS
);
84 static int mdoc_fn_pre(MDOC_ARGS
);
85 static int mdoc_ft_pre(MDOC_ARGS
);
86 static int mdoc_em_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_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_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 {NULL
, 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 {NULL
, NULL
}, /* 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 {NULL
, 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 {NULL
, NULL
}, /* Es */ /* TODO */
239 {NULL
, NULL
}, /* En */ /* TODO */
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 */
248 static const char * const lists
[LIST_MAX
] = {
264 html_mdoc(void *arg
, const struct mdoc
*m
)
269 h
= (struct html
*)arg
;
272 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
273 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
281 * Calculate the scaling unit passed in a `-width' argument. This uses
282 * either a native scaling unit (e.g., 1i, 2m) or the string length of
286 a2width(const char *p
, struct roffsu
*su
)
289 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
291 su
->scale
= html_strlen(p
);
297 * See the same function in mdoc_term.c for documentation.
300 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
303 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
306 if (n
->prev
->tok
== n
->tok
&&
310 print_otag(h
, TAG_BR
, 0, NULL
);
314 switch (n
->prev
->tok
) {
324 print_otag(h
, TAG_P
, 0, NULL
);
327 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
328 print_otag(h
, TAG_P
, 0, NULL
);
333 print_otag(h
, TAG_BR
, 0, NULL
);
340 * Calculate the scaling unit passed in an `-offset' argument. This
341 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
342 * predefined strings (indent, etc.), or the string length of the value.
345 a2offs(const char *p
, struct roffsu
*su
)
348 /* FIXME: "right"? */
350 if (0 == strcmp(p
, "left"))
351 SCALE_HS_INIT(su
, 0);
352 else if (0 == strcmp(p
, "indent"))
353 SCALE_HS_INIT(su
, INDENT
);
354 else if (0 == strcmp(p
, "indent-two"))
355 SCALE_HS_INIT(su
, INDENT
* 2);
356 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
358 su
->scale
= html_strlen(p
);
364 print_mdoc(MDOC_ARGS
)
368 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
369 print_mdoc_head(m
, n
, h
);
372 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
373 print_mdoc_nodelist(m
, n
, h
);
380 print_mdoc_head(MDOC_ARGS
)
385 bufcat_fmt(h
, "%s(%s)", m
->title
, m
->msec
);
388 bufcat_fmt(h
, " (%s)", m
->arch
);
390 print_otag(h
, TAG_TITLE
, 0, NULL
);
391 print_text(h
, h
->buf
);
396 print_mdoc_nodelist(MDOC_ARGS
)
399 print_mdoc_node(m
, n
, h
);
401 print_mdoc_nodelist(m
, n
->next
, h
);
406 print_mdoc_node(MDOC_ARGS
)
416 child
= mdoc_root_pre(m
, n
, h
);
419 /* No tables in this mode... */
420 assert(NULL
== h
->tblt
);
423 * Make sure that if we're in a literal mode already
424 * (i.e., within a <PRE>) don't print the newline.
426 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
427 if ( ! (HTML_LITERAL
& h
->flags
))
428 print_otag(h
, TAG_BR
, 0, NULL
);
429 if (MDOC_DELIMC
& n
->flags
)
430 h
->flags
|= HTML_NOSPACE
;
431 print_text(h
, n
->string
);
432 if (MDOC_DELIMO
& n
->flags
)
433 h
->flags
|= HTML_NOSPACE
;
436 print_eqn(h
, n
->eqn
);
440 * This will take care of initialising all of the table
441 * state data for the first table, then tearing it down
444 print_tbl(h
, n
->span
);
448 * Close out the current table, if it's open, and unset
449 * the "meta" table state. This will be reopened on the
450 * next table element.
457 assert(NULL
== h
->tblt
);
458 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
459 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
463 if (HTML_KEEP
& h
->flags
) {
464 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
465 h
->flags
&= ~HTML_KEEP
;
466 h
->flags
|= HTML_PREKEEP
;
467 } else if (NULL
== n
->prev
) {
468 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
469 h
->flags
&= ~HTML_KEEP
;
470 h
->flags
|= HTML_PREKEEP
;
475 if (child
&& n
->child
)
476 print_mdoc_nodelist(m
, n
->child
, h
);
482 mdoc_root_post(m
, n
, h
);
487 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
488 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
495 mdoc_root_post(MDOC_ARGS
)
497 struct htmlpair tag
[3];
500 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
501 PAIR_CLASS_INIT(&tag
[1], "foot");
502 if (NULL
== h
->style
) {
503 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
504 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
505 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
506 print_otag(h
, TAG_COL
, 1, tag
);
507 print_otag(h
, TAG_COL
, 1, tag
);
509 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
511 t
= print_otag(h
, TAG_TBODY
, 0, NULL
);
513 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
515 PAIR_CLASS_INIT(&tag
[0], "foot-date");
516 print_otag(h
, TAG_TD
, 1, tag
);
518 print_text(h
, m
->date
);
521 PAIR_CLASS_INIT(&tag
[0], "foot-os");
522 if (NULL
== h
->style
) {
523 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
524 print_otag(h
, TAG_TD
, 2, tag
);
526 print_otag(h
, TAG_TD
, 1, tag
);
528 print_text(h
, m
->os
);
535 mdoc_root_pre(MDOC_ARGS
)
537 struct htmlpair tag
[3];
539 char b
[BUFSIZ
], title
[BUFSIZ
];
541 strlcpy(b
, m
->vol
, BUFSIZ
);
544 strlcat(b
, " (", BUFSIZ
);
545 strlcat(b
, m
->arch
, BUFSIZ
);
546 strlcat(b
, ")", BUFSIZ
);
549 snprintf(title
, BUFSIZ
- 1, "%s(%s)", m
->title
, m
->msec
);
551 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
552 PAIR_CLASS_INIT(&tag
[1], "head");
553 if (NULL
== h
->style
) {
554 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
555 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
556 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
557 print_otag(h
, TAG_COL
, 1, tag
);
558 print_otag(h
, TAG_COL
, 1, tag
);
559 print_otag(h
, TAG_COL
, 1, tag
);
561 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
563 print_otag(h
, TAG_TBODY
, 0, NULL
);
565 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
567 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
568 print_otag(h
, TAG_TD
, 1, tag
);
570 print_text(h
, title
);
573 PAIR_CLASS_INIT(&tag
[0], "head-vol");
574 if (NULL
== h
->style
) {
575 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
576 print_otag(h
, TAG_TD
, 2, tag
);
578 print_otag(h
, TAG_TD
, 1, tag
);
583 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
584 if (NULL
== h
->style
) {
585 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
586 print_otag(h
, TAG_TD
, 2, tag
);
588 print_otag(h
, TAG_TD
, 1, tag
);
590 print_text(h
, title
);
598 mdoc_sh_pre(MDOC_ARGS
)
602 if (MDOC_BLOCK
== n
->type
) {
603 PAIR_CLASS_INIT(&tag
, "section");
604 print_otag(h
, TAG_DIV
, 1, &tag
);
606 } else if (MDOC_BODY
== n
->type
)
611 for (n
= n
->child
; n
; n
= n
->next
) {
612 bufcat_id(h
, n
->string
);
617 PAIR_ID_INIT(&tag
, h
->buf
);
618 print_otag(h
, TAG_H1
, 1, &tag
);
625 mdoc_ss_pre(MDOC_ARGS
)
629 if (MDOC_BLOCK
== n
->type
) {
630 PAIR_CLASS_INIT(&tag
, "subsection");
631 print_otag(h
, TAG_DIV
, 1, &tag
);
633 } else if (MDOC_BODY
== n
->type
)
638 for (n
= n
->child
; n
; n
= n
->next
) {
639 bufcat_id(h
, n
->string
);
644 PAIR_ID_INIT(&tag
, h
->buf
);
645 print_otag(h
, TAG_H2
, 1, &tag
);
652 mdoc_fl_pre(MDOC_ARGS
)
656 PAIR_CLASS_INIT(&tag
, "flag");
657 print_otag(h
, TAG_B
, 1, &tag
);
659 /* `Cm' has no leading hyphen. */
661 if (MDOC_Cm
== n
->tok
)
664 print_text(h
, "\\-");
667 h
->flags
|= HTML_NOSPACE
;
668 else if (n
->next
&& n
->next
->line
== n
->line
)
669 h
->flags
|= HTML_NOSPACE
;
677 mdoc_nd_pre(MDOC_ARGS
)
681 if (MDOC_BODY
!= n
->type
)
684 /* XXX: this tag in theory can contain block elements. */
686 print_text(h
, "\\(em");
687 PAIR_CLASS_INIT(&tag
, "desc");
688 print_otag(h
, TAG_SPAN
, 1, &tag
);
694 mdoc_nm_pre(MDOC_ARGS
)
703 PAIR_CLASS_INIT(&tag
, "name");
704 print_otag(h
, TAG_B
, 1, &tag
);
705 if (NULL
== n
->child
&& m
->name
)
706 print_text(h
, m
->name
);
709 print_otag(h
, TAG_TD
, 0, NULL
);
710 if (NULL
== n
->child
&& m
->name
)
711 print_text(h
, m
->name
);
714 print_otag(h
, TAG_TD
, 0, NULL
);
721 PAIR_CLASS_INIT(&tag
, "synopsis");
722 print_otag(h
, TAG_TABLE
, 1, &tag
);
724 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
725 if (MDOC_TEXT
== n
->type
)
726 len
+= html_strlen(n
->string
);
728 if (0 == len
&& m
->name
)
729 len
= html_strlen(m
->name
);
731 SCALE_HS_INIT(&su
, (double)len
);
733 bufcat_su(h
, "width", &su
);
734 PAIR_STYLE_INIT(&tag
, h
);
735 print_otag(h
, TAG_COL
, 1, &tag
);
736 print_otag(h
, TAG_COL
, 0, NULL
);
737 print_otag(h
, TAG_TBODY
, 0, NULL
);
738 print_otag(h
, TAG_TR
, 0, NULL
);
745 mdoc_xr_pre(MDOC_ARGS
)
747 struct htmlpair tag
[2];
749 if (NULL
== n
->child
)
752 PAIR_CLASS_INIT(&tag
[0], "link-man");
755 buffmt_man(h
, n
->child
->string
,
757 n
->child
->next
->string
: NULL
);
758 PAIR_HREF_INIT(&tag
[1], h
->buf
);
759 print_otag(h
, TAG_A
, 2, tag
);
761 print_otag(h
, TAG_A
, 1, tag
);
764 print_text(h
, n
->string
);
766 if (NULL
== (n
= n
->next
))
769 h
->flags
|= HTML_NOSPACE
;
771 h
->flags
|= HTML_NOSPACE
;
772 print_text(h
, n
->string
);
773 h
->flags
|= HTML_NOSPACE
;
781 mdoc_ns_pre(MDOC_ARGS
)
784 if ( ! (MDOC_LINE
& n
->flags
))
785 h
->flags
|= HTML_NOSPACE
;
792 mdoc_ar_pre(MDOC_ARGS
)
796 PAIR_CLASS_INIT(&tag
, "arg");
797 print_otag(h
, TAG_I
, 1, &tag
);
804 mdoc_xx_pre(MDOC_ARGS
)
833 PAIR_CLASS_INIT(&tag
, "unix");
834 print_otag(h
, TAG_SPAN
, 1, &tag
);
839 h
->flags
|= HTML_KEEP
;
840 print_text(h
, n
->child
->string
);
849 mdoc_bx_pre(MDOC_ARGS
)
853 PAIR_CLASS_INIT(&tag
, "unix");
854 print_otag(h
, TAG_SPAN
, 1, &tag
);
856 if (NULL
!= (n
= n
->child
)) {
857 print_text(h
, n
->string
);
858 h
->flags
|= HTML_NOSPACE
;
859 print_text(h
, "BSD");
861 print_text(h
, "BSD");
865 if (NULL
!= (n
= n
->next
)) {
866 h
->flags
|= HTML_NOSPACE
;
868 h
->flags
|= HTML_NOSPACE
;
869 print_text(h
, n
->string
);
877 mdoc_it_pre(MDOC_ARGS
)
881 struct htmlpair tag
[2];
882 const struct mdoc_node
*bl
;
885 while (bl
&& MDOC_Bl
!= bl
->tok
)
890 type
= bl
->norm
->Bl
.type
;
893 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
897 if (MDOC_HEAD
== n
->type
) {
918 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
919 bufcat_su(h
, "margin-top", &su
);
920 PAIR_STYLE_INIT(&tag
[1], h
);
921 print_otag(h
, TAG_DT
, 2, tag
);
922 if (LIST_diag
!= type
)
924 PAIR_CLASS_INIT(&tag
[0], "diag");
925 print_otag(h
, TAG_B
, 1, tag
);
932 } else if (MDOC_BODY
== n
->type
) {
943 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
944 bufcat_su(h
, "margin-top", &su
);
945 PAIR_STYLE_INIT(&tag
[1], h
);
946 print_otag(h
, TAG_LI
, 2, tag
);
957 if (NULL
== bl
->norm
->Bl
.width
) {
958 print_otag(h
, TAG_DD
, 1, tag
);
961 a2width(bl
->norm
->Bl
.width
, &su
);
962 bufcat_su(h
, "margin-left", &su
);
963 PAIR_STYLE_INIT(&tag
[1], h
);
964 print_otag(h
, TAG_DD
, 2, tag
);
967 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
968 bufcat_su(h
, "margin-top", &su
);
969 PAIR_STYLE_INIT(&tag
[1], h
);
970 print_otag(h
, TAG_TD
, 2, tag
);
978 print_otag(h
, TAG_TR
, 1, tag
);
990 mdoc_bl_pre(MDOC_ARGS
)
993 struct htmlpair tag
[3];
999 if (MDOC_BODY
== n
->type
) {
1000 if (LIST_column
== n
->norm
->Bl
.type
)
1001 print_otag(h
, TAG_TBODY
, 0, NULL
);
1005 if (MDOC_HEAD
== n
->type
) {
1006 if (LIST_column
!= n
->norm
->Bl
.type
)
1010 * For each column, print out the <COL> tag with our
1011 * suggested width. The last column gets min-width, as
1012 * in terminal mode it auto-sizes to the width of the
1013 * screen and we want to preserve that behaviour.
1016 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1017 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1018 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1019 bufcat_su(h
, "width", &su
);
1021 bufcat_su(h
, "min-width", &su
);
1022 PAIR_STYLE_INIT(&tag
[0], h
);
1023 print_otag(h
, TAG_COL
, 1, tag
);
1029 SCALE_VS_INIT(&su
, 0);
1030 bufcat_su(h
, "margin-top", &su
);
1031 bufcat_su(h
, "margin-bottom", &su
);
1032 PAIR_STYLE_INIT(&tag
[0], h
);
1034 assert(lists
[n
->norm
->Bl
.type
]);
1035 strlcpy(buf
, "list ", BUFSIZ
);
1036 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1037 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1039 /* Set the block's left-hand margin. */
1041 if (n
->norm
->Bl
.offs
) {
1042 a2offs(n
->norm
->Bl
.offs
, &su
);
1043 bufcat_su(h
, "margin-left", &su
);
1046 switch (n
->norm
->Bl
.type
) {
1054 print_otag(h
, TAG_UL
, 2, tag
);
1057 print_otag(h
, TAG_OL
, 2, tag
);
1068 print_otag(h
, TAG_DL
, 2, tag
);
1071 print_otag(h
, TAG_TABLE
, 2, tag
);
1083 mdoc_ex_pre(MDOC_ARGS
)
1086 struct htmlpair tag
;
1090 print_otag(h
, TAG_BR
, 0, NULL
);
1092 PAIR_CLASS_INIT(&tag
, "utility");
1094 print_text(h
, "The");
1097 for (n
= n
->child
; n
; n
= n
->next
) {
1098 assert(MDOC_TEXT
== n
->type
);
1100 t
= print_otag(h
, TAG_B
, 1, &tag
);
1101 print_text(h
, n
->string
);
1104 if (nchild
> 2 && n
->next
) {
1105 h
->flags
|= HTML_NOSPACE
;
1109 if (n
->next
&& NULL
== n
->next
->next
)
1110 print_text(h
, "and");
1114 print_text(h
, "utilities exit");
1116 print_text(h
, "utility exits");
1118 print_text(h
, "0 on success, and >0 if an error occurs.");
1125 mdoc_em_pre(MDOC_ARGS
)
1127 struct htmlpair tag
;
1129 PAIR_CLASS_INIT(&tag
, "emph");
1130 print_otag(h
, TAG_SPAN
, 1, &tag
);
1137 mdoc_d1_pre(MDOC_ARGS
)
1139 struct htmlpair tag
[2];
1142 if (MDOC_BLOCK
!= n
->type
)
1145 SCALE_VS_INIT(&su
, 0);
1147 bufcat_su(h
, "margin-top", &su
);
1148 bufcat_su(h
, "margin-bottom", &su
);
1149 PAIR_STYLE_INIT(&tag
[0], h
);
1150 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1152 /* BLOCKQUOTE needs a block body. */
1154 PAIR_CLASS_INIT(&tag
[0], "display");
1155 print_otag(h
, TAG_DIV
, 1, tag
);
1157 if (MDOC_Dl
== n
->tok
) {
1158 PAIR_CLASS_INIT(&tag
[0], "lit");
1159 print_otag(h
, TAG_CODE
, 1, tag
);
1168 mdoc_sx_pre(MDOC_ARGS
)
1170 struct htmlpair tag
[2];
1174 for (n
= n
->child
; n
; n
= n
->next
) {
1175 bufcat_id(h
, n
->string
);
1180 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1181 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1183 print_otag(h
, TAG_I
, 1, tag
);
1184 print_otag(h
, TAG_A
, 2, tag
);
1191 mdoc_bd_pre(MDOC_ARGS
)
1193 struct htmlpair tag
[2];
1195 const struct mdoc_node
*nn
;
1198 if (MDOC_HEAD
== n
->type
)
1201 if (MDOC_BLOCK
== n
->type
) {
1202 comp
= n
->norm
->Bd
.comp
;
1203 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1204 if (MDOC_BLOCK
!= nn
->type
)
1206 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1212 print_otag(h
, TAG_P
, 0, NULL
);
1216 SCALE_HS_INIT(&su
, 0);
1217 if (n
->norm
->Bd
.offs
)
1218 a2offs(n
->norm
->Bd
.offs
, &su
);
1221 bufcat_su(h
, "margin-left", &su
);
1222 PAIR_STYLE_INIT(&tag
[0], h
);
1224 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1225 DISP_literal
!= n
->norm
->Bd
.type
) {
1226 PAIR_CLASS_INIT(&tag
[1], "display");
1227 print_otag(h
, TAG_DIV
, 2, tag
);
1231 PAIR_CLASS_INIT(&tag
[1], "lit display");
1232 print_otag(h
, TAG_PRE
, 2, tag
);
1234 /* This can be recursive: save & set our literal state. */
1236 sv
= h
->flags
& HTML_LITERAL
;
1237 h
->flags
|= HTML_LITERAL
;
1239 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1240 print_mdoc_node(m
, nn
, h
);
1242 * If the printed node flushes its own line, then we
1243 * needn't do it here as well. This is hacky, but the
1244 * notion of selective eoln whitespace is pretty dumb
1245 * anyway, so don't sweat it.
1267 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1270 print_text(h
, "\n");
1272 h
->flags
|= HTML_NOSPACE
;
1276 h
->flags
&= ~HTML_LITERAL
;
1284 mdoc_pa_pre(MDOC_ARGS
)
1286 struct htmlpair tag
;
1288 PAIR_CLASS_INIT(&tag
, "file");
1289 print_otag(h
, TAG_I
, 1, &tag
);
1296 mdoc_ad_pre(MDOC_ARGS
)
1298 struct htmlpair tag
;
1300 PAIR_CLASS_INIT(&tag
, "addr");
1301 print_otag(h
, TAG_I
, 1, &tag
);
1308 mdoc_an_pre(MDOC_ARGS
)
1310 struct htmlpair tag
;
1312 /* TODO: -split and -nosplit (see termp_an_pre()). */
1314 PAIR_CLASS_INIT(&tag
, "author");
1315 print_otag(h
, TAG_SPAN
, 1, &tag
);
1322 mdoc_cd_pre(MDOC_ARGS
)
1324 struct htmlpair tag
;
1327 PAIR_CLASS_INIT(&tag
, "config");
1328 print_otag(h
, TAG_B
, 1, &tag
);
1335 mdoc_dv_pre(MDOC_ARGS
)
1337 struct htmlpair tag
;
1339 PAIR_CLASS_INIT(&tag
, "define");
1340 print_otag(h
, TAG_SPAN
, 1, &tag
);
1347 mdoc_ev_pre(MDOC_ARGS
)
1349 struct htmlpair tag
;
1351 PAIR_CLASS_INIT(&tag
, "env");
1352 print_otag(h
, TAG_SPAN
, 1, &tag
);
1359 mdoc_er_pre(MDOC_ARGS
)
1361 struct htmlpair tag
;
1363 PAIR_CLASS_INIT(&tag
, "errno");
1364 print_otag(h
, TAG_SPAN
, 1, &tag
);
1371 mdoc_fa_pre(MDOC_ARGS
)
1373 const struct mdoc_node
*nn
;
1374 struct htmlpair tag
;
1377 PAIR_CLASS_INIT(&tag
, "farg");
1378 if (n
->parent
->tok
!= MDOC_Fo
) {
1379 print_otag(h
, TAG_I
, 1, &tag
);
1383 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1384 t
= print_otag(h
, TAG_I
, 1, &tag
);
1385 print_text(h
, nn
->string
);
1388 h
->flags
|= HTML_NOSPACE
;
1393 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1394 h
->flags
|= HTML_NOSPACE
;
1404 mdoc_fd_pre(MDOC_ARGS
)
1406 struct htmlpair tag
[2];
1414 if (NULL
== (n
= n
->child
))
1417 assert(MDOC_TEXT
== n
->type
);
1419 if (strcmp(n
->string
, "#include")) {
1420 PAIR_CLASS_INIT(&tag
[0], "macro");
1421 print_otag(h
, TAG_B
, 1, tag
);
1425 PAIR_CLASS_INIT(&tag
[0], "includes");
1426 print_otag(h
, TAG_B
, 1, tag
);
1427 print_text(h
, n
->string
);
1429 if (NULL
!= (n
= n
->next
)) {
1430 assert(MDOC_TEXT
== n
->type
);
1431 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1432 n
->string
+ 1 : n
->string
, BUFSIZ
);
1435 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1438 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1441 if (h
->base_includes
) {
1442 buffmt_includes(h
, buf
);
1443 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1447 t
= print_otag(h
, TAG_A
, i
, tag
);
1448 print_text(h
, n
->string
);
1454 for ( ; n
; n
= n
->next
) {
1455 assert(MDOC_TEXT
== n
->type
);
1456 print_text(h
, n
->string
);
1465 mdoc_vt_pre(MDOC_ARGS
)
1467 struct htmlpair tag
;
1469 if (MDOC_BLOCK
== n
->type
) {
1472 } else if (MDOC_ELEM
== n
->type
) {
1474 } else if (MDOC_HEAD
== n
->type
)
1477 PAIR_CLASS_INIT(&tag
, "type");
1478 print_otag(h
, TAG_SPAN
, 1, &tag
);
1485 mdoc_ft_pre(MDOC_ARGS
)
1487 struct htmlpair tag
;
1490 PAIR_CLASS_INIT(&tag
, "ftype");
1491 print_otag(h
, TAG_I
, 1, &tag
);
1498 mdoc_fn_pre(MDOC_ARGS
)
1501 struct htmlpair tag
[2];
1503 const char *sp
, *ep
;
1506 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1509 /* Split apart into type and name. */
1510 assert(n
->child
->string
);
1511 sp
= n
->child
->string
;
1513 ep
= strchr(sp
, ' ');
1515 PAIR_CLASS_INIT(&tag
[0], "ftype");
1516 t
= print_otag(h
, TAG_I
, 1, tag
);
1519 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1520 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1522 print_text(h
, nbuf
);
1524 ep
= strchr(sp
, ' ');
1529 PAIR_CLASS_INIT(&tag
[0], "fname");
1532 * FIXME: only refer to IDs that we know exist.
1536 if (MDOC_SYNPRETTY
& n
->flags
) {
1538 html_idcat(nbuf
, sp
, BUFSIZ
);
1539 PAIR_ID_INIT(&tag
[1], nbuf
);
1541 strlcpy(nbuf
, "#", BUFSIZ
);
1542 html_idcat(nbuf
, sp
, BUFSIZ
);
1543 PAIR_HREF_INIT(&tag
[1], nbuf
);
1547 t
= print_otag(h
, TAG_B
, 1, tag
);
1550 strlcpy(nbuf
, sp
, BUFSIZ
);
1551 print_text(h
, nbuf
);
1556 h
->flags
|= HTML_NOSPACE
;
1558 h
->flags
|= HTML_NOSPACE
;
1560 PAIR_CLASS_INIT(&tag
[0], "farg");
1562 bufcat_style(h
, "white-space", "nowrap");
1563 PAIR_STYLE_INIT(&tag
[1], h
);
1565 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1567 if (MDOC_SYNPRETTY
& n
->flags
)
1569 t
= print_otag(h
, TAG_I
, i
, tag
);
1570 print_text(h
, n
->string
);
1573 h
->flags
|= HTML_NOSPACE
;
1578 h
->flags
|= HTML_NOSPACE
;
1582 h
->flags
|= HTML_NOSPACE
;
1592 mdoc_sm_pre(MDOC_ARGS
)
1595 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1596 if (0 == strcmp("on", n
->child
->string
)) {
1598 * FIXME: no p->col to check. Thus, if we have
1605 * the "3" is preceded by a space.
1607 h
->flags
&= ~HTML_NOSPACE
;
1608 h
->flags
&= ~HTML_NONOSPACE
;
1610 h
->flags
|= HTML_NONOSPACE
;
1617 mdoc_pp_pre(MDOC_ARGS
)
1620 print_otag(h
, TAG_P
, 0, NULL
);
1627 mdoc_sp_pre(MDOC_ARGS
)
1630 struct htmlpair tag
;
1632 SCALE_VS_INIT(&su
, 1);
1634 if (MDOC_sp
== n
->tok
) {
1635 if (NULL
!= (n
= n
->child
))
1636 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1637 SCALE_VS_INIT(&su
, atoi(n
->string
));
1642 bufcat_su(h
, "height", &su
);
1643 PAIR_STYLE_INIT(&tag
, h
);
1644 print_otag(h
, TAG_DIV
, 1, &tag
);
1646 /* So the div isn't empty: */
1647 print_text(h
, "\\~");
1655 mdoc_lk_pre(MDOC_ARGS
)
1657 struct htmlpair tag
[2];
1659 if (NULL
== (n
= n
->child
))
1662 assert(MDOC_TEXT
== n
->type
);
1664 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1665 PAIR_HREF_INIT(&tag
[1], n
->string
);
1667 print_otag(h
, TAG_A
, 2, tag
);
1669 if (NULL
== n
->next
)
1670 print_text(h
, n
->string
);
1672 for (n
= n
->next
; n
; n
= n
->next
)
1673 print_text(h
, n
->string
);
1681 mdoc_mt_pre(MDOC_ARGS
)
1683 struct htmlpair tag
[2];
1686 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1688 for (n
= n
->child
; n
; n
= n
->next
) {
1689 assert(MDOC_TEXT
== n
->type
);
1692 bufcat(h
, "mailto:");
1693 bufcat(h
, n
->string
);
1695 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1696 t
= print_otag(h
, TAG_A
, 2, tag
);
1697 print_text(h
, n
->string
);
1707 mdoc_fo_pre(MDOC_ARGS
)
1709 struct htmlpair tag
;
1712 if (MDOC_BODY
== n
->type
) {
1713 h
->flags
|= HTML_NOSPACE
;
1715 h
->flags
|= HTML_NOSPACE
;
1717 } else if (MDOC_BLOCK
== n
->type
) {
1722 /* XXX: we drop non-initial arguments as per groff. */
1725 assert(n
->child
->string
);
1727 PAIR_CLASS_INIT(&tag
, "fname");
1728 t
= print_otag(h
, TAG_B
, 1, &tag
);
1729 print_text(h
, n
->child
->string
);
1737 mdoc_fo_post(MDOC_ARGS
)
1740 if (MDOC_BODY
!= n
->type
)
1742 h
->flags
|= HTML_NOSPACE
;
1744 h
->flags
|= HTML_NOSPACE
;
1751 mdoc_in_pre(MDOC_ARGS
)
1754 struct htmlpair tag
[2];
1759 PAIR_CLASS_INIT(&tag
[0], "includes");
1760 print_otag(h
, TAG_B
, 1, tag
);
1763 * The first argument of the `In' gets special treatment as
1764 * being a linked value. Subsequent values are printed
1765 * afterward. groff does similarly. This also handles the case
1769 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1770 print_text(h
, "#include");
1773 h
->flags
|= HTML_NOSPACE
;
1775 if (NULL
!= (n
= n
->child
)) {
1776 assert(MDOC_TEXT
== n
->type
);
1778 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1781 if (h
->base_includes
) {
1782 buffmt_includes(h
, n
->string
);
1783 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1787 t
= print_otag(h
, TAG_A
, i
, tag
);
1788 print_text(h
, n
->string
);
1794 h
->flags
|= HTML_NOSPACE
;
1797 for ( ; n
; n
= n
->next
) {
1798 assert(MDOC_TEXT
== n
->type
);
1799 print_text(h
, n
->string
);
1808 mdoc_ic_pre(MDOC_ARGS
)
1810 struct htmlpair tag
;
1812 PAIR_CLASS_INIT(&tag
, "cmd");
1813 print_otag(h
, TAG_B
, 1, &tag
);
1820 mdoc_rv_pre(MDOC_ARGS
)
1822 struct htmlpair tag
;
1827 print_otag(h
, TAG_BR
, 0, NULL
);
1829 PAIR_CLASS_INIT(&tag
, "fname");
1831 print_text(h
, "The");
1834 for (n
= n
->child
; n
; n
= n
->next
) {
1835 assert(MDOC_TEXT
== n
->type
);
1837 t
= print_otag(h
, TAG_B
, 1, &tag
);
1838 print_text(h
, n
->string
);
1841 h
->flags
|= HTML_NOSPACE
;
1842 print_text(h
, "()");
1844 if (nchild
> 2 && n
->next
) {
1845 h
->flags
|= HTML_NOSPACE
;
1849 if (n
->next
&& NULL
== n
->next
->next
)
1850 print_text(h
, "and");
1854 print_text(h
, "functions return");
1856 print_text(h
, "function returns");
1858 print_text(h
, "the value 0 if successful; otherwise the value "
1859 "-1 is returned and the global variable");
1861 PAIR_CLASS_INIT(&tag
, "var");
1862 t
= print_otag(h
, TAG_B
, 1, &tag
);
1863 print_text(h
, "errno");
1865 print_text(h
, "is set to indicate the error.");
1872 mdoc_va_pre(MDOC_ARGS
)
1874 struct htmlpair tag
;
1876 PAIR_CLASS_INIT(&tag
, "var");
1877 print_otag(h
, TAG_B
, 1, &tag
);
1884 mdoc_ap_pre(MDOC_ARGS
)
1887 h
->flags
|= HTML_NOSPACE
;
1888 print_text(h
, "\\(aq");
1889 h
->flags
|= HTML_NOSPACE
;
1896 mdoc_bf_pre(MDOC_ARGS
)
1898 struct htmlpair tag
[2];
1901 if (MDOC_HEAD
== n
->type
)
1903 else if (MDOC_BODY
!= n
->type
)
1906 if (FONT_Em
== n
->norm
->Bf
.font
)
1907 PAIR_CLASS_INIT(&tag
[0], "emph");
1908 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1909 PAIR_CLASS_INIT(&tag
[0], "symb");
1910 else if (FONT_Li
== n
->norm
->Bf
.font
)
1911 PAIR_CLASS_INIT(&tag
[0], "lit");
1913 PAIR_CLASS_INIT(&tag
[0], "none");
1916 * We want this to be inline-formatted, but needs to be div to
1917 * accept block children.
1920 bufcat_style(h
, "display", "inline");
1921 SCALE_HS_INIT(&su
, 1);
1922 /* Needs a left-margin for spacing. */
1923 bufcat_su(h
, "margin-left", &su
);
1924 PAIR_STYLE_INIT(&tag
[1], h
);
1925 print_otag(h
, TAG_DIV
, 2, tag
);
1932 mdoc_ms_pre(MDOC_ARGS
)
1934 struct htmlpair tag
;
1936 PAIR_CLASS_INIT(&tag
, "symb");
1937 print_otag(h
, TAG_SPAN
, 1, &tag
);
1944 mdoc_igndelim_pre(MDOC_ARGS
)
1947 h
->flags
|= HTML_IGNDELIM
;
1954 mdoc_pf_post(MDOC_ARGS
)
1957 h
->flags
|= HTML_NOSPACE
;
1963 mdoc_rs_pre(MDOC_ARGS
)
1965 struct htmlpair tag
;
1967 if (MDOC_BLOCK
!= n
->type
)
1970 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1971 print_otag(h
, TAG_P
, 0, NULL
);
1973 PAIR_CLASS_INIT(&tag
, "ref");
1974 print_otag(h
, TAG_SPAN
, 1, &tag
);
1982 mdoc_li_pre(MDOC_ARGS
)
1984 struct htmlpair tag
;
1986 PAIR_CLASS_INIT(&tag
, "lit");
1987 print_otag(h
, TAG_SPAN
, 1, &tag
);
1994 mdoc_sy_pre(MDOC_ARGS
)
1996 struct htmlpair tag
;
1998 PAIR_CLASS_INIT(&tag
, "symb");
1999 print_otag(h
, TAG_SPAN
, 1, &tag
);
2006 mdoc_bt_pre(MDOC_ARGS
)
2009 print_text(h
, "is currently in beta test.");
2016 mdoc_ud_pre(MDOC_ARGS
)
2019 print_text(h
, "currently under development.");
2026 mdoc_lb_pre(MDOC_ARGS
)
2028 struct htmlpair tag
;
2030 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2031 print_otag(h
, TAG_BR
, 0, NULL
);
2033 PAIR_CLASS_INIT(&tag
, "lib");
2034 print_otag(h
, TAG_SPAN
, 1, &tag
);
2041 mdoc__x_pre(MDOC_ARGS
)
2043 struct htmlpair tag
[2];
2050 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2051 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2052 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2053 print_text(h
, "and");
2056 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2060 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2063 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2066 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2070 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2074 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2077 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2080 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2083 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2086 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2089 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2092 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2095 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2102 if (MDOC__U
!= n
->tok
) {
2103 print_otag(h
, t
, 1, tag
);
2107 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2108 print_otag(h
, TAG_A
, 2, tag
);
2116 mdoc__x_post(MDOC_ARGS
)
2119 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2120 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2121 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2126 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2129 h
->flags
|= HTML_NOSPACE
;
2130 print_text(h
, n
->next
? "," : ".");
2136 mdoc_bk_pre(MDOC_ARGS
)
2145 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2146 h
->flags
|= HTML_PREKEEP
;
2159 mdoc_bk_post(MDOC_ARGS
)
2162 if (MDOC_BODY
== n
->type
)
2163 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2169 mdoc_quote_pre(MDOC_ARGS
)
2171 struct htmlpair tag
;
2173 if (MDOC_BODY
!= n
->type
)
2180 print_text(h
, "\\(la");
2185 print_text(h
, "\\(lC");
2190 print_text(h
, "\\(lB");
2195 print_text(h
, "\\(lB");
2196 h
->flags
|= HTML_NOSPACE
;
2197 PAIR_CLASS_INIT(&tag
, "opt");
2198 print_otag(h
, TAG_SPAN
, 1, &tag
);
2207 print_text(h
, "\\(lq");
2219 print_text(h
, "\\(oq");
2226 h
->flags
|= HTML_NOSPACE
;
2233 mdoc_quote_post(MDOC_ARGS
)
2236 if (MDOC_BODY
!= n
->type
)
2239 h
->flags
|= HTML_NOSPACE
;
2245 print_text(h
, "\\(ra");
2250 print_text(h
, "\\(rC");
2259 print_text(h
, "\\(rB");
2268 print_text(h
, "\\(rq");
2280 print_text(h
, "\\(aq");