1 /* $Id: mdoc_html.c,v 1.198 2014/08/14 00:31:43 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
30 #include "mandoc_aux.h"
38 #define MDOC_ARGS const struct mdoc_meta *meta, \
39 const struct mdoc_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static void print_mdoc(MDOC_ARGS
);
52 static void print_mdoc_head(MDOC_ARGS
);
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
55 static void synopsis_pre(struct html
*,
56 const struct mdoc_node
*);
58 static void a2width(const char *, struct roffsu
*);
59 static void a2offs(const char *, struct roffsu
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static int mdoc_ar_pre(MDOC_ARGS
);
70 static int mdoc_bd_pre(MDOC_ARGS
);
71 static int mdoc_bf_pre(MDOC_ARGS
);
72 static void mdoc_bk_post(MDOC_ARGS
);
73 static int mdoc_bk_pre(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static int mdoc_bt_pre(MDOC_ARGS
);
76 static int mdoc_bx_pre(MDOC_ARGS
);
77 static int mdoc_cd_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_pre(MDOC_ARGS
);
86 static int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_igndelim_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_pre(MDOC_ARGS
);
95 static int mdoc_lb_pre(MDOC_ARGS
);
96 static int mdoc_li_pre(MDOC_ARGS
);
97 static int mdoc_lk_pre(MDOC_ARGS
);
98 static int mdoc_mt_pre(MDOC_ARGS
);
99 static int mdoc_ms_pre(MDOC_ARGS
);
100 static int mdoc_nd_pre(MDOC_ARGS
);
101 static int mdoc_nm_pre(MDOC_ARGS
);
102 static int mdoc_ns_pre(MDOC_ARGS
);
103 static int mdoc_pa_pre(MDOC_ARGS
);
104 static void mdoc_pf_post(MDOC_ARGS
);
105 static int mdoc_pp_pre(MDOC_ARGS
);
106 static void mdoc_quote_post(MDOC_ARGS
);
107 static int mdoc_quote_pre(MDOC_ARGS
);
108 static int mdoc_rs_pre(MDOC_ARGS
);
109 static int mdoc_rv_pre(MDOC_ARGS
);
110 static int mdoc_sh_pre(MDOC_ARGS
);
111 static int mdoc_skip_pre(MDOC_ARGS
);
112 static int mdoc_sm_pre(MDOC_ARGS
);
113 static int mdoc_sp_pre(MDOC_ARGS
);
114 static int mdoc_ss_pre(MDOC_ARGS
);
115 static int mdoc_sx_pre(MDOC_ARGS
);
116 static int mdoc_sy_pre(MDOC_ARGS
);
117 static int mdoc_ud_pre(MDOC_ARGS
);
118 static int mdoc_va_pre(MDOC_ARGS
);
119 static int mdoc_vt_pre(MDOC_ARGS
);
120 static int mdoc_xr_pre(MDOC_ARGS
);
121 static int mdoc_xx_pre(MDOC_ARGS
);
123 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
124 {mdoc_ap_pre
, NULL
}, /* Ap */
125 {NULL
, NULL
}, /* Dd */
126 {NULL
, NULL
}, /* Dt */
127 {NULL
, NULL
}, /* Os */
128 {mdoc_sh_pre
, NULL
}, /* Sh */
129 {mdoc_ss_pre
, NULL
}, /* Ss */
130 {mdoc_pp_pre
, NULL
}, /* Pp */
131 {mdoc_d1_pre
, NULL
}, /* D1 */
132 {mdoc_d1_pre
, NULL
}, /* Dl */
133 {mdoc_bd_pre
, NULL
}, /* Bd */
134 {NULL
, NULL
}, /* Ed */
135 {mdoc_bl_pre
, NULL
}, /* Bl */
136 {NULL
, NULL
}, /* El */
137 {mdoc_it_pre
, NULL
}, /* It */
138 {mdoc_ad_pre
, NULL
}, /* Ad */
139 {mdoc_an_pre
, NULL
}, /* An */
140 {mdoc_ar_pre
, NULL
}, /* Ar */
141 {mdoc_cd_pre
, NULL
}, /* Cd */
142 {mdoc_fl_pre
, NULL
}, /* Cm */
143 {mdoc_dv_pre
, NULL
}, /* Dv */
144 {mdoc_er_pre
, NULL
}, /* Er */
145 {mdoc_ev_pre
, NULL
}, /* Ev */
146 {mdoc_ex_pre
, NULL
}, /* Ex */
147 {mdoc_fa_pre
, NULL
}, /* Fa */
148 {mdoc_fd_pre
, NULL
}, /* Fd */
149 {mdoc_fl_pre
, NULL
}, /* Fl */
150 {mdoc_fn_pre
, NULL
}, /* Fn */
151 {mdoc_ft_pre
, NULL
}, /* Ft */
152 {mdoc_ic_pre
, NULL
}, /* Ic */
153 {mdoc_in_pre
, NULL
}, /* In */
154 {mdoc_li_pre
, NULL
}, /* Li */
155 {mdoc_nd_pre
, NULL
}, /* Nd */
156 {mdoc_nm_pre
, NULL
}, /* Nm */
157 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
158 {mdoc_ft_pre
, NULL
}, /* Ot */
159 {mdoc_pa_pre
, NULL
}, /* Pa */
160 {mdoc_rv_pre
, NULL
}, /* Rv */
161 {NULL
, NULL
}, /* St */
162 {mdoc_va_pre
, NULL
}, /* Va */
163 {mdoc_vt_pre
, NULL
}, /* Vt */
164 {mdoc_xr_pre
, NULL
}, /* Xr */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
176 {NULL
, NULL
}, /* Ac */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
179 {NULL
, NULL
}, /* At */
180 {NULL
, NULL
}, /* Bc */
181 {mdoc_bf_pre
, NULL
}, /* Bf */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
184 {mdoc_xx_pre
, NULL
}, /* Bsx */
185 {mdoc_bx_pre
, NULL
}, /* Bx */
186 {NULL
, NULL
}, /* Db */
187 {NULL
, NULL
}, /* Dc */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
190 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 {NULL
, NULL
}, /* Ef */
192 {mdoc_em_pre
, NULL
}, /* Em */
193 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
194 {mdoc_xx_pre
, NULL
}, /* Fx */
195 {mdoc_ms_pre
, NULL
}, /* Ms */
196 {mdoc_igndelim_pre
, NULL
}, /* No */
197 {mdoc_ns_pre
, NULL
}, /* Ns */
198 {mdoc_xx_pre
, NULL
}, /* Nx */
199 {mdoc_xx_pre
, NULL
}, /* Ox */
200 {NULL
, NULL
}, /* Pc */
201 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
204 {NULL
, NULL
}, /* Qc */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
208 {NULL
, NULL
}, /* Re */
209 {mdoc_rs_pre
, NULL
}, /* Rs */
210 {NULL
, NULL
}, /* Sc */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
213 {mdoc_sm_pre
, NULL
}, /* Sm */
214 {mdoc_sx_pre
, NULL
}, /* Sx */
215 {mdoc_sy_pre
, NULL
}, /* Sy */
216 {NULL
, NULL
}, /* Tn */
217 {mdoc_xx_pre
, NULL
}, /* Ux */
218 {NULL
, NULL
}, /* Xc */
219 {NULL
, NULL
}, /* Xo */
220 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
221 {NULL
, NULL
}, /* Fc */
222 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
223 {NULL
, NULL
}, /* Oc */
224 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
225 {NULL
, NULL
}, /* Ek */
226 {mdoc_bt_pre
, NULL
}, /* Bt */
227 {NULL
, NULL
}, /* Hf */
228 {mdoc_em_pre
, NULL
}, /* Fr */
229 {mdoc_ud_pre
, NULL
}, /* Ud */
230 {mdoc_lb_pre
, NULL
}, /* Lb */
231 {mdoc_pp_pre
, NULL
}, /* Lp */
232 {mdoc_lk_pre
, NULL
}, /* Lk */
233 {mdoc_mt_pre
, NULL
}, /* Mt */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
236 {NULL
, NULL
}, /* Brc */
237 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
238 {mdoc_skip_pre
, NULL
}, /* Es */
239 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
240 {mdoc_xx_pre
, NULL
}, /* Dx */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
242 {mdoc_sp_pre
, NULL
}, /* br */
243 {mdoc_sp_pre
, NULL
}, /* sp */
244 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
245 {NULL
, NULL
}, /* Ta */
246 {mdoc_skip_pre
, NULL
}, /* ll */
249 static const char * const lists
[LIST_MAX
] = {
266 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
269 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
275 * Calculate the scaling unit passed in a `-width' argument. This uses
276 * either a native scaling unit (e.g., 1i, 2m) or the string length of
280 a2width(const char *p
, struct roffsu
*su
)
283 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
285 su
->scale
= html_strlen(p
);
290 * See the same function in mdoc_term.c for documentation.
293 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
296 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
299 if (n
->prev
->tok
== n
->tok
&&
303 print_otag(h
, TAG_BR
, 0, NULL
);
307 switch (n
->prev
->tok
) {
317 print_otag(h
, TAG_P
, 0, NULL
);
320 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
321 print_otag(h
, TAG_P
, 0, NULL
);
326 print_otag(h
, TAG_BR
, 0, NULL
);
332 * Calculate the scaling unit passed in an `-offset' argument. This
333 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
334 * predefined strings (indent, etc.), or the string length of the value.
337 a2offs(const char *p
, struct roffsu
*su
)
340 /* FIXME: "right"? */
342 if (0 == strcmp(p
, "left"))
343 SCALE_HS_INIT(su
, 0);
344 else if (0 == strcmp(p
, "indent"))
345 SCALE_HS_INIT(su
, INDENT
);
346 else if (0 == strcmp(p
, "indent-two"))
347 SCALE_HS_INIT(su
, INDENT
* 2);
348 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
349 SCALE_HS_INIT(su
, html_strlen(p
));
353 print_mdoc(MDOC_ARGS
)
358 PAIR_CLASS_INIT(&tag
, "mandoc");
360 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
362 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
363 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
364 print_mdoc_head(meta
, n
, h
);
366 print_otag(h
, TAG_BODY
, 0, NULL
);
367 print_otag(h
, TAG_DIV
, 1, &tag
);
369 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
371 print_mdoc_nodelist(meta
, n
, h
);
376 print_mdoc_head(MDOC_ARGS
)
381 bufcat(h
, meta
->title
);
383 bufcat_fmt(h
, "(%s)", meta
->msec
);
385 bufcat_fmt(h
, " (%s)", meta
->arch
);
387 print_otag(h
, TAG_TITLE
, 0, NULL
);
388 print_text(h
, h
->buf
);
392 print_mdoc_nodelist(MDOC_ARGS
)
395 print_mdoc_node(meta
, n
, h
);
397 print_mdoc_nodelist(meta
, n
->next
, h
);
401 print_mdoc_node(MDOC_ARGS
)
411 child
= mdoc_root_pre(meta
, n
, h
);
414 /* No tables in this mode... */
415 assert(NULL
== h
->tblt
);
418 * Make sure that if we're in a literal mode already
419 * (i.e., within a <PRE>) don't print the newline.
421 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
422 if ( ! (HTML_LITERAL
& h
->flags
))
423 print_otag(h
, TAG_BR
, 0, NULL
);
424 if (MDOC_DELIMC
& n
->flags
)
425 h
->flags
|= HTML_NOSPACE
;
426 print_text(h
, n
->string
);
427 if (MDOC_DELIMO
& n
->flags
)
428 h
->flags
|= HTML_NOSPACE
;
431 print_eqn(h
, n
->eqn
);
435 * This will take care of initialising all of the table
436 * state data for the first table, then tearing it down
439 print_tbl(h
, n
->span
);
443 * Close out the current table, if it's open, and unset
444 * the "meta" table state. This will be reopened on the
445 * next table element.
452 assert(NULL
== h
->tblt
);
453 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
454 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
458 if (HTML_KEEP
& h
->flags
) {
459 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
460 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
461 h
->flags
&= ~HTML_KEEP
;
462 h
->flags
|= HTML_PREKEEP
;
466 if (child
&& n
->child
)
467 print_mdoc_nodelist(meta
, n
->child
, h
);
473 mdoc_root_post(meta
, n
, h
);
478 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
479 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
485 mdoc_root_post(MDOC_ARGS
)
487 struct htmlpair tag
[3];
490 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
491 PAIR_CLASS_INIT(&tag
[1], "foot");
492 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
493 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
494 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
495 print_otag(h
, TAG_COL
, 1, tag
);
496 print_otag(h
, TAG_COL
, 1, tag
);
498 print_otag(h
, TAG_TBODY
, 0, NULL
);
500 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
502 PAIR_CLASS_INIT(&tag
[0], "foot-date");
503 print_otag(h
, TAG_TD
, 1, tag
);
504 print_text(h
, meta
->date
);
507 PAIR_CLASS_INIT(&tag
[0], "foot-os");
508 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
509 print_otag(h
, TAG_TD
, 2, tag
);
510 print_text(h
, meta
->os
);
515 mdoc_root_pre(MDOC_ARGS
)
517 struct htmlpair tag
[3];
519 char *volume
, *title
;
521 if (NULL
== meta
->arch
)
522 volume
= mandoc_strdup(meta
->vol
);
524 mandoc_asprintf(&volume
, "%s (%s)",
525 meta
->vol
, meta
->arch
);
527 if (NULL
== meta
->msec
)
528 title
= mandoc_strdup(meta
->title
);
530 mandoc_asprintf(&title
, "%s(%s)",
531 meta
->title
, meta
->msec
);
533 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
534 PAIR_CLASS_INIT(&tag
[1], "head");
535 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
536 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
537 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
538 print_otag(h
, TAG_COL
, 1, tag
);
539 print_otag(h
, TAG_COL
, 1, tag
);
540 print_otag(h
, TAG_COL
, 1, tag
);
542 print_otag(h
, TAG_TBODY
, 0, NULL
);
544 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
546 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
547 print_otag(h
, TAG_TD
, 1, tag
);
548 print_text(h
, title
);
551 PAIR_CLASS_INIT(&tag
[0], "head-vol");
552 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
553 print_otag(h
, TAG_TD
, 2, tag
);
554 print_text(h
, volume
);
557 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
558 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
559 print_otag(h
, TAG_TD
, 2, tag
);
560 print_text(h
, title
);
569 mdoc_sh_pre(MDOC_ARGS
)
573 if (MDOC_BLOCK
== n
->type
) {
574 PAIR_CLASS_INIT(&tag
, "section");
575 print_otag(h
, TAG_DIV
, 1, &tag
);
577 } else if (MDOC_BODY
== n
->type
)
583 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
584 bufcat_id(h
, n
->string
);
585 if (NULL
!= (n
= n
->next
))
590 PAIR_ID_INIT(&tag
, h
->buf
);
591 print_otag(h
, TAG_H1
, 1, &tag
);
593 print_otag(h
, TAG_H1
, 0, NULL
);
599 mdoc_ss_pre(MDOC_ARGS
)
603 if (MDOC_BLOCK
== n
->type
) {
604 PAIR_CLASS_INIT(&tag
, "subsection");
605 print_otag(h
, TAG_DIV
, 1, &tag
);
607 } else if (MDOC_BODY
== n
->type
)
613 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
614 bufcat_id(h
, n
->string
);
615 if (NULL
!= (n
= n
->next
))
620 PAIR_ID_INIT(&tag
, h
->buf
);
621 print_otag(h
, TAG_H2
, 1, &tag
);
623 print_otag(h
, TAG_H2
, 0, NULL
);
629 mdoc_fl_pre(MDOC_ARGS
)
633 PAIR_CLASS_INIT(&tag
, "flag");
634 print_otag(h
, TAG_B
, 1, &tag
);
636 /* `Cm' has no leading hyphen. */
638 if (MDOC_Cm
== n
->tok
)
641 print_text(h
, "\\-");
644 h
->flags
|= HTML_NOSPACE
;
645 else if (n
->next
&& n
->next
->line
== n
->line
)
646 h
->flags
|= HTML_NOSPACE
;
652 mdoc_nd_pre(MDOC_ARGS
)
656 if (MDOC_BODY
!= n
->type
)
659 /* XXX: this tag in theory can contain block elements. */
661 print_text(h
, "\\(em");
662 PAIR_CLASS_INIT(&tag
, "desc");
663 print_otag(h
, TAG_SPAN
, 1, &tag
);
668 mdoc_nm_pre(MDOC_ARGS
)
677 PAIR_CLASS_INIT(&tag
, "name");
678 print_otag(h
, TAG_B
, 1, &tag
);
679 if (NULL
== n
->child
&& meta
->name
)
680 print_text(h
, meta
->name
);
683 print_otag(h
, TAG_TD
, 0, NULL
);
684 if (NULL
== n
->child
&& meta
->name
)
685 print_text(h
, meta
->name
);
688 print_otag(h
, TAG_TD
, 0, NULL
);
695 PAIR_CLASS_INIT(&tag
, "synopsis");
696 print_otag(h
, TAG_TABLE
, 1, &tag
);
698 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
699 if (MDOC_TEXT
== n
->type
)
700 len
+= html_strlen(n
->string
);
702 if (0 == len
&& meta
->name
)
703 len
= html_strlen(meta
->name
);
705 SCALE_HS_INIT(&su
, len
);
707 bufcat_su(h
, "width", &su
);
708 PAIR_STYLE_INIT(&tag
, h
);
709 print_otag(h
, TAG_COL
, 1, &tag
);
710 print_otag(h
, TAG_COL
, 0, NULL
);
711 print_otag(h
, TAG_TBODY
, 0, NULL
);
712 print_otag(h
, TAG_TR
, 0, NULL
);
717 mdoc_xr_pre(MDOC_ARGS
)
719 struct htmlpair tag
[2];
721 if (NULL
== n
->child
)
724 PAIR_CLASS_INIT(&tag
[0], "link-man");
727 buffmt_man(h
, n
->child
->string
,
729 n
->child
->next
->string
: NULL
);
730 PAIR_HREF_INIT(&tag
[1], h
->buf
);
731 print_otag(h
, TAG_A
, 2, tag
);
733 print_otag(h
, TAG_A
, 1, tag
);
736 print_text(h
, n
->string
);
738 if (NULL
== (n
= n
->next
))
741 h
->flags
|= HTML_NOSPACE
;
743 h
->flags
|= HTML_NOSPACE
;
744 print_text(h
, n
->string
);
745 h
->flags
|= HTML_NOSPACE
;
751 mdoc_ns_pre(MDOC_ARGS
)
754 if ( ! (MDOC_LINE
& n
->flags
))
755 h
->flags
|= HTML_NOSPACE
;
760 mdoc_ar_pre(MDOC_ARGS
)
764 PAIR_CLASS_INIT(&tag
, "arg");
765 print_otag(h
, TAG_I
, 1, &tag
);
770 mdoc_xx_pre(MDOC_ARGS
)
799 PAIR_CLASS_INIT(&tag
, "unix");
800 print_otag(h
, TAG_SPAN
, 1, &tag
);
805 h
->flags
|= HTML_KEEP
;
806 print_text(h
, n
->child
->string
);
813 mdoc_bx_pre(MDOC_ARGS
)
817 PAIR_CLASS_INIT(&tag
, "unix");
818 print_otag(h
, TAG_SPAN
, 1, &tag
);
820 if (NULL
!= (n
= n
->child
)) {
821 print_text(h
, n
->string
);
822 h
->flags
|= HTML_NOSPACE
;
823 print_text(h
, "BSD");
825 print_text(h
, "BSD");
829 if (NULL
!= (n
= n
->next
)) {
830 h
->flags
|= HTML_NOSPACE
;
832 h
->flags
|= HTML_NOSPACE
;
833 print_text(h
, n
->string
);
840 mdoc_it_pre(MDOC_ARGS
)
844 struct htmlpair tag
[2];
845 const struct mdoc_node
*bl
;
848 while (bl
&& MDOC_Bl
!= bl
->tok
)
853 type
= bl
->norm
->Bl
.type
;
856 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
860 if (MDOC_HEAD
== n
->type
) {
881 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
882 bufcat_su(h
, "margin-top", &su
);
883 PAIR_STYLE_INIT(&tag
[1], h
);
884 print_otag(h
, TAG_DT
, 2, tag
);
885 if (LIST_diag
!= type
)
887 PAIR_CLASS_INIT(&tag
[0], "diag");
888 print_otag(h
, TAG_B
, 1, tag
);
895 } else if (MDOC_BODY
== n
->type
) {
906 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
907 bufcat_su(h
, "margin-top", &su
);
908 PAIR_STYLE_INIT(&tag
[1], h
);
909 print_otag(h
, TAG_LI
, 2, tag
);
920 if (NULL
== bl
->norm
->Bl
.width
) {
921 print_otag(h
, TAG_DD
, 1, tag
);
924 a2width(bl
->norm
->Bl
.width
, &su
);
925 bufcat_su(h
, "margin-left", &su
);
926 PAIR_STYLE_INIT(&tag
[1], h
);
927 print_otag(h
, TAG_DD
, 2, tag
);
930 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
931 bufcat_su(h
, "margin-top", &su
);
932 PAIR_STYLE_INIT(&tag
[1], h
);
933 print_otag(h
, TAG_TD
, 2, tag
);
941 print_otag(h
, TAG_TR
, 1, tag
);
952 mdoc_bl_pre(MDOC_ARGS
)
955 struct htmlpair tag
[3];
959 if (MDOC_BODY
== n
->type
) {
960 if (LIST_column
== n
->norm
->Bl
.type
)
961 print_otag(h
, TAG_TBODY
, 0, NULL
);
965 if (MDOC_HEAD
== n
->type
) {
966 if (LIST_column
!= n
->norm
->Bl
.type
)
970 * For each column, print out the <COL> tag with our
971 * suggested width. The last column gets min-width, as
972 * in terminal mode it auto-sizes to the width of the
973 * screen and we want to preserve that behaviour.
976 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
978 a2width(n
->norm
->Bl
.cols
[i
], &su
);
979 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
980 bufcat_su(h
, "width", &su
);
982 bufcat_su(h
, "min-width", &su
);
983 PAIR_STYLE_INIT(&tag
[0], h
);
984 print_otag(h
, TAG_COL
, 1, tag
);
990 SCALE_VS_INIT(&su
, 0);
992 bufcat_su(h
, "margin-top", &su
);
993 bufcat_su(h
, "margin-bottom", &su
);
994 PAIR_STYLE_INIT(&tag
[0], h
);
996 assert(lists
[n
->norm
->Bl
.type
]);
997 (void)strlcpy(buf
, "list ", BUFSIZ
);
998 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
999 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1001 /* Set the block's left-hand margin. */
1003 if (n
->norm
->Bl
.offs
) {
1004 a2offs(n
->norm
->Bl
.offs
, &su
);
1005 bufcat_su(h
, "margin-left", &su
);
1008 switch (n
->norm
->Bl
.type
) {
1016 print_otag(h
, TAG_UL
, 2, tag
);
1019 print_otag(h
, TAG_OL
, 2, tag
);
1030 print_otag(h
, TAG_DL
, 2, tag
);
1033 print_otag(h
, TAG_TABLE
, 2, tag
);
1044 mdoc_ex_pre(MDOC_ARGS
)
1047 struct htmlpair tag
;
1051 print_otag(h
, TAG_BR
, 0, NULL
);
1053 PAIR_CLASS_INIT(&tag
, "utility");
1055 print_text(h
, "The");
1058 for (n
= n
->child
; n
; n
= n
->next
) {
1059 assert(MDOC_TEXT
== n
->type
);
1061 t
= print_otag(h
, TAG_B
, 1, &tag
);
1062 print_text(h
, n
->string
);
1065 if (nchild
> 2 && n
->next
) {
1066 h
->flags
|= HTML_NOSPACE
;
1070 if (n
->next
&& NULL
== n
->next
->next
)
1071 print_text(h
, "and");
1075 print_text(h
, "utilities exit\\~0");
1077 print_text(h
, "utility exits\\~0");
1079 print_text(h
, "on success, and\\~>0 if an error occurs.");
1084 mdoc_em_pre(MDOC_ARGS
)
1086 struct htmlpair tag
;
1088 PAIR_CLASS_INIT(&tag
, "emph");
1089 print_otag(h
, TAG_SPAN
, 1, &tag
);
1094 mdoc_d1_pre(MDOC_ARGS
)
1096 struct htmlpair tag
[2];
1099 if (MDOC_BLOCK
!= n
->type
)
1102 SCALE_VS_INIT(&su
, 0);
1104 bufcat_su(h
, "margin-top", &su
);
1105 bufcat_su(h
, "margin-bottom", &su
);
1106 PAIR_STYLE_INIT(&tag
[0], h
);
1107 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1109 /* BLOCKQUOTE needs a block body. */
1111 PAIR_CLASS_INIT(&tag
[0], "display");
1112 print_otag(h
, TAG_DIV
, 1, tag
);
1114 if (MDOC_Dl
== n
->tok
) {
1115 PAIR_CLASS_INIT(&tag
[0], "lit");
1116 print_otag(h
, TAG_CODE
, 1, tag
);
1123 mdoc_sx_pre(MDOC_ARGS
)
1125 struct htmlpair tag
[2];
1130 for (n
= n
->child
; n
; ) {
1131 bufcat_id(h
, n
->string
);
1132 if (NULL
!= (n
= n
->next
))
1136 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1137 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1139 print_otag(h
, TAG_I
, 1, tag
);
1140 print_otag(h
, TAG_A
, 2, tag
);
1145 mdoc_bd_pre(MDOC_ARGS
)
1147 struct htmlpair tag
[2];
1149 const struct mdoc_node
*nn
;
1152 if (MDOC_HEAD
== n
->type
)
1155 if (MDOC_BLOCK
== n
->type
) {
1156 comp
= n
->norm
->Bd
.comp
;
1157 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1158 if (MDOC_BLOCK
!= nn
->type
)
1160 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1166 print_otag(h
, TAG_P
, 0, NULL
);
1170 SCALE_HS_INIT(&su
, 0);
1171 if (n
->norm
->Bd
.offs
)
1172 a2offs(n
->norm
->Bd
.offs
, &su
);
1175 bufcat_su(h
, "margin-left", &su
);
1176 PAIR_STYLE_INIT(&tag
[0], h
);
1178 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1179 DISP_literal
!= n
->norm
->Bd
.type
) {
1180 PAIR_CLASS_INIT(&tag
[1], "display");
1181 print_otag(h
, TAG_DIV
, 2, tag
);
1185 PAIR_CLASS_INIT(&tag
[1], "lit display");
1186 print_otag(h
, TAG_PRE
, 2, tag
);
1188 /* This can be recursive: save & set our literal state. */
1190 sv
= h
->flags
& HTML_LITERAL
;
1191 h
->flags
|= HTML_LITERAL
;
1193 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1194 print_mdoc_node(meta
, nn
, h
);
1196 * If the printed node flushes its own line, then we
1197 * needn't do it here as well. This is hacky, but the
1198 * notion of selective eoln whitespace is pretty dumb
1199 * anyway, so don't sweat it.
1221 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1224 print_text(h
, "\n");
1226 h
->flags
|= HTML_NOSPACE
;
1230 h
->flags
&= ~HTML_LITERAL
;
1236 mdoc_pa_pre(MDOC_ARGS
)
1238 struct htmlpair tag
;
1240 PAIR_CLASS_INIT(&tag
, "file");
1241 print_otag(h
, TAG_I
, 1, &tag
);
1246 mdoc_ad_pre(MDOC_ARGS
)
1248 struct htmlpair tag
;
1250 PAIR_CLASS_INIT(&tag
, "addr");
1251 print_otag(h
, TAG_I
, 1, &tag
);
1256 mdoc_an_pre(MDOC_ARGS
)
1258 struct htmlpair tag
;
1260 /* TODO: -split and -nosplit (see termp_an_pre()). */
1262 PAIR_CLASS_INIT(&tag
, "author");
1263 print_otag(h
, TAG_SPAN
, 1, &tag
);
1268 mdoc_cd_pre(MDOC_ARGS
)
1270 struct htmlpair tag
;
1273 PAIR_CLASS_INIT(&tag
, "config");
1274 print_otag(h
, TAG_B
, 1, &tag
);
1279 mdoc_dv_pre(MDOC_ARGS
)
1281 struct htmlpair tag
;
1283 PAIR_CLASS_INIT(&tag
, "define");
1284 print_otag(h
, TAG_SPAN
, 1, &tag
);
1289 mdoc_ev_pre(MDOC_ARGS
)
1291 struct htmlpair tag
;
1293 PAIR_CLASS_INIT(&tag
, "env");
1294 print_otag(h
, TAG_SPAN
, 1, &tag
);
1299 mdoc_er_pre(MDOC_ARGS
)
1301 struct htmlpair tag
;
1303 PAIR_CLASS_INIT(&tag
, "errno");
1304 print_otag(h
, TAG_SPAN
, 1, &tag
);
1309 mdoc_fa_pre(MDOC_ARGS
)
1311 const struct mdoc_node
*nn
;
1312 struct htmlpair tag
;
1315 PAIR_CLASS_INIT(&tag
, "farg");
1316 if (n
->parent
->tok
!= MDOC_Fo
) {
1317 print_otag(h
, TAG_I
, 1, &tag
);
1321 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1322 t
= print_otag(h
, TAG_I
, 1, &tag
);
1323 print_text(h
, nn
->string
);
1326 h
->flags
|= HTML_NOSPACE
;
1331 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1332 h
->flags
|= HTML_NOSPACE
;
1340 mdoc_fd_pre(MDOC_ARGS
)
1342 struct htmlpair tag
[2];
1350 if (NULL
== (n
= n
->child
))
1353 assert(MDOC_TEXT
== n
->type
);
1355 if (strcmp(n
->string
, "#include")) {
1356 PAIR_CLASS_INIT(&tag
[0], "macro");
1357 print_otag(h
, TAG_B
, 1, tag
);
1361 PAIR_CLASS_INIT(&tag
[0], "includes");
1362 print_otag(h
, TAG_B
, 1, tag
);
1363 print_text(h
, n
->string
);
1365 if (NULL
!= (n
= n
->next
)) {
1366 assert(MDOC_TEXT
== n
->type
);
1369 * XXX This is broken and not easy to fix.
1370 * When using -Oincludes, truncation may occur.
1371 * Dynamic allocation wouldn't help because
1372 * passing long strings to buffmt_includes()
1373 * does not work either.
1376 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1377 n
->string
+ 1 : n
->string
, BUFSIZ
);
1380 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1383 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1386 if (h
->base_includes
) {
1387 buffmt_includes(h
, buf
);
1388 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1392 t
= print_otag(h
, TAG_A
, i
, tag
);
1393 print_text(h
, n
->string
);
1399 for ( ; n
; n
= n
->next
) {
1400 assert(MDOC_TEXT
== n
->type
);
1401 print_text(h
, n
->string
);
1408 mdoc_vt_pre(MDOC_ARGS
)
1410 struct htmlpair tag
;
1412 if (MDOC_BLOCK
== n
->type
) {
1415 } else if (MDOC_ELEM
== n
->type
) {
1417 } else if (MDOC_HEAD
== n
->type
)
1420 PAIR_CLASS_INIT(&tag
, "type");
1421 print_otag(h
, TAG_SPAN
, 1, &tag
);
1426 mdoc_ft_pre(MDOC_ARGS
)
1428 struct htmlpair tag
;
1431 PAIR_CLASS_INIT(&tag
, "ftype");
1432 print_otag(h
, TAG_I
, 1, &tag
);
1437 mdoc_fn_pre(MDOC_ARGS
)
1440 struct htmlpair tag
[2];
1442 const char *sp
, *ep
;
1445 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1448 /* Split apart into type and name. */
1449 assert(n
->child
->string
);
1450 sp
= n
->child
->string
;
1452 ep
= strchr(sp
, ' ');
1454 PAIR_CLASS_INIT(&tag
[0], "ftype");
1455 t
= print_otag(h
, TAG_I
, 1, tag
);
1458 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1459 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1461 print_text(h
, nbuf
);
1463 ep
= strchr(sp
, ' ');
1468 PAIR_CLASS_INIT(&tag
[0], "fname");
1471 * FIXME: only refer to IDs that we know exist.
1475 if (MDOC_SYNPRETTY
& n
->flags
) {
1477 html_idcat(nbuf
, sp
, BUFSIZ
);
1478 PAIR_ID_INIT(&tag
[1], nbuf
);
1480 strlcpy(nbuf
, "#", BUFSIZ
);
1481 html_idcat(nbuf
, sp
, BUFSIZ
);
1482 PAIR_HREF_INIT(&tag
[1], nbuf
);
1486 t
= print_otag(h
, TAG_B
, 1, tag
);
1493 h
->flags
|= HTML_NOSPACE
;
1495 h
->flags
|= HTML_NOSPACE
;
1497 PAIR_CLASS_INIT(&tag
[0], "farg");
1499 bufcat_style(h
, "white-space", "nowrap");
1500 PAIR_STYLE_INIT(&tag
[1], h
);
1502 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1504 if (MDOC_SYNPRETTY
& n
->flags
)
1506 t
= print_otag(h
, TAG_I
, i
, tag
);
1507 print_text(h
, n
->string
);
1510 h
->flags
|= HTML_NOSPACE
;
1515 h
->flags
|= HTML_NOSPACE
;
1519 h
->flags
|= HTML_NOSPACE
;
1527 mdoc_sm_pre(MDOC_ARGS
)
1530 if (NULL
== n
->child
)
1531 h
->flags
^= HTML_NONOSPACE
;
1532 else if (0 == strcmp("on", n
->child
->string
))
1533 h
->flags
&= ~HTML_NONOSPACE
;
1535 h
->flags
|= HTML_NONOSPACE
;
1537 if ( ! (HTML_NONOSPACE
& h
->flags
))
1538 h
->flags
&= ~HTML_NOSPACE
;
1544 mdoc_skip_pre(MDOC_ARGS
)
1551 mdoc_pp_pre(MDOC_ARGS
)
1554 print_otag(h
, TAG_P
, 0, NULL
);
1559 mdoc_sp_pre(MDOC_ARGS
)
1562 struct htmlpair tag
;
1564 SCALE_VS_INIT(&su
, 1);
1566 if (MDOC_sp
== n
->tok
) {
1567 if (NULL
!= (n
= n
->child
))
1568 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1569 SCALE_VS_INIT(&su
, atoi(n
->string
));
1574 bufcat_su(h
, "height", &su
);
1575 PAIR_STYLE_INIT(&tag
, h
);
1576 print_otag(h
, TAG_DIV
, 1, &tag
);
1578 /* So the div isn't empty: */
1579 print_text(h
, "\\~");
1586 mdoc_lk_pre(MDOC_ARGS
)
1588 struct htmlpair tag
[2];
1590 if (NULL
== (n
= n
->child
))
1593 assert(MDOC_TEXT
== n
->type
);
1595 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1596 PAIR_HREF_INIT(&tag
[1], n
->string
);
1598 print_otag(h
, TAG_A
, 2, tag
);
1600 if (NULL
== n
->next
)
1601 print_text(h
, n
->string
);
1603 for (n
= n
->next
; n
; n
= n
->next
)
1604 print_text(h
, n
->string
);
1610 mdoc_mt_pre(MDOC_ARGS
)
1612 struct htmlpair tag
[2];
1615 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1617 for (n
= n
->child
; n
; n
= n
->next
) {
1618 assert(MDOC_TEXT
== n
->type
);
1621 bufcat(h
, "mailto:");
1622 bufcat(h
, n
->string
);
1624 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1625 t
= print_otag(h
, TAG_A
, 2, tag
);
1626 print_text(h
, n
->string
);
1634 mdoc_fo_pre(MDOC_ARGS
)
1636 struct htmlpair tag
;
1639 if (MDOC_BODY
== n
->type
) {
1640 h
->flags
|= HTML_NOSPACE
;
1642 h
->flags
|= HTML_NOSPACE
;
1644 } else if (MDOC_BLOCK
== n
->type
) {
1649 /* XXX: we drop non-initial arguments as per groff. */
1652 assert(n
->child
->string
);
1654 PAIR_CLASS_INIT(&tag
, "fname");
1655 t
= print_otag(h
, TAG_B
, 1, &tag
);
1656 print_text(h
, n
->child
->string
);
1662 mdoc_fo_post(MDOC_ARGS
)
1665 if (MDOC_BODY
!= n
->type
)
1667 h
->flags
|= HTML_NOSPACE
;
1669 h
->flags
|= HTML_NOSPACE
;
1674 mdoc_in_pre(MDOC_ARGS
)
1677 struct htmlpair tag
[2];
1682 PAIR_CLASS_INIT(&tag
[0], "includes");
1683 print_otag(h
, TAG_B
, 1, tag
);
1686 * The first argument of the `In' gets special treatment as
1687 * being a linked value. Subsequent values are printed
1688 * afterward. groff does similarly. This also handles the case
1692 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1693 print_text(h
, "#include");
1696 h
->flags
|= HTML_NOSPACE
;
1698 if (NULL
!= (n
= n
->child
)) {
1699 assert(MDOC_TEXT
== n
->type
);
1701 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1704 if (h
->base_includes
) {
1705 buffmt_includes(h
, n
->string
);
1706 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1710 t
= print_otag(h
, TAG_A
, i
, tag
);
1711 print_text(h
, n
->string
);
1717 h
->flags
|= HTML_NOSPACE
;
1720 for ( ; n
; n
= n
->next
) {
1721 assert(MDOC_TEXT
== n
->type
);
1722 print_text(h
, n
->string
);
1729 mdoc_ic_pre(MDOC_ARGS
)
1731 struct htmlpair tag
;
1733 PAIR_CLASS_INIT(&tag
, "cmd");
1734 print_otag(h
, TAG_B
, 1, &tag
);
1739 mdoc_rv_pre(MDOC_ARGS
)
1741 struct htmlpair tag
;
1746 print_otag(h
, TAG_BR
, 0, NULL
);
1748 PAIR_CLASS_INIT(&tag
, "fname");
1752 print_text(h
, "The");
1754 for (n
= n
->child
; n
; n
= n
->next
) {
1755 t
= print_otag(h
, TAG_B
, 1, &tag
);
1756 print_text(h
, n
->string
);
1759 h
->flags
|= HTML_NOSPACE
;
1760 print_text(h
, "()");
1762 if (n
->next
== NULL
)
1766 h
->flags
|= HTML_NOSPACE
;
1769 if (n
->next
->next
== NULL
)
1770 print_text(h
, "and");
1774 print_text(h
, "functions return");
1776 print_text(h
, "function returns");
1778 print_text(h
, "the value\\~0 if successful;");
1780 print_text(h
, "Upon successful completion,"
1781 " the value\\~0 is returned;");
1783 print_text(h
, "otherwise the value\\~\\-1 is returned"
1784 " and the global variable");
1786 PAIR_CLASS_INIT(&tag
, "var");
1787 t
= print_otag(h
, TAG_B
, 1, &tag
);
1788 print_text(h
, "errno");
1790 print_text(h
, "is set to indicate the error.");
1795 mdoc_va_pre(MDOC_ARGS
)
1797 struct htmlpair tag
;
1799 PAIR_CLASS_INIT(&tag
, "var");
1800 print_otag(h
, TAG_B
, 1, &tag
);
1805 mdoc_ap_pre(MDOC_ARGS
)
1808 h
->flags
|= HTML_NOSPACE
;
1809 print_text(h
, "\\(aq");
1810 h
->flags
|= HTML_NOSPACE
;
1815 mdoc_bf_pre(MDOC_ARGS
)
1817 struct htmlpair tag
[2];
1820 if (MDOC_HEAD
== n
->type
)
1822 else if (MDOC_BODY
!= n
->type
)
1825 if (FONT_Em
== n
->norm
->Bf
.font
)
1826 PAIR_CLASS_INIT(&tag
[0], "emph");
1827 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1828 PAIR_CLASS_INIT(&tag
[0], "symb");
1829 else if (FONT_Li
== n
->norm
->Bf
.font
)
1830 PAIR_CLASS_INIT(&tag
[0], "lit");
1832 PAIR_CLASS_INIT(&tag
[0], "none");
1835 * We want this to be inline-formatted, but needs to be div to
1836 * accept block children.
1839 bufcat_style(h
, "display", "inline");
1840 SCALE_HS_INIT(&su
, 1);
1841 /* Needs a left-margin for spacing. */
1842 bufcat_su(h
, "margin-left", &su
);
1843 PAIR_STYLE_INIT(&tag
[1], h
);
1844 print_otag(h
, TAG_DIV
, 2, tag
);
1849 mdoc_ms_pre(MDOC_ARGS
)
1851 struct htmlpair tag
;
1853 PAIR_CLASS_INIT(&tag
, "symb");
1854 print_otag(h
, TAG_SPAN
, 1, &tag
);
1859 mdoc_igndelim_pre(MDOC_ARGS
)
1862 h
->flags
|= HTML_IGNDELIM
;
1867 mdoc_pf_post(MDOC_ARGS
)
1870 h
->flags
|= HTML_NOSPACE
;
1874 mdoc_rs_pre(MDOC_ARGS
)
1876 struct htmlpair tag
;
1878 if (MDOC_BLOCK
!= n
->type
)
1881 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1882 print_otag(h
, TAG_P
, 0, NULL
);
1884 PAIR_CLASS_INIT(&tag
, "ref");
1885 print_otag(h
, TAG_SPAN
, 1, &tag
);
1890 mdoc_li_pre(MDOC_ARGS
)
1892 struct htmlpair tag
;
1894 PAIR_CLASS_INIT(&tag
, "lit");
1895 print_otag(h
, TAG_CODE
, 1, &tag
);
1900 mdoc_sy_pre(MDOC_ARGS
)
1902 struct htmlpair tag
;
1904 PAIR_CLASS_INIT(&tag
, "symb");
1905 print_otag(h
, TAG_SPAN
, 1, &tag
);
1910 mdoc_bt_pre(MDOC_ARGS
)
1913 print_text(h
, "is currently in beta test.");
1918 mdoc_ud_pre(MDOC_ARGS
)
1921 print_text(h
, "currently under development.");
1926 mdoc_lb_pre(MDOC_ARGS
)
1928 struct htmlpair tag
;
1930 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1931 print_otag(h
, TAG_BR
, 0, NULL
);
1933 PAIR_CLASS_INIT(&tag
, "lib");
1934 print_otag(h
, TAG_SPAN
, 1, &tag
);
1939 mdoc__x_pre(MDOC_ARGS
)
1941 struct htmlpair tag
[2];
1948 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1949 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1950 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1951 print_text(h
, "and");
1954 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1958 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1961 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1964 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1968 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1978 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1981 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1984 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1987 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1990 PAIR_CLASS_INIT(&tag
[0], "link-ref");
1993 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2000 if (MDOC__U
!= n
->tok
) {
2001 print_otag(h
, t
, 1, tag
);
2005 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2006 print_otag(h
, TAG_A
, 2, tag
);
2012 mdoc__x_post(MDOC_ARGS
)
2015 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2016 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2017 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2022 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2025 h
->flags
|= HTML_NOSPACE
;
2026 print_text(h
, n
->next
? "," : ".");
2030 mdoc_bk_pre(MDOC_ARGS
)
2039 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2040 h
->flags
|= HTML_PREKEEP
;
2051 mdoc_bk_post(MDOC_ARGS
)
2054 if (MDOC_BODY
== n
->type
)
2055 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2059 mdoc_quote_pre(MDOC_ARGS
)
2061 struct htmlpair tag
;
2063 if (MDOC_BODY
!= n
->type
)
2070 print_text(h
, "\\(la");
2075 print_text(h
, "\\(lC");
2080 print_text(h
, "\\(lB");
2085 print_text(h
, "\\(lB");
2086 h
->flags
|= HTML_NOSPACE
;
2087 PAIR_CLASS_INIT(&tag
, "opt");
2088 print_otag(h
, TAG_SPAN
, 1, &tag
);
2091 if (NULL
== n
->norm
->Es
||
2092 NULL
== n
->norm
->Es
->child
)
2094 print_text(h
, n
->norm
->Es
->child
->string
);
2105 print_text(h
, "\\(lq");
2113 print_text(h
, "\\(oq");
2114 h
->flags
|= HTML_NOSPACE
;
2115 PAIR_CLASS_INIT(&tag
, "lit");
2116 print_otag(h
, TAG_CODE
, 1, &tag
);
2121 print_text(h
, "\\(oq");
2128 h
->flags
|= HTML_NOSPACE
;
2133 mdoc_quote_post(MDOC_ARGS
)
2136 if (MDOC_BODY
!= n
->type
)
2139 if (MDOC_En
!= n
->tok
)
2140 h
->flags
|= HTML_NOSPACE
;
2146 print_text(h
, "\\(ra");
2151 print_text(h
, "\\(rC");
2160 print_text(h
, "\\(rB");
2163 if (NULL
!= n
->norm
->Es
&&
2164 NULL
!= n
->norm
->Es
->child
&&
2165 NULL
!= n
->norm
->Es
->child
->next
) {
2166 h
->flags
|= HTML_NOSPACE
;
2167 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2179 print_text(h
, "\\(rq");
2191 print_text(h
, "\\(cq");