]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.210 2014/11/17 06:44:58 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
*);
60 static void mdoc_root_post(MDOC_ARGS
);
61 static int mdoc_root_pre(MDOC_ARGS
);
63 static void mdoc__x_post(MDOC_ARGS
);
64 static int mdoc__x_pre(MDOC_ARGS
);
65 static int mdoc_ad_pre(MDOC_ARGS
);
66 static int mdoc_an_pre(MDOC_ARGS
);
67 static int mdoc_ap_pre(MDOC_ARGS
);
68 static int mdoc_ar_pre(MDOC_ARGS
);
69 static int mdoc_bd_pre(MDOC_ARGS
);
70 static int mdoc_bf_pre(MDOC_ARGS
);
71 static void mdoc_bk_post(MDOC_ARGS
);
72 static int mdoc_bk_pre(MDOC_ARGS
);
73 static int mdoc_bl_pre(MDOC_ARGS
);
74 static int mdoc_bt_pre(MDOC_ARGS
);
75 static int mdoc_bx_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_d1_pre(MDOC_ARGS
);
78 static int mdoc_dv_pre(MDOC_ARGS
);
79 static int mdoc_fa_pre(MDOC_ARGS
);
80 static int mdoc_fd_pre(MDOC_ARGS
);
81 static int mdoc_fl_pre(MDOC_ARGS
);
82 static int mdoc_fn_pre(MDOC_ARGS
);
83 static int mdoc_ft_pre(MDOC_ARGS
);
84 static int mdoc_em_pre(MDOC_ARGS
);
85 static int mdoc_er_pre(MDOC_ARGS
);
86 static int mdoc_ev_pre(MDOC_ARGS
);
87 static int mdoc_ex_pre(MDOC_ARGS
);
88 static void mdoc_fo_post(MDOC_ARGS
);
89 static int mdoc_fo_pre(MDOC_ARGS
);
90 static int mdoc_ic_pre(MDOC_ARGS
);
91 static int mdoc_igndelim_pre(MDOC_ARGS
);
92 static int mdoc_in_pre(MDOC_ARGS
);
93 static int mdoc_it_pre(MDOC_ARGS
);
94 static int mdoc_lb_pre(MDOC_ARGS
);
95 static int mdoc_li_pre(MDOC_ARGS
);
96 static int mdoc_lk_pre(MDOC_ARGS
);
97 static int mdoc_mt_pre(MDOC_ARGS
);
98 static int mdoc_ms_pre(MDOC_ARGS
);
99 static int mdoc_nd_pre(MDOC_ARGS
);
100 static int mdoc_nm_pre(MDOC_ARGS
);
101 static int mdoc_no_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_no_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 print_mdoc(MDOC_ARGS
)
337 PAIR_CLASS_INIT(&tag
, "mandoc");
339 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
341 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
342 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
343 print_mdoc_head(meta
, n
, h
);
345 print_otag(h
, TAG_BODY
, 0, NULL
);
346 print_otag(h
, TAG_DIV
, 1, &tag
);
348 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
350 print_mdoc_nodelist(meta
, n
, h
);
355 print_mdoc_head(MDOC_ARGS
)
360 bufcat(h
, meta
->title
);
362 bufcat_fmt(h
, "(%s)", meta
->msec
);
364 bufcat_fmt(h
, " (%s)", meta
->arch
);
366 print_otag(h
, TAG_TITLE
, 0, NULL
);
367 print_text(h
, h
->buf
);
371 print_mdoc_nodelist(MDOC_ARGS
)
374 print_mdoc_node(meta
, n
, h
);
376 print_mdoc_nodelist(meta
, n
->next
, h
);
380 print_mdoc_node(MDOC_ARGS
)
390 child
= mdoc_root_pre(meta
, n
, h
);
393 /* No tables in this mode... */
394 assert(NULL
== h
->tblt
);
397 * Make sure that if we're in a literal mode already
398 * (i.e., within a <PRE>) don't print the newline.
400 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
401 if ( ! (HTML_LITERAL
& h
->flags
))
402 print_otag(h
, TAG_BR
, 0, NULL
);
403 if (MDOC_DELIMC
& n
->flags
)
404 h
->flags
|= HTML_NOSPACE
;
405 print_text(h
, n
->string
);
406 if (MDOC_DELIMO
& n
->flags
)
407 h
->flags
|= HTML_NOSPACE
;
410 print_eqn(h
, n
->eqn
);
414 * This will take care of initialising all of the table
415 * state data for the first table, then tearing it down
418 print_tbl(h
, n
->span
);
422 * Close out the current table, if it's open, and unset
423 * the "meta" table state. This will be reopened on the
424 * next table element.
431 assert(NULL
== h
->tblt
);
432 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
433 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
437 if (HTML_KEEP
& h
->flags
) {
438 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
439 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
440 h
->flags
&= ~HTML_KEEP
;
441 h
->flags
|= HTML_PREKEEP
;
445 if (child
&& n
->child
)
446 print_mdoc_nodelist(meta
, n
->child
, h
);
452 mdoc_root_post(meta
, n
, h
);
457 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
458 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
464 mdoc_root_post(MDOC_ARGS
)
469 PAIR_CLASS_INIT(&tag
, "foot");
470 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
472 print_otag(h
, TAG_TBODY
, 0, NULL
);
474 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
476 PAIR_CLASS_INIT(&tag
, "foot-date");
477 print_otag(h
, TAG_TD
, 1, &tag
);
478 print_text(h
, meta
->date
);
481 PAIR_CLASS_INIT(&tag
, "foot-os");
482 print_otag(h
, TAG_TD
, 1, &tag
);
483 print_text(h
, meta
->os
);
488 mdoc_root_pre(MDOC_ARGS
)
492 char *volume
, *title
;
494 if (NULL
== meta
->arch
)
495 volume
= mandoc_strdup(meta
->vol
);
497 mandoc_asprintf(&volume
, "%s (%s)",
498 meta
->vol
, meta
->arch
);
500 if (NULL
== meta
->msec
)
501 title
= mandoc_strdup(meta
->title
);
503 mandoc_asprintf(&title
, "%s(%s)",
504 meta
->title
, meta
->msec
);
506 PAIR_CLASS_INIT(&tag
, "head");
507 t
= print_otag(h
, TAG_TABLE
, 1, &tag
);
509 print_otag(h
, TAG_TBODY
, 0, NULL
);
511 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
513 PAIR_CLASS_INIT(&tag
, "head-ltitle");
514 print_otag(h
, TAG_TD
, 1, &tag
);
515 print_text(h
, title
);
518 PAIR_CLASS_INIT(&tag
, "head-vol");
519 print_otag(h
, TAG_TD
, 1, &tag
);
520 print_text(h
, volume
);
523 PAIR_CLASS_INIT(&tag
, "head-rtitle");
524 print_otag(h
, TAG_TD
, 1, &tag
);
525 print_text(h
, title
);
534 mdoc_sh_pre(MDOC_ARGS
)
540 PAIR_CLASS_INIT(&tag
, "section");
541 print_otag(h
, TAG_DIV
, 1, &tag
);
544 if (n
->sec
== SEC_AUTHORS
)
545 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
554 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
555 bufcat_id(h
, n
->string
);
556 if (NULL
!= (n
= n
->next
))
561 PAIR_ID_INIT(&tag
, h
->buf
);
562 print_otag(h
, TAG_H1
, 1, &tag
);
564 print_otag(h
, TAG_H1
, 0, NULL
);
570 mdoc_ss_pre(MDOC_ARGS
)
574 if (MDOC_BLOCK
== n
->type
) {
575 PAIR_CLASS_INIT(&tag
, "subsection");
576 print_otag(h
, TAG_DIV
, 1, &tag
);
578 } else if (MDOC_BODY
== n
->type
)
584 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
585 bufcat_id(h
, n
->string
);
586 if (NULL
!= (n
= n
->next
))
591 PAIR_ID_INIT(&tag
, h
->buf
);
592 print_otag(h
, TAG_H2
, 1, &tag
);
594 print_otag(h
, TAG_H2
, 0, NULL
);
600 mdoc_fl_pre(MDOC_ARGS
)
604 PAIR_CLASS_INIT(&tag
, "flag");
605 print_otag(h
, TAG_B
, 1, &tag
);
607 /* `Cm' has no leading hyphen. */
609 if (MDOC_Cm
== n
->tok
)
612 print_text(h
, "\\-");
614 if ( ! (n
->nchild
== 0 &&
616 n
->next
->type
== MDOC_TEXT
||
617 n
->next
->flags
& MDOC_LINE
)))
618 h
->flags
|= HTML_NOSPACE
;
624 mdoc_nd_pre(MDOC_ARGS
)
628 if (MDOC_BODY
!= n
->type
)
631 /* XXX: this tag in theory can contain block elements. */
633 print_text(h
, "\\(em");
634 PAIR_CLASS_INIT(&tag
, "desc");
635 print_otag(h
, TAG_SPAN
, 1, &tag
);
640 mdoc_nm_pre(MDOC_ARGS
)
649 PAIR_CLASS_INIT(&tag
, "name");
650 print_otag(h
, TAG_B
, 1, &tag
);
651 if (NULL
== n
->child
&& meta
->name
)
652 print_text(h
, meta
->name
);
655 print_otag(h
, TAG_TD
, 0, NULL
);
656 if (NULL
== n
->child
&& meta
->name
)
657 print_text(h
, meta
->name
);
660 print_otag(h
, TAG_TD
, 0, NULL
);
667 PAIR_CLASS_INIT(&tag
, "synopsis");
668 print_otag(h
, TAG_TABLE
, 1, &tag
);
670 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
671 if (MDOC_TEXT
== n
->type
)
672 len
+= html_strlen(n
->string
);
674 if (0 == len
&& meta
->name
)
675 len
= html_strlen(meta
->name
);
677 SCALE_HS_INIT(&su
, len
);
679 bufcat_su(h
, "width", &su
);
680 PAIR_STYLE_INIT(&tag
, h
);
681 print_otag(h
, TAG_COL
, 1, &tag
);
682 print_otag(h
, TAG_COL
, 0, NULL
);
683 print_otag(h
, TAG_TBODY
, 0, NULL
);
684 print_otag(h
, TAG_TR
, 0, NULL
);
689 mdoc_xr_pre(MDOC_ARGS
)
691 struct htmlpair tag
[2];
693 if (NULL
== n
->child
)
696 PAIR_CLASS_INIT(&tag
[0], "link-man");
699 buffmt_man(h
, n
->child
->string
,
701 n
->child
->next
->string
: NULL
);
702 PAIR_HREF_INIT(&tag
[1], h
->buf
);
703 print_otag(h
, TAG_A
, 2, tag
);
705 print_otag(h
, TAG_A
, 1, tag
);
708 print_text(h
, n
->string
);
710 if (NULL
== (n
= n
->next
))
713 h
->flags
|= HTML_NOSPACE
;
715 h
->flags
|= HTML_NOSPACE
;
716 print_text(h
, n
->string
);
717 h
->flags
|= HTML_NOSPACE
;
723 mdoc_ns_pre(MDOC_ARGS
)
726 if ( ! (MDOC_LINE
& n
->flags
))
727 h
->flags
|= HTML_NOSPACE
;
732 mdoc_ar_pre(MDOC_ARGS
)
736 PAIR_CLASS_INIT(&tag
, "arg");
737 print_otag(h
, TAG_I
, 1, &tag
);
742 mdoc_xx_pre(MDOC_ARGS
)
771 PAIR_CLASS_INIT(&tag
, "unix");
772 print_otag(h
, TAG_SPAN
, 1, &tag
);
777 h
->flags
|= HTML_KEEP
;
778 print_text(h
, n
->child
->string
);
785 mdoc_bx_pre(MDOC_ARGS
)
789 PAIR_CLASS_INIT(&tag
, "unix");
790 print_otag(h
, TAG_SPAN
, 1, &tag
);
792 if (NULL
!= (n
= n
->child
)) {
793 print_text(h
, n
->string
);
794 h
->flags
|= HTML_NOSPACE
;
795 print_text(h
, "BSD");
797 print_text(h
, "BSD");
801 if (NULL
!= (n
= n
->next
)) {
802 h
->flags
|= HTML_NOSPACE
;
804 h
->flags
|= HTML_NOSPACE
;
805 print_text(h
, n
->string
);
812 mdoc_it_pre(MDOC_ARGS
)
816 struct htmlpair tag
[2];
817 const struct mdoc_node
*bl
;
820 while (bl
&& MDOC_Bl
!= bl
->tok
)
825 type
= bl
->norm
->Bl
.type
;
828 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
832 if (MDOC_HEAD
== n
->type
) {
853 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
854 bufcat_su(h
, "margin-top", &su
);
855 PAIR_STYLE_INIT(&tag
[1], h
);
856 print_otag(h
, TAG_DT
, 2, tag
);
857 if (LIST_diag
!= type
)
859 PAIR_CLASS_INIT(&tag
[0], "diag");
860 print_otag(h
, TAG_B
, 1, tag
);
867 } else if (MDOC_BODY
== n
->type
) {
878 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
879 bufcat_su(h
, "margin-top", &su
);
880 PAIR_STYLE_INIT(&tag
[1], h
);
881 print_otag(h
, TAG_LI
, 2, tag
);
892 if (NULL
== bl
->norm
->Bl
.width
) {
893 print_otag(h
, TAG_DD
, 1, tag
);
896 a2width(bl
->norm
->Bl
.width
, &su
);
897 bufcat_su(h
, "margin-left", &su
);
898 PAIR_STYLE_INIT(&tag
[1], h
);
899 print_otag(h
, TAG_DD
, 2, tag
);
902 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
903 bufcat_su(h
, "margin-top", &su
);
904 PAIR_STYLE_INIT(&tag
[1], h
);
905 print_otag(h
, TAG_TD
, 2, tag
);
913 print_otag(h
, TAG_TR
, 1, tag
);
924 mdoc_bl_pre(MDOC_ARGS
)
927 struct htmlpair tag
[3];
931 if (MDOC_BODY
== n
->type
) {
932 if (LIST_column
== n
->norm
->Bl
.type
)
933 print_otag(h
, TAG_TBODY
, 0, NULL
);
937 if (MDOC_HEAD
== n
->type
) {
938 if (LIST_column
!= n
->norm
->Bl
.type
)
942 * For each column, print out the <COL> tag with our
943 * suggested width. The last column gets min-width, as
944 * in terminal mode it auto-sizes to the width of the
945 * screen and we want to preserve that behaviour.
948 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
950 a2width(n
->norm
->Bl
.cols
[i
], &su
);
951 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
952 bufcat_su(h
, "width", &su
);
954 bufcat_su(h
, "min-width", &su
);
955 PAIR_STYLE_INIT(&tag
[0], h
);
956 print_otag(h
, TAG_COL
, 1, tag
);
962 SCALE_VS_INIT(&su
, 0);
964 bufcat_su(h
, "margin-top", &su
);
965 bufcat_su(h
, "margin-bottom", &su
);
966 PAIR_STYLE_INIT(&tag
[0], h
);
968 assert(lists
[n
->norm
->Bl
.type
]);
969 (void)strlcpy(buf
, "list ", BUFSIZ
);
970 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
971 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
973 /* Set the block's left-hand margin. */
975 if (n
->norm
->Bl
.offs
) {
976 a2width(n
->norm
->Bl
.offs
, &su
);
977 bufcat_su(h
, "margin-left", &su
);
980 switch (n
->norm
->Bl
.type
) {
988 print_otag(h
, TAG_UL
, 2, tag
);
991 print_otag(h
, TAG_OL
, 2, tag
);
1002 print_otag(h
, TAG_DL
, 2, tag
);
1005 print_otag(h
, TAG_TABLE
, 2, tag
);
1016 mdoc_ex_pre(MDOC_ARGS
)
1019 struct htmlpair tag
;
1023 print_otag(h
, TAG_BR
, 0, NULL
);
1025 PAIR_CLASS_INIT(&tag
, "utility");
1027 print_text(h
, "The");
1030 for (n
= n
->child
; n
; n
= n
->next
) {
1031 assert(MDOC_TEXT
== n
->type
);
1033 t
= print_otag(h
, TAG_B
, 1, &tag
);
1034 print_text(h
, n
->string
);
1037 if (nchild
> 2 && n
->next
) {
1038 h
->flags
|= HTML_NOSPACE
;
1042 if (n
->next
&& NULL
== n
->next
->next
)
1043 print_text(h
, "and");
1047 print_text(h
, "utilities exit\\~0");
1049 print_text(h
, "utility exits\\~0");
1051 print_text(h
, "on success, and\\~>0 if an error occurs.");
1056 mdoc_em_pre(MDOC_ARGS
)
1058 struct htmlpair tag
;
1060 PAIR_CLASS_INIT(&tag
, "emph");
1061 print_otag(h
, TAG_SPAN
, 1, &tag
);
1066 mdoc_d1_pre(MDOC_ARGS
)
1068 struct htmlpair tag
[2];
1071 if (MDOC_BLOCK
!= n
->type
)
1074 SCALE_VS_INIT(&su
, 0);
1076 bufcat_su(h
, "margin-top", &su
);
1077 bufcat_su(h
, "margin-bottom", &su
);
1078 PAIR_STYLE_INIT(&tag
[0], h
);
1079 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1081 /* BLOCKQUOTE needs a block body. */
1083 PAIR_CLASS_INIT(&tag
[0], "display");
1084 print_otag(h
, TAG_DIV
, 1, tag
);
1086 if (MDOC_Dl
== n
->tok
) {
1087 PAIR_CLASS_INIT(&tag
[0], "lit");
1088 print_otag(h
, TAG_CODE
, 1, tag
);
1095 mdoc_sx_pre(MDOC_ARGS
)
1097 struct htmlpair tag
[2];
1102 for (n
= n
->child
; n
; ) {
1103 bufcat_id(h
, n
->string
);
1104 if (NULL
!= (n
= n
->next
))
1108 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1109 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1111 print_otag(h
, TAG_I
, 1, tag
);
1112 print_otag(h
, TAG_A
, 2, tag
);
1117 mdoc_bd_pre(MDOC_ARGS
)
1119 struct htmlpair tag
[2];
1121 const struct mdoc_node
*nn
;
1124 if (MDOC_HEAD
== n
->type
)
1127 if (MDOC_BLOCK
== n
->type
) {
1128 comp
= n
->norm
->Bd
.comp
;
1129 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1130 if (MDOC_BLOCK
!= nn
->type
)
1132 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1142 /* Handle the -offset argument. */
1144 if (n
->norm
->Bd
.offs
== NULL
||
1145 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1146 SCALE_HS_INIT(&su
, 0);
1147 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1148 SCALE_HS_INIT(&su
, INDENT
);
1149 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1150 SCALE_HS_INIT(&su
, INDENT
* 2);
1152 a2width(n
->norm
->Bd
.offs
, &su
);
1155 bufcat_su(h
, "margin-left", &su
);
1156 PAIR_STYLE_INIT(&tag
[0], h
);
1158 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1159 DISP_literal
!= n
->norm
->Bd
.type
) {
1160 PAIR_CLASS_INIT(&tag
[1], "display");
1161 print_otag(h
, TAG_DIV
, 2, tag
);
1165 PAIR_CLASS_INIT(&tag
[1], "lit display");
1166 print_otag(h
, TAG_PRE
, 2, tag
);
1168 /* This can be recursive: save & set our literal state. */
1170 sv
= h
->flags
& HTML_LITERAL
;
1171 h
->flags
|= HTML_LITERAL
;
1173 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1174 print_mdoc_node(meta
, nn
, h
);
1176 * If the printed node flushes its own line, then we
1177 * needn't do it here as well. This is hacky, but the
1178 * notion of selective eoln whitespace is pretty dumb
1179 * anyway, so don't sweat it.
1201 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1204 print_text(h
, "\n");
1206 h
->flags
|= HTML_NOSPACE
;
1210 h
->flags
&= ~HTML_LITERAL
;
1216 mdoc_pa_pre(MDOC_ARGS
)
1218 struct htmlpair tag
;
1220 PAIR_CLASS_INIT(&tag
, "file");
1221 print_otag(h
, TAG_I
, 1, &tag
);
1226 mdoc_ad_pre(MDOC_ARGS
)
1228 struct htmlpair tag
;
1230 PAIR_CLASS_INIT(&tag
, "addr");
1231 print_otag(h
, TAG_I
, 1, &tag
);
1236 mdoc_an_pre(MDOC_ARGS
)
1238 struct htmlpair tag
;
1240 if (n
->norm
->An
.auth
== AUTH_split
) {
1241 h
->flags
&= ~HTML_NOSPLIT
;
1242 h
->flags
|= HTML_SPLIT
;
1245 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1246 h
->flags
&= ~HTML_SPLIT
;
1247 h
->flags
|= HTML_NOSPLIT
;
1251 if (n
->child
== NULL
)
1254 if (h
->flags
& HTML_SPLIT
)
1255 print_otag(h
, TAG_BR
, 0, NULL
);
1257 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
1258 h
->flags
|= HTML_SPLIT
;
1260 PAIR_CLASS_INIT(&tag
, "author");
1261 print_otag(h
, TAG_SPAN
, 1, &tag
);
1266 mdoc_cd_pre(MDOC_ARGS
)
1268 struct htmlpair tag
;
1271 PAIR_CLASS_INIT(&tag
, "config");
1272 print_otag(h
, TAG_B
, 1, &tag
);
1277 mdoc_dv_pre(MDOC_ARGS
)
1279 struct htmlpair tag
;
1281 PAIR_CLASS_INIT(&tag
, "define");
1282 print_otag(h
, TAG_SPAN
, 1, &tag
);
1287 mdoc_ev_pre(MDOC_ARGS
)
1289 struct htmlpair tag
;
1291 PAIR_CLASS_INIT(&tag
, "env");
1292 print_otag(h
, TAG_SPAN
, 1, &tag
);
1297 mdoc_er_pre(MDOC_ARGS
)
1299 struct htmlpair tag
;
1301 PAIR_CLASS_INIT(&tag
, "errno");
1302 print_otag(h
, TAG_SPAN
, 1, &tag
);
1307 mdoc_fa_pre(MDOC_ARGS
)
1309 const struct mdoc_node
*nn
;
1310 struct htmlpair tag
;
1313 PAIR_CLASS_INIT(&tag
, "farg");
1314 if (n
->parent
->tok
!= MDOC_Fo
) {
1315 print_otag(h
, TAG_I
, 1, &tag
);
1319 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1320 t
= print_otag(h
, TAG_I
, 1, &tag
);
1321 print_text(h
, nn
->string
);
1324 h
->flags
|= HTML_NOSPACE
;
1329 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1330 h
->flags
|= HTML_NOSPACE
;
1338 mdoc_fd_pre(MDOC_ARGS
)
1340 struct htmlpair tag
[2];
1348 if (NULL
== (n
= n
->child
))
1351 assert(MDOC_TEXT
== n
->type
);
1353 if (strcmp(n
->string
, "#include")) {
1354 PAIR_CLASS_INIT(&tag
[0], "macro");
1355 print_otag(h
, TAG_B
, 1, tag
);
1359 PAIR_CLASS_INIT(&tag
[0], "includes");
1360 print_otag(h
, TAG_B
, 1, tag
);
1361 print_text(h
, n
->string
);
1363 if (NULL
!= (n
= n
->next
)) {
1364 assert(MDOC_TEXT
== n
->type
);
1367 * XXX This is broken and not easy to fix.
1368 * When using -Oincludes, truncation may occur.
1369 * Dynamic allocation wouldn't help because
1370 * passing long strings to buffmt_includes()
1371 * does not work either.
1374 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1375 n
->string
+ 1 : n
->string
, BUFSIZ
);
1378 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1381 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1384 if (h
->base_includes
) {
1385 buffmt_includes(h
, buf
);
1386 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1390 t
= print_otag(h
, TAG_A
, i
, tag
);
1391 print_text(h
, n
->string
);
1397 for ( ; n
; n
= n
->next
) {
1398 assert(MDOC_TEXT
== n
->type
);
1399 print_text(h
, n
->string
);
1406 mdoc_vt_pre(MDOC_ARGS
)
1408 struct htmlpair tag
;
1410 if (MDOC_BLOCK
== n
->type
) {
1413 } else if (MDOC_ELEM
== n
->type
) {
1415 } else if (MDOC_HEAD
== n
->type
)
1418 PAIR_CLASS_INIT(&tag
, "type");
1419 print_otag(h
, TAG_SPAN
, 1, &tag
);
1424 mdoc_ft_pre(MDOC_ARGS
)
1426 struct htmlpair tag
;
1429 PAIR_CLASS_INIT(&tag
, "ftype");
1430 print_otag(h
, TAG_I
, 1, &tag
);
1435 mdoc_fn_pre(MDOC_ARGS
)
1438 struct htmlpair tag
[2];
1440 const char *sp
, *ep
;
1443 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1446 /* Split apart into type and name. */
1447 assert(n
->child
->string
);
1448 sp
= n
->child
->string
;
1450 ep
= strchr(sp
, ' ');
1452 PAIR_CLASS_INIT(&tag
[0], "ftype");
1453 t
= print_otag(h
, TAG_I
, 1, tag
);
1456 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1457 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1459 print_text(h
, nbuf
);
1461 ep
= strchr(sp
, ' ');
1466 PAIR_CLASS_INIT(&tag
[0], "fname");
1469 * FIXME: only refer to IDs that we know exist.
1473 if (MDOC_SYNPRETTY
& n
->flags
) {
1475 html_idcat(nbuf
, sp
, BUFSIZ
);
1476 PAIR_ID_INIT(&tag
[1], nbuf
);
1478 strlcpy(nbuf
, "#", BUFSIZ
);
1479 html_idcat(nbuf
, sp
, BUFSIZ
);
1480 PAIR_HREF_INIT(&tag
[1], nbuf
);
1484 t
= print_otag(h
, TAG_B
, 1, tag
);
1491 h
->flags
|= HTML_NOSPACE
;
1493 h
->flags
|= HTML_NOSPACE
;
1495 PAIR_CLASS_INIT(&tag
[0], "farg");
1497 bufcat_style(h
, "white-space", "nowrap");
1498 PAIR_STYLE_INIT(&tag
[1], h
);
1500 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1502 if (MDOC_SYNPRETTY
& n
->flags
)
1504 t
= print_otag(h
, TAG_I
, i
, tag
);
1505 print_text(h
, n
->string
);
1508 h
->flags
|= HTML_NOSPACE
;
1513 h
->flags
|= HTML_NOSPACE
;
1517 h
->flags
|= HTML_NOSPACE
;
1525 mdoc_sm_pre(MDOC_ARGS
)
1528 if (NULL
== n
->child
)
1529 h
->flags
^= HTML_NONOSPACE
;
1530 else if (0 == strcmp("on", n
->child
->string
))
1531 h
->flags
&= ~HTML_NONOSPACE
;
1533 h
->flags
|= HTML_NONOSPACE
;
1535 if ( ! (HTML_NONOSPACE
& h
->flags
))
1536 h
->flags
&= ~HTML_NOSPACE
;
1542 mdoc_skip_pre(MDOC_ARGS
)
1549 mdoc_pp_pre(MDOC_ARGS
)
1557 mdoc_sp_pre(MDOC_ARGS
)
1560 struct htmlpair tag
;
1562 SCALE_VS_INIT(&su
, 1);
1564 if (MDOC_sp
== n
->tok
) {
1565 if (NULL
!= (n
= n
->child
))
1566 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1567 SCALE_VS_INIT(&su
, atoi(n
->string
));
1572 bufcat_su(h
, "height", &su
);
1573 PAIR_STYLE_INIT(&tag
, h
);
1574 print_otag(h
, TAG_DIV
, 1, &tag
);
1576 /* So the div isn't empty: */
1577 print_text(h
, "\\~");
1584 mdoc_lk_pre(MDOC_ARGS
)
1586 struct htmlpair tag
[2];
1588 if (NULL
== (n
= n
->child
))
1591 assert(MDOC_TEXT
== n
->type
);
1593 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1594 PAIR_HREF_INIT(&tag
[1], n
->string
);
1596 print_otag(h
, TAG_A
, 2, tag
);
1598 if (NULL
== n
->next
)
1599 print_text(h
, n
->string
);
1601 for (n
= n
->next
; n
; n
= n
->next
)
1602 print_text(h
, n
->string
);
1608 mdoc_mt_pre(MDOC_ARGS
)
1610 struct htmlpair tag
[2];
1613 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1615 for (n
= n
->child
; n
; n
= n
->next
) {
1616 assert(MDOC_TEXT
== n
->type
);
1619 bufcat(h
, "mailto:");
1620 bufcat(h
, n
->string
);
1622 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1623 t
= print_otag(h
, TAG_A
, 2, tag
);
1624 print_text(h
, n
->string
);
1632 mdoc_fo_pre(MDOC_ARGS
)
1634 struct htmlpair tag
;
1637 if (MDOC_BODY
== n
->type
) {
1638 h
->flags
|= HTML_NOSPACE
;
1640 h
->flags
|= HTML_NOSPACE
;
1642 } else if (MDOC_BLOCK
== n
->type
) {
1647 /* XXX: we drop non-initial arguments as per groff. */
1650 assert(n
->child
->string
);
1652 PAIR_CLASS_INIT(&tag
, "fname");
1653 t
= print_otag(h
, TAG_B
, 1, &tag
);
1654 print_text(h
, n
->child
->string
);
1660 mdoc_fo_post(MDOC_ARGS
)
1663 if (MDOC_BODY
!= n
->type
)
1665 h
->flags
|= HTML_NOSPACE
;
1667 h
->flags
|= HTML_NOSPACE
;
1672 mdoc_in_pre(MDOC_ARGS
)
1675 struct htmlpair tag
[2];
1680 PAIR_CLASS_INIT(&tag
[0], "includes");
1681 print_otag(h
, TAG_B
, 1, tag
);
1684 * The first argument of the `In' gets special treatment as
1685 * being a linked value. Subsequent values are printed
1686 * afterward. groff does similarly. This also handles the case
1690 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1691 print_text(h
, "#include");
1694 h
->flags
|= HTML_NOSPACE
;
1696 if (NULL
!= (n
= n
->child
)) {
1697 assert(MDOC_TEXT
== n
->type
);
1699 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1702 if (h
->base_includes
) {
1703 buffmt_includes(h
, n
->string
);
1704 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1708 t
= print_otag(h
, TAG_A
, i
, tag
);
1709 print_text(h
, n
->string
);
1715 h
->flags
|= HTML_NOSPACE
;
1718 for ( ; n
; n
= n
->next
) {
1719 assert(MDOC_TEXT
== n
->type
);
1720 print_text(h
, n
->string
);
1727 mdoc_ic_pre(MDOC_ARGS
)
1729 struct htmlpair tag
;
1731 PAIR_CLASS_INIT(&tag
, "cmd");
1732 print_otag(h
, TAG_B
, 1, &tag
);
1737 mdoc_rv_pre(MDOC_ARGS
)
1739 struct htmlpair tag
;
1744 print_otag(h
, TAG_BR
, 0, NULL
);
1746 PAIR_CLASS_INIT(&tag
, "fname");
1750 print_text(h
, "The");
1752 for (n
= n
->child
; n
; n
= n
->next
) {
1753 t
= print_otag(h
, TAG_B
, 1, &tag
);
1754 print_text(h
, n
->string
);
1757 h
->flags
|= HTML_NOSPACE
;
1758 print_text(h
, "()");
1760 if (n
->next
== NULL
)
1764 h
->flags
|= HTML_NOSPACE
;
1767 if (n
->next
->next
== NULL
)
1768 print_text(h
, "and");
1772 print_text(h
, "functions return");
1774 print_text(h
, "function returns");
1776 print_text(h
, "the value\\~0 if successful;");
1778 print_text(h
, "Upon successful completion,"
1779 " the value\\~0 is returned;");
1781 print_text(h
, "otherwise the value\\~\\-1 is returned"
1782 " and the global variable");
1784 PAIR_CLASS_INIT(&tag
, "var");
1785 t
= print_otag(h
, TAG_B
, 1, &tag
);
1786 print_text(h
, "errno");
1788 print_text(h
, "is set to indicate the error.");
1793 mdoc_va_pre(MDOC_ARGS
)
1795 struct htmlpair tag
;
1797 PAIR_CLASS_INIT(&tag
, "var");
1798 print_otag(h
, TAG_B
, 1, &tag
);
1803 mdoc_ap_pre(MDOC_ARGS
)
1806 h
->flags
|= HTML_NOSPACE
;
1807 print_text(h
, "\\(aq");
1808 h
->flags
|= HTML_NOSPACE
;
1813 mdoc_bf_pre(MDOC_ARGS
)
1815 struct htmlpair tag
[2];
1818 if (MDOC_HEAD
== n
->type
)
1820 else if (MDOC_BODY
!= n
->type
)
1823 if (FONT_Em
== n
->norm
->Bf
.font
)
1824 PAIR_CLASS_INIT(&tag
[0], "emph");
1825 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1826 PAIR_CLASS_INIT(&tag
[0], "symb");
1827 else if (FONT_Li
== n
->norm
->Bf
.font
)
1828 PAIR_CLASS_INIT(&tag
[0], "lit");
1830 PAIR_CLASS_INIT(&tag
[0], "none");
1833 * We want this to be inline-formatted, but needs to be div to
1834 * accept block children.
1837 bufcat_style(h
, "display", "inline");
1838 SCALE_HS_INIT(&su
, 1);
1839 /* Needs a left-margin for spacing. */
1840 bufcat_su(h
, "margin-left", &su
);
1841 PAIR_STYLE_INIT(&tag
[1], h
);
1842 print_otag(h
, TAG_DIV
, 2, tag
);
1847 mdoc_ms_pre(MDOC_ARGS
)
1849 struct htmlpair tag
;
1851 PAIR_CLASS_INIT(&tag
, "symb");
1852 print_otag(h
, TAG_SPAN
, 1, &tag
);
1857 mdoc_igndelim_pre(MDOC_ARGS
)
1860 h
->flags
|= HTML_IGNDELIM
;
1865 mdoc_pf_post(MDOC_ARGS
)
1868 h
->flags
|= HTML_NOSPACE
;
1872 mdoc_rs_pre(MDOC_ARGS
)
1874 struct htmlpair tag
;
1876 if (MDOC_BLOCK
!= n
->type
)
1879 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1882 PAIR_CLASS_INIT(&tag
, "ref");
1883 print_otag(h
, TAG_SPAN
, 1, &tag
);
1888 mdoc_no_pre(MDOC_ARGS
)
1890 struct htmlpair tag
;
1892 PAIR_CLASS_INIT(&tag
, "none");
1893 print_otag(h
, TAG_CODE
, 1, &tag
);
1898 mdoc_li_pre(MDOC_ARGS
)
1900 struct htmlpair tag
;
1902 PAIR_CLASS_INIT(&tag
, "lit");
1903 print_otag(h
, TAG_CODE
, 1, &tag
);
1908 mdoc_sy_pre(MDOC_ARGS
)
1910 struct htmlpair tag
;
1912 PAIR_CLASS_INIT(&tag
, "symb");
1913 print_otag(h
, TAG_SPAN
, 1, &tag
);
1918 mdoc_bt_pre(MDOC_ARGS
)
1921 print_text(h
, "is currently in beta test.");
1926 mdoc_ud_pre(MDOC_ARGS
)
1929 print_text(h
, "currently under development.");
1934 mdoc_lb_pre(MDOC_ARGS
)
1936 struct htmlpair tag
;
1938 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
1939 print_otag(h
, TAG_BR
, 0, NULL
);
1941 PAIR_CLASS_INIT(&tag
, "lib");
1942 print_otag(h
, TAG_SPAN
, 1, &tag
);
1947 mdoc__x_pre(MDOC_ARGS
)
1949 struct htmlpair tag
[2];
1956 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
1957 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1958 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1959 print_text(h
, "and");
1962 PAIR_CLASS_INIT(&tag
[0], "ref-book");
1966 PAIR_CLASS_INIT(&tag
[0], "ref-city");
1969 PAIR_CLASS_INIT(&tag
[0], "ref-date");
1972 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
1976 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
1980 PAIR_CLASS_INIT(&tag
[0], "ref-num");
1983 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
1986 PAIR_CLASS_INIT(&tag
[0], "ref-page");
1989 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
1992 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
1995 PAIR_CLASS_INIT(&tag
[0], "ref-title");
1998 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2001 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2008 if (MDOC__U
!= n
->tok
) {
2009 print_otag(h
, t
, 1, tag
);
2013 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2014 print_otag(h
, TAG_A
, 2, tag
);
2020 mdoc__x_post(MDOC_ARGS
)
2023 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2024 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2025 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2030 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2033 h
->flags
|= HTML_NOSPACE
;
2034 print_text(h
, n
->next
? "," : ".");
2038 mdoc_bk_pre(MDOC_ARGS
)
2047 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2048 h
->flags
|= HTML_PREKEEP
;
2059 mdoc_bk_post(MDOC_ARGS
)
2062 if (MDOC_BODY
== n
->type
)
2063 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2067 mdoc_quote_pre(MDOC_ARGS
)
2069 struct htmlpair tag
;
2071 if (MDOC_BODY
!= n
->type
)
2078 print_text(h
, "\\(la");
2083 print_text(h
, "\\(lC");
2088 print_text(h
, "\\(lB");
2093 print_text(h
, "\\(lB");
2094 h
->flags
|= HTML_NOSPACE
;
2095 PAIR_CLASS_INIT(&tag
, "opt");
2096 print_otag(h
, TAG_SPAN
, 1, &tag
);
2099 if (NULL
== n
->norm
->Es
||
2100 NULL
== n
->norm
->Es
->child
)
2102 print_text(h
, n
->norm
->Es
->child
->string
);
2113 print_text(h
, "\\(lq");
2121 print_text(h
, "\\(oq");
2122 h
->flags
|= HTML_NOSPACE
;
2123 PAIR_CLASS_INIT(&tag
, "lit");
2124 print_otag(h
, TAG_CODE
, 1, &tag
);
2129 print_text(h
, "\\(oq");
2136 h
->flags
|= HTML_NOSPACE
;
2141 mdoc_quote_post(MDOC_ARGS
)
2144 if (MDOC_BODY
!= n
->type
)
2147 if (MDOC_En
!= n
->tok
)
2148 h
->flags
|= HTML_NOSPACE
;
2154 print_text(h
, "\\(ra");
2159 print_text(h
, "\\(rC");
2168 print_text(h
, "\\(rB");
2171 if (NULL
!= n
->norm
->Es
&&
2172 NULL
!= n
->norm
->Es
->child
&&
2173 NULL
!= n
->norm
->Es
->child
->next
) {
2174 h
->flags
|= HTML_NOSPACE
;
2175 print_text(h
, n
->norm
->Es
->child
->next
->string
);
2187 print_text(h
, "\\(rq");
2199 print_text(h
, "\\(cq");