]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.173 2011/07/21 11:34:53 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
)
417 child
= mdoc_root_pre(m
, n
, h
);
420 /* No tables in this mode... */
421 assert(NULL
== h
->tblt
);
424 * Make sure that if we're in a literal mode already
425 * (i.e., within a <PRE>) don't print the newline.
427 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
428 if ( ! (HTML_LITERAL
& h
->flags
))
429 print_otag(h
, TAG_BR
, 0, NULL
);
430 if (MDOC_DELIMC
& n
->flags
)
431 h
->flags
|= HTML_NOSPACE
;
432 print_text(h
, n
->string
);
433 if (MDOC_DELIMO
& n
->flags
)
434 h
->flags
|= HTML_NOSPACE
;
437 PAIR_CLASS_INIT(&tag
, "eqn");
438 /*print_otag(h, TAG_SPAN, 1, &tag);
439 print_text(h, n->eqn->data);*/
443 * This will take care of initialising all of the table
444 * state data for the first table, then tearing it down
447 print_tbl(h
, n
->span
);
451 * Close out the current table, if it's open, and unset
452 * the "meta" table state. This will be reopened on the
453 * next table element.
460 assert(NULL
== h
->tblt
);
461 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
462 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
466 if (HTML_KEEP
& h
->flags
) {
467 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
468 h
->flags
&= ~HTML_KEEP
;
469 h
->flags
|= HTML_PREKEEP
;
470 } else if (NULL
== n
->prev
) {
471 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
472 h
->flags
&= ~HTML_KEEP
;
473 h
->flags
|= HTML_PREKEEP
;
478 if (child
&& n
->child
)
479 print_mdoc_nodelist(m
, n
->child
, h
);
485 mdoc_root_post(m
, n
, h
);
490 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
491 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
498 mdoc_root_post(MDOC_ARGS
)
500 struct htmlpair tag
[3];
503 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
504 PAIR_CLASS_INIT(&tag
[1], "foot");
505 if (NULL
== h
->style
) {
506 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
507 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
508 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
509 print_otag(h
, TAG_COL
, 1, tag
);
510 print_otag(h
, TAG_COL
, 1, tag
);
512 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
514 t
= print_otag(h
, TAG_TBODY
, 0, NULL
);
516 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
518 PAIR_CLASS_INIT(&tag
[0], "foot-date");
519 print_otag(h
, TAG_TD
, 1, tag
);
521 print_text(h
, m
->date
);
524 PAIR_CLASS_INIT(&tag
[0], "foot-os");
525 if (NULL
== h
->style
) {
526 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
527 print_otag(h
, TAG_TD
, 2, tag
);
529 print_otag(h
, TAG_TD
, 1, tag
);
531 print_text(h
, m
->os
);
538 mdoc_root_pre(MDOC_ARGS
)
540 struct htmlpair tag
[3];
542 char b
[BUFSIZ
], title
[BUFSIZ
];
544 strlcpy(b
, m
->vol
, BUFSIZ
);
547 strlcat(b
, " (", BUFSIZ
);
548 strlcat(b
, m
->arch
, BUFSIZ
);
549 strlcat(b
, ")", BUFSIZ
);
552 snprintf(title
, BUFSIZ
- 1, "%s(%s)", m
->title
, m
->msec
);
554 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
555 PAIR_CLASS_INIT(&tag
[1], "head");
556 if (NULL
== h
->style
) {
557 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
558 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
559 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
560 print_otag(h
, TAG_COL
, 1, tag
);
561 print_otag(h
, TAG_COL
, 1, tag
);
562 print_otag(h
, TAG_COL
, 1, tag
);
564 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
566 print_otag(h
, TAG_TBODY
, 0, NULL
);
568 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
570 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
571 print_otag(h
, TAG_TD
, 1, tag
);
573 print_text(h
, title
);
576 PAIR_CLASS_INIT(&tag
[0], "head-vol");
577 if (NULL
== h
->style
) {
578 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
579 print_otag(h
, TAG_TD
, 2, tag
);
581 print_otag(h
, TAG_TD
, 1, tag
);
586 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
587 if (NULL
== h
->style
) {
588 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
589 print_otag(h
, TAG_TD
, 2, tag
);
591 print_otag(h
, TAG_TD
, 1, tag
);
593 print_text(h
, title
);
601 mdoc_sh_pre(MDOC_ARGS
)
605 if (MDOC_BLOCK
== n
->type
) {
606 PAIR_CLASS_INIT(&tag
, "section");
607 print_otag(h
, TAG_DIV
, 1, &tag
);
609 } else if (MDOC_BODY
== n
->type
)
614 for (n
= n
->child
; n
; n
= n
->next
) {
615 bufcat_id(h
, n
->string
);
620 PAIR_ID_INIT(&tag
, h
->buf
);
621 print_otag(h
, TAG_H1
, 1, &tag
);
628 mdoc_ss_pre(MDOC_ARGS
)
632 if (MDOC_BLOCK
== n
->type
) {
633 PAIR_CLASS_INIT(&tag
, "subsection");
634 print_otag(h
, TAG_DIV
, 1, &tag
);
636 } else if (MDOC_BODY
== n
->type
)
641 for (n
= n
->child
; n
; n
= n
->next
) {
642 bufcat_id(h
, n
->string
);
647 PAIR_ID_INIT(&tag
, h
->buf
);
648 print_otag(h
, TAG_H2
, 1, &tag
);
655 mdoc_fl_pre(MDOC_ARGS
)
659 PAIR_CLASS_INIT(&tag
, "flag");
660 print_otag(h
, TAG_B
, 1, &tag
);
662 /* `Cm' has no leading hyphen. */
664 if (MDOC_Cm
== n
->tok
)
667 print_text(h
, "\\-");
670 h
->flags
|= HTML_NOSPACE
;
671 else if (n
->next
&& n
->next
->line
== n
->line
)
672 h
->flags
|= HTML_NOSPACE
;
680 mdoc_nd_pre(MDOC_ARGS
)
684 if (MDOC_BODY
!= n
->type
)
687 /* XXX: this tag in theory can contain block elements. */
689 print_text(h
, "\\(em");
690 PAIR_CLASS_INIT(&tag
, "desc");
691 print_otag(h
, TAG_SPAN
, 1, &tag
);
697 mdoc_nm_pre(MDOC_ARGS
)
706 PAIR_CLASS_INIT(&tag
, "name");
707 print_otag(h
, TAG_B
, 1, &tag
);
708 if (NULL
== n
->child
&& m
->name
)
709 print_text(h
, m
->name
);
712 print_otag(h
, TAG_TD
, 0, NULL
);
713 if (NULL
== n
->child
&& m
->name
)
714 print_text(h
, m
->name
);
717 print_otag(h
, TAG_TD
, 0, NULL
);
724 PAIR_CLASS_INIT(&tag
, "synopsis");
725 print_otag(h
, TAG_TABLE
, 1, &tag
);
727 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
728 if (MDOC_TEXT
== n
->type
)
729 len
+= html_strlen(n
->string
);
731 if (0 == len
&& m
->name
)
732 len
= html_strlen(m
->name
);
734 SCALE_HS_INIT(&su
, (double)len
);
736 bufcat_su(h
, "width", &su
);
737 PAIR_STYLE_INIT(&tag
, h
);
738 print_otag(h
, TAG_COL
, 1, &tag
);
739 print_otag(h
, TAG_COL
, 0, NULL
);
740 print_otag(h
, TAG_TBODY
, 0, NULL
);
741 print_otag(h
, TAG_TR
, 0, NULL
);
748 mdoc_xr_pre(MDOC_ARGS
)
750 struct htmlpair tag
[2];
752 if (NULL
== n
->child
)
755 PAIR_CLASS_INIT(&tag
[0], "link-man");
758 buffmt_man(h
, n
->child
->string
,
760 n
->child
->next
->string
: NULL
);
761 PAIR_HREF_INIT(&tag
[1], h
->buf
);
762 print_otag(h
, TAG_A
, 2, tag
);
764 print_otag(h
, TAG_A
, 1, tag
);
767 print_text(h
, n
->string
);
769 if (NULL
== (n
= n
->next
))
772 h
->flags
|= HTML_NOSPACE
;
774 h
->flags
|= HTML_NOSPACE
;
775 print_text(h
, n
->string
);
776 h
->flags
|= HTML_NOSPACE
;
784 mdoc_ns_pre(MDOC_ARGS
)
787 if ( ! (MDOC_LINE
& n
->flags
))
788 h
->flags
|= HTML_NOSPACE
;
795 mdoc_ar_pre(MDOC_ARGS
)
799 PAIR_CLASS_INIT(&tag
, "arg");
800 print_otag(h
, TAG_I
, 1, &tag
);
807 mdoc_xx_pre(MDOC_ARGS
)
836 PAIR_CLASS_INIT(&tag
, "unix");
837 print_otag(h
, TAG_SPAN
, 1, &tag
);
842 h
->flags
|= HTML_KEEP
;
843 print_text(h
, n
->child
->string
);
852 mdoc_bx_pre(MDOC_ARGS
)
856 PAIR_CLASS_INIT(&tag
, "unix");
857 print_otag(h
, TAG_SPAN
, 1, &tag
);
859 if (NULL
!= (n
= n
->child
)) {
860 print_text(h
, n
->string
);
861 h
->flags
|= HTML_NOSPACE
;
862 print_text(h
, "BSD");
864 print_text(h
, "BSD");
868 if (NULL
!= (n
= n
->next
)) {
869 h
->flags
|= HTML_NOSPACE
;
871 h
->flags
|= HTML_NOSPACE
;
872 print_text(h
, n
->string
);
880 mdoc_it_pre(MDOC_ARGS
)
884 struct htmlpair tag
[2];
885 const struct mdoc_node
*bl
;
888 while (bl
&& MDOC_Bl
!= bl
->tok
)
893 type
= bl
->norm
->Bl
.type
;
896 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
900 if (MDOC_HEAD
== n
->type
) {
921 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
922 bufcat_su(h
, "margin-top", &su
);
923 PAIR_STYLE_INIT(&tag
[1], h
);
924 print_otag(h
, TAG_DT
, 2, tag
);
925 if (LIST_diag
!= type
)
927 PAIR_CLASS_INIT(&tag
[0], "diag");
928 print_otag(h
, TAG_B
, 1, tag
);
935 } else if (MDOC_BODY
== n
->type
) {
946 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
947 bufcat_su(h
, "margin-top", &su
);
948 PAIR_STYLE_INIT(&tag
[1], h
);
949 print_otag(h
, TAG_LI
, 2, tag
);
960 if (NULL
== bl
->norm
->Bl
.width
) {
961 print_otag(h
, TAG_DD
, 1, tag
);
964 a2width(bl
->norm
->Bl
.width
, &su
);
965 bufcat_su(h
, "margin-left", &su
);
966 PAIR_STYLE_INIT(&tag
[1], h
);
967 print_otag(h
, TAG_DD
, 2, tag
);
970 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
971 bufcat_su(h
, "margin-top", &su
);
972 PAIR_STYLE_INIT(&tag
[1], h
);
973 print_otag(h
, TAG_TD
, 2, tag
);
981 print_otag(h
, TAG_TR
, 1, tag
);
993 mdoc_bl_pre(MDOC_ARGS
)
996 struct htmlpair tag
[3];
1002 if (MDOC_BODY
== n
->type
) {
1003 if (LIST_column
== n
->norm
->Bl
.type
)
1004 print_otag(h
, TAG_TBODY
, 0, NULL
);
1008 if (MDOC_HEAD
== n
->type
) {
1009 if (LIST_column
!= n
->norm
->Bl
.type
)
1013 * For each column, print out the <COL> tag with our
1014 * suggested width. The last column gets min-width, as
1015 * in terminal mode it auto-sizes to the width of the
1016 * screen and we want to preserve that behaviour.
1019 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1020 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1021 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1022 bufcat_su(h
, "width", &su
);
1024 bufcat_su(h
, "min-width", &su
);
1025 PAIR_STYLE_INIT(&tag
[0], h
);
1026 print_otag(h
, TAG_COL
, 1, tag
);
1032 SCALE_VS_INIT(&su
, 0);
1033 bufcat_su(h
, "margin-top", &su
);
1034 bufcat_su(h
, "margin-bottom", &su
);
1035 PAIR_STYLE_INIT(&tag
[0], h
);
1037 assert(lists
[n
->norm
->Bl
.type
]);
1038 strlcpy(buf
, "list ", BUFSIZ
);
1039 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1040 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1042 /* Set the block's left-hand margin. */
1044 if (n
->norm
->Bl
.offs
) {
1045 a2offs(n
->norm
->Bl
.offs
, &su
);
1046 bufcat_su(h
, "margin-left", &su
);
1049 switch (n
->norm
->Bl
.type
) {
1057 print_otag(h
, TAG_UL
, 2, tag
);
1060 print_otag(h
, TAG_OL
, 2, tag
);
1071 print_otag(h
, TAG_DL
, 2, tag
);
1074 print_otag(h
, TAG_TABLE
, 2, tag
);
1086 mdoc_ex_pre(MDOC_ARGS
)
1089 struct htmlpair tag
;
1093 print_otag(h
, TAG_BR
, 0, NULL
);
1095 PAIR_CLASS_INIT(&tag
, "utility");
1097 print_text(h
, "The");
1100 for (n
= n
->child
; n
; n
= n
->next
) {
1101 assert(MDOC_TEXT
== n
->type
);
1103 t
= print_otag(h
, TAG_B
, 1, &tag
);
1104 print_text(h
, n
->string
);
1107 if (nchild
> 2 && n
->next
) {
1108 h
->flags
|= HTML_NOSPACE
;
1112 if (n
->next
&& NULL
== n
->next
->next
)
1113 print_text(h
, "and");
1117 print_text(h
, "utilities exit");
1119 print_text(h
, "utility exits");
1121 print_text(h
, "0 on success, and >0 if an error occurs.");
1128 mdoc_em_pre(MDOC_ARGS
)
1130 struct htmlpair tag
;
1132 PAIR_CLASS_INIT(&tag
, "emph");
1133 print_otag(h
, TAG_SPAN
, 1, &tag
);
1140 mdoc_d1_pre(MDOC_ARGS
)
1142 struct htmlpair tag
[2];
1145 if (MDOC_BLOCK
!= n
->type
)
1148 SCALE_VS_INIT(&su
, 0);
1150 bufcat_su(h
, "margin-top", &su
);
1151 bufcat_su(h
, "margin-bottom", &su
);
1152 PAIR_STYLE_INIT(&tag
[0], h
);
1153 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1155 /* BLOCKQUOTE needs a block body. */
1157 PAIR_CLASS_INIT(&tag
[0], "display");
1158 print_otag(h
, TAG_DIV
, 1, tag
);
1160 if (MDOC_Dl
== n
->tok
) {
1161 PAIR_CLASS_INIT(&tag
[0], "lit");
1162 print_otag(h
, TAG_CODE
, 1, tag
);
1171 mdoc_sx_pre(MDOC_ARGS
)
1173 struct htmlpair tag
[2];
1177 for (n
= n
->child
; n
; n
= n
->next
) {
1178 bufcat_id(h
, n
->string
);
1183 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1184 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1186 print_otag(h
, TAG_I
, 1, tag
);
1187 print_otag(h
, TAG_A
, 2, tag
);
1194 mdoc_bd_pre(MDOC_ARGS
)
1196 struct htmlpair tag
[2];
1198 const struct mdoc_node
*nn
;
1201 if (MDOC_HEAD
== n
->type
)
1204 if (MDOC_BLOCK
== n
->type
) {
1205 comp
= n
->norm
->Bd
.comp
;
1206 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1207 if (MDOC_BLOCK
!= nn
->type
)
1209 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1215 print_otag(h
, TAG_P
, 0, NULL
);
1219 SCALE_HS_INIT(&su
, 0);
1220 if (n
->norm
->Bd
.offs
)
1221 a2offs(n
->norm
->Bd
.offs
, &su
);
1224 bufcat_su(h
, "margin-left", &su
);
1225 PAIR_STYLE_INIT(&tag
[0], h
);
1227 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1228 DISP_literal
!= n
->norm
->Bd
.type
) {
1229 PAIR_CLASS_INIT(&tag
[1], "display");
1230 print_otag(h
, TAG_DIV
, 2, tag
);
1234 PAIR_CLASS_INIT(&tag
[1], "lit display");
1235 print_otag(h
, TAG_PRE
, 2, tag
);
1237 /* This can be recursive: save & set our literal state. */
1239 sv
= h
->flags
& HTML_LITERAL
;
1240 h
->flags
|= HTML_LITERAL
;
1242 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1243 print_mdoc_node(m
, nn
, h
);
1245 * If the printed node flushes its own line, then we
1246 * needn't do it here as well. This is hacky, but the
1247 * notion of selective eoln whitespace is pretty dumb
1248 * anyway, so don't sweat it.
1270 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1273 print_text(h
, "\n");
1275 h
->flags
|= HTML_NOSPACE
;
1279 h
->flags
&= ~HTML_LITERAL
;
1287 mdoc_pa_pre(MDOC_ARGS
)
1289 struct htmlpair tag
;
1291 PAIR_CLASS_INIT(&tag
, "file");
1292 print_otag(h
, TAG_I
, 1, &tag
);
1299 mdoc_ad_pre(MDOC_ARGS
)
1301 struct htmlpair tag
;
1303 PAIR_CLASS_INIT(&tag
, "addr");
1304 print_otag(h
, TAG_I
, 1, &tag
);
1311 mdoc_an_pre(MDOC_ARGS
)
1313 struct htmlpair tag
;
1315 /* TODO: -split and -nosplit (see termp_an_pre()). */
1317 PAIR_CLASS_INIT(&tag
, "author");
1318 print_otag(h
, TAG_SPAN
, 1, &tag
);
1325 mdoc_cd_pre(MDOC_ARGS
)
1327 struct htmlpair tag
;
1330 PAIR_CLASS_INIT(&tag
, "config");
1331 print_otag(h
, TAG_B
, 1, &tag
);
1338 mdoc_dv_pre(MDOC_ARGS
)
1340 struct htmlpair tag
;
1342 PAIR_CLASS_INIT(&tag
, "define");
1343 print_otag(h
, TAG_SPAN
, 1, &tag
);
1350 mdoc_ev_pre(MDOC_ARGS
)
1352 struct htmlpair tag
;
1354 PAIR_CLASS_INIT(&tag
, "env");
1355 print_otag(h
, TAG_SPAN
, 1, &tag
);
1362 mdoc_er_pre(MDOC_ARGS
)
1364 struct htmlpair tag
;
1366 PAIR_CLASS_INIT(&tag
, "errno");
1367 print_otag(h
, TAG_SPAN
, 1, &tag
);
1374 mdoc_fa_pre(MDOC_ARGS
)
1376 const struct mdoc_node
*nn
;
1377 struct htmlpair tag
;
1380 PAIR_CLASS_INIT(&tag
, "farg");
1381 if (n
->parent
->tok
!= MDOC_Fo
) {
1382 print_otag(h
, TAG_I
, 1, &tag
);
1386 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1387 t
= print_otag(h
, TAG_I
, 1, &tag
);
1388 print_text(h
, nn
->string
);
1391 h
->flags
|= HTML_NOSPACE
;
1396 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1397 h
->flags
|= HTML_NOSPACE
;
1407 mdoc_fd_pre(MDOC_ARGS
)
1409 struct htmlpair tag
[2];
1417 if (NULL
== (n
= n
->child
))
1420 assert(MDOC_TEXT
== n
->type
);
1422 if (strcmp(n
->string
, "#include")) {
1423 PAIR_CLASS_INIT(&tag
[0], "macro");
1424 print_otag(h
, TAG_B
, 1, tag
);
1428 PAIR_CLASS_INIT(&tag
[0], "includes");
1429 print_otag(h
, TAG_B
, 1, tag
);
1430 print_text(h
, n
->string
);
1432 if (NULL
!= (n
= n
->next
)) {
1433 assert(MDOC_TEXT
== n
->type
);
1434 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1435 n
->string
+ 1 : n
->string
, BUFSIZ
);
1438 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1441 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1444 if (h
->base_includes
) {
1445 buffmt_includes(h
, buf
);
1446 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1450 t
= print_otag(h
, TAG_A
, i
, tag
);
1451 print_text(h
, n
->string
);
1457 for ( ; n
; n
= n
->next
) {
1458 assert(MDOC_TEXT
== n
->type
);
1459 print_text(h
, n
->string
);
1468 mdoc_vt_pre(MDOC_ARGS
)
1470 struct htmlpair tag
;
1472 if (MDOC_BLOCK
== n
->type
) {
1475 } else if (MDOC_ELEM
== n
->type
) {
1477 } else if (MDOC_HEAD
== n
->type
)
1480 PAIR_CLASS_INIT(&tag
, "type");
1481 print_otag(h
, TAG_SPAN
, 1, &tag
);
1488 mdoc_ft_pre(MDOC_ARGS
)
1490 struct htmlpair tag
;
1493 PAIR_CLASS_INIT(&tag
, "ftype");
1494 print_otag(h
, TAG_I
, 1, &tag
);
1501 mdoc_fn_pre(MDOC_ARGS
)
1504 struct htmlpair tag
[2];
1506 const char *sp
, *ep
;
1509 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1512 /* Split apart into type and name. */
1513 assert(n
->child
->string
);
1514 sp
= n
->child
->string
;
1516 ep
= strchr(sp
, ' ');
1518 PAIR_CLASS_INIT(&tag
[0], "ftype");
1519 t
= print_otag(h
, TAG_I
, 1, tag
);
1522 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1523 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1525 print_text(h
, nbuf
);
1527 ep
= strchr(sp
, ' ');
1532 PAIR_CLASS_INIT(&tag
[0], "fname");
1535 * FIXME: only refer to IDs that we know exist.
1539 if (MDOC_SYNPRETTY
& n
->flags
) {
1541 html_idcat(nbuf
, sp
, BUFSIZ
);
1542 PAIR_ID_INIT(&tag
[1], nbuf
);
1544 strlcpy(nbuf
, "#", BUFSIZ
);
1545 html_idcat(nbuf
, sp
, BUFSIZ
);
1546 PAIR_HREF_INIT(&tag
[1], nbuf
);
1550 t
= print_otag(h
, TAG_B
, 1, tag
);
1553 strlcpy(nbuf
, sp
, BUFSIZ
);
1554 print_text(h
, nbuf
);
1559 h
->flags
|= HTML_NOSPACE
;
1561 h
->flags
|= HTML_NOSPACE
;
1563 PAIR_CLASS_INIT(&tag
[0], "farg");
1565 bufcat_style(h
, "white-space", "nowrap");
1566 PAIR_STYLE_INIT(&tag
[1], h
);
1568 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1570 if (MDOC_SYNPRETTY
& n
->flags
)
1572 t
= print_otag(h
, TAG_I
, i
, tag
);
1573 print_text(h
, n
->string
);
1576 h
->flags
|= HTML_NOSPACE
;
1581 h
->flags
|= HTML_NOSPACE
;
1585 h
->flags
|= HTML_NOSPACE
;
1595 mdoc_sm_pre(MDOC_ARGS
)
1598 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1599 if (0 == strcmp("on", n
->child
->string
)) {
1601 * FIXME: no p->col to check. Thus, if we have
1608 * the "3" is preceded by a space.
1610 h
->flags
&= ~HTML_NOSPACE
;
1611 h
->flags
&= ~HTML_NONOSPACE
;
1613 h
->flags
|= HTML_NONOSPACE
;
1620 mdoc_pp_pre(MDOC_ARGS
)
1623 print_otag(h
, TAG_P
, 0, NULL
);
1630 mdoc_sp_pre(MDOC_ARGS
)
1633 struct htmlpair tag
;
1635 SCALE_VS_INIT(&su
, 1);
1637 if (MDOC_sp
== n
->tok
) {
1638 if (NULL
!= (n
= n
->child
))
1639 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1640 SCALE_VS_INIT(&su
, atoi(n
->string
));
1645 bufcat_su(h
, "height", &su
);
1646 PAIR_STYLE_INIT(&tag
, h
);
1647 print_otag(h
, TAG_DIV
, 1, &tag
);
1649 /* So the div isn't empty: */
1650 print_text(h
, "\\~");
1658 mdoc_lk_pre(MDOC_ARGS
)
1660 struct htmlpair tag
[2];
1662 if (NULL
== (n
= n
->child
))
1665 assert(MDOC_TEXT
== n
->type
);
1667 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1668 PAIR_HREF_INIT(&tag
[1], n
->string
);
1670 print_otag(h
, TAG_A
, 2, tag
);
1672 if (NULL
== n
->next
)
1673 print_text(h
, n
->string
);
1675 for (n
= n
->next
; n
; n
= n
->next
)
1676 print_text(h
, n
->string
);
1684 mdoc_mt_pre(MDOC_ARGS
)
1686 struct htmlpair tag
[2];
1689 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1691 for (n
= n
->child
; n
; n
= n
->next
) {
1692 assert(MDOC_TEXT
== n
->type
);
1695 bufcat(h
, "mailto:");
1696 bufcat(h
, n
->string
);
1698 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1699 t
= print_otag(h
, TAG_A
, 2, tag
);
1700 print_text(h
, n
->string
);
1710 mdoc_fo_pre(MDOC_ARGS
)
1712 struct htmlpair tag
;
1715 if (MDOC_BODY
== n
->type
) {
1716 h
->flags
|= HTML_NOSPACE
;
1718 h
->flags
|= HTML_NOSPACE
;
1720 } else if (MDOC_BLOCK
== n
->type
) {
1725 /* XXX: we drop non-initial arguments as per groff. */
1728 assert(n
->child
->string
);
1730 PAIR_CLASS_INIT(&tag
, "fname");
1731 t
= print_otag(h
, TAG_B
, 1, &tag
);
1732 print_text(h
, n
->child
->string
);
1740 mdoc_fo_post(MDOC_ARGS
)
1743 if (MDOC_BODY
!= n
->type
)
1745 h
->flags
|= HTML_NOSPACE
;
1747 h
->flags
|= HTML_NOSPACE
;
1754 mdoc_in_pre(MDOC_ARGS
)
1757 struct htmlpair tag
[2];
1762 PAIR_CLASS_INIT(&tag
[0], "includes");
1763 print_otag(h
, TAG_B
, 1, tag
);
1766 * The first argument of the `In' gets special treatment as
1767 * being a linked value. Subsequent values are printed
1768 * afterward. groff does similarly. This also handles the case
1772 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1773 print_text(h
, "#include");
1776 h
->flags
|= HTML_NOSPACE
;
1778 if (NULL
!= (n
= n
->child
)) {
1779 assert(MDOC_TEXT
== n
->type
);
1781 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1784 if (h
->base_includes
) {
1785 buffmt_includes(h
, n
->string
);
1786 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1790 t
= print_otag(h
, TAG_A
, i
, tag
);
1791 print_text(h
, n
->string
);
1797 h
->flags
|= HTML_NOSPACE
;
1800 for ( ; n
; n
= n
->next
) {
1801 assert(MDOC_TEXT
== n
->type
);
1802 print_text(h
, n
->string
);
1811 mdoc_ic_pre(MDOC_ARGS
)
1813 struct htmlpair tag
;
1815 PAIR_CLASS_INIT(&tag
, "cmd");
1816 print_otag(h
, TAG_B
, 1, &tag
);
1823 mdoc_rv_pre(MDOC_ARGS
)
1825 struct htmlpair tag
;
1830 print_otag(h
, TAG_BR
, 0, NULL
);
1832 PAIR_CLASS_INIT(&tag
, "fname");
1834 print_text(h
, "The");
1837 for (n
= n
->child
; n
; n
= n
->next
) {
1838 assert(MDOC_TEXT
== n
->type
);
1840 t
= print_otag(h
, TAG_B
, 1, &tag
);
1841 print_text(h
, n
->string
);
1844 h
->flags
|= HTML_NOSPACE
;
1845 print_text(h
, "()");
1847 if (nchild
> 2 && n
->next
) {
1848 h
->flags
|= HTML_NOSPACE
;
1852 if (n
->next
&& NULL
== n
->next
->next
)
1853 print_text(h
, "and");
1857 print_text(h
, "functions return");
1859 print_text(h
, "function returns");
1861 print_text(h
, "the value 0 if successful; otherwise the value "
1862 "-1 is returned and the global variable");
1864 PAIR_CLASS_INIT(&tag
, "var");
1865 t
= print_otag(h
, TAG_B
, 1, &tag
);
1866 print_text(h
, "errno");
1868 print_text(h
, "is set to indicate the error.");
1875 mdoc_va_pre(MDOC_ARGS
)
1877 struct htmlpair tag
;
1879 PAIR_CLASS_INIT(&tag
, "var");
1880 print_otag(h
, TAG_B
, 1, &tag
);
1887 mdoc_ap_pre(MDOC_ARGS
)
1890 h
->flags
|= HTML_NOSPACE
;
1891 print_text(h
, "\\(aq");
1892 h
->flags
|= HTML_NOSPACE
;
1899 mdoc_bf_pre(MDOC_ARGS
)
1901 struct htmlpair tag
[2];
1904 if (MDOC_HEAD
== n
->type
)
1906 else if (MDOC_BODY
!= n
->type
)
1909 if (FONT_Em
== n
->norm
->Bf
.font
)
1910 PAIR_CLASS_INIT(&tag
[0], "emph");
1911 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1912 PAIR_CLASS_INIT(&tag
[0], "symb");
1913 else if (FONT_Li
== n
->norm
->Bf
.font
)
1914 PAIR_CLASS_INIT(&tag
[0], "lit");
1916 PAIR_CLASS_INIT(&tag
[0], "none");
1919 * We want this to be inline-formatted, but needs to be div to
1920 * accept block children.
1923 bufcat_style(h
, "display", "inline");
1924 SCALE_HS_INIT(&su
, 1);
1925 /* Needs a left-margin for spacing. */
1926 bufcat_su(h
, "margin-left", &su
);
1927 PAIR_STYLE_INIT(&tag
[1], h
);
1928 print_otag(h
, TAG_DIV
, 2, tag
);
1935 mdoc_ms_pre(MDOC_ARGS
)
1937 struct htmlpair tag
;
1939 PAIR_CLASS_INIT(&tag
, "symb");
1940 print_otag(h
, TAG_SPAN
, 1, &tag
);
1947 mdoc_igndelim_pre(MDOC_ARGS
)
1950 h
->flags
|= HTML_IGNDELIM
;
1957 mdoc_pf_post(MDOC_ARGS
)
1960 h
->flags
|= HTML_NOSPACE
;
1966 mdoc_rs_pre(MDOC_ARGS
)
1968 struct htmlpair tag
;
1970 if (MDOC_BLOCK
!= n
->type
)
1973 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1974 print_otag(h
, TAG_P
, 0, NULL
);
1976 PAIR_CLASS_INIT(&tag
, "ref");
1977 print_otag(h
, TAG_SPAN
, 1, &tag
);
1985 mdoc_li_pre(MDOC_ARGS
)
1987 struct htmlpair tag
;
1989 PAIR_CLASS_INIT(&tag
, "lit");
1990 print_otag(h
, TAG_SPAN
, 1, &tag
);
1997 mdoc_sy_pre(MDOC_ARGS
)
1999 struct htmlpair tag
;
2001 PAIR_CLASS_INIT(&tag
, "symb");
2002 print_otag(h
, TAG_SPAN
, 1, &tag
);
2009 mdoc_bt_pre(MDOC_ARGS
)
2012 print_text(h
, "is currently in beta test.");
2019 mdoc_ud_pre(MDOC_ARGS
)
2022 print_text(h
, "currently under development.");
2029 mdoc_lb_pre(MDOC_ARGS
)
2031 struct htmlpair tag
;
2033 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2034 print_otag(h
, TAG_BR
, 0, NULL
);
2036 PAIR_CLASS_INIT(&tag
, "lib");
2037 print_otag(h
, TAG_SPAN
, 1, &tag
);
2044 mdoc__x_pre(MDOC_ARGS
)
2046 struct htmlpair tag
[2];
2053 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2054 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2055 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2056 print_text(h
, "and");
2059 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2063 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2066 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2069 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2073 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2077 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2080 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2083 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2086 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2089 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2092 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2095 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2098 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2105 if (MDOC__U
!= n
->tok
) {
2106 print_otag(h
, t
, 1, tag
);
2110 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2111 print_otag(h
, TAG_A
, 2, tag
);
2119 mdoc__x_post(MDOC_ARGS
)
2122 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2123 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2124 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2129 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2132 h
->flags
|= HTML_NOSPACE
;
2133 print_text(h
, n
->next
? "," : ".");
2139 mdoc_bk_pre(MDOC_ARGS
)
2148 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2149 h
->flags
|= HTML_PREKEEP
;
2162 mdoc_bk_post(MDOC_ARGS
)
2165 if (MDOC_BODY
== n
->type
)
2166 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2172 mdoc_quote_pre(MDOC_ARGS
)
2174 struct htmlpair tag
;
2176 if (MDOC_BODY
!= n
->type
)
2183 print_text(h
, "\\(la");
2188 print_text(h
, "\\(lC");
2193 print_text(h
, "\\(lB");
2198 print_text(h
, "\\(lB");
2199 h
->flags
|= HTML_NOSPACE
;
2200 PAIR_CLASS_INIT(&tag
, "opt");
2201 print_otag(h
, TAG_SPAN
, 1, &tag
);
2210 print_text(h
, "\\(lq");
2222 print_text(h
, "\\(oq");
2229 h
->flags
|= HTML_NOSPACE
;
2236 mdoc_quote_post(MDOC_ARGS
)
2239 if (MDOC_BODY
!= n
->type
)
2242 h
->flags
|= HTML_NOSPACE
;
2248 print_text(h
, "\\(ra");
2253 print_text(h
, "\\(rC");
2262 print_text(h
, "\\(rB");
2271 print_text(h
, "\\(rq");
2283 print_text(h
, "\\(aq");