]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.215 2014/12/01 08:05:52 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>
29 #include "mandoc_aux.h"
37 #define MDOC_ARGS const struct mdoc_meta *meta, \
38 const struct mdoc_node *n, \
42 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
46 int (*pre
)(MDOC_ARGS
);
47 void (*post
)(MDOC_ARGS
);
50 static void print_mdoc(MDOC_ARGS
);
51 static void print_mdoc_head(MDOC_ARGS
);
52 static void print_mdoc_node(MDOC_ARGS
);
53 static void print_mdoc_nodelist(MDOC_ARGS
);
54 static void synopsis_pre(struct html
*,
55 const struct mdoc_node
*);
57 static void a2width(const char *, struct roffsu
*);
59 static void mdoc_root_post(MDOC_ARGS
);
60 static int mdoc_root_pre(MDOC_ARGS
);
62 static void mdoc__x_post(MDOC_ARGS
);
63 static int mdoc__x_pre(MDOC_ARGS
);
64 static int mdoc_ad_pre(MDOC_ARGS
);
65 static int mdoc_an_pre(MDOC_ARGS
);
66 static int mdoc_ap_pre(MDOC_ARGS
);
67 static int mdoc_ar_pre(MDOC_ARGS
);
68 static int mdoc_bd_pre(MDOC_ARGS
);
69 static int mdoc_bf_pre(MDOC_ARGS
);
70 static void mdoc_bk_post(MDOC_ARGS
);
71 static int mdoc_bk_pre(MDOC_ARGS
);
72 static int mdoc_bl_pre(MDOC_ARGS
);
73 static int mdoc_bt_pre(MDOC_ARGS
);
74 static int mdoc_bx_pre(MDOC_ARGS
);
75 static int mdoc_cd_pre(MDOC_ARGS
);
76 static int mdoc_d1_pre(MDOC_ARGS
);
77 static int mdoc_dv_pre(MDOC_ARGS
);
78 static int mdoc_fa_pre(MDOC_ARGS
);
79 static int mdoc_fd_pre(MDOC_ARGS
);
80 static int mdoc_fl_pre(MDOC_ARGS
);
81 static int mdoc_fn_pre(MDOC_ARGS
);
82 static int mdoc_ft_pre(MDOC_ARGS
);
83 static int mdoc_em_pre(MDOC_ARGS
);
84 static int mdoc_er_pre(MDOC_ARGS
);
85 static int mdoc_ev_pre(MDOC_ARGS
);
86 static int mdoc_ex_pre(MDOC_ARGS
);
87 static void mdoc_fo_post(MDOC_ARGS
);
88 static int mdoc_fo_pre(MDOC_ARGS
);
89 static int mdoc_ic_pre(MDOC_ARGS
);
90 static int mdoc_igndelim_pre(MDOC_ARGS
);
91 static int mdoc_in_pre(MDOC_ARGS
);
92 static int mdoc_it_pre(MDOC_ARGS
);
93 static int mdoc_lb_pre(MDOC_ARGS
);
94 static int mdoc_li_pre(MDOC_ARGS
);
95 static int mdoc_lk_pre(MDOC_ARGS
);
96 static int mdoc_mt_pre(MDOC_ARGS
);
97 static int mdoc_ms_pre(MDOC_ARGS
);
98 static int mdoc_nd_pre(MDOC_ARGS
);
99 static int mdoc_nm_pre(MDOC_ARGS
);
100 static int mdoc_no_pre(MDOC_ARGS
);
101 static int mdoc_ns_pre(MDOC_ARGS
);
102 static int mdoc_pa_pre(MDOC_ARGS
);
103 static void mdoc_pf_post(MDOC_ARGS
);
104 static int mdoc_pp_pre(MDOC_ARGS
);
105 static void mdoc_quote_post(MDOC_ARGS
);
106 static int mdoc_quote_pre(MDOC_ARGS
);
107 static int mdoc_rs_pre(MDOC_ARGS
);
108 static int mdoc_rv_pre(MDOC_ARGS
);
109 static int mdoc_sh_pre(MDOC_ARGS
);
110 static int mdoc_skip_pre(MDOC_ARGS
);
111 static int mdoc_sm_pre(MDOC_ARGS
);
112 static int mdoc_sp_pre(MDOC_ARGS
);
113 static int mdoc_ss_pre(MDOC_ARGS
);
114 static int mdoc_sx_pre(MDOC_ARGS
);
115 static int mdoc_sy_pre(MDOC_ARGS
);
116 static int mdoc_ud_pre(MDOC_ARGS
);
117 static int mdoc_va_pre(MDOC_ARGS
);
118 static int mdoc_vt_pre(MDOC_ARGS
);
119 static int mdoc_xr_pre(MDOC_ARGS
);
120 static int mdoc_xx_pre(MDOC_ARGS
);
122 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
123 {mdoc_ap_pre
, NULL
}, /* Ap */
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ar_pre
, NULL
}, /* Ar */
140 {mdoc_cd_pre
, NULL
}, /* Cd */
141 {mdoc_fl_pre
, NULL
}, /* Cm */
142 {mdoc_dv_pre
, NULL
}, /* Dv */
143 {mdoc_er_pre
, NULL
}, /* Er */
144 {mdoc_ev_pre
, NULL
}, /* Ev */
145 {mdoc_ex_pre
, NULL
}, /* Ex */
146 {mdoc_fa_pre
, NULL
}, /* Fa */
147 {mdoc_fd_pre
, NULL
}, /* Fd */
148 {mdoc_fl_pre
, NULL
}, /* Fl */
149 {mdoc_fn_pre
, NULL
}, /* Fn */
150 {mdoc_ft_pre
, NULL
}, /* Ft */
151 {mdoc_ic_pre
, NULL
}, /* Ic */
152 {mdoc_in_pre
, NULL
}, /* In */
153 {mdoc_li_pre
, NULL
}, /* Li */
154 {mdoc_nd_pre
, NULL
}, /* Nd */
155 {mdoc_nm_pre
, NULL
}, /* Nm */
156 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
157 {mdoc_ft_pre
, NULL
}, /* Ot */
158 {mdoc_pa_pre
, NULL
}, /* Pa */
159 {mdoc_rv_pre
, NULL
}, /* Rv */
160 {NULL
, NULL
}, /* St */
161 {mdoc_va_pre
, NULL
}, /* Va */
162 {mdoc_vt_pre
, NULL
}, /* Vt */
163 {mdoc_xr_pre
, NULL
}, /* Xr */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
175 {NULL
, NULL
}, /* Ac */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
178 {NULL
, NULL
}, /* At */
179 {NULL
, NULL
}, /* Bc */
180 {mdoc_bf_pre
, NULL
}, /* Bf */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
183 {mdoc_xx_pre
, NULL
}, /* Bsx */
184 {mdoc_bx_pre
, NULL
}, /* Bx */
185 {mdoc_skip_pre
, NULL
}, /* Db */
186 {NULL
, NULL
}, /* Dc */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
189 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
190 {NULL
, NULL
}, /* Ef */
191 {mdoc_em_pre
, NULL
}, /* Em */
192 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
193 {mdoc_xx_pre
, NULL
}, /* Fx */
194 {mdoc_ms_pre
, NULL
}, /* Ms */
195 {mdoc_no_pre
, NULL
}, /* No */
196 {mdoc_ns_pre
, NULL
}, /* Ns */
197 {mdoc_xx_pre
, NULL
}, /* Nx */
198 {mdoc_xx_pre
, NULL
}, /* Ox */
199 {NULL
, NULL
}, /* Pc */
200 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
203 {NULL
, NULL
}, /* Qc */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
207 {NULL
, NULL
}, /* Re */
208 {mdoc_rs_pre
, NULL
}, /* Rs */
209 {NULL
, NULL
}, /* Sc */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
212 {mdoc_sm_pre
, NULL
}, /* Sm */
213 {mdoc_sx_pre
, NULL
}, /* Sx */
214 {mdoc_sy_pre
, NULL
}, /* Sy */
215 {NULL
, NULL
}, /* Tn */
216 {mdoc_xx_pre
, NULL
}, /* Ux */
217 {NULL
, NULL
}, /* Xc */
218 {NULL
, NULL
}, /* Xo */
219 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
220 {NULL
, NULL
}, /* Fc */
221 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
222 {NULL
, NULL
}, /* Oc */
223 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
224 {NULL
, NULL
}, /* Ek */
225 {mdoc_bt_pre
, NULL
}, /* Bt */
226 {NULL
, NULL
}, /* Hf */
227 {mdoc_em_pre
, NULL
}, /* Fr */
228 {mdoc_ud_pre
, NULL
}, /* Ud */
229 {mdoc_lb_pre
, NULL
}, /* Lb */
230 {mdoc_pp_pre
, NULL
}, /* Lp */
231 {mdoc_lk_pre
, NULL
}, /* Lk */
232 {mdoc_mt_pre
, NULL
}, /* Mt */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
235 {NULL
, NULL
}, /* Brc */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
237 {mdoc_skip_pre
, NULL
}, /* Es */
238 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
239 {mdoc_xx_pre
, NULL
}, /* Dx */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
241 {mdoc_sp_pre
, NULL
}, /* br */
242 {mdoc_sp_pre
, NULL
}, /* sp */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
245 {mdoc_skip_pre
, NULL
}, /* ll */
248 static const char * const lists
[LIST_MAX
] = {
265 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
268 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
274 * Calculate the scaling unit passed in a `-width' argument. This uses
275 * either a native scaling unit (e.g., 1i, 2m) or the string length of
279 a2width(const char *p
, struct roffsu
*su
)
282 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
284 su
->scale
= html_strlen(p
);
289 * See the same function in mdoc_term.c for documentation.
292 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
295 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
298 if (n
->prev
->tok
== n
->tok
&&
302 print_otag(h
, TAG_BR
, 0, NULL
);
306 switch (n
->prev
->tok
) {
319 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
325 print_otag(h
, TAG_BR
, 0, NULL
);
331 print_mdoc(MDOC_ARGS
)
336 PAIR_CLASS_INIT(&tag
, "mandoc");
338 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
340 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
341 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
342 print_mdoc_head(meta
, n
, h
);
344 print_otag(h
, TAG_BODY
, 0, NULL
);
345 print_otag(h
, TAG_DIV
, 1, &tag
);
347 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
349 print_mdoc_nodelist(meta
, n
, h
);
354 print_mdoc_head(MDOC_ARGS
)
359 bufcat(h
, meta
->title
);
361 bufcat_fmt(h
, "(%s)", meta
->msec
);
363 bufcat_fmt(h
, " (%s)", meta
->arch
);
365 print_otag(h
, TAG_TITLE
, 0, NULL
);
366 print_text(h
, h
->buf
);
370 print_mdoc_nodelist(MDOC_ARGS
)
373 print_mdoc_node(meta
, n
, h
);
375 print_mdoc_nodelist(meta
, n
->next
, h
);
379 print_mdoc_node(MDOC_ARGS
)
389 child
= mdoc_root_pre(meta
, n
, h
);
392 /* No tables in this mode... */
393 assert(NULL
== h
->tblt
);
396 * Make sure that if we're in a literal mode already
397 * (i.e., within a <PRE>) don't print the newline.
399 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
400 if ( ! (HTML_LITERAL
& h
->flags
))
401 print_otag(h
, TAG_BR
, 0, NULL
);
402 if (MDOC_DELIMC
& n
->flags
)
403 h
->flags
|= HTML_NOSPACE
;
404 print_text(h
, n
->string
);
405 if (MDOC_DELIMO
& n
->flags
)
406 h
->flags
|= HTML_NOSPACE
;
409 print_eqn(h
, n
->eqn
);
413 * This will take care of initialising all of the table
414 * state data for the first table, then tearing it down
417 print_tbl(h
, n
->span
);
421 * Close out the current table, if it's open, and unset
422 * the "meta" table state. This will be reopened on the
423 * next table element.
425 if (h
->tblt
!= NULL
) {
429 assert(h
->tblt
== NULL
);
430 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
431 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
435 if (HTML_KEEP
& h
->flags
) {
436 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
437 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
438 h
->flags
&= ~HTML_KEEP
;
439 h
->flags
|= HTML_PREKEEP
;
443 if (child
&& n
->child
)
444 print_mdoc_nodelist(meta
, n
->child
, h
);
450 mdoc_root_post(meta
, n
, h
);
455 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& MDOC_ENDED
)
457 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
458 if (n
->end
!= ENDBODY_NOT
)
459 n
->pending
->flags
|= MDOC_ENDED
;
460 if (n
->end
== ENDBODY_NOSPACE
)
461 h
->flags
|= HTML_NOSPACE
;
467 mdoc_root_post(MDOC_ARGS
)
472 PAIR_CLASS_INIT(&tag
, "foot");
473 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
475 print_otag(h
, TAG_TBODY
, 0, NULL
);
477 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
479 PAIR_CLASS_INIT(&tag
, "foot-date");
480 print_otag(h
, TAG_TD
, 1, &tag
);
481 print_text(h
, meta
->date
);
484 PAIR_CLASS_INIT(&tag
, "foot-os");
485 print_otag(h
, TAG_TD
, 1, &tag
);
486 print_text(h
, meta
->os
);
491 mdoc_root_pre(MDOC_ARGS
)
495 char *volume
, *title
;
497 if (NULL
== meta
->arch
)
498 volume
= mandoc_strdup(meta
->vol
);
500 mandoc_asprintf(&volume
, "%s (%s)",
501 meta
->vol
, meta
->arch
);
503 if (NULL
== meta
->msec
)
504 title
= mandoc_strdup(meta
->title
);
506 mandoc_asprintf(&title
, "%s(%s)",
507 meta
->title
, meta
->msec
);
509 PAIR_CLASS_INIT(&tag
, "head");
510 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
512 print_otag(h
, TAG_TBODY
, 0, NULL
);
514 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
516 PAIR_CLASS_INIT(&tag
, "head-ltitle");
517 print_otag(h
, TAG_TD
, 1, &tag
);
518 print_text(h
, title
);
521 PAIR_CLASS_INIT(&tag
, "head-vol");
522 print_otag(h
, TAG_TD
, 1, &tag
);
523 print_text(h
, volume
);
526 PAIR_CLASS_INIT(&tag
, "head-rtitle");
527 print_otag(h
, TAG_TD
, 1, &tag
);
528 print_text(h
, title
);
537 mdoc_sh_pre(MDOC_ARGS
)
543 PAIR_CLASS_INIT(&tag
, "section");
544 print_otag(h
, TAG_DIV
, 1, &tag
);
547 if (n
->sec
== SEC_AUTHORS
)
548 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
557 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
558 bufcat_id(h
, n
->string
);
559 if (NULL
!= (n
= n
->next
))
564 PAIR_ID_INIT(&tag
, h
->buf
);
565 print_otag(h
, TAG_H1
, 1, &tag
);
567 print_otag(h
, TAG_H1
, 0, NULL
);
573 mdoc_ss_pre(MDOC_ARGS
)
577 if (MDOC_BLOCK
== n
->type
) {
578 PAIR_CLASS_INIT(&tag
, "subsection");
579 print_otag(h
, TAG_DIV
, 1, &tag
);
581 } else if (MDOC_BODY
== n
->type
)
587 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
588 bufcat_id(h
, n
->string
);
589 if (NULL
!= (n
= n
->next
))
594 PAIR_ID_INIT(&tag
, h
->buf
);
595 print_otag(h
, TAG_H2
, 1, &tag
);
597 print_otag(h
, TAG_H2
, 0, NULL
);
603 mdoc_fl_pre(MDOC_ARGS
)
607 PAIR_CLASS_INIT(&tag
, "flag");
608 print_otag(h
, TAG_B
, 1, &tag
);
610 /* `Cm' has no leading hyphen. */
612 if (MDOC_Cm
== n
->tok
)
615 print_text(h
, "\\-");
617 if ( ! (n
->nchild
== 0 &&
619 n
->next
->type
== MDOC_TEXT
||
620 n
->next
->flags
& MDOC_LINE
)))
621 h
->flags
|= HTML_NOSPACE
;
627 mdoc_nd_pre(MDOC_ARGS
)
631 if (MDOC_BODY
!= n
->type
)
634 /* XXX: this tag in theory can contain block elements. */
636 print_text(h
, "\\(em");
637 PAIR_CLASS_INIT(&tag
, "desc");
638 print_otag(h
, TAG_SPAN
, 1, &tag
);
643 mdoc_nm_pre(MDOC_ARGS
)
652 PAIR_CLASS_INIT(&tag
, "name");
653 print_otag(h
, TAG_B
, 1, &tag
);
654 if (NULL
== n
->child
&& meta
->name
)
655 print_text(h
, meta
->name
);
658 print_otag(h
, TAG_TD
, 0, NULL
);
659 if (NULL
== n
->child
&& meta
->name
)
660 print_text(h
, meta
->name
);
663 print_otag(h
, TAG_TD
, 0, NULL
);
670 PAIR_CLASS_INIT(&tag
, "synopsis");
671 print_otag(h
, TAG_TABLE
, 1, &tag
);
673 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
674 if (MDOC_TEXT
== n
->type
)
675 len
+= html_strlen(n
->string
);
677 if (0 == len
&& meta
->name
)
678 len
= html_strlen(meta
->name
);
680 SCALE_HS_INIT(&su
, len
);
682 bufcat_su(h
, "width", &su
);
683 PAIR_STYLE_INIT(&tag
, h
);
684 print_otag(h
, TAG_COL
, 1, &tag
);
685 print_otag(h
, TAG_COL
, 0, NULL
);
686 print_otag(h
, TAG_TBODY
, 0, NULL
);
687 print_otag(h
, TAG_TR
, 0, NULL
);
692 mdoc_xr_pre(MDOC_ARGS
)
694 struct htmlpair tag
[2];
696 if (NULL
== n
->child
)
699 PAIR_CLASS_INIT(&tag
[0], "link-man");
702 buffmt_man(h
, n
->child
->string
,
704 n
->child
->next
->string
: NULL
);
705 PAIR_HREF_INIT(&tag
[1], h
->buf
);
706 print_otag(h
, TAG_A
, 2, tag
);
708 print_otag(h
, TAG_A
, 1, tag
);
711 print_text(h
, n
->string
);
713 if (NULL
== (n
= n
->next
))
716 h
->flags
|= HTML_NOSPACE
;
718 h
->flags
|= HTML_NOSPACE
;
719 print_text(h
, n
->string
);
720 h
->flags
|= HTML_NOSPACE
;
726 mdoc_ns_pre(MDOC_ARGS
)
729 if ( ! (MDOC_LINE
& n
->flags
))
730 h
->flags
|= HTML_NOSPACE
;
735 mdoc_ar_pre(MDOC_ARGS
)
739 PAIR_CLASS_INIT(&tag
, "arg");
740 print_otag(h
, TAG_I
, 1, &tag
);
745 mdoc_xx_pre(MDOC_ARGS
)
774 PAIR_CLASS_INIT(&tag
, "unix");
775 print_otag(h
, TAG_SPAN
, 1, &tag
);
780 h
->flags
|= HTML_KEEP
;
781 print_text(h
, n
->child
->string
);
788 mdoc_bx_pre(MDOC_ARGS
)
792 PAIR_CLASS_INIT(&tag
, "unix");
793 print_otag(h
, TAG_SPAN
, 1, &tag
);
795 if (NULL
!= (n
= n
->child
)) {
796 print_text(h
, n
->string
);
797 h
->flags
|= HTML_NOSPACE
;
798 print_text(h
, "BSD");
800 print_text(h
, "BSD");
804 if (NULL
!= (n
= n
->next
)) {
805 h
->flags
|= HTML_NOSPACE
;
807 h
->flags
|= HTML_NOSPACE
;
808 print_text(h
, n
->string
);
815 mdoc_it_pre(MDOC_ARGS
)
819 struct htmlpair tag
[2];
820 const struct mdoc_node
*bl
;
823 while (bl
&& MDOC_Bl
!= bl
->tok
)
828 type
= bl
->norm
->Bl
.type
;
831 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
835 if (MDOC_HEAD
== n
->type
) {
856 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
857 bufcat_su(h
, "margin-top", &su
);
858 PAIR_STYLE_INIT(&tag
[1], h
);
859 print_otag(h
, TAG_DT
, 2, tag
);
860 if (LIST_diag
!= type
)
862 PAIR_CLASS_INIT(&tag
[0], "diag");
863 print_otag(h
, TAG_B
, 1, tag
);
870 } else if (MDOC_BODY
== n
->type
) {
881 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
882 bufcat_su(h
, "margin-top", &su
);
883 PAIR_STYLE_INIT(&tag
[1], h
);
884 print_otag(h
, TAG_LI
, 2, tag
);
895 if (NULL
== bl
->norm
->Bl
.width
) {
896 print_otag(h
, TAG_DD
, 1, tag
);
899 a2width(bl
->norm
->Bl
.width
, &su
);
900 bufcat_su(h
, "margin-left", &su
);
901 PAIR_STYLE_INIT(&tag
[1], h
);
902 print_otag(h
, TAG_DD
, 2, tag
);
905 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
906 bufcat_su(h
, "margin-top", &su
);
907 PAIR_STYLE_INIT(&tag
[1], h
);
908 print_otag(h
, TAG_TD
, 2, tag
);
916 print_otag(h
, TAG_TR
, 1, tag
);
927 mdoc_bl_pre(MDOC_ARGS
)
930 struct htmlpair tag
[3];
934 if (MDOC_BODY
== n
->type
) {
935 if (LIST_column
== n
->norm
->Bl
.type
)
936 print_otag(h
, TAG_TBODY
, 0, NULL
);
940 if (MDOC_HEAD
== n
->type
) {
941 if (LIST_column
!= n
->norm
->Bl
.type
)
945 * For each column, print out the <COL> tag with our
946 * suggested width. The last column gets min-width, as
947 * in terminal mode it auto-sizes to the width of the
948 * screen and we want to preserve that behaviour.
951 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
953 a2width(n
->norm
->Bl
.cols
[i
], &su
);
954 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
955 bufcat_su(h
, "width", &su
);
957 bufcat_su(h
, "min-width", &su
);
958 PAIR_STYLE_INIT(&tag
[0], h
);
959 print_otag(h
, TAG_COL
, 1, tag
);
965 SCALE_VS_INIT(&su
, 0);
967 bufcat_su(h
, "margin-top", &su
);
968 bufcat_su(h
, "margin-bottom", &su
);
969 PAIR_STYLE_INIT(&tag
[0], h
);
971 assert(lists
[n
->norm
->Bl
.type
]);
972 (void)strlcpy(buf
, "list ", BUFSIZ
);
973 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
974 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
976 /* Set the block's left-hand margin. */
978 if (n
->norm
->Bl
.offs
) {
979 a2width(n
->norm
->Bl
.offs
, &su
);
980 bufcat_su(h
, "margin-left", &su
);
983 switch (n
->norm
->Bl
.type
) {
991 print_otag(h
, TAG_UL
, 2, tag
);
994 print_otag(h
, TAG_OL
, 2, tag
);
1005 print_otag(h
, TAG_DL
, 2, tag
);
1008 print_otag(h
, TAG_TABLE
, 2, tag
);
1019 mdoc_ex_pre(MDOC_ARGS
)
1022 struct htmlpair tag
;
1026 print_otag(h
, TAG_BR
, 0, NULL
);
1028 PAIR_CLASS_INIT(&tag
, "utility");
1030 print_text(h
, "The");
1033 for (n
= n
->child
; n
; n
= n
->next
) {
1034 assert(MDOC_TEXT
== n
->type
);
1036 t
= print_otag(h
, TAG_B
, 1, &tag
);
1037 print_text(h
, n
->string
);
1040 if (nchild
> 2 && n
->next
) {
1041 h
->flags
|= HTML_NOSPACE
;
1045 if (n
->next
&& NULL
== n
->next
->next
)
1046 print_text(h
, "and");
1050 print_text(h
, "utilities exit\\~0");
1052 print_text(h
, "utility exits\\~0");
1054 print_text(h
, "on success, and\\~>0 if an error occurs.");
1059 mdoc_em_pre(MDOC_ARGS
)
1061 struct htmlpair tag
;
1063 PAIR_CLASS_INIT(&tag
, "emph");
1064 print_otag(h
, TAG_SPAN
, 1, &tag
);
1069 mdoc_d1_pre(MDOC_ARGS
)
1071 struct htmlpair tag
[2];
1074 if (MDOC_BLOCK
!= n
->type
)
1077 SCALE_VS_INIT(&su
, 0);
1079 bufcat_su(h
, "margin-top", &su
);
1080 bufcat_su(h
, "margin-bottom", &su
);
1081 PAIR_STYLE_INIT(&tag
[0], h
);
1082 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1084 /* BLOCKQUOTE needs a block body. */
1086 PAIR_CLASS_INIT(&tag
[0], "display");
1087 print_otag(h
, TAG_DIV
, 1, tag
);
1089 if (MDOC_Dl
== n
->tok
) {
1090 PAIR_CLASS_INIT(&tag
[0], "lit");
1091 print_otag(h
, TAG_CODE
, 1, tag
);
1098 mdoc_sx_pre(MDOC_ARGS
)
1100 struct htmlpair tag
[2];
1105 for (n
= n
->child
; n
; ) {
1106 bufcat_id(h
, n
->string
);
1107 if (NULL
!= (n
= n
->next
))
1111 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1112 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1114 print_otag(h
, TAG_I
, 1, tag
);
1115 print_otag(h
, TAG_A
, 2, tag
);
1120 mdoc_bd_pre(MDOC_ARGS
)
1122 struct htmlpair tag
[2];
1124 const struct mdoc_node
*nn
;
1127 if (MDOC_HEAD
== n
->type
)
1130 if (MDOC_BLOCK
== n
->type
) {
1131 comp
= n
->norm
->Bd
.comp
;
1132 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1133 if (MDOC_BLOCK
!= nn
->type
)
1135 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1145 /* Handle the -offset argument. */
1147 if (n
->norm
->Bd
.offs
== NULL
||
1148 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1149 SCALE_HS_INIT(&su
, 0);
1150 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1151 SCALE_HS_INIT(&su
, INDENT
);
1152 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1153 SCALE_HS_INIT(&su
, INDENT
* 2);
1155 a2width(n
->norm
->Bd
.offs
, &su
);
1158 bufcat_su(h
, "margin-left", &su
);
1159 PAIR_STYLE_INIT(&tag
[0], h
);
1161 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1162 DISP_literal
!= n
->norm
->Bd
.type
) {
1163 PAIR_CLASS_INIT(&tag
[1], "display");
1164 print_otag(h
, TAG_DIV
, 2, tag
);
1168 PAIR_CLASS_INIT(&tag
[1], "lit display");
1169 print_otag(h
, TAG_PRE
, 2, tag
);
1171 /* This can be recursive: save & set our literal state. */
1173 sv
= h
->flags
& HTML_LITERAL
;
1174 h
->flags
|= HTML_LITERAL
;
1176 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1177 print_mdoc_node(meta
, nn
, h
);
1179 * If the printed node flushes its own line, then we
1180 * needn't do it here as well. This is hacky, but the
1181 * notion of selective eoln whitespace is pretty dumb
1182 * anyway, so don't sweat it.
1204 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1207 print_text(h
, "\n");
1209 h
->flags
|= HTML_NOSPACE
;
1213 h
->flags
&= ~HTML_LITERAL
;
1219 mdoc_pa_pre(MDOC_ARGS
)
1221 struct htmlpair tag
;
1223 PAIR_CLASS_INIT(&tag
, "file");
1224 print_otag(h
, TAG_I
, 1, &tag
);
1229 mdoc_ad_pre(MDOC_ARGS
)
1231 struct htmlpair tag
;
1233 PAIR_CLASS_INIT(&tag
, "addr");
1234 print_otag(h
, TAG_I
, 1, &tag
);
1239 mdoc_an_pre(MDOC_ARGS
)
1241 struct htmlpair tag
;
1243 if (n
->norm
->An
.auth
== AUTH_split
) {
1244 h
->flags
&= ~HTML_NOSPLIT
;
1245 h
->flags
|= HTML_SPLIT
;
1248 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1249 h
->flags
&= ~HTML_SPLIT
;
1250 h
->flags
|= HTML_NOSPLIT
;
1254 if (n
->child
== NULL
)
1257 if (h
->flags
& HTML_SPLIT
)
1258 print_otag(h
, TAG_BR
, 0, NULL
);
1260 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1261 h
->flags
|= HTML_SPLIT
;
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
)
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 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1872 h
->flags
|= HTML_NOSPACE
;
1876 mdoc_rs_pre(MDOC_ARGS
)
1878 struct htmlpair tag
;
1880 if (MDOC_BLOCK
!= n
->type
)
1883 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1886 PAIR_CLASS_INIT(&tag
, "ref");
1887 print_otag(h
, TAG_SPAN
, 1, &tag
);
1892 mdoc_no_pre(MDOC_ARGS
)
1894 struct htmlpair tag
;
1896 PAIR_CLASS_INIT(&tag
, "none");
1897 print_otag(h
, TAG_CODE
, 1, &tag
);
1902 mdoc_li_pre(MDOC_ARGS
)
1904 struct htmlpair tag
;
1906 PAIR_CLASS_INIT(&tag
, "lit");
1907 print_otag(h
, TAG_CODE
, 1, &tag
);
1912 mdoc_sy_pre(MDOC_ARGS
)
1914 struct htmlpair tag
;
1916 PAIR_CLASS_INIT(&tag
, "symb");
1917 print_otag(h
, TAG_SPAN
, 1, &tag
);
1922 mdoc_bt_pre(MDOC_ARGS
)
1925 print_text(h
, "is currently in beta test.");
1930 mdoc_ud_pre(MDOC_ARGS
)
1933 print_text(h
, "currently under development.");
1938 mdoc_lb_pre(MDOC_ARGS
)
1940 struct htmlpair tag
;
1942 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1943 print_otag(h
, TAG_BR
, 0, NULL
);
1945 PAIR_CLASS_INIT(&tag
, "lib");
1946 print_otag(h
, TAG_SPAN
, 1, &tag
);
1951 mdoc__x_pre(MDOC_ARGS
)
1953 struct htmlpair tag
[2];
1960 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1961 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1962 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1963 print_text(h
, "and");
1966 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1970 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1973 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1976 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1980 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1984 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1987 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1990 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1993 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1996 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1999 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2002 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2005 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2012 if (MDOC__U
!= n
->tok
) {
2013 print_otag(h
, t
, 1, tag
);
2017 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2018 print_otag(h
, TAG_A
, 2, tag
);
2024 mdoc__x_post(MDOC_ARGS
)
2027 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2028 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2029 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2034 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2037 h
->flags
|= HTML_NOSPACE
;
2038 print_text(h
, n
->next
? "," : ".");
2042 mdoc_bk_pre(MDOC_ARGS
)
2051 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2052 h
->flags
|= HTML_PREKEEP
;
2063 mdoc_bk_post(MDOC_ARGS
)
2066 if (MDOC_BODY
== n
->type
)
2067 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2071 mdoc_quote_pre(MDOC_ARGS
)
2073 struct htmlpair tag
;
2075 if (MDOC_BODY
!= n
->type
)
2082 print_text(h
, n
->parent
->prev
!= NULL
&&
2083 n
->parent
->prev
->tok
== MDOC_An
? "<" : "\\(la");
2088 print_text(h
, "\\(lC");
2093 print_text(h
, "\\(lB");
2098 print_text(h
, "\\(lB");
2099 h
->flags
|= HTML_NOSPACE
;
2100 PAIR_CLASS_INIT(&tag
, "opt");
2101 print_otag(h
, TAG_SPAN
, 1, &tag
);
2104 if (NULL
== n
->norm
->Es
||
2105 NULL
== n
->norm
->Es
->child
)
2107 print_text(h
, n
->norm
->Es
->child
->string
);
2118 print_text(h
, "\\(lq");
2126 print_text(h
, "\\(oq");
2127 h
->flags
|= HTML_NOSPACE
;
2128 PAIR_CLASS_INIT(&tag
, "lit");
2129 print_otag(h
, TAG_CODE
, 1, &tag
);
2134 print_text(h
, "\\(oq");
2141 h
->flags
|= HTML_NOSPACE
;
2146 mdoc_quote_post(MDOC_ARGS
)
2149 if (n
->type
!= MDOC_BODY
&& n
->type
!= MDOC_ELEM
)
2152 if ( ! (n
->tok
== MDOC_En
||
2153 (n
->tok
== MDOC_Eo
&& n
->end
== ENDBODY_SPACE
)))
2154 h
->flags
|= HTML_NOSPACE
;
2160 print_text(h
, n
->parent
->prev
!= NULL
&&
2161 n
->parent
->prev
->tok
== MDOC_An
? ">" : "\\(ra");
2166 print_text(h
, "\\(rC");
2175 print_text(h
, "\\(rB");
2178 if (NULL
!= n
->norm
->Es
&&
2179 NULL
!= n
->norm
->Es
->child
&&
2180 NULL
!= n
->norm
->Es
->child
->next
) {
2181 h
->flags
|= HTML_NOSPACE
;
2182 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2194 print_text(h
, "\\(rq");
2206 print_text(h
, "\\(cq");