]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.199 2014/08/21 12:57:17 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
, "\\-");
643 if ( ! (n
->nchild
== 0 &&
645 n
->next
->type
== MDOC_TEXT
||
646 n
->next
->flags
& MDOC_LINE
)))
647 h
->flags
|= HTML_NOSPACE
;
653 mdoc_nd_pre(MDOC_ARGS
)
657 if (MDOC_BODY
!= n
->type
)
660 /* XXX: this tag in theory can contain block elements. */
662 print_text(h
, "\\(em");
663 PAIR_CLASS_INIT(&tag
, "desc");
664 print_otag(h
, TAG_SPAN
, 1, &tag
);
669 mdoc_nm_pre(MDOC_ARGS
)
678 PAIR_CLASS_INIT(&tag
, "name");
679 print_otag(h
, TAG_B
, 1, &tag
);
680 if (NULL
== n
->child
&& meta
->name
)
681 print_text(h
, meta
->name
);
684 print_otag(h
, TAG_TD
, 0, NULL
);
685 if (NULL
== n
->child
&& meta
->name
)
686 print_text(h
, meta
->name
);
689 print_otag(h
, TAG_TD
, 0, NULL
);
696 PAIR_CLASS_INIT(&tag
, "synopsis");
697 print_otag(h
, TAG_TABLE
, 1, &tag
);
699 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
700 if (MDOC_TEXT
== n
->type
)
701 len
+= html_strlen(n
->string
);
703 if (0 == len
&& meta
->name
)
704 len
= html_strlen(meta
->name
);
706 SCALE_HS_INIT(&su
, len
);
708 bufcat_su(h
, "width", &su
);
709 PAIR_STYLE_INIT(&tag
, h
);
710 print_otag(h
, TAG_COL
, 1, &tag
);
711 print_otag(h
, TAG_COL
, 0, NULL
);
712 print_otag(h
, TAG_TBODY
, 0, NULL
);
713 print_otag(h
, TAG_TR
, 0, NULL
);
718 mdoc_xr_pre(MDOC_ARGS
)
720 struct htmlpair tag
[2];
722 if (NULL
== n
->child
)
725 PAIR_CLASS_INIT(&tag
[0], "link-man");
728 buffmt_man(h
, n
->child
->string
,
730 n
->child
->next
->string
: NULL
);
731 PAIR_HREF_INIT(&tag
[1], h
->buf
);
732 print_otag(h
, TAG_A
, 2, tag
);
734 print_otag(h
, TAG_A
, 1, tag
);
737 print_text(h
, n
->string
);
739 if (NULL
== (n
= n
->next
))
742 h
->flags
|= HTML_NOSPACE
;
744 h
->flags
|= HTML_NOSPACE
;
745 print_text(h
, n
->string
);
746 h
->flags
|= HTML_NOSPACE
;
752 mdoc_ns_pre(MDOC_ARGS
)
755 if ( ! (MDOC_LINE
& n
->flags
))
756 h
->flags
|= HTML_NOSPACE
;
761 mdoc_ar_pre(MDOC_ARGS
)
765 PAIR_CLASS_INIT(&tag
, "arg");
766 print_otag(h
, TAG_I
, 1, &tag
);
771 mdoc_xx_pre(MDOC_ARGS
)
800 PAIR_CLASS_INIT(&tag
, "unix");
801 print_otag(h
, TAG_SPAN
, 1, &tag
);
806 h
->flags
|= HTML_KEEP
;
807 print_text(h
, n
->child
->string
);
814 mdoc_bx_pre(MDOC_ARGS
)
818 PAIR_CLASS_INIT(&tag
, "unix");
819 print_otag(h
, TAG_SPAN
, 1, &tag
);
821 if (NULL
!= (n
= n
->child
)) {
822 print_text(h
, n
->string
);
823 h
->flags
|= HTML_NOSPACE
;
824 print_text(h
, "BSD");
826 print_text(h
, "BSD");
830 if (NULL
!= (n
= n
->next
)) {
831 h
->flags
|= HTML_NOSPACE
;
833 h
->flags
|= HTML_NOSPACE
;
834 print_text(h
, n
->string
);
841 mdoc_it_pre(MDOC_ARGS
)
845 struct htmlpair tag
[2];
846 const struct mdoc_node
*bl
;
849 while (bl
&& MDOC_Bl
!= bl
->tok
)
854 type
= bl
->norm
->Bl
.type
;
857 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
861 if (MDOC_HEAD
== n
->type
) {
882 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
883 bufcat_su(h
, "margin-top", &su
);
884 PAIR_STYLE_INIT(&tag
[1], h
);
885 print_otag(h
, TAG_DT
, 2, tag
);
886 if (LIST_diag
!= type
)
888 PAIR_CLASS_INIT(&tag
[0], "diag");
889 print_otag(h
, TAG_B
, 1, tag
);
896 } else if (MDOC_BODY
== n
->type
) {
907 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
908 bufcat_su(h
, "margin-top", &su
);
909 PAIR_STYLE_INIT(&tag
[1], h
);
910 print_otag(h
, TAG_LI
, 2, tag
);
921 if (NULL
== bl
->norm
->Bl
.width
) {
922 print_otag(h
, TAG_DD
, 1, tag
);
925 a2width(bl
->norm
->Bl
.width
, &su
);
926 bufcat_su(h
, "margin-left", &su
);
927 PAIR_STYLE_INIT(&tag
[1], h
);
928 print_otag(h
, TAG_DD
, 2, tag
);
931 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
932 bufcat_su(h
, "margin-top", &su
);
933 PAIR_STYLE_INIT(&tag
[1], h
);
934 print_otag(h
, TAG_TD
, 2, tag
);
942 print_otag(h
, TAG_TR
, 1, tag
);
953 mdoc_bl_pre(MDOC_ARGS
)
956 struct htmlpair tag
[3];
960 if (MDOC_BODY
== n
->type
) {
961 if (LIST_column
== n
->norm
->Bl
.type
)
962 print_otag(h
, TAG_TBODY
, 0, NULL
);
966 if (MDOC_HEAD
== n
->type
) {
967 if (LIST_column
!= n
->norm
->Bl
.type
)
971 * For each column, print out the <COL> tag with our
972 * suggested width. The last column gets min-width, as
973 * in terminal mode it auto-sizes to the width of the
974 * screen and we want to preserve that behaviour.
977 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
979 a2width(n
->norm
->Bl
.cols
[i
], &su
);
980 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
981 bufcat_su(h
, "width", &su
);
983 bufcat_su(h
, "min-width", &su
);
984 PAIR_STYLE_INIT(&tag
[0], h
);
985 print_otag(h
, TAG_COL
, 1, tag
);
991 SCALE_VS_INIT(&su
, 0);
993 bufcat_su(h
, "margin-top", &su
);
994 bufcat_su(h
, "margin-bottom", &su
);
995 PAIR_STYLE_INIT(&tag
[0], h
);
997 assert(lists
[n
->norm
->Bl
.type
]);
998 (void)strlcpy(buf
, "list ", BUFSIZ
);
999 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1000 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1002 /* Set the block's left-hand margin. */
1004 if (n
->norm
->Bl
.offs
) {
1005 a2offs(n
->norm
->Bl
.offs
, &su
);
1006 bufcat_su(h
, "margin-left", &su
);
1009 switch (n
->norm
->Bl
.type
) {
1017 print_otag(h
, TAG_UL
, 2, tag
);
1020 print_otag(h
, TAG_OL
, 2, tag
);
1031 print_otag(h
, TAG_DL
, 2, tag
);
1034 print_otag(h
, TAG_TABLE
, 2, tag
);
1045 mdoc_ex_pre(MDOC_ARGS
)
1048 struct htmlpair tag
;
1052 print_otag(h
, TAG_BR
, 0, NULL
);
1054 PAIR_CLASS_INIT(&tag
, "utility");
1056 print_text(h
, "The");
1059 for (n
= n
->child
; n
; n
= n
->next
) {
1060 assert(MDOC_TEXT
== n
->type
);
1062 t
= print_otag(h
, TAG_B
, 1, &tag
);
1063 print_text(h
, n
->string
);
1066 if (nchild
> 2 && n
->next
) {
1067 h
->flags
|= HTML_NOSPACE
;
1071 if (n
->next
&& NULL
== n
->next
->next
)
1072 print_text(h
, "and");
1076 print_text(h
, "utilities exit\\~0");
1078 print_text(h
, "utility exits\\~0");
1080 print_text(h
, "on success, and\\~>0 if an error occurs.");
1085 mdoc_em_pre(MDOC_ARGS
)
1087 struct htmlpair tag
;
1089 PAIR_CLASS_INIT(&tag
, "emph");
1090 print_otag(h
, TAG_SPAN
, 1, &tag
);
1095 mdoc_d1_pre(MDOC_ARGS
)
1097 struct htmlpair tag
[2];
1100 if (MDOC_BLOCK
!= n
->type
)
1103 SCALE_VS_INIT(&su
, 0);
1105 bufcat_su(h
, "margin-top", &su
);
1106 bufcat_su(h
, "margin-bottom", &su
);
1107 PAIR_STYLE_INIT(&tag
[0], h
);
1108 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1110 /* BLOCKQUOTE needs a block body. */
1112 PAIR_CLASS_INIT(&tag
[0], "display");
1113 print_otag(h
, TAG_DIV
, 1, tag
);
1115 if (MDOC_Dl
== n
->tok
) {
1116 PAIR_CLASS_INIT(&tag
[0], "lit");
1117 print_otag(h
, TAG_CODE
, 1, tag
);
1124 mdoc_sx_pre(MDOC_ARGS
)
1126 struct htmlpair tag
[2];
1131 for (n
= n
->child
; n
; ) {
1132 bufcat_id(h
, n
->string
);
1133 if (NULL
!= (n
= n
->next
))
1137 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1138 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1140 print_otag(h
, TAG_I
, 1, tag
);
1141 print_otag(h
, TAG_A
, 2, tag
);
1146 mdoc_bd_pre(MDOC_ARGS
)
1148 struct htmlpair tag
[2];
1150 const struct mdoc_node
*nn
;
1153 if (MDOC_HEAD
== n
->type
)
1156 if (MDOC_BLOCK
== n
->type
) {
1157 comp
= n
->norm
->Bd
.comp
;
1158 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1159 if (MDOC_BLOCK
!= nn
->type
)
1161 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1167 print_otag(h
, TAG_P
, 0, NULL
);
1171 SCALE_HS_INIT(&su
, 0);
1172 if (n
->norm
->Bd
.offs
)
1173 a2offs(n
->norm
->Bd
.offs
, &su
);
1176 bufcat_su(h
, "margin-left", &su
);
1177 PAIR_STYLE_INIT(&tag
[0], h
);
1179 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1180 DISP_literal
!= n
->norm
->Bd
.type
) {
1181 PAIR_CLASS_INIT(&tag
[1], "display");
1182 print_otag(h
, TAG_DIV
, 2, tag
);
1186 PAIR_CLASS_INIT(&tag
[1], "lit display");
1187 print_otag(h
, TAG_PRE
, 2, tag
);
1189 /* This can be recursive: save & set our literal state. */
1191 sv
= h
->flags
& HTML_LITERAL
;
1192 h
->flags
|= HTML_LITERAL
;
1194 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1195 print_mdoc_node(meta
, nn
, h
);
1197 * If the printed node flushes its own line, then we
1198 * needn't do it here as well. This is hacky, but the
1199 * notion of selective eoln whitespace is pretty dumb
1200 * anyway, so don't sweat it.
1222 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1225 print_text(h
, "\n");
1227 h
->flags
|= HTML_NOSPACE
;
1231 h
->flags
&= ~HTML_LITERAL
;
1237 mdoc_pa_pre(MDOC_ARGS
)
1239 struct htmlpair tag
;
1241 PAIR_CLASS_INIT(&tag
, "file");
1242 print_otag(h
, TAG_I
, 1, &tag
);
1247 mdoc_ad_pre(MDOC_ARGS
)
1249 struct htmlpair tag
;
1251 PAIR_CLASS_INIT(&tag
, "addr");
1252 print_otag(h
, TAG_I
, 1, &tag
);
1257 mdoc_an_pre(MDOC_ARGS
)
1259 struct htmlpair tag
;
1261 /* TODO: -split and -nosplit (see termp_an_pre()). */
1263 PAIR_CLASS_INIT(&tag
, "author");
1264 print_otag(h
, TAG_SPAN
, 1, &tag
);
1269 mdoc_cd_pre(MDOC_ARGS
)
1271 struct htmlpair tag
;
1274 PAIR_CLASS_INIT(&tag
, "config");
1275 print_otag(h
, TAG_B
, 1, &tag
);
1280 mdoc_dv_pre(MDOC_ARGS
)
1282 struct htmlpair tag
;
1284 PAIR_CLASS_INIT(&tag
, "define");
1285 print_otag(h
, TAG_SPAN
, 1, &tag
);
1290 mdoc_ev_pre(MDOC_ARGS
)
1292 struct htmlpair tag
;
1294 PAIR_CLASS_INIT(&tag
, "env");
1295 print_otag(h
, TAG_SPAN
, 1, &tag
);
1300 mdoc_er_pre(MDOC_ARGS
)
1302 struct htmlpair tag
;
1304 PAIR_CLASS_INIT(&tag
, "errno");
1305 print_otag(h
, TAG_SPAN
, 1, &tag
);
1310 mdoc_fa_pre(MDOC_ARGS
)
1312 const struct mdoc_node
*nn
;
1313 struct htmlpair tag
;
1316 PAIR_CLASS_INIT(&tag
, "farg");
1317 if (n
->parent
->tok
!= MDOC_Fo
) {
1318 print_otag(h
, TAG_I
, 1, &tag
);
1322 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1323 t
= print_otag(h
, TAG_I
, 1, &tag
);
1324 print_text(h
, nn
->string
);
1327 h
->flags
|= HTML_NOSPACE
;
1332 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1333 h
->flags
|= HTML_NOSPACE
;
1341 mdoc_fd_pre(MDOC_ARGS
)
1343 struct htmlpair tag
[2];
1351 if (NULL
== (n
= n
->child
))
1354 assert(MDOC_TEXT
== n
->type
);
1356 if (strcmp(n
->string
, "#include")) {
1357 PAIR_CLASS_INIT(&tag
[0], "macro");
1358 print_otag(h
, TAG_B
, 1, tag
);
1362 PAIR_CLASS_INIT(&tag
[0], "includes");
1363 print_otag(h
, TAG_B
, 1, tag
);
1364 print_text(h
, n
->string
);
1366 if (NULL
!= (n
= n
->next
)) {
1367 assert(MDOC_TEXT
== n
->type
);
1370 * XXX This is broken and not easy to fix.
1371 * When using -Oincludes, truncation may occur.
1372 * Dynamic allocation wouldn't help because
1373 * passing long strings to buffmt_includes()
1374 * does not work either.
1377 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1378 n
->string
+ 1 : n
->string
, BUFSIZ
);
1381 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1384 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1387 if (h
->base_includes
) {
1388 buffmt_includes(h
, buf
);
1389 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1393 t
= print_otag(h
, TAG_A
, i
, tag
);
1394 print_text(h
, n
->string
);
1400 for ( ; n
; n
= n
->next
) {
1401 assert(MDOC_TEXT
== n
->type
);
1402 print_text(h
, n
->string
);
1409 mdoc_vt_pre(MDOC_ARGS
)
1411 struct htmlpair tag
;
1413 if (MDOC_BLOCK
== n
->type
) {
1416 } else if (MDOC_ELEM
== n
->type
) {
1418 } else if (MDOC_HEAD
== n
->type
)
1421 PAIR_CLASS_INIT(&tag
, "type");
1422 print_otag(h
, TAG_SPAN
, 1, &tag
);
1427 mdoc_ft_pre(MDOC_ARGS
)
1429 struct htmlpair tag
;
1432 PAIR_CLASS_INIT(&tag
, "ftype");
1433 print_otag(h
, TAG_I
, 1, &tag
);
1438 mdoc_fn_pre(MDOC_ARGS
)
1441 struct htmlpair tag
[2];
1443 const char *sp
, *ep
;
1446 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1449 /* Split apart into type and name. */
1450 assert(n
->child
->string
);
1451 sp
= n
->child
->string
;
1453 ep
= strchr(sp
, ' ');
1455 PAIR_CLASS_INIT(&tag
[0], "ftype");
1456 t
= print_otag(h
, TAG_I
, 1, tag
);
1459 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1460 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1462 print_text(h
, nbuf
);
1464 ep
= strchr(sp
, ' ');
1469 PAIR_CLASS_INIT(&tag
[0], "fname");
1472 * FIXME: only refer to IDs that we know exist.
1476 if (MDOC_SYNPRETTY
& n
->flags
) {
1478 html_idcat(nbuf
, sp
, BUFSIZ
);
1479 PAIR_ID_INIT(&tag
[1], nbuf
);
1481 strlcpy(nbuf
, "#", BUFSIZ
);
1482 html_idcat(nbuf
, sp
, BUFSIZ
);
1483 PAIR_HREF_INIT(&tag
[1], nbuf
);
1487 t
= print_otag(h
, TAG_B
, 1, tag
);
1494 h
->flags
|= HTML_NOSPACE
;
1496 h
->flags
|= HTML_NOSPACE
;
1498 PAIR_CLASS_INIT(&tag
[0], "farg");
1500 bufcat_style(h
, "white-space", "nowrap");
1501 PAIR_STYLE_INIT(&tag
[1], h
);
1503 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1505 if (MDOC_SYNPRETTY
& n
->flags
)
1507 t
= print_otag(h
, TAG_I
, i
, tag
);
1508 print_text(h
, n
->string
);
1511 h
->flags
|= HTML_NOSPACE
;
1516 h
->flags
|= HTML_NOSPACE
;
1520 h
->flags
|= HTML_NOSPACE
;
1528 mdoc_sm_pre(MDOC_ARGS
)
1531 if (NULL
== n
->child
)
1532 h
->flags
^= HTML_NONOSPACE
;
1533 else if (0 == strcmp("on", n
->child
->string
))
1534 h
->flags
&= ~HTML_NONOSPACE
;
1536 h
->flags
|= HTML_NONOSPACE
;
1538 if ( ! (HTML_NONOSPACE
& h
->flags
))
1539 h
->flags
&= ~HTML_NOSPACE
;
1545 mdoc_skip_pre(MDOC_ARGS
)
1552 mdoc_pp_pre(MDOC_ARGS
)
1555 print_otag(h
, TAG_P
, 0, NULL
);
1560 mdoc_sp_pre(MDOC_ARGS
)
1563 struct htmlpair tag
;
1565 SCALE_VS_INIT(&su
, 1);
1567 if (MDOC_sp
== n
->tok
) {
1568 if (NULL
!= (n
= n
->child
))
1569 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1570 SCALE_VS_INIT(&su
, atoi(n
->string
));
1575 bufcat_su(h
, "height", &su
);
1576 PAIR_STYLE_INIT(&tag
, h
);
1577 print_otag(h
, TAG_DIV
, 1, &tag
);
1579 /* So the div isn't empty: */
1580 print_text(h
, "\\~");
1587 mdoc_lk_pre(MDOC_ARGS
)
1589 struct htmlpair tag
[2];
1591 if (NULL
== (n
= n
->child
))
1594 assert(MDOC_TEXT
== n
->type
);
1596 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1597 PAIR_HREF_INIT(&tag
[1], n
->string
);
1599 print_otag(h
, TAG_A
, 2, tag
);
1601 if (NULL
== n
->next
)
1602 print_text(h
, n
->string
);
1604 for (n
= n
->next
; n
; n
= n
->next
)
1605 print_text(h
, n
->string
);
1611 mdoc_mt_pre(MDOC_ARGS
)
1613 struct htmlpair tag
[2];
1616 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1618 for (n
= n
->child
; n
; n
= n
->next
) {
1619 assert(MDOC_TEXT
== n
->type
);
1622 bufcat(h
, "mailto:");
1623 bufcat(h
, n
->string
);
1625 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1626 t
= print_otag(h
, TAG_A
, 2, tag
);
1627 print_text(h
, n
->string
);
1635 mdoc_fo_pre(MDOC_ARGS
)
1637 struct htmlpair tag
;
1640 if (MDOC_BODY
== n
->type
) {
1641 h
->flags
|= HTML_NOSPACE
;
1643 h
->flags
|= HTML_NOSPACE
;
1645 } else if (MDOC_BLOCK
== n
->type
) {
1650 /* XXX: we drop non-initial arguments as per groff. */
1653 assert(n
->child
->string
);
1655 PAIR_CLASS_INIT(&tag
, "fname");
1656 t
= print_otag(h
, TAG_B
, 1, &tag
);
1657 print_text(h
, n
->child
->string
);
1663 mdoc_fo_post(MDOC_ARGS
)
1666 if (MDOC_BODY
!= n
->type
)
1668 h
->flags
|= HTML_NOSPACE
;
1670 h
->flags
|= HTML_NOSPACE
;
1675 mdoc_in_pre(MDOC_ARGS
)
1678 struct htmlpair tag
[2];
1683 PAIR_CLASS_INIT(&tag
[0], "includes");
1684 print_otag(h
, TAG_B
, 1, tag
);
1687 * The first argument of the `In' gets special treatment as
1688 * being a linked value. Subsequent values are printed
1689 * afterward. groff does similarly. This also handles the case
1693 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1694 print_text(h
, "#include");
1697 h
->flags
|= HTML_NOSPACE
;
1699 if (NULL
!= (n
= n
->child
)) {
1700 assert(MDOC_TEXT
== n
->type
);
1702 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1705 if (h
->base_includes
) {
1706 buffmt_includes(h
, n
->string
);
1707 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1711 t
= print_otag(h
, TAG_A
, i
, tag
);
1712 print_text(h
, n
->string
);
1718 h
->flags
|= HTML_NOSPACE
;
1721 for ( ; n
; n
= n
->next
) {
1722 assert(MDOC_TEXT
== n
->type
);
1723 print_text(h
, n
->string
);
1730 mdoc_ic_pre(MDOC_ARGS
)
1732 struct htmlpair tag
;
1734 PAIR_CLASS_INIT(&tag
, "cmd");
1735 print_otag(h
, TAG_B
, 1, &tag
);
1740 mdoc_rv_pre(MDOC_ARGS
)
1742 struct htmlpair tag
;
1747 print_otag(h
, TAG_BR
, 0, NULL
);
1749 PAIR_CLASS_INIT(&tag
, "fname");
1753 print_text(h
, "The");
1755 for (n
= n
->child
; n
; n
= n
->next
) {
1756 t
= print_otag(h
, TAG_B
, 1, &tag
);
1757 print_text(h
, n
->string
);
1760 h
->flags
|= HTML_NOSPACE
;
1761 print_text(h
, "()");
1763 if (n
->next
== NULL
)
1767 h
->flags
|= HTML_NOSPACE
;
1770 if (n
->next
->next
== NULL
)
1771 print_text(h
, "and");
1775 print_text(h
, "functions return");
1777 print_text(h
, "function returns");
1779 print_text(h
, "the value\\~0 if successful;");
1781 print_text(h
, "Upon successful completion,"
1782 " the value\\~0 is returned;");
1784 print_text(h
, "otherwise the value\\~\\-1 is returned"
1785 " and the global variable");
1787 PAIR_CLASS_INIT(&tag
, "var");
1788 t
= print_otag(h
, TAG_B
, 1, &tag
);
1789 print_text(h
, "errno");
1791 print_text(h
, "is set to indicate the error.");
1796 mdoc_va_pre(MDOC_ARGS
)
1798 struct htmlpair tag
;
1800 PAIR_CLASS_INIT(&tag
, "var");
1801 print_otag(h
, TAG_B
, 1, &tag
);
1806 mdoc_ap_pre(MDOC_ARGS
)
1809 h
->flags
|= HTML_NOSPACE
;
1810 print_text(h
, "\\(aq");
1811 h
->flags
|= HTML_NOSPACE
;
1816 mdoc_bf_pre(MDOC_ARGS
)
1818 struct htmlpair tag
[2];
1821 if (MDOC_HEAD
== n
->type
)
1823 else if (MDOC_BODY
!= n
->type
)
1826 if (FONT_Em
== n
->norm
->Bf
.font
)
1827 PAIR_CLASS_INIT(&tag
[0], "emph");
1828 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1829 PAIR_CLASS_INIT(&tag
[0], "symb");
1830 else if (FONT_Li
== n
->norm
->Bf
.font
)
1831 PAIR_CLASS_INIT(&tag
[0], "lit");
1833 PAIR_CLASS_INIT(&tag
[0], "none");
1836 * We want this to be inline-formatted, but needs to be div to
1837 * accept block children.
1840 bufcat_style(h
, "display", "inline");
1841 SCALE_HS_INIT(&su
, 1);
1842 /* Needs a left-margin for spacing. */
1843 bufcat_su(h
, "margin-left", &su
);
1844 PAIR_STYLE_INIT(&tag
[1], h
);
1845 print_otag(h
, TAG_DIV
, 2, tag
);
1850 mdoc_ms_pre(MDOC_ARGS
)
1852 struct htmlpair tag
;
1854 PAIR_CLASS_INIT(&tag
, "symb");
1855 print_otag(h
, TAG_SPAN
, 1, &tag
);
1860 mdoc_igndelim_pre(MDOC_ARGS
)
1863 h
->flags
|= HTML_IGNDELIM
;
1868 mdoc_pf_post(MDOC_ARGS
)
1871 h
->flags
|= HTML_NOSPACE
;
1875 mdoc_rs_pre(MDOC_ARGS
)
1877 struct htmlpair tag
;
1879 if (MDOC_BLOCK
!= n
->type
)
1882 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1883 print_otag(h
, TAG_P
, 0, NULL
);
1885 PAIR_CLASS_INIT(&tag
, "ref");
1886 print_otag(h
, TAG_SPAN
, 1, &tag
);
1891 mdoc_li_pre(MDOC_ARGS
)
1893 struct htmlpair tag
;
1895 PAIR_CLASS_INIT(&tag
, "lit");
1896 print_otag(h
, TAG_CODE
, 1, &tag
);
1901 mdoc_sy_pre(MDOC_ARGS
)
1903 struct htmlpair tag
;
1905 PAIR_CLASS_INIT(&tag
, "symb");
1906 print_otag(h
, TAG_SPAN
, 1, &tag
);
1911 mdoc_bt_pre(MDOC_ARGS
)
1914 print_text(h
, "is currently in beta test.");
1919 mdoc_ud_pre(MDOC_ARGS
)
1922 print_text(h
, "currently under development.");
1927 mdoc_lb_pre(MDOC_ARGS
)
1929 struct htmlpair tag
;
1931 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1932 print_otag(h
, TAG_BR
, 0, NULL
);
1934 PAIR_CLASS_INIT(&tag
, "lib");
1935 print_otag(h
, TAG_SPAN
, 1, &tag
);
1940 mdoc__x_pre(MDOC_ARGS
)
1942 struct htmlpair tag
[2];
1949 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1950 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1951 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1952 print_text(h
, "and");
1955 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1959 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1962 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1965 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1969 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1973 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1976 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1982 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1985 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1988 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1991 PAIR_CLASS_INIT(&tag
[0], "link-ref");
1994 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2001 if (MDOC__U
!= n
->tok
) {
2002 print_otag(h
, t
, 1, tag
);
2006 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2007 print_otag(h
, TAG_A
, 2, tag
);
2013 mdoc__x_post(MDOC_ARGS
)
2016 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2017 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2018 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2023 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2026 h
->flags
|= HTML_NOSPACE
;
2027 print_text(h
, n
->next
? "," : ".");
2031 mdoc_bk_pre(MDOC_ARGS
)
2040 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2041 h
->flags
|= HTML_PREKEEP
;
2052 mdoc_bk_post(MDOC_ARGS
)
2055 if (MDOC_BODY
== n
->type
)
2056 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2060 mdoc_quote_pre(MDOC_ARGS
)
2062 struct htmlpair tag
;
2064 if (MDOC_BODY
!= n
->type
)
2071 print_text(h
, "\\(la");
2076 print_text(h
, "\\(lC");
2081 print_text(h
, "\\(lB");
2086 print_text(h
, "\\(lB");
2087 h
->flags
|= HTML_NOSPACE
;
2088 PAIR_CLASS_INIT(&tag
, "opt");
2089 print_otag(h
, TAG_SPAN
, 1, &tag
);
2092 if (NULL
== n
->norm
->Es
||
2093 NULL
== n
->norm
->Es
->child
)
2095 print_text(h
, n
->norm
->Es
->child
->string
);
2106 print_text(h
, "\\(lq");
2114 print_text(h
, "\\(oq");
2115 h
->flags
|= HTML_NOSPACE
;
2116 PAIR_CLASS_INIT(&tag
, "lit");
2117 print_otag(h
, TAG_CODE
, 1, &tag
);
2122 print_text(h
, "\\(oq");
2129 h
->flags
|= HTML_NOSPACE
;
2134 mdoc_quote_post(MDOC_ARGS
)
2137 if (MDOC_BODY
!= n
->type
)
2140 if (MDOC_En
!= n
->tok
)
2141 h
->flags
|= HTML_NOSPACE
;
2147 print_text(h
, "\\(ra");
2152 print_text(h
, "\\(rC");
2161 print_text(h
, "\\(rB");
2164 if (NULL
!= n
->norm
->Es
&&
2165 NULL
!= n
->norm
->Es
->child
&&
2166 NULL
!= n
->norm
->Es
->child
->next
) {
2167 h
->flags
|= HTML_NOSPACE
;
2168 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2180 print_text(h
, "\\(rq");
2192 print_text(h
, "\\(cq");