]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.208 2014/10/10 15:26:29 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 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
) {
320 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
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
)
490 PAIR_CLASS_INIT(&tag
, "foot");
491 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
493 print_otag(h
, TAG_TBODY
, 0, NULL
);
495 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
497 PAIR_CLASS_INIT(&tag
, "foot-date");
498 print_otag(h
, TAG_TD
, 1, &tag
);
499 print_text(h
, meta
->date
);
502 PAIR_CLASS_INIT(&tag
, "foot-os");
503 print_otag(h
, TAG_TD
, 1, &tag
);
504 print_text(h
, meta
->os
);
509 mdoc_root_pre(MDOC_ARGS
)
513 char *volume
, *title
;
515 if (NULL
== meta
->arch
)
516 volume
= mandoc_strdup(meta
->vol
);
518 mandoc_asprintf(&volume
, "%s (%s)",
519 meta
->vol
, meta
->arch
);
521 if (NULL
== meta
->msec
)
522 title
= mandoc_strdup(meta
->title
);
524 mandoc_asprintf(&title
, "%s(%s)",
525 meta
->title
, meta
->msec
);
527 PAIR_CLASS_INIT(&tag
, "head");
528 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
530 print_otag(h
, TAG_TBODY
, 0, NULL
);
532 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
534 PAIR_CLASS_INIT(&tag
, "head-ltitle");
535 print_otag(h
, TAG_TD
, 1, &tag
);
536 print_text(h
, title
);
539 PAIR_CLASS_INIT(&tag
, "head-vol");
540 print_otag(h
, TAG_TD
, 1, &tag
);
541 print_text(h
, volume
);
544 PAIR_CLASS_INIT(&tag
, "head-rtitle");
545 print_otag(h
, TAG_TD
, 1, &tag
);
546 print_text(h
, title
);
555 mdoc_sh_pre(MDOC_ARGS
)
561 PAIR_CLASS_INIT(&tag
, "section");
562 print_otag(h
, TAG_DIV
, 1, &tag
);
565 if (n
->sec
== SEC_AUTHORS
)
566 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
575 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
576 bufcat_id(h
, n
->string
);
577 if (NULL
!= (n
= n
->next
))
582 PAIR_ID_INIT(&tag
, h
->buf
);
583 print_otag(h
, TAG_H1
, 1, &tag
);
585 print_otag(h
, TAG_H1
, 0, NULL
);
591 mdoc_ss_pre(MDOC_ARGS
)
595 if (MDOC_BLOCK
== n
->type
) {
596 PAIR_CLASS_INIT(&tag
, "subsection");
597 print_otag(h
, TAG_DIV
, 1, &tag
);
599 } else if (MDOC_BODY
== n
->type
)
605 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
606 bufcat_id(h
, n
->string
);
607 if (NULL
!= (n
= n
->next
))
612 PAIR_ID_INIT(&tag
, h
->buf
);
613 print_otag(h
, TAG_H2
, 1, &tag
);
615 print_otag(h
, TAG_H2
, 0, NULL
);
621 mdoc_fl_pre(MDOC_ARGS
)
625 PAIR_CLASS_INIT(&tag
, "flag");
626 print_otag(h
, TAG_B
, 1, &tag
);
628 /* `Cm' has no leading hyphen. */
630 if (MDOC_Cm
== n
->tok
)
633 print_text(h
, "\\-");
635 if ( ! (n
->nchild
== 0 &&
637 n
->next
->type
== MDOC_TEXT
||
638 n
->next
->flags
& MDOC_LINE
)))
639 h
->flags
|= HTML_NOSPACE
;
645 mdoc_nd_pre(MDOC_ARGS
)
649 if (MDOC_BODY
!= n
->type
)
652 /* XXX: this tag in theory can contain block elements. */
654 print_text(h
, "\\(em");
655 PAIR_CLASS_INIT(&tag
, "desc");
656 print_otag(h
, TAG_SPAN
, 1, &tag
);
661 mdoc_nm_pre(MDOC_ARGS
)
670 PAIR_CLASS_INIT(&tag
, "name");
671 print_otag(h
, TAG_B
, 1, &tag
);
672 if (NULL
== n
->child
&& meta
->name
)
673 print_text(h
, meta
->name
);
676 print_otag(h
, TAG_TD
, 0, NULL
);
677 if (NULL
== n
->child
&& meta
->name
)
678 print_text(h
, meta
->name
);
681 print_otag(h
, TAG_TD
, 0, NULL
);
688 PAIR_CLASS_INIT(&tag
, "synopsis");
689 print_otag(h
, TAG_TABLE
, 1, &tag
);
691 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
692 if (MDOC_TEXT
== n
->type
)
693 len
+= html_strlen(n
->string
);
695 if (0 == len
&& meta
->name
)
696 len
= html_strlen(meta
->name
);
698 SCALE_HS_INIT(&su
, len
);
700 bufcat_su(h
, "width", &su
);
701 PAIR_STYLE_INIT(&tag
, h
);
702 print_otag(h
, TAG_COL
, 1, &tag
);
703 print_otag(h
, TAG_COL
, 0, NULL
);
704 print_otag(h
, TAG_TBODY
, 0, NULL
);
705 print_otag(h
, TAG_TR
, 0, NULL
);
710 mdoc_xr_pre(MDOC_ARGS
)
712 struct htmlpair tag
[2];
714 if (NULL
== n
->child
)
717 PAIR_CLASS_INIT(&tag
[0], "link-man");
720 buffmt_man(h
, n
->child
->string
,
722 n
->child
->next
->string
: NULL
);
723 PAIR_HREF_INIT(&tag
[1], h
->buf
);
724 print_otag(h
, TAG_A
, 2, tag
);
726 print_otag(h
, TAG_A
, 1, tag
);
729 print_text(h
, n
->string
);
731 if (NULL
== (n
= n
->next
))
734 h
->flags
|= HTML_NOSPACE
;
736 h
->flags
|= HTML_NOSPACE
;
737 print_text(h
, n
->string
);
738 h
->flags
|= HTML_NOSPACE
;
744 mdoc_ns_pre(MDOC_ARGS
)
747 if ( ! (MDOC_LINE
& n
->flags
))
748 h
->flags
|= HTML_NOSPACE
;
753 mdoc_ar_pre(MDOC_ARGS
)
757 PAIR_CLASS_INIT(&tag
, "arg");
758 print_otag(h
, TAG_I
, 1, &tag
);
763 mdoc_xx_pre(MDOC_ARGS
)
792 PAIR_CLASS_INIT(&tag
, "unix");
793 print_otag(h
, TAG_SPAN
, 1, &tag
);
798 h
->flags
|= HTML_KEEP
;
799 print_text(h
, n
->child
->string
);
806 mdoc_bx_pre(MDOC_ARGS
)
810 PAIR_CLASS_INIT(&tag
, "unix");
811 print_otag(h
, TAG_SPAN
, 1, &tag
);
813 if (NULL
!= (n
= n
->child
)) {
814 print_text(h
, n
->string
);
815 h
->flags
|= HTML_NOSPACE
;
816 print_text(h
, "BSD");
818 print_text(h
, "BSD");
822 if (NULL
!= (n
= n
->next
)) {
823 h
->flags
|= HTML_NOSPACE
;
825 h
->flags
|= HTML_NOSPACE
;
826 print_text(h
, n
->string
);
833 mdoc_it_pre(MDOC_ARGS
)
837 struct htmlpair tag
[2];
838 const struct mdoc_node
*bl
;
841 while (bl
&& MDOC_Bl
!= bl
->tok
)
846 type
= bl
->norm
->Bl
.type
;
849 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
853 if (MDOC_HEAD
== n
->type
) {
874 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
875 bufcat_su(h
, "margin-top", &su
);
876 PAIR_STYLE_INIT(&tag
[1], h
);
877 print_otag(h
, TAG_DT
, 2, tag
);
878 if (LIST_diag
!= type
)
880 PAIR_CLASS_INIT(&tag
[0], "diag");
881 print_otag(h
, TAG_B
, 1, tag
);
888 } else if (MDOC_BODY
== n
->type
) {
899 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
900 bufcat_su(h
, "margin-top", &su
);
901 PAIR_STYLE_INIT(&tag
[1], h
);
902 print_otag(h
, TAG_LI
, 2, tag
);
913 if (NULL
== bl
->norm
->Bl
.width
) {
914 print_otag(h
, TAG_DD
, 1, tag
);
917 a2width(bl
->norm
->Bl
.width
, &su
);
918 bufcat_su(h
, "margin-left", &su
);
919 PAIR_STYLE_INIT(&tag
[1], h
);
920 print_otag(h
, TAG_DD
, 2, tag
);
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_TD
, 2, tag
);
934 print_otag(h
, TAG_TR
, 1, tag
);
945 mdoc_bl_pre(MDOC_ARGS
)
948 struct htmlpair tag
[3];
952 if (MDOC_BODY
== n
->type
) {
953 if (LIST_column
== n
->norm
->Bl
.type
)
954 print_otag(h
, TAG_TBODY
, 0, NULL
);
958 if (MDOC_HEAD
== n
->type
) {
959 if (LIST_column
!= n
->norm
->Bl
.type
)
963 * For each column, print out the <COL> tag with our
964 * suggested width. The last column gets min-width, as
965 * in terminal mode it auto-sizes to the width of the
966 * screen and we want to preserve that behaviour.
969 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
971 a2width(n
->norm
->Bl
.cols
[i
], &su
);
972 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
973 bufcat_su(h
, "width", &su
);
975 bufcat_su(h
, "min-width", &su
);
976 PAIR_STYLE_INIT(&tag
[0], h
);
977 print_otag(h
, TAG_COL
, 1, tag
);
983 SCALE_VS_INIT(&su
, 0);
985 bufcat_su(h
, "margin-top", &su
);
986 bufcat_su(h
, "margin-bottom", &su
);
987 PAIR_STYLE_INIT(&tag
[0], h
);
989 assert(lists
[n
->norm
->Bl
.type
]);
990 (void)strlcpy(buf
, "list ", BUFSIZ
);
991 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
992 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
994 /* Set the block's left-hand margin. */
996 if (n
->norm
->Bl
.offs
) {
997 a2offs(n
->norm
->Bl
.offs
, &su
);
998 bufcat_su(h
, "margin-left", &su
);
1001 switch (n
->norm
->Bl
.type
) {
1009 print_otag(h
, TAG_UL
, 2, tag
);
1012 print_otag(h
, TAG_OL
, 2, tag
);
1023 print_otag(h
, TAG_DL
, 2, tag
);
1026 print_otag(h
, TAG_TABLE
, 2, tag
);
1037 mdoc_ex_pre(MDOC_ARGS
)
1040 struct htmlpair tag
;
1044 print_otag(h
, TAG_BR
, 0, NULL
);
1046 PAIR_CLASS_INIT(&tag
, "utility");
1048 print_text(h
, "The");
1051 for (n
= n
->child
; n
; n
= n
->next
) {
1052 assert(MDOC_TEXT
== n
->type
);
1054 t
= print_otag(h
, TAG_B
, 1, &tag
);
1055 print_text(h
, n
->string
);
1058 if (nchild
> 2 && n
->next
) {
1059 h
->flags
|= HTML_NOSPACE
;
1063 if (n
->next
&& NULL
== n
->next
->next
)
1064 print_text(h
, "and");
1068 print_text(h
, "utilities exit\\~0");
1070 print_text(h
, "utility exits\\~0");
1072 print_text(h
, "on success, and\\~>0 if an error occurs.");
1077 mdoc_em_pre(MDOC_ARGS
)
1079 struct htmlpair tag
;
1081 PAIR_CLASS_INIT(&tag
, "emph");
1082 print_otag(h
, TAG_SPAN
, 1, &tag
);
1087 mdoc_d1_pre(MDOC_ARGS
)
1089 struct htmlpair tag
[2];
1092 if (MDOC_BLOCK
!= n
->type
)
1095 SCALE_VS_INIT(&su
, 0);
1097 bufcat_su(h
, "margin-top", &su
);
1098 bufcat_su(h
, "margin-bottom", &su
);
1099 PAIR_STYLE_INIT(&tag
[0], h
);
1100 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1102 /* BLOCKQUOTE needs a block body. */
1104 PAIR_CLASS_INIT(&tag
[0], "display");
1105 print_otag(h
, TAG_DIV
, 1, tag
);
1107 if (MDOC_Dl
== n
->tok
) {
1108 PAIR_CLASS_INIT(&tag
[0], "lit");
1109 print_otag(h
, TAG_CODE
, 1, tag
);
1116 mdoc_sx_pre(MDOC_ARGS
)
1118 struct htmlpair tag
[2];
1123 for (n
= n
->child
; n
; ) {
1124 bufcat_id(h
, n
->string
);
1125 if (NULL
!= (n
= n
->next
))
1129 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1130 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1132 print_otag(h
, TAG_I
, 1, tag
);
1133 print_otag(h
, TAG_A
, 2, tag
);
1138 mdoc_bd_pre(MDOC_ARGS
)
1140 struct htmlpair tag
[2];
1142 const struct mdoc_node
*nn
;
1145 if (MDOC_HEAD
== n
->type
)
1148 if (MDOC_BLOCK
== n
->type
) {
1149 comp
= n
->norm
->Bd
.comp
;
1150 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1151 if (MDOC_BLOCK
!= nn
->type
)
1153 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1163 SCALE_HS_INIT(&su
, 0);
1164 if (n
->norm
->Bd
.offs
)
1165 a2offs(n
->norm
->Bd
.offs
, &su
);
1168 bufcat_su(h
, "margin-left", &su
);
1169 PAIR_STYLE_INIT(&tag
[0], h
);
1171 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1172 DISP_literal
!= n
->norm
->Bd
.type
) {
1173 PAIR_CLASS_INIT(&tag
[1], "display");
1174 print_otag(h
, TAG_DIV
, 2, tag
);
1178 PAIR_CLASS_INIT(&tag
[1], "lit display");
1179 print_otag(h
, TAG_PRE
, 2, tag
);
1181 /* This can be recursive: save & set our literal state. */
1183 sv
= h
->flags
& HTML_LITERAL
;
1184 h
->flags
|= HTML_LITERAL
;
1186 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1187 print_mdoc_node(meta
, nn
, h
);
1189 * If the printed node flushes its own line, then we
1190 * needn't do it here as well. This is hacky, but the
1191 * notion of selective eoln whitespace is pretty dumb
1192 * anyway, so don't sweat it.
1214 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1217 print_text(h
, "\n");
1219 h
->flags
|= HTML_NOSPACE
;
1223 h
->flags
&= ~HTML_LITERAL
;
1229 mdoc_pa_pre(MDOC_ARGS
)
1231 struct htmlpair tag
;
1233 PAIR_CLASS_INIT(&tag
, "file");
1234 print_otag(h
, TAG_I
, 1, &tag
);
1239 mdoc_ad_pre(MDOC_ARGS
)
1241 struct htmlpair tag
;
1243 PAIR_CLASS_INIT(&tag
, "addr");
1244 print_otag(h
, TAG_I
, 1, &tag
);
1249 mdoc_an_pre(MDOC_ARGS
)
1251 struct htmlpair tag
;
1253 if (n
->norm
->An
.auth
== AUTH_split
) {
1254 h
->flags
&= ~HTML_NOSPLIT
;
1255 h
->flags
|= HTML_SPLIT
;
1258 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1259 h
->flags
&= ~HTML_SPLIT
;
1260 h
->flags
|= HTML_NOSPLIT
;
1264 if (n
->child
== NULL
)
1267 if (h
->flags
& HTML_SPLIT
)
1268 print_otag(h
, TAG_BR
, 0, NULL
);
1270 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1271 h
->flags
|= HTML_SPLIT
;
1273 PAIR_CLASS_INIT(&tag
, "author");
1274 print_otag(h
, TAG_SPAN
, 1, &tag
);
1279 mdoc_cd_pre(MDOC_ARGS
)
1281 struct htmlpair tag
;
1284 PAIR_CLASS_INIT(&tag
, "config");
1285 print_otag(h
, TAG_B
, 1, &tag
);
1290 mdoc_dv_pre(MDOC_ARGS
)
1292 struct htmlpair tag
;
1294 PAIR_CLASS_INIT(&tag
, "define");
1295 print_otag(h
, TAG_SPAN
, 1, &tag
);
1300 mdoc_ev_pre(MDOC_ARGS
)
1302 struct htmlpair tag
;
1304 PAIR_CLASS_INIT(&tag
, "env");
1305 print_otag(h
, TAG_SPAN
, 1, &tag
);
1310 mdoc_er_pre(MDOC_ARGS
)
1312 struct htmlpair tag
;
1314 PAIR_CLASS_INIT(&tag
, "errno");
1315 print_otag(h
, TAG_SPAN
, 1, &tag
);
1320 mdoc_fa_pre(MDOC_ARGS
)
1322 const struct mdoc_node
*nn
;
1323 struct htmlpair tag
;
1326 PAIR_CLASS_INIT(&tag
, "farg");
1327 if (n
->parent
->tok
!= MDOC_Fo
) {
1328 print_otag(h
, TAG_I
, 1, &tag
);
1332 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1333 t
= print_otag(h
, TAG_I
, 1, &tag
);
1334 print_text(h
, nn
->string
);
1337 h
->flags
|= HTML_NOSPACE
;
1342 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1343 h
->flags
|= HTML_NOSPACE
;
1351 mdoc_fd_pre(MDOC_ARGS
)
1353 struct htmlpair tag
[2];
1361 if (NULL
== (n
= n
->child
))
1364 assert(MDOC_TEXT
== n
->type
);
1366 if (strcmp(n
->string
, "#include")) {
1367 PAIR_CLASS_INIT(&tag
[0], "macro");
1368 print_otag(h
, TAG_B
, 1, tag
);
1372 PAIR_CLASS_INIT(&tag
[0], "includes");
1373 print_otag(h
, TAG_B
, 1, tag
);
1374 print_text(h
, n
->string
);
1376 if (NULL
!= (n
= n
->next
)) {
1377 assert(MDOC_TEXT
== n
->type
);
1380 * XXX This is broken and not easy to fix.
1381 * When using -Oincludes, truncation may occur.
1382 * Dynamic allocation wouldn't help because
1383 * passing long strings to buffmt_includes()
1384 * does not work either.
1387 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1388 n
->string
+ 1 : n
->string
, BUFSIZ
);
1391 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1394 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1397 if (h
->base_includes
) {
1398 buffmt_includes(h
, buf
);
1399 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1403 t
= print_otag(h
, TAG_A
, i
, tag
);
1404 print_text(h
, n
->string
);
1410 for ( ; n
; n
= n
->next
) {
1411 assert(MDOC_TEXT
== n
->type
);
1412 print_text(h
, n
->string
);
1419 mdoc_vt_pre(MDOC_ARGS
)
1421 struct htmlpair tag
;
1423 if (MDOC_BLOCK
== n
->type
) {
1426 } else if (MDOC_ELEM
== n
->type
) {
1428 } else if (MDOC_HEAD
== n
->type
)
1431 PAIR_CLASS_INIT(&tag
, "type");
1432 print_otag(h
, TAG_SPAN
, 1, &tag
);
1437 mdoc_ft_pre(MDOC_ARGS
)
1439 struct htmlpair tag
;
1442 PAIR_CLASS_INIT(&tag
, "ftype");
1443 print_otag(h
, TAG_I
, 1, &tag
);
1448 mdoc_fn_pre(MDOC_ARGS
)
1451 struct htmlpair tag
[2];
1453 const char *sp
, *ep
;
1456 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1459 /* Split apart into type and name. */
1460 assert(n
->child
->string
);
1461 sp
= n
->child
->string
;
1463 ep
= strchr(sp
, ' ');
1465 PAIR_CLASS_INIT(&tag
[0], "ftype");
1466 t
= print_otag(h
, TAG_I
, 1, tag
);
1469 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1470 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1472 print_text(h
, nbuf
);
1474 ep
= strchr(sp
, ' ');
1479 PAIR_CLASS_INIT(&tag
[0], "fname");
1482 * FIXME: only refer to IDs that we know exist.
1486 if (MDOC_SYNPRETTY
& n
->flags
) {
1488 html_idcat(nbuf
, sp
, BUFSIZ
);
1489 PAIR_ID_INIT(&tag
[1], nbuf
);
1491 strlcpy(nbuf
, "#", BUFSIZ
);
1492 html_idcat(nbuf
, sp
, BUFSIZ
);
1493 PAIR_HREF_INIT(&tag
[1], nbuf
);
1497 t
= print_otag(h
, TAG_B
, 1, tag
);
1504 h
->flags
|= HTML_NOSPACE
;
1506 h
->flags
|= HTML_NOSPACE
;
1508 PAIR_CLASS_INIT(&tag
[0], "farg");
1510 bufcat_style(h
, "white-space", "nowrap");
1511 PAIR_STYLE_INIT(&tag
[1], h
);
1513 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1515 if (MDOC_SYNPRETTY
& n
->flags
)
1517 t
= print_otag(h
, TAG_I
, i
, tag
);
1518 print_text(h
, n
->string
);
1521 h
->flags
|= HTML_NOSPACE
;
1526 h
->flags
|= HTML_NOSPACE
;
1530 h
->flags
|= HTML_NOSPACE
;
1538 mdoc_sm_pre(MDOC_ARGS
)
1541 if (NULL
== n
->child
)
1542 h
->flags
^= HTML_NONOSPACE
;
1543 else if (0 == strcmp("on", n
->child
->string
))
1544 h
->flags
&= ~HTML_NONOSPACE
;
1546 h
->flags
|= HTML_NONOSPACE
;
1548 if ( ! (HTML_NONOSPACE
& h
->flags
))
1549 h
->flags
&= ~HTML_NOSPACE
;
1555 mdoc_skip_pre(MDOC_ARGS
)
1562 mdoc_pp_pre(MDOC_ARGS
)
1570 mdoc_sp_pre(MDOC_ARGS
)
1573 struct htmlpair tag
;
1575 SCALE_VS_INIT(&su
, 1);
1577 if (MDOC_sp
== n
->tok
) {
1578 if (NULL
!= (n
= n
->child
))
1579 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1580 SCALE_VS_INIT(&su
, atoi(n
->string
));
1585 bufcat_su(h
, "height", &su
);
1586 PAIR_STYLE_INIT(&tag
, h
);
1587 print_otag(h
, TAG_DIV
, 1, &tag
);
1589 /* So the div isn't empty: */
1590 print_text(h
, "\\~");
1597 mdoc_lk_pre(MDOC_ARGS
)
1599 struct htmlpair tag
[2];
1601 if (NULL
== (n
= n
->child
))
1604 assert(MDOC_TEXT
== n
->type
);
1606 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1607 PAIR_HREF_INIT(&tag
[1], n
->string
);
1609 print_otag(h
, TAG_A
, 2, tag
);
1611 if (NULL
== n
->next
)
1612 print_text(h
, n
->string
);
1614 for (n
= n
->next
; n
; n
= n
->next
)
1615 print_text(h
, n
->string
);
1621 mdoc_mt_pre(MDOC_ARGS
)
1623 struct htmlpair tag
[2];
1626 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1628 for (n
= n
->child
; n
; n
= n
->next
) {
1629 assert(MDOC_TEXT
== n
->type
);
1632 bufcat(h
, "mailto:");
1633 bufcat(h
, n
->string
);
1635 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1636 t
= print_otag(h
, TAG_A
, 2, tag
);
1637 print_text(h
, n
->string
);
1645 mdoc_fo_pre(MDOC_ARGS
)
1647 struct htmlpair tag
;
1650 if (MDOC_BODY
== n
->type
) {
1651 h
->flags
|= HTML_NOSPACE
;
1653 h
->flags
|= HTML_NOSPACE
;
1655 } else if (MDOC_BLOCK
== n
->type
) {
1660 /* XXX: we drop non-initial arguments as per groff. */
1663 assert(n
->child
->string
);
1665 PAIR_CLASS_INIT(&tag
, "fname");
1666 t
= print_otag(h
, TAG_B
, 1, &tag
);
1667 print_text(h
, n
->child
->string
);
1673 mdoc_fo_post(MDOC_ARGS
)
1676 if (MDOC_BODY
!= n
->type
)
1678 h
->flags
|= HTML_NOSPACE
;
1680 h
->flags
|= HTML_NOSPACE
;
1685 mdoc_in_pre(MDOC_ARGS
)
1688 struct htmlpair tag
[2];
1693 PAIR_CLASS_INIT(&tag
[0], "includes");
1694 print_otag(h
, TAG_B
, 1, tag
);
1697 * The first argument of the `In' gets special treatment as
1698 * being a linked value. Subsequent values are printed
1699 * afterward. groff does similarly. This also handles the case
1703 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1704 print_text(h
, "#include");
1707 h
->flags
|= HTML_NOSPACE
;
1709 if (NULL
!= (n
= n
->child
)) {
1710 assert(MDOC_TEXT
== n
->type
);
1712 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1715 if (h
->base_includes
) {
1716 buffmt_includes(h
, n
->string
);
1717 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1721 t
= print_otag(h
, TAG_A
, i
, tag
);
1722 print_text(h
, n
->string
);
1728 h
->flags
|= HTML_NOSPACE
;
1731 for ( ; n
; n
= n
->next
) {
1732 assert(MDOC_TEXT
== n
->type
);
1733 print_text(h
, n
->string
);
1740 mdoc_ic_pre(MDOC_ARGS
)
1742 struct htmlpair tag
;
1744 PAIR_CLASS_INIT(&tag
, "cmd");
1745 print_otag(h
, TAG_B
, 1, &tag
);
1750 mdoc_rv_pre(MDOC_ARGS
)
1752 struct htmlpair tag
;
1757 print_otag(h
, TAG_BR
, 0, NULL
);
1759 PAIR_CLASS_INIT(&tag
, "fname");
1763 print_text(h
, "The");
1765 for (n
= n
->child
; n
; n
= n
->next
) {
1766 t
= print_otag(h
, TAG_B
, 1, &tag
);
1767 print_text(h
, n
->string
);
1770 h
->flags
|= HTML_NOSPACE
;
1771 print_text(h
, "()");
1773 if (n
->next
== NULL
)
1777 h
->flags
|= HTML_NOSPACE
;
1780 if (n
->next
->next
== NULL
)
1781 print_text(h
, "and");
1785 print_text(h
, "functions return");
1787 print_text(h
, "function returns");
1789 print_text(h
, "the value\\~0 if successful;");
1791 print_text(h
, "Upon successful completion,"
1792 " the value\\~0 is returned;");
1794 print_text(h
, "otherwise the value\\~\\-1 is returned"
1795 " and the global variable");
1797 PAIR_CLASS_INIT(&tag
, "var");
1798 t
= print_otag(h
, TAG_B
, 1, &tag
);
1799 print_text(h
, "errno");
1801 print_text(h
, "is set to indicate the error.");
1806 mdoc_va_pre(MDOC_ARGS
)
1808 struct htmlpair tag
;
1810 PAIR_CLASS_INIT(&tag
, "var");
1811 print_otag(h
, TAG_B
, 1, &tag
);
1816 mdoc_ap_pre(MDOC_ARGS
)
1819 h
->flags
|= HTML_NOSPACE
;
1820 print_text(h
, "\\(aq");
1821 h
->flags
|= HTML_NOSPACE
;
1826 mdoc_bf_pre(MDOC_ARGS
)
1828 struct htmlpair tag
[2];
1831 if (MDOC_HEAD
== n
->type
)
1833 else if (MDOC_BODY
!= n
->type
)
1836 if (FONT_Em
== n
->norm
->Bf
.font
)
1837 PAIR_CLASS_INIT(&tag
[0], "emph");
1838 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1839 PAIR_CLASS_INIT(&tag
[0], "symb");
1840 else if (FONT_Li
== n
->norm
->Bf
.font
)
1841 PAIR_CLASS_INIT(&tag
[0], "lit");
1843 PAIR_CLASS_INIT(&tag
[0], "none");
1846 * We want this to be inline-formatted, but needs to be div to
1847 * accept block children.
1850 bufcat_style(h
, "display", "inline");
1851 SCALE_HS_INIT(&su
, 1);
1852 /* Needs a left-margin for spacing. */
1853 bufcat_su(h
, "margin-left", &su
);
1854 PAIR_STYLE_INIT(&tag
[1], h
);
1855 print_otag(h
, TAG_DIV
, 2, tag
);
1860 mdoc_ms_pre(MDOC_ARGS
)
1862 struct htmlpair tag
;
1864 PAIR_CLASS_INIT(&tag
, "symb");
1865 print_otag(h
, TAG_SPAN
, 1, &tag
);
1870 mdoc_igndelim_pre(MDOC_ARGS
)
1873 h
->flags
|= HTML_IGNDELIM
;
1878 mdoc_pf_post(MDOC_ARGS
)
1881 h
->flags
|= HTML_NOSPACE
;
1885 mdoc_rs_pre(MDOC_ARGS
)
1887 struct htmlpair tag
;
1889 if (MDOC_BLOCK
!= n
->type
)
1892 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1895 PAIR_CLASS_INIT(&tag
, "ref");
1896 print_otag(h
, TAG_SPAN
, 1, &tag
);
1901 mdoc_li_pre(MDOC_ARGS
)
1903 struct htmlpair tag
;
1905 PAIR_CLASS_INIT(&tag
, "lit");
1906 print_otag(h
, TAG_CODE
, 1, &tag
);
1911 mdoc_sy_pre(MDOC_ARGS
)
1913 struct htmlpair tag
;
1915 PAIR_CLASS_INIT(&tag
, "symb");
1916 print_otag(h
, TAG_SPAN
, 1, &tag
);
1921 mdoc_bt_pre(MDOC_ARGS
)
1924 print_text(h
, "is currently in beta test.");
1929 mdoc_ud_pre(MDOC_ARGS
)
1932 print_text(h
, "currently under development.");
1937 mdoc_lb_pre(MDOC_ARGS
)
1939 struct htmlpair tag
;
1941 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1942 print_otag(h
, TAG_BR
, 0, NULL
);
1944 PAIR_CLASS_INIT(&tag
, "lib");
1945 print_otag(h
, TAG_SPAN
, 1, &tag
);
1950 mdoc__x_pre(MDOC_ARGS
)
1952 struct htmlpair tag
[2];
1959 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1960 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1961 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1962 print_text(h
, "and");
1965 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1969 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1975 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1979 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1983 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1986 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1989 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1992 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1995 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1998 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2001 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2004 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2011 if (MDOC__U
!= n
->tok
) {
2012 print_otag(h
, t
, 1, tag
);
2016 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2017 print_otag(h
, TAG_A
, 2, tag
);
2023 mdoc__x_post(MDOC_ARGS
)
2026 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2027 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2028 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2033 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2036 h
->flags
|= HTML_NOSPACE
;
2037 print_text(h
, n
->next
? "," : ".");
2041 mdoc_bk_pre(MDOC_ARGS
)
2050 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2051 h
->flags
|= HTML_PREKEEP
;
2062 mdoc_bk_post(MDOC_ARGS
)
2065 if (MDOC_BODY
== n
->type
)
2066 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2070 mdoc_quote_pre(MDOC_ARGS
)
2072 struct htmlpair tag
;
2074 if (MDOC_BODY
!= n
->type
)
2081 print_text(h
, "\\(la");
2086 print_text(h
, "\\(lC");
2091 print_text(h
, "\\(lB");
2096 print_text(h
, "\\(lB");
2097 h
->flags
|= HTML_NOSPACE
;
2098 PAIR_CLASS_INIT(&tag
, "opt");
2099 print_otag(h
, TAG_SPAN
, 1, &tag
);
2102 if (NULL
== n
->norm
->Es
||
2103 NULL
== n
->norm
->Es
->child
)
2105 print_text(h
, n
->norm
->Es
->child
->string
);
2116 print_text(h
, "\\(lq");
2124 print_text(h
, "\\(oq");
2125 h
->flags
|= HTML_NOSPACE
;
2126 PAIR_CLASS_INIT(&tag
, "lit");
2127 print_otag(h
, TAG_CODE
, 1, &tag
);
2132 print_text(h
, "\\(oq");
2139 h
->flags
|= HTML_NOSPACE
;
2144 mdoc_quote_post(MDOC_ARGS
)
2147 if (MDOC_BODY
!= n
->type
)
2150 if (MDOC_En
!= n
->tok
)
2151 h
->flags
|= HTML_NOSPACE
;
2157 print_text(h
, "\\(ra");
2162 print_text(h
, "\\(rC");
2171 print_text(h
, "\\(rB");
2174 if (NULL
!= n
->norm
->Es
&&
2175 NULL
!= n
->norm
->Es
->child
&&
2176 NULL
!= n
->norm
->Es
->child
->next
) {
2177 h
->flags
|= HTML_NOSPACE
;
2178 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2190 print_text(h
, "\\(rq");
2202 print_text(h
, "\\(cq");