]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.178 2011/08/26 09:03:17 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>
38 #define MDOC_ARGS const struct mdoc_meta *m, \
39 const struct mdoc_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static void print_mdoc(MDOC_ARGS
);
52 static void print_mdoc_head(MDOC_ARGS
);
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
55 static void synopsis_pre(struct html
*,
56 const struct mdoc_node
*);
58 static void a2width(const char *, struct roffsu
*);
59 static void a2offs(const char *, struct roffsu
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static int mdoc_ar_pre(MDOC_ARGS
);
70 static int mdoc_bd_pre(MDOC_ARGS
);
71 static int mdoc_bf_pre(MDOC_ARGS
);
72 static void mdoc_bk_post(MDOC_ARGS
);
73 static int mdoc_bk_pre(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static int mdoc_bt_pre(MDOC_ARGS
);
76 static int mdoc_bx_pre(MDOC_ARGS
);
77 static int mdoc_cd_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_pre(MDOC_ARGS
);
86 static int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_igndelim_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_pre(MDOC_ARGS
);
95 static int mdoc_lb_pre(MDOC_ARGS
);
96 static int mdoc_li_pre(MDOC_ARGS
);
97 static int mdoc_lk_pre(MDOC_ARGS
);
98 static int mdoc_mt_pre(MDOC_ARGS
);
99 static int mdoc_ms_pre(MDOC_ARGS
);
100 static int mdoc_nd_pre(MDOC_ARGS
);
101 static int mdoc_nm_pre(MDOC_ARGS
);
102 static int mdoc_ns_pre(MDOC_ARGS
);
103 static int mdoc_pa_pre(MDOC_ARGS
);
104 static void mdoc_pf_post(MDOC_ARGS
);
105 static int mdoc_pp_pre(MDOC_ARGS
);
106 static void mdoc_quote_post(MDOC_ARGS
);
107 static int mdoc_quote_pre(MDOC_ARGS
);
108 static int mdoc_rs_pre(MDOC_ARGS
);
109 static int mdoc_rv_pre(MDOC_ARGS
);
110 static int mdoc_sh_pre(MDOC_ARGS
);
111 static int mdoc_sm_pre(MDOC_ARGS
);
112 static int mdoc_sp_pre(MDOC_ARGS
);
113 static int mdoc_ss_pre(MDOC_ARGS
);
114 static int mdoc_sx_pre(MDOC_ARGS
);
115 static int mdoc_sy_pre(MDOC_ARGS
);
116 static int mdoc_ud_pre(MDOC_ARGS
);
117 static int mdoc_va_pre(MDOC_ARGS
);
118 static int mdoc_vt_pre(MDOC_ARGS
);
119 static int mdoc_xr_pre(MDOC_ARGS
);
120 static int mdoc_xx_pre(MDOC_ARGS
);
122 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
123 {mdoc_ap_pre
, NULL
}, /* Ap */
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ar_pre
, NULL
}, /* Ar */
140 {mdoc_cd_pre
, NULL
}, /* Cd */
141 {mdoc_fl_pre
, NULL
}, /* Cm */
142 {mdoc_dv_pre
, NULL
}, /* Dv */
143 {mdoc_er_pre
, NULL
}, /* Er */
144 {mdoc_ev_pre
, NULL
}, /* Ev */
145 {mdoc_ex_pre
, NULL
}, /* Ex */
146 {mdoc_fa_pre
, NULL
}, /* Fa */
147 {mdoc_fd_pre
, NULL
}, /* Fd */
148 {mdoc_fl_pre
, NULL
}, /* Fl */
149 {mdoc_fn_pre
, NULL
}, /* Fn */
150 {mdoc_ft_pre
, NULL
}, /* Ft */
151 {mdoc_ic_pre
, NULL
}, /* Ic */
152 {mdoc_in_pre
, NULL
}, /* In */
153 {mdoc_li_pre
, NULL
}, /* Li */
154 {mdoc_nd_pre
, NULL
}, /* Nd */
155 {mdoc_nm_pre
, NULL
}, /* Nm */
156 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
157 {NULL
, NULL
}, /* Ot */
158 {mdoc_pa_pre
, NULL
}, /* Pa */
159 {mdoc_rv_pre
, NULL
}, /* Rv */
160 {NULL
, NULL
}, /* St */
161 {mdoc_va_pre
, NULL
}, /* Va */
162 {mdoc_vt_pre
, NULL
}, /* Vt */
163 {mdoc_xr_pre
, NULL
}, /* Xr */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
175 {NULL
, NULL
}, /* Ac */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
178 {NULL
, NULL
}, /* At */
179 {NULL
, NULL
}, /* Bc */
180 {mdoc_bf_pre
, NULL
}, /* Bf */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
183 {mdoc_xx_pre
, NULL
}, /* Bsx */
184 {mdoc_bx_pre
, NULL
}, /* Bx */
185 {NULL
, NULL
}, /* Db */
186 {NULL
, NULL
}, /* Dc */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
189 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
190 {NULL
, NULL
}, /* Ef */
191 {mdoc_em_pre
, NULL
}, /* Em */
192 {NULL
, NULL
}, /* Eo */
193 {mdoc_xx_pre
, NULL
}, /* Fx */
194 {mdoc_ms_pre
, NULL
}, /* Ms */
195 {mdoc_igndelim_pre
, NULL
}, /* No */
196 {mdoc_ns_pre
, NULL
}, /* Ns */
197 {mdoc_xx_pre
, NULL
}, /* Nx */
198 {mdoc_xx_pre
, NULL
}, /* Ox */
199 {NULL
, NULL
}, /* Pc */
200 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
203 {NULL
, NULL
}, /* Qc */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
207 {NULL
, NULL
}, /* Re */
208 {mdoc_rs_pre
, NULL
}, /* Rs */
209 {NULL
, NULL
}, /* Sc */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
212 {mdoc_sm_pre
, NULL
}, /* Sm */
213 {mdoc_sx_pre
, NULL
}, /* Sx */
214 {mdoc_sy_pre
, NULL
}, /* Sy */
215 {NULL
, NULL
}, /* Tn */
216 {mdoc_xx_pre
, NULL
}, /* Ux */
217 {NULL
, NULL
}, /* Xc */
218 {NULL
, NULL
}, /* Xo */
219 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
220 {NULL
, NULL
}, /* Fc */
221 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
222 {NULL
, NULL
}, /* Oc */
223 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
224 {NULL
, NULL
}, /* Ek */
225 {mdoc_bt_pre
, NULL
}, /* Bt */
226 {NULL
, NULL
}, /* Hf */
227 {NULL
, NULL
}, /* Fr */
228 {mdoc_ud_pre
, NULL
}, /* Ud */
229 {mdoc_lb_pre
, NULL
}, /* Lb */
230 {mdoc_pp_pre
, NULL
}, /* Lp */
231 {mdoc_lk_pre
, NULL
}, /* Lk */
232 {mdoc_mt_pre
, NULL
}, /* Mt */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
235 {NULL
, NULL
}, /* Brc */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
237 {NULL
, NULL
}, /* Es */ /* TODO */
238 {NULL
, NULL
}, /* En */ /* TODO */
239 {mdoc_xx_pre
, NULL
}, /* Dx */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
241 {mdoc_sp_pre
, NULL
}, /* br */
242 {mdoc_sp_pre
, NULL
}, /* sp */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
247 static const char * const lists
[LIST_MAX
] = {
263 html_mdoc(void *arg
, const struct mdoc
*m
)
268 h
= (struct html
*)arg
;
271 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
272 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
280 * Calculate the scaling unit passed in a `-width' argument. This uses
281 * either a native scaling unit (e.g., 1i, 2m) or the string length of
285 a2width(const char *p
, struct roffsu
*su
)
288 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
290 su
->scale
= html_strlen(p
);
296 * See the same function in mdoc_term.c for documentation.
299 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
302 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
305 if (n
->prev
->tok
== n
->tok
&&
309 print_otag(h
, TAG_BR
, 0, NULL
);
313 switch (n
->prev
->tok
) {
323 print_otag(h
, TAG_P
, 0, NULL
);
326 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
327 print_otag(h
, TAG_P
, 0, NULL
);
332 print_otag(h
, TAG_BR
, 0, NULL
);
339 * Calculate the scaling unit passed in an `-offset' argument. This
340 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
341 * predefined strings (indent, etc.), or the string length of the value.
344 a2offs(const char *p
, struct roffsu
*su
)
347 /* FIXME: "right"? */
349 if (0 == strcmp(p
, "left"))
350 SCALE_HS_INIT(su
, 0);
351 else if (0 == strcmp(p
, "indent"))
352 SCALE_HS_INIT(su
, INDENT
);
353 else if (0 == strcmp(p
, "indent-two"))
354 SCALE_HS_INIT(su
, INDENT
* 2);
355 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
356 SCALE_HS_INIT(su
, html_strlen(p
));
361 print_mdoc(MDOC_ARGS
)
365 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
366 print_mdoc_head(m
, n
, h
);
369 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
370 print_mdoc_nodelist(m
, n
, h
);
377 print_mdoc_head(MDOC_ARGS
)
382 bufcat_fmt(h
, "%s(%s)", m
->title
, m
->msec
);
385 bufcat_fmt(h
, " (%s)", m
->arch
);
387 print_otag(h
, TAG_TITLE
, 0, NULL
);
388 print_text(h
, h
->buf
);
393 print_mdoc_nodelist(MDOC_ARGS
)
396 print_mdoc_node(m
, n
, h
);
398 print_mdoc_nodelist(m
, n
->next
, h
);
403 print_mdoc_node(MDOC_ARGS
)
413 child
= mdoc_root_pre(m
, n
, h
);
416 /* No tables in this mode... */
417 assert(NULL
== h
->tblt
);
420 * Make sure that if we're in a literal mode already
421 * (i.e., within a <PRE>) don't print the newline.
423 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
424 if ( ! (HTML_LITERAL
& h
->flags
))
425 print_otag(h
, TAG_BR
, 0, NULL
);
426 if (MDOC_DELIMC
& n
->flags
)
427 h
->flags
|= HTML_NOSPACE
;
428 print_text(h
, n
->string
);
429 if (MDOC_DELIMO
& n
->flags
)
430 h
->flags
|= HTML_NOSPACE
;
433 print_eqn(h
, n
->eqn
);
437 * This will take care of initialising all of the table
438 * state data for the first table, then tearing it down
441 print_tbl(h
, n
->span
);
445 * Close out the current table, if it's open, and unset
446 * the "meta" table state. This will be reopened on the
447 * next table element.
454 assert(NULL
== h
->tblt
);
455 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
456 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
460 if (HTML_KEEP
& h
->flags
) {
461 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
462 h
->flags
&= ~HTML_KEEP
;
463 h
->flags
|= HTML_PREKEEP
;
464 } else if (NULL
== n
->prev
) {
465 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
466 h
->flags
&= ~HTML_KEEP
;
467 h
->flags
|= HTML_PREKEEP
;
472 if (child
&& n
->child
)
473 print_mdoc_nodelist(m
, n
->child
, h
);
479 mdoc_root_post(m
, n
, h
);
484 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
485 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
492 mdoc_root_post(MDOC_ARGS
)
494 struct htmlpair tag
[3];
497 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
498 PAIR_CLASS_INIT(&tag
[1], "foot");
499 if (NULL
== h
->style
) {
500 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
501 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
502 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
503 print_otag(h
, TAG_COL
, 1, tag
);
504 print_otag(h
, TAG_COL
, 1, tag
);
506 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
508 t
= print_otag(h
, TAG_TBODY
, 0, NULL
);
510 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
512 PAIR_CLASS_INIT(&tag
[0], "foot-date");
513 print_otag(h
, TAG_TD
, 1, tag
);
515 print_text(h
, m
->date
);
518 PAIR_CLASS_INIT(&tag
[0], "foot-os");
519 if (NULL
== h
->style
) {
520 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
521 print_otag(h
, TAG_TD
, 2, tag
);
523 print_otag(h
, TAG_TD
, 1, tag
);
525 print_text(h
, m
->os
);
532 mdoc_root_pre(MDOC_ARGS
)
534 struct htmlpair tag
[3];
536 char b
[BUFSIZ
], title
[BUFSIZ
];
538 strlcpy(b
, m
->vol
, BUFSIZ
);
541 strlcat(b
, " (", BUFSIZ
);
542 strlcat(b
, m
->arch
, BUFSIZ
);
543 strlcat(b
, ")", BUFSIZ
);
546 snprintf(title
, BUFSIZ
- 1, "%s(%s)", m
->title
, m
->msec
);
548 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
549 PAIR_CLASS_INIT(&tag
[1], "head");
550 if (NULL
== h
->style
) {
551 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
552 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
553 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
554 print_otag(h
, TAG_COL
, 1, tag
);
555 print_otag(h
, TAG_COL
, 1, tag
);
556 print_otag(h
, TAG_COL
, 1, tag
);
558 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
560 print_otag(h
, TAG_TBODY
, 0, NULL
);
562 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
564 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
565 print_otag(h
, TAG_TD
, 1, tag
);
567 print_text(h
, title
);
570 PAIR_CLASS_INIT(&tag
[0], "head-vol");
571 if (NULL
== h
->style
) {
572 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
573 print_otag(h
, TAG_TD
, 2, tag
);
575 print_otag(h
, TAG_TD
, 1, tag
);
580 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
581 if (NULL
== h
->style
) {
582 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
583 print_otag(h
, TAG_TD
, 2, tag
);
585 print_otag(h
, TAG_TD
, 1, tag
);
587 print_text(h
, title
);
595 mdoc_sh_pre(MDOC_ARGS
)
599 if (MDOC_BLOCK
== n
->type
) {
600 PAIR_CLASS_INIT(&tag
, "section");
601 print_otag(h
, TAG_DIV
, 1, &tag
);
603 } else if (MDOC_BODY
== n
->type
)
609 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
610 bufcat_id(h
, n
->string
);
611 if (NULL
!= (n
= n
->next
))
616 PAIR_ID_INIT(&tag
, h
->buf
);
617 print_otag(h
, TAG_H1
, 1, &tag
);
619 print_otag(h
, TAG_H1
, 0, NULL
);
626 mdoc_ss_pre(MDOC_ARGS
)
630 if (MDOC_BLOCK
== n
->type
) {
631 PAIR_CLASS_INIT(&tag
, "subsection");
632 print_otag(h
, TAG_DIV
, 1, &tag
);
634 } else if (MDOC_BODY
== n
->type
)
640 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
641 bufcat_id(h
, n
->string
);
642 if (NULL
!= (n
= n
->next
))
647 PAIR_ID_INIT(&tag
, h
->buf
);
648 print_otag(h
, TAG_H2
, 1, &tag
);
650 print_otag(h
, TAG_H2
, 0, NULL
);
658 mdoc_fl_pre(MDOC_ARGS
)
662 PAIR_CLASS_INIT(&tag
, "flag");
663 print_otag(h
, TAG_B
, 1, &tag
);
665 /* `Cm' has no leading hyphen. */
667 if (MDOC_Cm
== n
->tok
)
670 print_text(h
, "\\-");
673 h
->flags
|= HTML_NOSPACE
;
674 else if (n
->next
&& n
->next
->line
== n
->line
)
675 h
->flags
|= HTML_NOSPACE
;
683 mdoc_nd_pre(MDOC_ARGS
)
687 if (MDOC_BODY
!= n
->type
)
690 /* XXX: this tag in theory can contain block elements. */
692 print_text(h
, "\\(em");
693 PAIR_CLASS_INIT(&tag
, "desc");
694 print_otag(h
, TAG_SPAN
, 1, &tag
);
700 mdoc_nm_pre(MDOC_ARGS
)
709 PAIR_CLASS_INIT(&tag
, "name");
710 print_otag(h
, TAG_B
, 1, &tag
);
711 if (NULL
== n
->child
&& m
->name
)
712 print_text(h
, m
->name
);
715 print_otag(h
, TAG_TD
, 0, NULL
);
716 if (NULL
== n
->child
&& m
->name
)
717 print_text(h
, m
->name
);
720 print_otag(h
, TAG_TD
, 0, NULL
);
727 PAIR_CLASS_INIT(&tag
, "synopsis");
728 print_otag(h
, TAG_TABLE
, 1, &tag
);
730 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
731 if (MDOC_TEXT
== n
->type
)
732 len
+= html_strlen(n
->string
);
734 if (0 == len
&& m
->name
)
735 len
= html_strlen(m
->name
);
737 SCALE_HS_INIT(&su
, (double)len
);
739 bufcat_su(h
, "width", &su
);
740 PAIR_STYLE_INIT(&tag
, h
);
741 print_otag(h
, TAG_COL
, 1, &tag
);
742 print_otag(h
, TAG_COL
, 0, NULL
);
743 print_otag(h
, TAG_TBODY
, 0, NULL
);
744 print_otag(h
, TAG_TR
, 0, NULL
);
751 mdoc_xr_pre(MDOC_ARGS
)
753 struct htmlpair tag
[2];
755 if (NULL
== n
->child
)
758 PAIR_CLASS_INIT(&tag
[0], "link-man");
761 buffmt_man(h
, n
->child
->string
,
763 n
->child
->next
->string
: NULL
);
764 PAIR_HREF_INIT(&tag
[1], h
->buf
);
765 print_otag(h
, TAG_A
, 2, tag
);
767 print_otag(h
, TAG_A
, 1, tag
);
770 print_text(h
, n
->string
);
772 if (NULL
== (n
= n
->next
))
775 h
->flags
|= HTML_NOSPACE
;
777 h
->flags
|= HTML_NOSPACE
;
778 print_text(h
, n
->string
);
779 h
->flags
|= HTML_NOSPACE
;
787 mdoc_ns_pre(MDOC_ARGS
)
790 if ( ! (MDOC_LINE
& n
->flags
))
791 h
->flags
|= HTML_NOSPACE
;
798 mdoc_ar_pre(MDOC_ARGS
)
802 PAIR_CLASS_INIT(&tag
, "arg");
803 print_otag(h
, TAG_I
, 1, &tag
);
810 mdoc_xx_pre(MDOC_ARGS
)
839 PAIR_CLASS_INIT(&tag
, "unix");
840 print_otag(h
, TAG_SPAN
, 1, &tag
);
845 h
->flags
|= HTML_KEEP
;
846 print_text(h
, n
->child
->string
);
855 mdoc_bx_pre(MDOC_ARGS
)
859 PAIR_CLASS_INIT(&tag
, "unix");
860 print_otag(h
, TAG_SPAN
, 1, &tag
);
862 if (NULL
!= (n
= n
->child
)) {
863 print_text(h
, n
->string
);
864 h
->flags
|= HTML_NOSPACE
;
865 print_text(h
, "BSD");
867 print_text(h
, "BSD");
871 if (NULL
!= (n
= n
->next
)) {
872 h
->flags
|= HTML_NOSPACE
;
874 h
->flags
|= HTML_NOSPACE
;
875 print_text(h
, n
->string
);
883 mdoc_it_pre(MDOC_ARGS
)
887 struct htmlpair tag
[2];
888 const struct mdoc_node
*bl
;
891 while (bl
&& MDOC_Bl
!= bl
->tok
)
896 type
= bl
->norm
->Bl
.type
;
899 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
903 if (MDOC_HEAD
== n
->type
) {
924 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
925 bufcat_su(h
, "margin-top", &su
);
926 PAIR_STYLE_INIT(&tag
[1], h
);
927 print_otag(h
, TAG_DT
, 2, tag
);
928 if (LIST_diag
!= type
)
930 PAIR_CLASS_INIT(&tag
[0], "diag");
931 print_otag(h
, TAG_B
, 1, tag
);
938 } else if (MDOC_BODY
== n
->type
) {
949 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
950 bufcat_su(h
, "margin-top", &su
);
951 PAIR_STYLE_INIT(&tag
[1], h
);
952 print_otag(h
, TAG_LI
, 2, tag
);
963 if (NULL
== bl
->norm
->Bl
.width
) {
964 print_otag(h
, TAG_DD
, 1, tag
);
967 a2width(bl
->norm
->Bl
.width
, &su
);
968 bufcat_su(h
, "margin-left", &su
);
969 PAIR_STYLE_INIT(&tag
[1], h
);
970 print_otag(h
, TAG_DD
, 2, tag
);
973 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
974 bufcat_su(h
, "margin-top", &su
);
975 PAIR_STYLE_INIT(&tag
[1], h
);
976 print_otag(h
, TAG_TD
, 2, tag
);
984 print_otag(h
, TAG_TR
, 1, tag
);
996 mdoc_bl_pre(MDOC_ARGS
)
999 struct htmlpair tag
[3];
1005 if (MDOC_BODY
== n
->type
) {
1006 if (LIST_column
== n
->norm
->Bl
.type
)
1007 print_otag(h
, TAG_TBODY
, 0, NULL
);
1011 if (MDOC_HEAD
== n
->type
) {
1012 if (LIST_column
!= n
->norm
->Bl
.type
)
1016 * For each column, print out the <COL> tag with our
1017 * suggested width. The last column gets min-width, as
1018 * in terminal mode it auto-sizes to the width of the
1019 * screen and we want to preserve that behaviour.
1022 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1023 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1024 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1025 bufcat_su(h
, "width", &su
);
1027 bufcat_su(h
, "min-width", &su
);
1028 PAIR_STYLE_INIT(&tag
[0], h
);
1029 print_otag(h
, TAG_COL
, 1, tag
);
1035 SCALE_VS_INIT(&su
, 0);
1036 bufcat_su(h
, "margin-top", &su
);
1037 bufcat_su(h
, "margin-bottom", &su
);
1038 PAIR_STYLE_INIT(&tag
[0], h
);
1040 assert(lists
[n
->norm
->Bl
.type
]);
1041 strlcpy(buf
, "list ", BUFSIZ
);
1042 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1043 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1045 /* Set the block's left-hand margin. */
1047 if (n
->norm
->Bl
.offs
) {
1048 a2offs(n
->norm
->Bl
.offs
, &su
);
1049 bufcat_su(h
, "margin-left", &su
);
1052 switch (n
->norm
->Bl
.type
) {
1060 print_otag(h
, TAG_UL
, 2, tag
);
1063 print_otag(h
, TAG_OL
, 2, tag
);
1074 print_otag(h
, TAG_DL
, 2, tag
);
1077 print_otag(h
, TAG_TABLE
, 2, tag
);
1089 mdoc_ex_pre(MDOC_ARGS
)
1092 struct htmlpair tag
;
1096 print_otag(h
, TAG_BR
, 0, NULL
);
1098 PAIR_CLASS_INIT(&tag
, "utility");
1100 print_text(h
, "The");
1103 for (n
= n
->child
; n
; n
= n
->next
) {
1104 assert(MDOC_TEXT
== n
->type
);
1106 t
= print_otag(h
, TAG_B
, 1, &tag
);
1107 print_text(h
, n
->string
);
1110 if (nchild
> 2 && n
->next
) {
1111 h
->flags
|= HTML_NOSPACE
;
1115 if (n
->next
&& NULL
== n
->next
->next
)
1116 print_text(h
, "and");
1120 print_text(h
, "utilities exit");
1122 print_text(h
, "utility exits");
1124 print_text(h
, "0 on success, and >0 if an error occurs.");
1131 mdoc_em_pre(MDOC_ARGS
)
1133 struct htmlpair tag
;
1135 PAIR_CLASS_INIT(&tag
, "emph");
1136 print_otag(h
, TAG_SPAN
, 1, &tag
);
1143 mdoc_d1_pre(MDOC_ARGS
)
1145 struct htmlpair tag
[2];
1148 if (MDOC_BLOCK
!= n
->type
)
1151 SCALE_VS_INIT(&su
, 0);
1153 bufcat_su(h
, "margin-top", &su
);
1154 bufcat_su(h
, "margin-bottom", &su
);
1155 PAIR_STYLE_INIT(&tag
[0], h
);
1156 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1158 /* BLOCKQUOTE needs a block body. */
1160 PAIR_CLASS_INIT(&tag
[0], "display");
1161 print_otag(h
, TAG_DIV
, 1, tag
);
1163 if (MDOC_Dl
== n
->tok
) {
1164 PAIR_CLASS_INIT(&tag
[0], "lit");
1165 print_otag(h
, TAG_CODE
, 1, tag
);
1174 mdoc_sx_pre(MDOC_ARGS
)
1176 struct htmlpair tag
[2];
1181 for (n
= n
->child
; n
; ) {
1182 bufcat_id(h
, n
->string
);
1183 if (NULL
!= (n
= n
->next
))
1187 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1188 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1190 print_otag(h
, TAG_I
, 1, tag
);
1191 print_otag(h
, TAG_A
, 2, tag
);
1198 mdoc_bd_pre(MDOC_ARGS
)
1200 struct htmlpair tag
[2];
1202 const struct mdoc_node
*nn
;
1205 if (MDOC_HEAD
== n
->type
)
1208 if (MDOC_BLOCK
== n
->type
) {
1209 comp
= n
->norm
->Bd
.comp
;
1210 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1211 if (MDOC_BLOCK
!= nn
->type
)
1213 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1219 print_otag(h
, TAG_P
, 0, NULL
);
1223 SCALE_HS_INIT(&su
, 0);
1224 if (n
->norm
->Bd
.offs
)
1225 a2offs(n
->norm
->Bd
.offs
, &su
);
1228 bufcat_su(h
, "margin-left", &su
);
1229 PAIR_STYLE_INIT(&tag
[0], h
);
1231 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1232 DISP_literal
!= n
->norm
->Bd
.type
) {
1233 PAIR_CLASS_INIT(&tag
[1], "display");
1234 print_otag(h
, TAG_DIV
, 2, tag
);
1238 PAIR_CLASS_INIT(&tag
[1], "lit display");
1239 print_otag(h
, TAG_PRE
, 2, tag
);
1241 /* This can be recursive: save & set our literal state. */
1243 sv
= h
->flags
& HTML_LITERAL
;
1244 h
->flags
|= HTML_LITERAL
;
1246 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1247 print_mdoc_node(m
, nn
, h
);
1249 * If the printed node flushes its own line, then we
1250 * needn't do it here as well. This is hacky, but the
1251 * notion of selective eoln whitespace is pretty dumb
1252 * anyway, so don't sweat it.
1274 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1277 print_text(h
, "\n");
1279 h
->flags
|= HTML_NOSPACE
;
1283 h
->flags
&= ~HTML_LITERAL
;
1291 mdoc_pa_pre(MDOC_ARGS
)
1293 struct htmlpair tag
;
1295 PAIR_CLASS_INIT(&tag
, "file");
1296 print_otag(h
, TAG_I
, 1, &tag
);
1303 mdoc_ad_pre(MDOC_ARGS
)
1305 struct htmlpair tag
;
1307 PAIR_CLASS_INIT(&tag
, "addr");
1308 print_otag(h
, TAG_I
, 1, &tag
);
1315 mdoc_an_pre(MDOC_ARGS
)
1317 struct htmlpair tag
;
1319 /* TODO: -split and -nosplit (see termp_an_pre()). */
1321 PAIR_CLASS_INIT(&tag
, "author");
1322 print_otag(h
, TAG_SPAN
, 1, &tag
);
1329 mdoc_cd_pre(MDOC_ARGS
)
1331 struct htmlpair tag
;
1334 PAIR_CLASS_INIT(&tag
, "config");
1335 print_otag(h
, TAG_B
, 1, &tag
);
1342 mdoc_dv_pre(MDOC_ARGS
)
1344 struct htmlpair tag
;
1346 PAIR_CLASS_INIT(&tag
, "define");
1347 print_otag(h
, TAG_SPAN
, 1, &tag
);
1354 mdoc_ev_pre(MDOC_ARGS
)
1356 struct htmlpair tag
;
1358 PAIR_CLASS_INIT(&tag
, "env");
1359 print_otag(h
, TAG_SPAN
, 1, &tag
);
1366 mdoc_er_pre(MDOC_ARGS
)
1368 struct htmlpair tag
;
1370 PAIR_CLASS_INIT(&tag
, "errno");
1371 print_otag(h
, TAG_SPAN
, 1, &tag
);
1378 mdoc_fa_pre(MDOC_ARGS
)
1380 const struct mdoc_node
*nn
;
1381 struct htmlpair tag
;
1384 PAIR_CLASS_INIT(&tag
, "farg");
1385 if (n
->parent
->tok
!= MDOC_Fo
) {
1386 print_otag(h
, TAG_I
, 1, &tag
);
1390 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1391 t
= print_otag(h
, TAG_I
, 1, &tag
);
1392 print_text(h
, nn
->string
);
1395 h
->flags
|= HTML_NOSPACE
;
1400 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1401 h
->flags
|= HTML_NOSPACE
;
1411 mdoc_fd_pre(MDOC_ARGS
)
1413 struct htmlpair tag
[2];
1421 if (NULL
== (n
= n
->child
))
1424 assert(MDOC_TEXT
== n
->type
);
1426 if (strcmp(n
->string
, "#include")) {
1427 PAIR_CLASS_INIT(&tag
[0], "macro");
1428 print_otag(h
, TAG_B
, 1, tag
);
1432 PAIR_CLASS_INIT(&tag
[0], "includes");
1433 print_otag(h
, TAG_B
, 1, tag
);
1434 print_text(h
, n
->string
);
1436 if (NULL
!= (n
= n
->next
)) {
1437 assert(MDOC_TEXT
== n
->type
);
1438 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1439 n
->string
+ 1 : n
->string
, BUFSIZ
);
1442 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1445 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1448 if (h
->base_includes
) {
1449 buffmt_includes(h
, buf
);
1450 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1454 t
= print_otag(h
, TAG_A
, i
, tag
);
1455 print_text(h
, n
->string
);
1461 for ( ; n
; n
= n
->next
) {
1462 assert(MDOC_TEXT
== n
->type
);
1463 print_text(h
, n
->string
);
1472 mdoc_vt_pre(MDOC_ARGS
)
1474 struct htmlpair tag
;
1476 if (MDOC_BLOCK
== n
->type
) {
1479 } else if (MDOC_ELEM
== n
->type
) {
1481 } else if (MDOC_HEAD
== n
->type
)
1484 PAIR_CLASS_INIT(&tag
, "type");
1485 print_otag(h
, TAG_SPAN
, 1, &tag
);
1492 mdoc_ft_pre(MDOC_ARGS
)
1494 struct htmlpair tag
;
1497 PAIR_CLASS_INIT(&tag
, "ftype");
1498 print_otag(h
, TAG_I
, 1, &tag
);
1505 mdoc_fn_pre(MDOC_ARGS
)
1508 struct htmlpair tag
[2];
1510 const char *sp
, *ep
;
1513 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1516 /* Split apart into type and name. */
1517 assert(n
->child
->string
);
1518 sp
= n
->child
->string
;
1520 ep
= strchr(sp
, ' ');
1522 PAIR_CLASS_INIT(&tag
[0], "ftype");
1523 t
= print_otag(h
, TAG_I
, 1, tag
);
1526 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1527 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1529 print_text(h
, nbuf
);
1531 ep
= strchr(sp
, ' ');
1536 PAIR_CLASS_INIT(&tag
[0], "fname");
1539 * FIXME: only refer to IDs that we know exist.
1543 if (MDOC_SYNPRETTY
& n
->flags
) {
1545 html_idcat(nbuf
, sp
, BUFSIZ
);
1546 PAIR_ID_INIT(&tag
[1], nbuf
);
1548 strlcpy(nbuf
, "#", BUFSIZ
);
1549 html_idcat(nbuf
, sp
, BUFSIZ
);
1550 PAIR_HREF_INIT(&tag
[1], nbuf
);
1554 t
= print_otag(h
, TAG_B
, 1, tag
);
1557 strlcpy(nbuf
, sp
, BUFSIZ
);
1558 print_text(h
, nbuf
);
1563 h
->flags
|= HTML_NOSPACE
;
1565 h
->flags
|= HTML_NOSPACE
;
1567 PAIR_CLASS_INIT(&tag
[0], "farg");
1569 bufcat_style(h
, "white-space", "nowrap");
1570 PAIR_STYLE_INIT(&tag
[1], h
);
1572 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1574 if (MDOC_SYNPRETTY
& n
->flags
)
1576 t
= print_otag(h
, TAG_I
, i
, tag
);
1577 print_text(h
, n
->string
);
1580 h
->flags
|= HTML_NOSPACE
;
1585 h
->flags
|= HTML_NOSPACE
;
1589 h
->flags
|= HTML_NOSPACE
;
1599 mdoc_sm_pre(MDOC_ARGS
)
1602 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1603 if (0 == strcmp("on", n
->child
->string
)) {
1605 * FIXME: no p->col to check. Thus, if we have
1612 * the "3" is preceded by a space.
1614 h
->flags
&= ~HTML_NOSPACE
;
1615 h
->flags
&= ~HTML_NONOSPACE
;
1617 h
->flags
|= HTML_NONOSPACE
;
1624 mdoc_pp_pre(MDOC_ARGS
)
1627 print_otag(h
, TAG_P
, 0, NULL
);
1634 mdoc_sp_pre(MDOC_ARGS
)
1637 struct htmlpair tag
;
1639 SCALE_VS_INIT(&su
, 1);
1641 if (MDOC_sp
== n
->tok
) {
1642 if (NULL
!= (n
= n
->child
))
1643 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1644 SCALE_VS_INIT(&su
, atoi(n
->string
));
1649 bufcat_su(h
, "height", &su
);
1650 PAIR_STYLE_INIT(&tag
, h
);
1651 print_otag(h
, TAG_DIV
, 1, &tag
);
1653 /* So the div isn't empty: */
1654 print_text(h
, "\\~");
1662 mdoc_lk_pre(MDOC_ARGS
)
1664 struct htmlpair tag
[2];
1666 if (NULL
== (n
= n
->child
))
1669 assert(MDOC_TEXT
== n
->type
);
1671 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1672 PAIR_HREF_INIT(&tag
[1], n
->string
);
1674 print_otag(h
, TAG_A
, 2, tag
);
1676 if (NULL
== n
->next
)
1677 print_text(h
, n
->string
);
1679 for (n
= n
->next
; n
; n
= n
->next
)
1680 print_text(h
, n
->string
);
1688 mdoc_mt_pre(MDOC_ARGS
)
1690 struct htmlpair tag
[2];
1693 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1695 for (n
= n
->child
; n
; n
= n
->next
) {
1696 assert(MDOC_TEXT
== n
->type
);
1699 bufcat(h
, "mailto:");
1700 bufcat(h
, n
->string
);
1702 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1703 t
= print_otag(h
, TAG_A
, 2, tag
);
1704 print_text(h
, n
->string
);
1714 mdoc_fo_pre(MDOC_ARGS
)
1716 struct htmlpair tag
;
1719 if (MDOC_BODY
== n
->type
) {
1720 h
->flags
|= HTML_NOSPACE
;
1722 h
->flags
|= HTML_NOSPACE
;
1724 } else if (MDOC_BLOCK
== n
->type
) {
1729 /* XXX: we drop non-initial arguments as per groff. */
1732 assert(n
->child
->string
);
1734 PAIR_CLASS_INIT(&tag
, "fname");
1735 t
= print_otag(h
, TAG_B
, 1, &tag
);
1736 print_text(h
, n
->child
->string
);
1744 mdoc_fo_post(MDOC_ARGS
)
1747 if (MDOC_BODY
!= n
->type
)
1749 h
->flags
|= HTML_NOSPACE
;
1751 h
->flags
|= HTML_NOSPACE
;
1758 mdoc_in_pre(MDOC_ARGS
)
1761 struct htmlpair tag
[2];
1766 PAIR_CLASS_INIT(&tag
[0], "includes");
1767 print_otag(h
, TAG_B
, 1, tag
);
1770 * The first argument of the `In' gets special treatment as
1771 * being a linked value. Subsequent values are printed
1772 * afterward. groff does similarly. This also handles the case
1776 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1777 print_text(h
, "#include");
1780 h
->flags
|= HTML_NOSPACE
;
1782 if (NULL
!= (n
= n
->child
)) {
1783 assert(MDOC_TEXT
== n
->type
);
1785 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1788 if (h
->base_includes
) {
1789 buffmt_includes(h
, n
->string
);
1790 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1794 t
= print_otag(h
, TAG_A
, i
, tag
);
1795 print_text(h
, n
->string
);
1801 h
->flags
|= HTML_NOSPACE
;
1804 for ( ; n
; n
= n
->next
) {
1805 assert(MDOC_TEXT
== n
->type
);
1806 print_text(h
, n
->string
);
1815 mdoc_ic_pre(MDOC_ARGS
)
1817 struct htmlpair tag
;
1819 PAIR_CLASS_INIT(&tag
, "cmd");
1820 print_otag(h
, TAG_B
, 1, &tag
);
1827 mdoc_rv_pre(MDOC_ARGS
)
1829 struct htmlpair tag
;
1834 print_otag(h
, TAG_BR
, 0, NULL
);
1836 PAIR_CLASS_INIT(&tag
, "fname");
1838 print_text(h
, "The");
1841 for (n
= n
->child
; n
; n
= n
->next
) {
1842 assert(MDOC_TEXT
== n
->type
);
1844 t
= print_otag(h
, TAG_B
, 1, &tag
);
1845 print_text(h
, n
->string
);
1848 h
->flags
|= HTML_NOSPACE
;
1849 print_text(h
, "()");
1851 if (nchild
> 2 && n
->next
) {
1852 h
->flags
|= HTML_NOSPACE
;
1856 if (n
->next
&& NULL
== n
->next
->next
)
1857 print_text(h
, "and");
1861 print_text(h
, "functions return");
1863 print_text(h
, "function returns");
1865 print_text(h
, "the value 0 if successful; otherwise the value "
1866 "-1 is returned and the global variable");
1868 PAIR_CLASS_INIT(&tag
, "var");
1869 t
= print_otag(h
, TAG_B
, 1, &tag
);
1870 print_text(h
, "errno");
1872 print_text(h
, "is set to indicate the error.");
1879 mdoc_va_pre(MDOC_ARGS
)
1881 struct htmlpair tag
;
1883 PAIR_CLASS_INIT(&tag
, "var");
1884 print_otag(h
, TAG_B
, 1, &tag
);
1891 mdoc_ap_pre(MDOC_ARGS
)
1894 h
->flags
|= HTML_NOSPACE
;
1895 print_text(h
, "\\(aq");
1896 h
->flags
|= HTML_NOSPACE
;
1903 mdoc_bf_pre(MDOC_ARGS
)
1905 struct htmlpair tag
[2];
1908 if (MDOC_HEAD
== n
->type
)
1910 else if (MDOC_BODY
!= n
->type
)
1913 if (FONT_Em
== n
->norm
->Bf
.font
)
1914 PAIR_CLASS_INIT(&tag
[0], "emph");
1915 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1916 PAIR_CLASS_INIT(&tag
[0], "symb");
1917 else if (FONT_Li
== n
->norm
->Bf
.font
)
1918 PAIR_CLASS_INIT(&tag
[0], "lit");
1920 PAIR_CLASS_INIT(&tag
[0], "none");
1923 * We want this to be inline-formatted, but needs to be div to
1924 * accept block children.
1927 bufcat_style(h
, "display", "inline");
1928 SCALE_HS_INIT(&su
, 1);
1929 /* Needs a left-margin for spacing. */
1930 bufcat_su(h
, "margin-left", &su
);
1931 PAIR_STYLE_INIT(&tag
[1], h
);
1932 print_otag(h
, TAG_DIV
, 2, tag
);
1939 mdoc_ms_pre(MDOC_ARGS
)
1941 struct htmlpair tag
;
1943 PAIR_CLASS_INIT(&tag
, "symb");
1944 print_otag(h
, TAG_SPAN
, 1, &tag
);
1951 mdoc_igndelim_pre(MDOC_ARGS
)
1954 h
->flags
|= HTML_IGNDELIM
;
1961 mdoc_pf_post(MDOC_ARGS
)
1964 h
->flags
|= HTML_NOSPACE
;
1970 mdoc_rs_pre(MDOC_ARGS
)
1972 struct htmlpair tag
;
1974 if (MDOC_BLOCK
!= n
->type
)
1977 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1978 print_otag(h
, TAG_P
, 0, NULL
);
1980 PAIR_CLASS_INIT(&tag
, "ref");
1981 print_otag(h
, TAG_SPAN
, 1, &tag
);
1989 mdoc_li_pre(MDOC_ARGS
)
1991 struct htmlpair tag
;
1993 PAIR_CLASS_INIT(&tag
, "lit");
1994 print_otag(h
, TAG_CODE
, 1, &tag
);
2001 mdoc_sy_pre(MDOC_ARGS
)
2003 struct htmlpair tag
;
2005 PAIR_CLASS_INIT(&tag
, "symb");
2006 print_otag(h
, TAG_SPAN
, 1, &tag
);
2013 mdoc_bt_pre(MDOC_ARGS
)
2016 print_text(h
, "is currently in beta test.");
2023 mdoc_ud_pre(MDOC_ARGS
)
2026 print_text(h
, "currently under development.");
2033 mdoc_lb_pre(MDOC_ARGS
)
2035 struct htmlpair tag
;
2037 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2038 print_otag(h
, TAG_BR
, 0, NULL
);
2040 PAIR_CLASS_INIT(&tag
, "lib");
2041 print_otag(h
, TAG_SPAN
, 1, &tag
);
2048 mdoc__x_pre(MDOC_ARGS
)
2050 struct htmlpair tag
[2];
2057 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2058 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2059 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2060 print_text(h
, "and");
2063 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2067 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2070 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2073 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2077 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2081 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2084 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2087 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2090 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2093 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2096 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2099 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2102 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2109 if (MDOC__U
!= n
->tok
) {
2110 print_otag(h
, t
, 1, tag
);
2114 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2115 print_otag(h
, TAG_A
, 2, tag
);
2123 mdoc__x_post(MDOC_ARGS
)
2126 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2127 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2128 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2133 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2136 h
->flags
|= HTML_NOSPACE
;
2137 print_text(h
, n
->next
? "," : ".");
2143 mdoc_bk_pre(MDOC_ARGS
)
2152 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2153 h
->flags
|= HTML_PREKEEP
;
2166 mdoc_bk_post(MDOC_ARGS
)
2169 if (MDOC_BODY
== n
->type
)
2170 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2176 mdoc_quote_pre(MDOC_ARGS
)
2178 struct htmlpair tag
;
2180 if (MDOC_BODY
!= n
->type
)
2187 print_text(h
, "\\(la");
2192 print_text(h
, "\\(lC");
2197 print_text(h
, "\\(lB");
2202 print_text(h
, "\\(lB");
2203 h
->flags
|= HTML_NOSPACE
;
2204 PAIR_CLASS_INIT(&tag
, "opt");
2205 print_otag(h
, TAG_SPAN
, 1, &tag
);
2214 print_text(h
, "\\(lq");
2222 print_text(h
, "\\(oq");
2223 h
->flags
|= HTML_NOSPACE
;
2224 PAIR_CLASS_INIT(&tag
, "lit");
2225 print_otag(h
, TAG_CODE
, 1, &tag
);
2230 print_text(h
, "\\(oq");
2237 h
->flags
|= HTML_NOSPACE
;
2244 mdoc_quote_post(MDOC_ARGS
)
2247 if (MDOC_BODY
!= n
->type
)
2250 h
->flags
|= HTML_NOSPACE
;
2256 print_text(h
, "\\(ra");
2261 print_text(h
, "\\(rC");
2270 print_text(h
, "\\(rB");
2279 print_text(h
, "\\(rq");
2291 print_text(h
, "\\(aq");