]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.162 2011/04/04 16:48:18 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
39 #define MDOC_ARGS const struct mdoc_meta *m, \
40 const struct mdoc_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static void print_mdoc(MDOC_ARGS
);
53 static void print_mdoc_head(MDOC_ARGS
);
54 static void print_mdoc_node(MDOC_ARGS
);
55 static void print_mdoc_nodelist(MDOC_ARGS
);
56 static void synopsis_pre(struct html
*,
57 const struct mdoc_node
*);
59 static void a2width(const char *, struct roffsu
*);
60 static void a2offs(const char *, struct roffsu
*);
62 static void mdoc_root_post(MDOC_ARGS
);
63 static int mdoc_root_pre(MDOC_ARGS
);
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static int mdoc_bt_pre(MDOC_ARGS
);
77 static int mdoc_bx_pre(MDOC_ARGS
);
78 static int mdoc_cd_pre(MDOC_ARGS
);
79 static int mdoc_d1_pre(MDOC_ARGS
);
80 static int mdoc_dv_pre(MDOC_ARGS
);
81 static int mdoc_fa_pre(MDOC_ARGS
);
82 static int mdoc_fd_pre(MDOC_ARGS
);
83 static int mdoc_fl_pre(MDOC_ARGS
);
84 static int mdoc_fn_pre(MDOC_ARGS
);
85 static int mdoc_ft_pre(MDOC_ARGS
);
86 static int mdoc_em_pre(MDOC_ARGS
);
87 static int mdoc_er_pre(MDOC_ARGS
);
88 static int mdoc_ev_pre(MDOC_ARGS
);
89 static int mdoc_ex_pre(MDOC_ARGS
);
90 static void mdoc_fo_post(MDOC_ARGS
);
91 static int mdoc_fo_pre(MDOC_ARGS
);
92 static int mdoc_ic_pre(MDOC_ARGS
);
93 static int mdoc_igndelim_pre(MDOC_ARGS
);
94 static int mdoc_in_pre(MDOC_ARGS
);
95 static int mdoc_it_pre(MDOC_ARGS
);
96 static int mdoc_lb_pre(MDOC_ARGS
);
97 static int mdoc_li_pre(MDOC_ARGS
);
98 static int mdoc_lk_pre(MDOC_ARGS
);
99 static int mdoc_mt_pre(MDOC_ARGS
);
100 static int mdoc_ms_pre(MDOC_ARGS
);
101 static int mdoc_nd_pre(MDOC_ARGS
);
102 static int mdoc_nm_pre(MDOC_ARGS
);
103 static int mdoc_ns_pre(MDOC_ARGS
);
104 static int mdoc_pa_pre(MDOC_ARGS
);
105 static void mdoc_pf_post(MDOC_ARGS
);
106 static int mdoc_pp_pre(MDOC_ARGS
);
107 static void mdoc_quote_post(MDOC_ARGS
);
108 static int mdoc_quote_pre(MDOC_ARGS
);
109 static int mdoc_rs_pre(MDOC_ARGS
);
110 static int mdoc_rv_pre(MDOC_ARGS
);
111 static int mdoc_sh_pre(MDOC_ARGS
);
112 static int mdoc_sm_pre(MDOC_ARGS
);
113 static int mdoc_sp_pre(MDOC_ARGS
);
114 static int mdoc_ss_pre(MDOC_ARGS
);
115 static int mdoc_sx_pre(MDOC_ARGS
);
116 static int mdoc_sy_pre(MDOC_ARGS
);
117 static int mdoc_ud_pre(MDOC_ARGS
);
118 static int mdoc_va_pre(MDOC_ARGS
);
119 static int mdoc_vt_pre(MDOC_ARGS
);
120 static int mdoc_xr_pre(MDOC_ARGS
);
121 static int mdoc_xx_pre(MDOC_ARGS
);
123 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
124 {mdoc_ap_pre
, NULL
}, /* Ap */
125 {NULL
, NULL
}, /* Dd */
126 {NULL
, NULL
}, /* Dt */
127 {NULL
, NULL
}, /* Os */
128 {mdoc_sh_pre
, NULL
}, /* Sh */
129 {mdoc_ss_pre
, NULL
}, /* Ss */
130 {mdoc_pp_pre
, NULL
}, /* Pp */
131 {mdoc_d1_pre
, NULL
}, /* D1 */
132 {mdoc_d1_pre
, NULL
}, /* Dl */
133 {mdoc_bd_pre
, NULL
}, /* Bd */
134 {NULL
, NULL
}, /* Ed */
135 {mdoc_bl_pre
, NULL
}, /* Bl */
136 {NULL
, NULL
}, /* El */
137 {mdoc_it_pre
, NULL
}, /* It */
138 {mdoc_ad_pre
, NULL
}, /* Ad */
139 {mdoc_an_pre
, NULL
}, /* An */
140 {mdoc_ar_pre
, NULL
}, /* Ar */
141 {mdoc_cd_pre
, NULL
}, /* Cd */
142 {mdoc_fl_pre
, NULL
}, /* Cm */
143 {mdoc_dv_pre
, NULL
}, /* Dv */
144 {mdoc_er_pre
, NULL
}, /* Er */
145 {mdoc_ev_pre
, NULL
}, /* Ev */
146 {mdoc_ex_pre
, NULL
}, /* Ex */
147 {mdoc_fa_pre
, NULL
}, /* Fa */
148 {mdoc_fd_pre
, NULL
}, /* Fd */
149 {mdoc_fl_pre
, NULL
}, /* Fl */
150 {mdoc_fn_pre
, NULL
}, /* Fn */
151 {mdoc_ft_pre
, NULL
}, /* Ft */
152 {mdoc_ic_pre
, NULL
}, /* Ic */
153 {mdoc_in_pre
, NULL
}, /* In */
154 {mdoc_li_pre
, NULL
}, /* Li */
155 {mdoc_nd_pre
, NULL
}, /* Nd */
156 {mdoc_nm_pre
, NULL
}, /* Nm */
157 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
158 {NULL
, NULL
}, /* Ot */
159 {mdoc_pa_pre
, NULL
}, /* Pa */
160 {mdoc_rv_pre
, NULL
}, /* Rv */
161 {NULL
, NULL
}, /* St */
162 {mdoc_va_pre
, NULL
}, /* Va */
163 {mdoc_vt_pre
, NULL
}, /* Vt */
164 {mdoc_xr_pre
, NULL
}, /* Xr */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
176 {NULL
, NULL
}, /* Ac */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
179 {NULL
, NULL
}, /* At */
180 {NULL
, NULL
}, /* Bc */
181 {mdoc_bf_pre
, NULL
}, /* Bf */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
184 {mdoc_xx_pre
, NULL
}, /* Bsx */
185 {mdoc_bx_pre
, NULL
}, /* Bx */
186 {NULL
, NULL
}, /* Db */
187 {NULL
, NULL
}, /* Dc */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
190 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 {NULL
, NULL
}, /* Ef */
192 {mdoc_em_pre
, NULL
}, /* Em */
193 {NULL
, NULL
}, /* Eo */
194 {mdoc_xx_pre
, NULL
}, /* Fx */
195 {mdoc_ms_pre
, NULL
}, /* Ms */
196 {mdoc_igndelim_pre
, NULL
}, /* No */
197 {mdoc_ns_pre
, NULL
}, /* Ns */
198 {mdoc_xx_pre
, NULL
}, /* Nx */
199 {mdoc_xx_pre
, NULL
}, /* Ox */
200 {NULL
, NULL
}, /* Pc */
201 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
204 {NULL
, NULL
}, /* Qc */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
208 {NULL
, NULL
}, /* Re */
209 {mdoc_rs_pre
, NULL
}, /* Rs */
210 {NULL
, NULL
}, /* Sc */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
213 {mdoc_sm_pre
, NULL
}, /* Sm */
214 {mdoc_sx_pre
, NULL
}, /* Sx */
215 {mdoc_sy_pre
, NULL
}, /* Sy */
216 {NULL
, NULL
}, /* Tn */
217 {mdoc_xx_pre
, NULL
}, /* Ux */
218 {NULL
, NULL
}, /* Xc */
219 {NULL
, NULL
}, /* Xo */
220 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
221 {NULL
, NULL
}, /* Fc */
222 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
223 {NULL
, NULL
}, /* Oc */
224 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
225 {NULL
, NULL
}, /* Ek */
226 {mdoc_bt_pre
, NULL
}, /* Bt */
227 {NULL
, NULL
}, /* Hf */
228 {NULL
, NULL
}, /* Fr */
229 {mdoc_ud_pre
, NULL
}, /* Ud */
230 {mdoc_lb_pre
, NULL
}, /* Lb */
231 {mdoc_pp_pre
, NULL
}, /* Lp */
232 {mdoc_lk_pre
, NULL
}, /* Lk */
233 {mdoc_mt_pre
, NULL
}, /* Mt */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
236 {NULL
, NULL
}, /* Brc */
237 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
238 {NULL
, NULL
}, /* Es */ /* TODO */
239 {NULL
, NULL
}, /* En */ /* TODO */
240 {mdoc_xx_pre
, NULL
}, /* Dx */
241 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
242 {mdoc_sp_pre
, NULL
}, /* br */
243 {mdoc_sp_pre
, NULL
}, /* sp */
244 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
245 {NULL
, NULL
}, /* Ta */
248 static const char * const lists
[LIST_MAX
] = {
264 html_mdoc(void *arg
, const struct mdoc
*m
)
269 h
= (struct html
*)arg
;
272 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
273 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
281 * Calculate the scaling unit passed in a `-width' argument. This uses
282 * either a native scaling unit (e.g., 1i, 2m) or the string length of
286 a2width(const char *p
, struct roffsu
*su
)
289 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
291 su
->scale
= (int)strlen(p
);
297 * See the same function in mdoc_term.c for documentation.
300 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
303 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
306 if (n
->prev
->tok
== n
->tok
&&
310 print_otag(h
, TAG_BR
, 0, NULL
);
314 switch (n
->prev
->tok
) {
324 print_otag(h
, TAG_P
, 0, NULL
);
327 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
328 print_otag(h
, TAG_P
, 0, NULL
);
333 print_otag(h
, TAG_BR
, 0, NULL
);
340 * Calculate the scaling unit passed in an `-offset' argument. This
341 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
342 * predefined strings (indent, etc.), or the string length of the value.
345 a2offs(const char *p
, struct roffsu
*su
)
348 /* FIXME: "right"? */
350 if (0 == strcmp(p
, "left"))
351 SCALE_HS_INIT(su
, 0);
352 else if (0 == strcmp(p
, "indent"))
353 SCALE_HS_INIT(su
, INDENT
);
354 else if (0 == strcmp(p
, "indent-two"))
355 SCALE_HS_INIT(su
, INDENT
* 2);
356 else if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
358 su
->scale
= (int)strlen(p
);
364 print_mdoc(MDOC_ARGS
)
368 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
369 print_mdoc_head(m
, n
, h
);
372 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
373 print_mdoc_nodelist(m
, n
, h
);
380 print_mdoc_head(MDOC_ARGS
)
385 buffmt(h
, "%s(%s)", m
->title
, m
->msec
);
393 print_otag(h
, TAG_TITLE
, 0, NULL
);
394 print_text(h
, h
->buf
);
399 print_mdoc_nodelist(MDOC_ARGS
)
402 print_mdoc_node(m
, n
, h
);
404 print_mdoc_nodelist(m
, n
->next
, h
);
409 print_mdoc_node(MDOC_ARGS
)
421 child
= mdoc_root_pre(m
, n
, h
);
424 /* No tables in this mode... */
425 assert(NULL
== h
->tblt
);
428 * Make sure that if we're in a literal mode already
429 * (i.e., within a <PRE>) don't print the newline.
431 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
432 if ( ! (HTML_LITERAL
& h
->flags
))
433 print_otag(h
, TAG_BR
, 0, NULL
);
434 if (MDOC_DELIMC
& n
->flags
)
435 h
->flags
|= HTML_NOSPACE
;
436 print_text(h
, n
->string
);
437 if (MDOC_DELIMO
& n
->flags
)
438 h
->flags
|= HTML_NOSPACE
;
441 PAIR_CLASS_INIT(&tag
, "eqn");
442 print_otag(h
, TAG_SPAN
, 1, &tag
);
443 print_text(h
, n
->eqn
->data
);
447 * This will take care of initialising all of the table
448 * state data for the first table, then tearing it down
451 print_tbl(h
, n
->span
);
455 * Close out the current table, if it's open, and unset
456 * the "meta" table state. This will be reopened on the
457 * next table element.
464 assert(NULL
== h
->tblt
);
465 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
466 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
470 if (HTML_KEEP
& h
->flags
) {
471 if (n
->prev
&& n
->prev
->line
!= n
->line
) {
472 h
->flags
&= ~HTML_KEEP
;
473 h
->flags
|= HTML_PREKEEP
;
474 } else if (NULL
== n
->prev
) {
475 if (n
->parent
&& n
->parent
->line
!= n
->line
) {
476 h
->flags
&= ~HTML_KEEP
;
477 h
->flags
|= HTML_PREKEEP
;
482 if (child
&& n
->child
)
483 print_mdoc_nodelist(m
, n
->child
, h
);
490 mdoc_root_post(m
, n
, h
);
495 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
496 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
503 mdoc_root_post(MDOC_ARGS
)
505 struct htmlpair tag
[3];
508 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
509 PAIR_CLASS_INIT(&tag
[1], "foot");
510 if (NULL
== h
->style
) {
511 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
512 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
513 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
514 print_otag(h
, TAG_COL
, 1, tag
);
515 print_otag(h
, TAG_COL
, 1, tag
);
517 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
519 t
= print_otag(h
, TAG_TBODY
, 0, NULL
);
521 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
523 PAIR_CLASS_INIT(&tag
[0], "foot-date");
524 print_otag(h
, TAG_TD
, 1, tag
);
526 print_text(h
, m
->date
);
529 PAIR_CLASS_INIT(&tag
[0], "foot-os");
530 if (NULL
== h
->style
) {
531 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
532 print_otag(h
, TAG_TD
, 2, tag
);
534 print_otag(h
, TAG_TD
, 1, tag
);
536 print_text(h
, m
->os
);
543 mdoc_root_pre(MDOC_ARGS
)
545 struct htmlpair tag
[3];
547 char b
[BUFSIZ
], title
[BUFSIZ
];
549 strlcpy(b
, m
->vol
, BUFSIZ
);
552 strlcat(b
, " (", BUFSIZ
);
553 strlcat(b
, m
->arch
, BUFSIZ
);
554 strlcat(b
, ")", BUFSIZ
);
557 snprintf(title
, BUFSIZ
- 1, "%s(%s)", m
->title
, m
->msec
);
559 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
560 PAIR_CLASS_INIT(&tag
[1], "head");
561 if (NULL
== h
->style
) {
562 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
563 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
564 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
565 print_otag(h
, TAG_COL
, 1, tag
);
566 print_otag(h
, TAG_COL
, 1, tag
);
567 print_otag(h
, TAG_COL
, 1, tag
);
569 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
571 print_otag(h
, TAG_TBODY
, 0, NULL
);
573 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
575 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
576 print_otag(h
, TAG_TD
, 1, tag
);
578 print_text(h
, title
);
581 PAIR_CLASS_INIT(&tag
[0], "head-vol");
582 if (NULL
== h
->style
) {
583 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
584 print_otag(h
, TAG_TD
, 2, tag
);
586 print_otag(h
, TAG_TD
, 1, tag
);
591 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
592 if (NULL
== h
->style
) {
593 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
594 print_otag(h
, TAG_TD
, 2, tag
);
596 print_otag(h
, TAG_TD
, 1, tag
);
598 print_text(h
, title
);
606 mdoc_sh_pre(MDOC_ARGS
)
611 if (MDOC_BLOCK
== n
->type
) {
612 PAIR_CLASS_INIT(&tag
, "section");
613 print_otag(h
, TAG_DIV
, 1, &tag
);
615 } else if (MDOC_BODY
== n
->type
)
619 for (n
= n
->child
; n
; n
= n
->next
) {
620 html_idcat(buf
, n
->string
, BUFSIZ
);
622 html_idcat(buf
, " ", BUFSIZ
);
625 PAIR_ID_INIT(&tag
, buf
);
626 print_otag(h
, TAG_H1
, 1, &tag
);
633 mdoc_ss_pre(MDOC_ARGS
)
638 if (MDOC_BLOCK
== n
->type
) {
639 PAIR_CLASS_INIT(&tag
, "subsection");
640 print_otag(h
, TAG_DIV
, 1, &tag
);
642 } else if (MDOC_BODY
== n
->type
)
646 for (n
= n
->child
; n
; n
= n
->next
) {
647 html_idcat(buf
, n
->string
, BUFSIZ
);
649 html_idcat(buf
, " ", BUFSIZ
);
652 PAIR_ID_INIT(&tag
, buf
);
653 print_otag(h
, TAG_H2
, 1, &tag
);
660 mdoc_fl_pre(MDOC_ARGS
)
664 PAIR_CLASS_INIT(&tag
, "flag");
665 print_otag(h
, TAG_B
, 1, &tag
);
667 /* `Cm' has no leading hyphen. */
669 if (MDOC_Cm
== n
->tok
)
672 print_text(h
, "\\-");
675 h
->flags
|= HTML_NOSPACE
;
676 else if (n
->next
&& n
->next
->line
== n
->line
)
677 h
->flags
|= HTML_NOSPACE
;
685 mdoc_nd_pre(MDOC_ARGS
)
689 if (MDOC_BODY
!= n
->type
)
692 /* XXX: this tag in theory can contain block elements. */
694 print_text(h
, "\\(em");
695 PAIR_CLASS_INIT(&tag
, "desc");
696 print_otag(h
, TAG_SPAN
, 1, &tag
);
702 mdoc_nm_pre(MDOC_ARGS
)
711 PAIR_CLASS_INIT(&tag
, "name");
712 print_otag(h
, TAG_B
, 1, &tag
);
713 if (NULL
== n
->child
&& m
->name
)
714 print_text(h
, m
->name
);
717 print_otag(h
, TAG_TD
, 0, NULL
);
718 if (NULL
== n
->child
&& m
->name
)
719 print_text(h
, m
->name
);
722 print_otag(h
, TAG_TD
, 0, NULL
);
729 PAIR_CLASS_INIT(&tag
, "synopsis");
730 print_otag(h
, TAG_TABLE
, 1, &tag
);
732 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
733 if (MDOC_TEXT
== n
->type
)
734 len
+= strlen(n
->string
);
736 if (0 == len
&& m
->name
)
737 len
= strlen(m
->name
);
739 SCALE_HS_INIT(&su
, (double)len
);
740 bufcat_su(h
, "width", &su
);
741 PAIR_STYLE_INIT(&tag
, h
);
742 print_otag(h
, TAG_COL
, 1, &tag
);
743 print_otag(h
, TAG_COL
, 0, NULL
);
744 print_otag(h
, TAG_TBODY
, 0, NULL
);
745 print_otag(h
, TAG_TR
, 0, NULL
);
752 mdoc_xr_pre(MDOC_ARGS
)
754 struct htmlpair tag
[2];
756 if (NULL
== n
->child
)
759 PAIR_CLASS_INIT(&tag
[0], "link-man");
762 buffmt_man(h
, n
->child
->string
,
764 n
->child
->next
->string
: NULL
);
765 PAIR_HREF_INIT(&tag
[1], h
->buf
);
766 print_otag(h
, TAG_A
, 2, tag
);
768 print_otag(h
, TAG_A
, 1, tag
);
771 print_text(h
, n
->string
);
773 if (NULL
== (n
= n
->next
))
776 h
->flags
|= HTML_NOSPACE
;
778 h
->flags
|= HTML_NOSPACE
;
779 print_text(h
, n
->string
);
780 h
->flags
|= HTML_NOSPACE
;
788 mdoc_ns_pre(MDOC_ARGS
)
791 if ( ! (MDOC_LINE
& n
->flags
))
792 h
->flags
|= HTML_NOSPACE
;
799 mdoc_ar_pre(MDOC_ARGS
)
803 PAIR_CLASS_INIT(&tag
, "arg");
804 print_otag(h
, TAG_I
, 1, &tag
);
811 mdoc_xx_pre(MDOC_ARGS
)
840 PAIR_CLASS_INIT(&tag
, "unix");
841 print_otag(h
, TAG_SPAN
, 1, &tag
);
846 h
->flags
|= HTML_KEEP
;
847 print_text(h
, n
->child
->string
);
856 mdoc_bx_pre(MDOC_ARGS
)
860 PAIR_CLASS_INIT(&tag
, "unix");
861 print_otag(h
, TAG_SPAN
, 1, &tag
);
863 if (NULL
!= (n
= n
->child
)) {
864 print_text(h
, n
->string
);
865 h
->flags
|= HTML_NOSPACE
;
866 print_text(h
, "BSD");
868 print_text(h
, "BSD");
872 if (NULL
!= (n
= n
->next
)) {
873 h
->flags
|= HTML_NOSPACE
;
875 h
->flags
|= HTML_NOSPACE
;
876 print_text(h
, n
->string
);
884 mdoc_it_pre(MDOC_ARGS
)
888 struct htmlpair tag
[2];
889 const struct mdoc_node
*bl
;
892 while (bl
&& MDOC_Bl
!= bl
->tok
)
897 type
= bl
->norm
->Bl
.type
;
900 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
902 if (MDOC_HEAD
== n
->type
) {
923 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
924 bufcat_su(h
, "margin-top", &su
);
925 PAIR_STYLE_INIT(&tag
[1], h
);
926 print_otag(h
, TAG_DT
, 2, tag
);
927 if (LIST_diag
!= type
)
929 PAIR_CLASS_INIT(&tag
[0], "diag");
930 print_otag(h
, TAG_B
, 1, tag
);
937 } else if (MDOC_BODY
== n
->type
) {
948 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
949 bufcat_su(h
, "margin-top", &su
);
950 PAIR_STYLE_INIT(&tag
[1], h
);
951 print_otag(h
, TAG_LI
, 2, tag
);
962 if (NULL
== bl
->norm
->Bl
.width
) {
963 print_otag(h
, TAG_DD
, 1, tag
);
966 a2width(bl
->norm
->Bl
.width
, &su
);
967 bufcat_su(h
, "margin-left", &su
);
968 PAIR_STYLE_INIT(&tag
[1], h
);
969 print_otag(h
, TAG_DD
, 2, tag
);
972 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
973 bufcat_su(h
, "margin-top", &su
);
974 PAIR_STYLE_INIT(&tag
[1], h
);
975 print_otag(h
, TAG_TD
, 2, tag
);
983 print_otag(h
, TAG_TR
, 1, tag
);
995 mdoc_bl_pre(MDOC_ARGS
)
998 struct htmlpair tag
[3];
1002 if (MDOC_BODY
== n
->type
) {
1003 if (LIST_column
== n
->norm
->Bl
.type
)
1004 print_otag(h
, TAG_TBODY
, 0, NULL
);
1008 if (MDOC_HEAD
== n
->type
) {
1009 if (LIST_column
!= n
->norm
->Bl
.type
)
1013 * For each column, print out the <COL> tag with our
1014 * suggested width. The last column gets min-width, as
1015 * in terminal mode it auto-sizes to the width of the
1016 * screen and we want to preserve that behaviour.
1019 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1020 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1022 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1023 bufcat_su(h
, "width", &su
);
1025 bufcat_su(h
, "min-width", &su
);
1026 PAIR_STYLE_INIT(&tag
[0], h
);
1027 print_otag(h
, TAG_COL
, 1, tag
);
1033 SCALE_VS_INIT(&su
, 0);
1034 bufcat_su(h
, "margin-top", &su
);
1035 bufcat_su(h
, "margin-bottom", &su
);
1036 PAIR_STYLE_INIT(&tag
[0], h
);
1038 assert(lists
[n
->norm
->Bl
.type
]);
1039 strlcpy(buf
, "list ", BUFSIZ
);
1040 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1041 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1043 /* Set the block's left-hand margin. */
1045 if (n
->norm
->Bl
.offs
) {
1046 a2offs(n
->norm
->Bl
.offs
, &su
);
1047 bufcat_su(h
, "margin-left", &su
);
1050 switch (n
->norm
->Bl
.type
) {
1058 print_otag(h
, TAG_UL
, 2, tag
);
1061 print_otag(h
, TAG_OL
, 2, tag
);
1072 print_otag(h
, TAG_DL
, 2, tag
);
1075 print_otag(h
, TAG_TABLE
, 2, tag
);
1087 mdoc_ex_pre(MDOC_ARGS
)
1090 struct htmlpair tag
;
1094 print_otag(h
, TAG_BR
, 0, NULL
);
1096 PAIR_CLASS_INIT(&tag
, "utility");
1098 print_text(h
, "The");
1101 for (n
= n
->child
; n
; n
= n
->next
) {
1102 assert(MDOC_TEXT
== n
->type
);
1104 t
= print_otag(h
, TAG_B
, 1, &tag
);
1105 print_text(h
, n
->string
);
1108 if (nchild
> 2 && n
->next
) {
1109 h
->flags
|= HTML_NOSPACE
;
1113 if (n
->next
&& NULL
== n
->next
->next
)
1114 print_text(h
, "and");
1118 print_text(h
, "utilities exit");
1120 print_text(h
, "utility exits");
1122 print_text(h
, "0 on success, and >0 if an error occurs.");
1129 mdoc_em_pre(MDOC_ARGS
)
1131 struct htmlpair tag
;
1133 PAIR_CLASS_INIT(&tag
, "emph");
1134 print_otag(h
, TAG_SPAN
, 1, &tag
);
1141 mdoc_d1_pre(MDOC_ARGS
)
1143 struct htmlpair tag
[2];
1146 if (MDOC_BLOCK
!= n
->type
)
1149 SCALE_VS_INIT(&su
, 0);
1150 bufcat_su(h
, "margin-top", &su
);
1151 bufcat_su(h
, "margin-bottom", &su
);
1152 PAIR_STYLE_INIT(&tag
[0], h
);
1153 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1155 /* BLOCKQUOTE needs a block body. */
1157 PAIR_CLASS_INIT(&tag
[0], "display");
1158 print_otag(h
, TAG_DIV
, 1, tag
);
1160 if (MDOC_Dl
== n
->tok
) {
1161 PAIR_CLASS_INIT(&tag
[0], "lit");
1162 print_otag(h
, TAG_CODE
, 1, tag
);
1171 mdoc_sx_pre(MDOC_ARGS
)
1173 struct htmlpair tag
[2];
1176 strlcpy(buf
, "#", BUFSIZ
);
1177 for (n
= n
->child
; n
; n
= n
->next
) {
1178 html_idcat(buf
, n
->string
, BUFSIZ
);
1180 html_idcat(buf
, " ", BUFSIZ
);
1183 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1184 PAIR_HREF_INIT(&tag
[1], buf
);
1186 print_otag(h
, TAG_I
, 1, tag
);
1187 print_otag(h
, TAG_A
, 2, tag
);
1194 mdoc_bd_pre(MDOC_ARGS
)
1196 struct htmlpair tag
[2];
1198 const struct mdoc_node
*nn
;
1201 if (MDOC_HEAD
== n
->type
)
1204 if (MDOC_BLOCK
== n
->type
) {
1205 comp
= n
->norm
->Bd
.comp
;
1206 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1207 if (MDOC_BLOCK
!= nn
->type
)
1209 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1215 print_otag(h
, TAG_P
, 0, NULL
);
1219 SCALE_HS_INIT(&su
, 0);
1220 if (n
->norm
->Bd
.offs
)
1221 a2offs(n
->norm
->Bd
.offs
, &su
);
1223 bufcat_su(h
, "margin-left", &su
);
1224 PAIR_STYLE_INIT(&tag
[0], h
);
1226 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1227 DISP_literal
!= n
->norm
->Bd
.type
) {
1228 PAIR_CLASS_INIT(&tag
[1], "display");
1229 print_otag(h
, TAG_DIV
, 2, tag
);
1233 PAIR_CLASS_INIT(&tag
[1], "lit display");
1234 print_otag(h
, TAG_PRE
, 2, tag
);
1236 /* This can be recursive: save & set our literal state. */
1238 sv
= h
->flags
& HTML_LITERAL
;
1239 h
->flags
|= HTML_LITERAL
;
1241 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1242 print_mdoc_node(m
, nn
, h
);
1244 * If the printed node flushes its own line, then we
1245 * needn't do it here as well. This is hacky, but the
1246 * notion of selective eoln whitespace is pretty dumb
1247 * anyway, so don't sweat it.
1269 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1272 print_text(h
, "\n");
1274 h
->flags
|= HTML_NOSPACE
;
1278 h
->flags
&= ~HTML_LITERAL
;
1286 mdoc_pa_pre(MDOC_ARGS
)
1288 struct htmlpair tag
;
1290 PAIR_CLASS_INIT(&tag
, "file");
1291 print_otag(h
, TAG_I
, 1, &tag
);
1298 mdoc_ad_pre(MDOC_ARGS
)
1300 struct htmlpair tag
;
1302 PAIR_CLASS_INIT(&tag
, "addr");
1303 print_otag(h
, TAG_I
, 1, &tag
);
1310 mdoc_an_pre(MDOC_ARGS
)
1312 struct htmlpair tag
;
1314 /* TODO: -split and -nosplit (see termp_an_pre()). */
1316 PAIR_CLASS_INIT(&tag
, "author");
1317 print_otag(h
, TAG_SPAN
, 1, &tag
);
1324 mdoc_cd_pre(MDOC_ARGS
)
1326 struct htmlpair tag
;
1329 PAIR_CLASS_INIT(&tag
, "config");
1330 print_otag(h
, TAG_B
, 1, &tag
);
1337 mdoc_dv_pre(MDOC_ARGS
)
1339 struct htmlpair tag
;
1341 PAIR_CLASS_INIT(&tag
, "define");
1342 print_otag(h
, TAG_SPAN
, 1, &tag
);
1349 mdoc_ev_pre(MDOC_ARGS
)
1351 struct htmlpair tag
;
1353 PAIR_CLASS_INIT(&tag
, "env");
1354 print_otag(h
, TAG_SPAN
, 1, &tag
);
1361 mdoc_er_pre(MDOC_ARGS
)
1363 struct htmlpair tag
;
1365 PAIR_CLASS_INIT(&tag
, "errno");
1366 print_otag(h
, TAG_SPAN
, 1, &tag
);
1373 mdoc_fa_pre(MDOC_ARGS
)
1375 const struct mdoc_node
*nn
;
1376 struct htmlpair tag
;
1379 PAIR_CLASS_INIT(&tag
, "farg");
1380 if (n
->parent
->tok
!= MDOC_Fo
) {
1381 print_otag(h
, TAG_I
, 1, &tag
);
1385 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1386 t
= print_otag(h
, TAG_I
, 1, &tag
);
1387 print_text(h
, nn
->string
);
1390 h
->flags
|= HTML_NOSPACE
;
1395 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1396 h
->flags
|= HTML_NOSPACE
;
1406 mdoc_fd_pre(MDOC_ARGS
)
1408 struct htmlpair tag
[2];
1416 if (NULL
== (n
= n
->child
))
1419 assert(MDOC_TEXT
== n
->type
);
1421 if (strcmp(n
->string
, "#include")) {
1422 PAIR_CLASS_INIT(&tag
[0], "macro");
1423 print_otag(h
, TAG_B
, 1, tag
);
1427 PAIR_CLASS_INIT(&tag
[0], "includes");
1428 print_otag(h
, TAG_B
, 1, tag
);
1429 print_text(h
, n
->string
);
1431 if (NULL
!= (n
= n
->next
)) {
1432 assert(MDOC_TEXT
== n
->type
);
1433 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1434 n
->string
+ 1 : n
->string
, BUFSIZ
);
1437 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1440 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1444 if (h
->base_includes
) {
1445 buffmt_includes(h
, buf
);
1446 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1450 t
= print_otag(h
, TAG_A
, i
, tag
);
1451 print_text(h
, n
->string
);
1457 for ( ; n
; n
= n
->next
) {
1458 assert(MDOC_TEXT
== n
->type
);
1459 print_text(h
, n
->string
);
1468 mdoc_vt_pre(MDOC_ARGS
)
1470 struct htmlpair tag
;
1472 if (MDOC_BLOCK
== n
->type
) {
1475 } else if (MDOC_ELEM
== n
->type
) {
1477 } else if (MDOC_HEAD
== n
->type
)
1480 PAIR_CLASS_INIT(&tag
, "type");
1481 print_otag(h
, TAG_SPAN
, 1, &tag
);
1488 mdoc_ft_pre(MDOC_ARGS
)
1490 struct htmlpair tag
;
1493 PAIR_CLASS_INIT(&tag
, "ftype");
1494 print_otag(h
, TAG_I
, 1, &tag
);
1501 mdoc_fn_pre(MDOC_ARGS
)
1504 struct htmlpair tag
[2];
1506 const char *sp
, *ep
;
1509 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1512 /* Split apart into type and name. */
1513 assert(n
->child
->string
);
1514 sp
= n
->child
->string
;
1516 ep
= strchr(sp
, ' ');
1518 PAIR_CLASS_INIT(&tag
[0], "ftype");
1519 t
= print_otag(h
, TAG_I
, 1, tag
);
1522 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1523 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1525 print_text(h
, nbuf
);
1527 ep
= strchr(sp
, ' ');
1532 PAIR_CLASS_INIT(&tag
[0], "fname");
1535 * FIXME: only refer to IDs that we know exist.
1539 if (MDOC_SYNPRETTY
& n
->flags
) {
1541 html_idcat(nbuf
, sp
, BUFSIZ
);
1542 PAIR_ID_INIT(&tag
[1], nbuf
);
1544 strlcpy(nbuf
, "#", BUFSIZ
);
1545 html_idcat(nbuf
, sp
, BUFSIZ
);
1546 PAIR_HREF_INIT(&tag
[1], nbuf
);
1550 t
= print_otag(h
, TAG_B
, 1, tag
);
1553 strlcpy(nbuf
, sp
, BUFSIZ
);
1554 print_text(h
, nbuf
);
1559 h
->flags
|= HTML_NOSPACE
;
1563 PAIR_CLASS_INIT(&tag
[0], "farg");
1564 bufcat_style(h
, "white-space", "nowrap");
1565 PAIR_STYLE_INIT(&tag
[1], h
);
1567 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1569 if (MDOC_SYNPRETTY
& n
->flags
)
1571 t
= print_otag(h
, TAG_I
, i
, tag
);
1572 print_text(h
, n
->string
);
1575 h
->flags
|= HTML_NOSPACE
;
1580 h
->flags
|= HTML_NOSPACE
;
1584 h
->flags
|= HTML_NOSPACE
;
1594 mdoc_sm_pre(MDOC_ARGS
)
1597 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1598 if (0 == strcmp("on", n
->child
->string
)) {
1600 * FIXME: no p->col to check. Thus, if we have
1607 * the "3" is preceded by a space.
1609 h
->flags
&= ~HTML_NOSPACE
;
1610 h
->flags
&= ~HTML_NONOSPACE
;
1612 h
->flags
|= HTML_NONOSPACE
;
1619 mdoc_pp_pre(MDOC_ARGS
)
1622 print_otag(h
, TAG_P
, 0, NULL
);
1629 mdoc_sp_pre(MDOC_ARGS
)
1632 struct htmlpair tag
;
1634 SCALE_VS_INIT(&su
, 1);
1636 if (MDOC_sp
== n
->tok
) {
1638 a2roffsu(n
->child
->string
, &su
, SCALE_VS
);
1642 bufcat_su(h
, "height", &su
);
1643 PAIR_STYLE_INIT(&tag
, h
);
1644 print_otag(h
, TAG_DIV
, 1, &tag
);
1646 /* So the div isn't empty: */
1647 print_text(h
, "\\~");
1655 mdoc_lk_pre(MDOC_ARGS
)
1657 struct htmlpair tag
[2];
1659 if (NULL
== (n
= n
->child
))
1662 assert(MDOC_TEXT
== n
->type
);
1664 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1665 PAIR_HREF_INIT(&tag
[1], n
->string
);
1667 print_otag(h
, TAG_A
, 2, tag
);
1669 for (n
= n
->next
; n
; n
= n
->next
) {
1670 assert(MDOC_TEXT
== n
->type
);
1671 print_text(h
, n
->string
);
1680 mdoc_mt_pre(MDOC_ARGS
)
1682 struct htmlpair tag
[2];
1685 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1687 for (n
= n
->child
; n
; n
= n
->next
) {
1688 assert(MDOC_TEXT
== n
->type
);
1691 bufcat(h
, "mailto:");
1692 bufcat(h
, n
->string
);
1694 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1695 t
= print_otag(h
, TAG_A
, 2, tag
);
1696 print_text(h
, n
->string
);
1706 mdoc_fo_pre(MDOC_ARGS
)
1708 struct htmlpair tag
;
1711 if (MDOC_BODY
== n
->type
) {
1712 h
->flags
|= HTML_NOSPACE
;
1714 h
->flags
|= HTML_NOSPACE
;
1716 } else if (MDOC_BLOCK
== n
->type
) {
1721 /* XXX: we drop non-initial arguments as per groff. */
1724 assert(n
->child
->string
);
1726 PAIR_CLASS_INIT(&tag
, "fname");
1727 t
= print_otag(h
, TAG_B
, 1, &tag
);
1728 print_text(h
, n
->child
->string
);
1736 mdoc_fo_post(MDOC_ARGS
)
1739 if (MDOC_BODY
!= n
->type
)
1741 h
->flags
|= HTML_NOSPACE
;
1743 h
->flags
|= HTML_NOSPACE
;
1750 mdoc_in_pre(MDOC_ARGS
)
1753 struct htmlpair tag
[2];
1758 PAIR_CLASS_INIT(&tag
[0], "includes");
1759 print_otag(h
, TAG_B
, 1, tag
);
1762 * The first argument of the `In' gets special treatment as
1763 * being a linked value. Subsequent values are printed
1764 * afterward. groff does similarly. This also handles the case
1768 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1769 print_text(h
, "#include");
1772 h
->flags
|= HTML_NOSPACE
;
1774 if (NULL
!= (n
= n
->child
)) {
1775 assert(MDOC_TEXT
== n
->type
);
1777 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1782 if (h
->base_includes
) {
1783 buffmt_includes(h
, n
->string
);
1784 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1788 t
= print_otag(h
, TAG_A
, i
, tag
);
1789 print_text(h
, n
->string
);
1795 h
->flags
|= HTML_NOSPACE
;
1798 for ( ; n
; n
= n
->next
) {
1799 assert(MDOC_TEXT
== n
->type
);
1800 print_text(h
, n
->string
);
1809 mdoc_ic_pre(MDOC_ARGS
)
1811 struct htmlpair tag
;
1813 PAIR_CLASS_INIT(&tag
, "cmd");
1814 print_otag(h
, TAG_B
, 1, &tag
);
1821 mdoc_rv_pre(MDOC_ARGS
)
1823 struct htmlpair tag
;
1828 print_otag(h
, TAG_BR
, 0, NULL
);
1830 PAIR_CLASS_INIT(&tag
, "fname");
1832 print_text(h
, "The");
1835 for (n
= n
->child
; n
; n
= n
->next
) {
1836 assert(MDOC_TEXT
== n
->type
);
1838 t
= print_otag(h
, TAG_B
, 1, &tag
);
1839 print_text(h
, n
->string
);
1842 h
->flags
|= HTML_NOSPACE
;
1843 print_text(h
, "()");
1845 if (nchild
> 2 && n
->next
) {
1846 h
->flags
|= HTML_NOSPACE
;
1850 if (n
->next
&& NULL
== n
->next
->next
)
1851 print_text(h
, "and");
1855 print_text(h
, "functions return");
1857 print_text(h
, "function returns");
1859 print_text(h
, "the value 0 if successful; otherwise the value "
1860 "-1 is returned and the global variable");
1862 PAIR_CLASS_INIT(&tag
, "var");
1863 t
= print_otag(h
, TAG_B
, 1, &tag
);
1864 print_text(h
, "errno");
1866 print_text(h
, "is set to indicate the error.");
1873 mdoc_va_pre(MDOC_ARGS
)
1875 struct htmlpair tag
;
1877 PAIR_CLASS_INIT(&tag
, "var");
1878 print_otag(h
, TAG_B
, 1, &tag
);
1885 mdoc_ap_pre(MDOC_ARGS
)
1888 h
->flags
|= HTML_NOSPACE
;
1889 print_text(h
, "\\(aq");
1890 h
->flags
|= HTML_NOSPACE
;
1897 mdoc_bf_pre(MDOC_ARGS
)
1899 struct htmlpair tag
[2];
1902 if (MDOC_HEAD
== n
->type
)
1904 else if (MDOC_BODY
!= n
->type
)
1907 if (FONT_Em
== n
->norm
->Bf
.font
)
1908 PAIR_CLASS_INIT(&tag
[0], "emph");
1909 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1910 PAIR_CLASS_INIT(&tag
[0], "symb");
1911 else if (FONT_Li
== n
->norm
->Bf
.font
)
1912 PAIR_CLASS_INIT(&tag
[0], "lit");
1914 PAIR_CLASS_INIT(&tag
[0], "none");
1917 * We want this to be inline-formatted, but needs to be div to
1918 * accept block children.
1920 bufcat_style(h
, "display", "inline");
1921 SCALE_HS_INIT(&su
, 1);
1922 /* Needs a left-margin for spacing. */
1923 bufcat_su(h
, "margin-left", &su
);
1924 PAIR_STYLE_INIT(&tag
[1], h
);
1925 print_otag(h
, TAG_DIV
, 2, tag
);
1932 mdoc_ms_pre(MDOC_ARGS
)
1934 struct htmlpair tag
;
1936 PAIR_CLASS_INIT(&tag
, "symb");
1937 print_otag(h
, TAG_SPAN
, 1, &tag
);
1944 mdoc_igndelim_pre(MDOC_ARGS
)
1947 h
->flags
|= HTML_IGNDELIM
;
1954 mdoc_pf_post(MDOC_ARGS
)
1957 h
->flags
|= HTML_NOSPACE
;
1963 mdoc_rs_pre(MDOC_ARGS
)
1965 struct htmlpair tag
;
1967 if (MDOC_BLOCK
!= n
->type
)
1970 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1971 print_otag(h
, TAG_P
, 0, NULL
);
1973 PAIR_CLASS_INIT(&tag
, "ref");
1974 print_otag(h
, TAG_SPAN
, 1, &tag
);
1982 mdoc_li_pre(MDOC_ARGS
)
1984 struct htmlpair tag
;
1986 PAIR_CLASS_INIT(&tag
, "lit");
1987 print_otag(h
, TAG_SPAN
, 1, &tag
);
1994 mdoc_sy_pre(MDOC_ARGS
)
1996 struct htmlpair tag
;
1998 PAIR_CLASS_INIT(&tag
, "symb");
1999 print_otag(h
, TAG_SPAN
, 1, &tag
);
2006 mdoc_bt_pre(MDOC_ARGS
)
2009 print_text(h
, "is currently in beta test.");
2016 mdoc_ud_pre(MDOC_ARGS
)
2019 print_text(h
, "currently under development.");
2026 mdoc_lb_pre(MDOC_ARGS
)
2028 struct htmlpair tag
;
2030 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2031 print_otag(h
, TAG_BR
, 0, NULL
);
2033 PAIR_CLASS_INIT(&tag
, "lib");
2034 print_otag(h
, TAG_SPAN
, 1, &tag
);
2041 mdoc__x_pre(MDOC_ARGS
)
2043 struct htmlpair tag
[2];
2050 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2051 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2052 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2053 print_text(h
, "and");
2056 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2060 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2063 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2066 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2070 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2074 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2077 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2080 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2083 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2086 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2089 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2092 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2095 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2102 if (MDOC__U
!= n
->tok
) {
2103 print_otag(h
, t
, 1, tag
);
2107 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2108 print_otag(h
, TAG_A
, 2, tag
);
2116 mdoc__x_post(MDOC_ARGS
)
2119 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2120 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2121 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2126 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2129 h
->flags
|= HTML_NOSPACE
;
2130 print_text(h
, n
->next
? "," : ".");
2136 mdoc_bk_pre(MDOC_ARGS
)
2145 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2146 h
->flags
|= HTML_PREKEEP
;
2159 mdoc_bk_post(MDOC_ARGS
)
2162 if (MDOC_BODY
== n
->type
)
2163 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2169 mdoc_quote_pre(MDOC_ARGS
)
2171 struct htmlpair tag
;
2173 if (MDOC_BODY
!= n
->type
)
2180 print_text(h
, "\\(la");
2185 print_text(h
, "\\(lC");
2190 print_text(h
, "\\(lB");
2195 print_text(h
, "\\(lB");
2196 h
->flags
|= HTML_NOSPACE
;
2197 PAIR_CLASS_INIT(&tag
, "opt");
2198 print_otag(h
, TAG_SPAN
, 1, &tag
);
2207 print_text(h
, "\\(lq");
2219 print_text(h
, "\\(oq");
2226 h
->flags
|= HTML_NOSPACE
;
2233 mdoc_quote_post(MDOC_ARGS
)
2236 if (MDOC_BODY
!= n
->type
)
2239 h
->flags
|= HTML_NOSPACE
;
2245 print_text(h
, "\\(ra");
2250 print_text(h
, "\\(rC");
2259 print_text(h
, "\\(rB");
2268 print_text(h
, "\\(rq");
2280 print_text(h
, "\\(aq");