xref: /titanic_52/usr/src/cmd/mandoc/mdoc_html.c (revision 260e9a87725c090ba5835b1f9f0b62fa2f96036f)
1*260e9a87SYuri Pankov /*	$Id: mdoc_html.c,v 1.226 2015/03/03 21:11:34 schwarze Exp $ */
295c635efSGarrett D'Amore /*
3*260e9a87SYuri Pankov  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4*260e9a87SYuri Pankov  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
595c635efSGarrett D'Amore  *
695c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
795c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
895c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
995c635efSGarrett D'Amore  *
1095c635efSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1295c635efSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1395c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1495c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1595c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1695c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1795c635efSGarrett D'Amore  */
1895c635efSGarrett D'Amore #include "config.h"
1995c635efSGarrett D'Amore 
2095c635efSGarrett D'Amore #include <sys/types.h>
2195c635efSGarrett D'Amore 
2295c635efSGarrett D'Amore #include <assert.h>
2395c635efSGarrett D'Amore #include <ctype.h>
2495c635efSGarrett D'Amore #include <stdio.h>
2595c635efSGarrett D'Amore #include <stdlib.h>
2695c635efSGarrett D'Amore #include <string.h>
2795c635efSGarrett D'Amore #include <unistd.h>
2895c635efSGarrett D'Amore 
29*260e9a87SYuri Pankov #include "mandoc_aux.h"
30*260e9a87SYuri Pankov #include "mdoc.h"
3195c635efSGarrett D'Amore #include "out.h"
3295c635efSGarrett D'Amore #include "html.h"
3395c635efSGarrett D'Amore #include "main.h"
3495c635efSGarrett D'Amore 
3595c635efSGarrett D'Amore #define	INDENT		 5
3695c635efSGarrett D'Amore 
37698f87a4SGarrett D'Amore #define	MDOC_ARGS	  const struct mdoc_meta *meta, \
38*260e9a87SYuri Pankov 			  struct mdoc_node *n, \
3995c635efSGarrett D'Amore 			  struct html *h
4095c635efSGarrett D'Amore 
4195c635efSGarrett D'Amore #ifndef MIN
4295c635efSGarrett D'Amore #define	MIN(a,b)	((/*CONSTCOND*/(a)<(b))?(a):(b))
4395c635efSGarrett D'Amore #endif
4495c635efSGarrett D'Amore 
4595c635efSGarrett D'Amore struct	htmlmdoc {
4695c635efSGarrett D'Amore 	int		(*pre)(MDOC_ARGS);
4795c635efSGarrett D'Amore 	void		(*post)(MDOC_ARGS);
4895c635efSGarrett D'Amore };
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore static	void		  print_mdoc(MDOC_ARGS);
5195c635efSGarrett D'Amore static	void		  print_mdoc_head(MDOC_ARGS);
5295c635efSGarrett D'Amore static	void		  print_mdoc_node(MDOC_ARGS);
5395c635efSGarrett D'Amore static	void		  print_mdoc_nodelist(MDOC_ARGS);
5495c635efSGarrett D'Amore static	void		  synopsis_pre(struct html *,
5595c635efSGarrett D'Amore 				const struct mdoc_node *);
5695c635efSGarrett D'Amore 
5795c635efSGarrett D'Amore static	void		  a2width(const char *, struct roffsu *);
5895c635efSGarrett D'Amore 
5995c635efSGarrett D'Amore static	void		  mdoc_root_post(MDOC_ARGS);
6095c635efSGarrett D'Amore static	int		  mdoc_root_pre(MDOC_ARGS);
6195c635efSGarrett D'Amore 
6295c635efSGarrett D'Amore static	void		  mdoc__x_post(MDOC_ARGS);
6395c635efSGarrett D'Amore static	int		  mdoc__x_pre(MDOC_ARGS);
6495c635efSGarrett D'Amore static	int		  mdoc_ad_pre(MDOC_ARGS);
6595c635efSGarrett D'Amore static	int		  mdoc_an_pre(MDOC_ARGS);
6695c635efSGarrett D'Amore static	int		  mdoc_ap_pre(MDOC_ARGS);
6795c635efSGarrett D'Amore static	int		  mdoc_ar_pre(MDOC_ARGS);
6895c635efSGarrett D'Amore static	int		  mdoc_bd_pre(MDOC_ARGS);
6995c635efSGarrett D'Amore static	int		  mdoc_bf_pre(MDOC_ARGS);
7095c635efSGarrett D'Amore static	void		  mdoc_bk_post(MDOC_ARGS);
7195c635efSGarrett D'Amore static	int		  mdoc_bk_pre(MDOC_ARGS);
7295c635efSGarrett D'Amore static	int		  mdoc_bl_pre(MDOC_ARGS);
7395c635efSGarrett D'Amore static	int		  mdoc_bt_pre(MDOC_ARGS);
7495c635efSGarrett D'Amore static	int		  mdoc_bx_pre(MDOC_ARGS);
7595c635efSGarrett D'Amore static	int		  mdoc_cd_pre(MDOC_ARGS);
7695c635efSGarrett D'Amore static	int		  mdoc_d1_pre(MDOC_ARGS);
7795c635efSGarrett D'Amore static	int		  mdoc_dv_pre(MDOC_ARGS);
7895c635efSGarrett D'Amore static	int		  mdoc_fa_pre(MDOC_ARGS);
7995c635efSGarrett D'Amore static	int		  mdoc_fd_pre(MDOC_ARGS);
8095c635efSGarrett D'Amore static	int		  mdoc_fl_pre(MDOC_ARGS);
8195c635efSGarrett D'Amore static	int		  mdoc_fn_pre(MDOC_ARGS);
8295c635efSGarrett D'Amore static	int		  mdoc_ft_pre(MDOC_ARGS);
8395c635efSGarrett D'Amore static	int		  mdoc_em_pre(MDOC_ARGS);
84*260e9a87SYuri Pankov static	void		  mdoc_eo_post(MDOC_ARGS);
85*260e9a87SYuri Pankov static	int		  mdoc_eo_pre(MDOC_ARGS);
8695c635efSGarrett D'Amore static	int		  mdoc_er_pre(MDOC_ARGS);
8795c635efSGarrett D'Amore static	int		  mdoc_ev_pre(MDOC_ARGS);
8895c635efSGarrett D'Amore static	int		  mdoc_ex_pre(MDOC_ARGS);
8995c635efSGarrett D'Amore static	void		  mdoc_fo_post(MDOC_ARGS);
9095c635efSGarrett D'Amore static	int		  mdoc_fo_pre(MDOC_ARGS);
9195c635efSGarrett D'Amore static	int		  mdoc_ic_pre(MDOC_ARGS);
9295c635efSGarrett D'Amore static	int		  mdoc_igndelim_pre(MDOC_ARGS);
9395c635efSGarrett D'Amore static	int		  mdoc_in_pre(MDOC_ARGS);
9495c635efSGarrett D'Amore static	int		  mdoc_it_pre(MDOC_ARGS);
9595c635efSGarrett D'Amore static	int		  mdoc_lb_pre(MDOC_ARGS);
9695c635efSGarrett D'Amore static	int		  mdoc_li_pre(MDOC_ARGS);
9795c635efSGarrett D'Amore static	int		  mdoc_lk_pre(MDOC_ARGS);
9895c635efSGarrett D'Amore static	int		  mdoc_mt_pre(MDOC_ARGS);
9995c635efSGarrett D'Amore static	int		  mdoc_ms_pre(MDOC_ARGS);
10095c635efSGarrett D'Amore static	int		  mdoc_nd_pre(MDOC_ARGS);
10195c635efSGarrett D'Amore static	int		  mdoc_nm_pre(MDOC_ARGS);
102*260e9a87SYuri Pankov static	int		  mdoc_no_pre(MDOC_ARGS);
10395c635efSGarrett D'Amore static	int		  mdoc_ns_pre(MDOC_ARGS);
10495c635efSGarrett D'Amore static	int		  mdoc_pa_pre(MDOC_ARGS);
10595c635efSGarrett D'Amore static	void		  mdoc_pf_post(MDOC_ARGS);
10695c635efSGarrett D'Amore static	int		  mdoc_pp_pre(MDOC_ARGS);
10795c635efSGarrett D'Amore static	void		  mdoc_quote_post(MDOC_ARGS);
10895c635efSGarrett D'Amore static	int		  mdoc_quote_pre(MDOC_ARGS);
10995c635efSGarrett D'Amore static	int		  mdoc_rs_pre(MDOC_ARGS);
11095c635efSGarrett D'Amore static	int		  mdoc_rv_pre(MDOC_ARGS);
11195c635efSGarrett D'Amore static	int		  mdoc_sh_pre(MDOC_ARGS);
112*260e9a87SYuri Pankov static	int		  mdoc_skip_pre(MDOC_ARGS);
11395c635efSGarrett D'Amore static	int		  mdoc_sm_pre(MDOC_ARGS);
11495c635efSGarrett D'Amore static	int		  mdoc_sp_pre(MDOC_ARGS);
11595c635efSGarrett D'Amore static	int		  mdoc_ss_pre(MDOC_ARGS);
11695c635efSGarrett D'Amore static	int		  mdoc_sx_pre(MDOC_ARGS);
11795c635efSGarrett D'Amore static	int		  mdoc_sy_pre(MDOC_ARGS);
11895c635efSGarrett D'Amore static	int		  mdoc_ud_pre(MDOC_ARGS);
11995c635efSGarrett D'Amore static	int		  mdoc_va_pre(MDOC_ARGS);
12095c635efSGarrett D'Amore static	int		  mdoc_vt_pre(MDOC_ARGS);
12195c635efSGarrett D'Amore static	int		  mdoc_xr_pre(MDOC_ARGS);
12295c635efSGarrett D'Amore static	int		  mdoc_xx_pre(MDOC_ARGS);
12395c635efSGarrett D'Amore 
12495c635efSGarrett D'Amore static	const struct htmlmdoc mdocs[MDOC_MAX] = {
12595c635efSGarrett D'Amore 	{mdoc_ap_pre, NULL}, /* Ap */
12695c635efSGarrett D'Amore 	{NULL, NULL}, /* Dd */
12795c635efSGarrett D'Amore 	{NULL, NULL}, /* Dt */
12895c635efSGarrett D'Amore 	{NULL, NULL}, /* Os */
12995c635efSGarrett D'Amore 	{mdoc_sh_pre, NULL }, /* Sh */
13095c635efSGarrett D'Amore 	{mdoc_ss_pre, NULL }, /* Ss */
13195c635efSGarrett D'Amore 	{mdoc_pp_pre, NULL}, /* Pp */
13295c635efSGarrett D'Amore 	{mdoc_d1_pre, NULL}, /* D1 */
13395c635efSGarrett D'Amore 	{mdoc_d1_pre, NULL}, /* Dl */
13495c635efSGarrett D'Amore 	{mdoc_bd_pre, NULL}, /* Bd */
13595c635efSGarrett D'Amore 	{NULL, NULL}, /* Ed */
13695c635efSGarrett D'Amore 	{mdoc_bl_pre, NULL}, /* Bl */
13795c635efSGarrett D'Amore 	{NULL, NULL}, /* El */
13895c635efSGarrett D'Amore 	{mdoc_it_pre, NULL}, /* It */
13995c635efSGarrett D'Amore 	{mdoc_ad_pre, NULL}, /* Ad */
14095c635efSGarrett D'Amore 	{mdoc_an_pre, NULL}, /* An */
14195c635efSGarrett D'Amore 	{mdoc_ar_pre, NULL}, /* Ar */
14295c635efSGarrett D'Amore 	{mdoc_cd_pre, NULL}, /* Cd */
14395c635efSGarrett D'Amore 	{mdoc_fl_pre, NULL}, /* Cm */
14495c635efSGarrett D'Amore 	{mdoc_dv_pre, NULL}, /* Dv */
14595c635efSGarrett D'Amore 	{mdoc_er_pre, NULL}, /* Er */
14695c635efSGarrett D'Amore 	{mdoc_ev_pre, NULL}, /* Ev */
14795c635efSGarrett D'Amore 	{mdoc_ex_pre, NULL}, /* Ex */
14895c635efSGarrett D'Amore 	{mdoc_fa_pre, NULL}, /* Fa */
14995c635efSGarrett D'Amore 	{mdoc_fd_pre, NULL}, /* Fd */
15095c635efSGarrett D'Amore 	{mdoc_fl_pre, NULL}, /* Fl */
15195c635efSGarrett D'Amore 	{mdoc_fn_pre, NULL}, /* Fn */
15295c635efSGarrett D'Amore 	{mdoc_ft_pre, NULL}, /* Ft */
15395c635efSGarrett D'Amore 	{mdoc_ic_pre, NULL}, /* Ic */
15495c635efSGarrett D'Amore 	{mdoc_in_pre, NULL}, /* In */
15595c635efSGarrett D'Amore 	{mdoc_li_pre, NULL}, /* Li */
15695c635efSGarrett D'Amore 	{mdoc_nd_pre, NULL}, /* Nd */
15795c635efSGarrett D'Amore 	{mdoc_nm_pre, NULL}, /* Nm */
15895c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Op */
159*260e9a87SYuri Pankov 	{mdoc_ft_pre, NULL}, /* Ot */
16095c635efSGarrett D'Amore 	{mdoc_pa_pre, NULL}, /* Pa */
16195c635efSGarrett D'Amore 	{mdoc_rv_pre, NULL}, /* Rv */
16295c635efSGarrett D'Amore 	{NULL, NULL}, /* St */
16395c635efSGarrett D'Amore 	{mdoc_va_pre, NULL}, /* Va */
16495c635efSGarrett D'Amore 	{mdoc_vt_pre, NULL}, /* Vt */
16595c635efSGarrett D'Amore 	{mdoc_xr_pre, NULL}, /* Xr */
16695c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %A */
16795c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %B */
16895c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %D */
16995c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %I */
17095c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %J */
17195c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %N */
17295c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %O */
17395c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %P */
17495c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %R */
17595c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %T */
17695c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %V */
17795c635efSGarrett D'Amore 	{NULL, NULL}, /* Ac */
17895c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Ao */
17995c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Aq */
18095c635efSGarrett D'Amore 	{NULL, NULL}, /* At */
18195c635efSGarrett D'Amore 	{NULL, NULL}, /* Bc */
18295c635efSGarrett D'Amore 	{mdoc_bf_pre, NULL}, /* Bf */
18395c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Bo */
18495c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Bq */
18595c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Bsx */
18695c635efSGarrett D'Amore 	{mdoc_bx_pre, NULL}, /* Bx */
187*260e9a87SYuri Pankov 	{mdoc_skip_pre, NULL}, /* Db */
18895c635efSGarrett D'Amore 	{NULL, NULL}, /* Dc */
18995c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Do */
19095c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Dq */
19195c635efSGarrett D'Amore 	{NULL, NULL}, /* Ec */ /* FIXME: no space */
19295c635efSGarrett D'Amore 	{NULL, NULL}, /* Ef */
19395c635efSGarrett D'Amore 	{mdoc_em_pre, NULL}, /* Em */
194*260e9a87SYuri Pankov 	{mdoc_eo_pre, mdoc_eo_post}, /* Eo */
19595c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Fx */
19695c635efSGarrett D'Amore 	{mdoc_ms_pre, NULL}, /* Ms */
197*260e9a87SYuri Pankov 	{mdoc_no_pre, NULL}, /* No */
19895c635efSGarrett D'Amore 	{mdoc_ns_pre, NULL}, /* Ns */
19995c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Nx */
20095c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Ox */
20195c635efSGarrett D'Amore 	{NULL, NULL}, /* Pc */
20295c635efSGarrett D'Amore 	{mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
20395c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Po */
20495c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Pq */
20595c635efSGarrett D'Amore 	{NULL, NULL}, /* Qc */
20695c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Ql */
20795c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Qo */
20895c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Qq */
20995c635efSGarrett D'Amore 	{NULL, NULL}, /* Re */
21095c635efSGarrett D'Amore 	{mdoc_rs_pre, NULL}, /* Rs */
21195c635efSGarrett D'Amore 	{NULL, NULL}, /* Sc */
21295c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* So */
21395c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Sq */
21495c635efSGarrett D'Amore 	{mdoc_sm_pre, NULL}, /* Sm */
21595c635efSGarrett D'Amore 	{mdoc_sx_pre, NULL}, /* Sx */
21695c635efSGarrett D'Amore 	{mdoc_sy_pre, NULL}, /* Sy */
21795c635efSGarrett D'Amore 	{NULL, NULL}, /* Tn */
21895c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Ux */
21995c635efSGarrett D'Amore 	{NULL, NULL}, /* Xc */
22095c635efSGarrett D'Amore 	{NULL, NULL}, /* Xo */
22195c635efSGarrett D'Amore 	{mdoc_fo_pre, mdoc_fo_post}, /* Fo */
22295c635efSGarrett D'Amore 	{NULL, NULL}, /* Fc */
22395c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Oo */
22495c635efSGarrett D'Amore 	{NULL, NULL}, /* Oc */
22595c635efSGarrett D'Amore 	{mdoc_bk_pre, mdoc_bk_post}, /* Bk */
22695c635efSGarrett D'Amore 	{NULL, NULL}, /* Ek */
22795c635efSGarrett D'Amore 	{mdoc_bt_pre, NULL}, /* Bt */
22895c635efSGarrett D'Amore 	{NULL, NULL}, /* Hf */
229*260e9a87SYuri Pankov 	{mdoc_em_pre, NULL}, /* Fr */
23095c635efSGarrett D'Amore 	{mdoc_ud_pre, NULL}, /* Ud */
23195c635efSGarrett D'Amore 	{mdoc_lb_pre, NULL}, /* Lb */
23295c635efSGarrett D'Amore 	{mdoc_pp_pre, NULL}, /* Lp */
23395c635efSGarrett D'Amore 	{mdoc_lk_pre, NULL}, /* Lk */
23495c635efSGarrett D'Amore 	{mdoc_mt_pre, NULL}, /* Mt */
23595c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Brq */
23695c635efSGarrett D'Amore 	{mdoc_quote_pre, mdoc_quote_post}, /* Bro */
23795c635efSGarrett D'Amore 	{NULL, NULL}, /* Brc */
23895c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %C */
239*260e9a87SYuri Pankov 	{mdoc_skip_pre, NULL}, /* Es */
240*260e9a87SYuri Pankov 	{mdoc_quote_pre, mdoc_quote_post}, /* En */
24195c635efSGarrett D'Amore 	{mdoc_xx_pre, NULL}, /* Dx */
24295c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %Q */
24395c635efSGarrett D'Amore 	{mdoc_sp_pre, NULL}, /* br */
24495c635efSGarrett D'Amore 	{mdoc_sp_pre, NULL}, /* sp */
24595c635efSGarrett D'Amore 	{mdoc__x_pre, mdoc__x_post}, /* %U */
24695c635efSGarrett D'Amore 	{NULL, NULL}, /* Ta */
247*260e9a87SYuri Pankov 	{mdoc_skip_pre, NULL}, /* ll */
24895c635efSGarrett D'Amore };
24995c635efSGarrett D'Amore 
25095c635efSGarrett D'Amore static	const char * const lists[LIST_MAX] = {
25195c635efSGarrett D'Amore 	NULL,
25295c635efSGarrett D'Amore 	"list-bul",
25395c635efSGarrett D'Amore 	"list-col",
25495c635efSGarrett D'Amore 	"list-dash",
25595c635efSGarrett D'Amore 	"list-diag",
25695c635efSGarrett D'Amore 	"list-enum",
25795c635efSGarrett D'Amore 	"list-hang",
25895c635efSGarrett D'Amore 	"list-hyph",
25995c635efSGarrett D'Amore 	"list-inset",
26095c635efSGarrett D'Amore 	"list-item",
26195c635efSGarrett D'Amore 	"list-ohang",
26295c635efSGarrett D'Amore 	"list-tag"
26395c635efSGarrett D'Amore };
26495c635efSGarrett D'Amore 
265*260e9a87SYuri Pankov 
26695c635efSGarrett D'Amore void
267698f87a4SGarrett D'Amore html_mdoc(void *arg, const struct mdoc *mdoc)
26895c635efSGarrett D'Amore {
26995c635efSGarrett D'Amore 
270*260e9a87SYuri Pankov 	print_mdoc(mdoc_meta(mdoc), mdoc_node(mdoc)->child,
271698f87a4SGarrett D'Amore 	    (struct html *)arg);
27295c635efSGarrett D'Amore 	putchar('\n');
27395c635efSGarrett D'Amore }
27495c635efSGarrett D'Amore 
27595c635efSGarrett D'Amore /*
27695c635efSGarrett D'Amore  * Calculate the scaling unit passed in a `-width' argument.  This uses
27795c635efSGarrett D'Amore  * either a native scaling unit (e.g., 1i, 2m) or the string length of
27895c635efSGarrett D'Amore  * the value.
27995c635efSGarrett D'Amore  */
28095c635efSGarrett D'Amore static void
28195c635efSGarrett D'Amore a2width(const char *p, struct roffsu *su)
28295c635efSGarrett D'Amore {
28395c635efSGarrett D'Amore 
284*260e9a87SYuri Pankov 	if (a2roffsu(p, su, SCALE_MAX) < 2) {
285*260e9a87SYuri Pankov 		su->unit = SCALE_EN;
28695c635efSGarrett D'Amore 		su->scale = html_strlen(p);
287*260e9a87SYuri Pankov 	} else if (su->scale < 0.0)
288*260e9a87SYuri Pankov 		su->scale = 0.0;
28995c635efSGarrett D'Amore }
29095c635efSGarrett D'Amore 
29195c635efSGarrett D'Amore /*
29295c635efSGarrett D'Amore  * See the same function in mdoc_term.c for documentation.
29395c635efSGarrett D'Amore  */
29495c635efSGarrett D'Amore static void
29595c635efSGarrett D'Amore synopsis_pre(struct html *h, const struct mdoc_node *n)
29695c635efSGarrett D'Amore {
29795c635efSGarrett D'Amore 
29895c635efSGarrett D'Amore 	if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
29995c635efSGarrett D'Amore 		return;
30095c635efSGarrett D'Amore 
30195c635efSGarrett D'Amore 	if (n->prev->tok == n->tok &&
30295c635efSGarrett D'Amore 	    MDOC_Fo != n->tok &&
30395c635efSGarrett D'Amore 	    MDOC_Ft != n->tok &&
30495c635efSGarrett D'Amore 	    MDOC_Fn != n->tok) {
30595c635efSGarrett D'Amore 		print_otag(h, TAG_BR, 0, NULL);
30695c635efSGarrett D'Amore 		return;
30795c635efSGarrett D'Amore 	}
30895c635efSGarrett D'Amore 
30995c635efSGarrett D'Amore 	switch (n->prev->tok) {
310*260e9a87SYuri Pankov 	case MDOC_Fd:
31195c635efSGarrett D'Amore 		/* FALLTHROUGH */
312*260e9a87SYuri Pankov 	case MDOC_Fn:
31395c635efSGarrett D'Amore 		/* FALLTHROUGH */
314*260e9a87SYuri Pankov 	case MDOC_Fo:
31595c635efSGarrett D'Amore 		/* FALLTHROUGH */
316*260e9a87SYuri Pankov 	case MDOC_In:
31795c635efSGarrett D'Amore 		/* FALLTHROUGH */
318*260e9a87SYuri Pankov 	case MDOC_Vt:
319*260e9a87SYuri Pankov 		print_paragraph(h);
32095c635efSGarrett D'Amore 		break;
321*260e9a87SYuri Pankov 	case MDOC_Ft:
32295c635efSGarrett D'Amore 		if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
323*260e9a87SYuri Pankov 			print_paragraph(h);
32495c635efSGarrett D'Amore 			break;
32595c635efSGarrett D'Amore 		}
32695c635efSGarrett D'Amore 		/* FALLTHROUGH */
32795c635efSGarrett D'Amore 	default:
32895c635efSGarrett D'Amore 		print_otag(h, TAG_BR, 0, NULL);
32995c635efSGarrett D'Amore 		break;
33095c635efSGarrett D'Amore 	}
33195c635efSGarrett D'Amore }
33295c635efSGarrett D'Amore 
33395c635efSGarrett D'Amore static void
33495c635efSGarrett D'Amore print_mdoc(MDOC_ARGS)
33595c635efSGarrett D'Amore {
33695c635efSGarrett D'Amore 	struct tag	*t, *tt;
33795c635efSGarrett D'Amore 	struct htmlpair	 tag;
33895c635efSGarrett D'Amore 
33995c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "mandoc");
34095c635efSGarrett D'Amore 
34195c635efSGarrett D'Amore 	if ( ! (HTML_FRAGMENT & h->oflags)) {
34295c635efSGarrett D'Amore 		print_gen_decls(h);
34395c635efSGarrett D'Amore 		t = print_otag(h, TAG_HTML, 0, NULL);
34495c635efSGarrett D'Amore 		tt = print_otag(h, TAG_HEAD, 0, NULL);
345698f87a4SGarrett D'Amore 		print_mdoc_head(meta, n, h);
34695c635efSGarrett D'Amore 		print_tagq(h, tt);
34795c635efSGarrett D'Amore 		print_otag(h, TAG_BODY, 0, NULL);
34895c635efSGarrett D'Amore 		print_otag(h, TAG_DIV, 1, &tag);
34995c635efSGarrett D'Amore 	} else
35095c635efSGarrett D'Amore 		t = print_otag(h, TAG_DIV, 1, &tag);
35195c635efSGarrett D'Amore 
352698f87a4SGarrett D'Amore 	print_mdoc_nodelist(meta, n, h);
35395c635efSGarrett D'Amore 	print_tagq(h, t);
35495c635efSGarrett D'Amore }
35595c635efSGarrett D'Amore 
35695c635efSGarrett D'Amore static void
35795c635efSGarrett D'Amore print_mdoc_head(MDOC_ARGS)
35895c635efSGarrett D'Amore {
35995c635efSGarrett D'Amore 
36095c635efSGarrett D'Amore 	print_gen_head(h);
36195c635efSGarrett D'Amore 	bufinit(h);
362*260e9a87SYuri Pankov 	bufcat(h, meta->title);
363*260e9a87SYuri Pankov 	if (meta->msec)
364*260e9a87SYuri Pankov 		bufcat_fmt(h, "(%s)", meta->msec);
365698f87a4SGarrett D'Amore 	if (meta->arch)
366698f87a4SGarrett D'Amore 		bufcat_fmt(h, " (%s)", meta->arch);
36795c635efSGarrett D'Amore 
36895c635efSGarrett D'Amore 	print_otag(h, TAG_TITLE, 0, NULL);
36995c635efSGarrett D'Amore 	print_text(h, h->buf);
37095c635efSGarrett D'Amore }
37195c635efSGarrett D'Amore 
37295c635efSGarrett D'Amore static void
37395c635efSGarrett D'Amore print_mdoc_nodelist(MDOC_ARGS)
37495c635efSGarrett D'Amore {
37595c635efSGarrett D'Amore 
376*260e9a87SYuri Pankov 	while (n != NULL) {
377698f87a4SGarrett D'Amore 		print_mdoc_node(meta, n, h);
378*260e9a87SYuri Pankov 		n = n->next;
37995c635efSGarrett D'Amore 	}
380*260e9a87SYuri Pankov }
38195c635efSGarrett D'Amore 
38295c635efSGarrett D'Amore static void
38395c635efSGarrett D'Amore print_mdoc_node(MDOC_ARGS)
38495c635efSGarrett D'Amore {
38595c635efSGarrett D'Amore 	int		 child;
38695c635efSGarrett D'Amore 	struct tag	*t;
38795c635efSGarrett D'Amore 
38895c635efSGarrett D'Amore 	child = 1;
38995c635efSGarrett D'Amore 	t = h->tags.head;
390*260e9a87SYuri Pankov 	n->flags &= ~MDOC_ENDED;
39195c635efSGarrett D'Amore 
39295c635efSGarrett D'Amore 	switch (n->type) {
393*260e9a87SYuri Pankov 	case MDOC_ROOT:
394698f87a4SGarrett D'Amore 		child = mdoc_root_pre(meta, n, h);
39595c635efSGarrett D'Amore 		break;
396*260e9a87SYuri Pankov 	case MDOC_TEXT:
39795c635efSGarrett D'Amore 		/* No tables in this mode... */
39895c635efSGarrett D'Amore 		assert(NULL == h->tblt);
39995c635efSGarrett D'Amore 
40095c635efSGarrett D'Amore 		/*
40195c635efSGarrett D'Amore 		 * Make sure that if we're in a literal mode already
40295c635efSGarrett D'Amore 		 * (i.e., within a <PRE>) don't print the newline.
40395c635efSGarrett D'Amore 		 */
40495c635efSGarrett D'Amore 		if (' ' == *n->string && MDOC_LINE & n->flags)
40595c635efSGarrett D'Amore 			if ( ! (HTML_LITERAL & h->flags))
40695c635efSGarrett D'Amore 				print_otag(h, TAG_BR, 0, NULL);
40795c635efSGarrett D'Amore 		if (MDOC_DELIMC & n->flags)
40895c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
40995c635efSGarrett D'Amore 		print_text(h, n->string);
41095c635efSGarrett D'Amore 		if (MDOC_DELIMO & n->flags)
41195c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
41295c635efSGarrett D'Amore 		return;
413*260e9a87SYuri Pankov 	case MDOC_EQN:
414*260e9a87SYuri Pankov 		if (n->flags & MDOC_LINE)
415*260e9a87SYuri Pankov 			putchar('\n');
41695c635efSGarrett D'Amore 		print_eqn(h, n->eqn);
41795c635efSGarrett D'Amore 		break;
418*260e9a87SYuri Pankov 	case MDOC_TBL:
41995c635efSGarrett D'Amore 		/*
42095c635efSGarrett D'Amore 		 * This will take care of initialising all of the table
42195c635efSGarrett D'Amore 		 * state data for the first table, then tearing it down
42295c635efSGarrett D'Amore 		 * for the last one.
42395c635efSGarrett D'Amore 		 */
42495c635efSGarrett D'Amore 		print_tbl(h, n->span);
42595c635efSGarrett D'Amore 		return;
42695c635efSGarrett D'Amore 	default:
42795c635efSGarrett D'Amore 		/*
42895c635efSGarrett D'Amore 		 * Close out the current table, if it's open, and unset
42995c635efSGarrett D'Amore 		 * the "meta" table state.  This will be reopened on the
43095c635efSGarrett D'Amore 		 * next table element.
43195c635efSGarrett D'Amore 		 */
432*260e9a87SYuri Pankov 		if (h->tblt != NULL) {
43395c635efSGarrett D'Amore 			print_tblclose(h);
43495c635efSGarrett D'Amore 			t = h->tags.head;
43595c635efSGarrett D'Amore 		}
436*260e9a87SYuri Pankov 		assert(h->tblt == NULL);
437*260e9a87SYuri Pankov 		if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
438698f87a4SGarrett D'Amore 			child = (*mdocs[n->tok].pre)(meta, n, h);
43995c635efSGarrett D'Amore 		break;
44095c635efSGarrett D'Amore 	}
44195c635efSGarrett D'Amore 
442*260e9a87SYuri Pankov 	if (h->flags & HTML_KEEP && n->flags & MDOC_LINE) {
44395c635efSGarrett D'Amore 		h->flags &= ~HTML_KEEP;
44495c635efSGarrett D'Amore 		h->flags |= HTML_PREKEEP;
44595c635efSGarrett D'Amore 	}
44695c635efSGarrett D'Amore 
44795c635efSGarrett D'Amore 	if (child && n->child)
448698f87a4SGarrett D'Amore 		print_mdoc_nodelist(meta, n->child, h);
44995c635efSGarrett D'Amore 
45095c635efSGarrett D'Amore 	print_stagq(h, t);
45195c635efSGarrett D'Amore 
45295c635efSGarrett D'Amore 	switch (n->type) {
453*260e9a87SYuri Pankov 	case MDOC_ROOT:
454698f87a4SGarrett D'Amore 		mdoc_root_post(meta, n, h);
45595c635efSGarrett D'Amore 		break;
456*260e9a87SYuri Pankov 	case MDOC_EQN:
45795c635efSGarrett D'Amore 		break;
45895c635efSGarrett D'Amore 	default:
459*260e9a87SYuri Pankov 		if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED)
460*260e9a87SYuri Pankov 			break;
461698f87a4SGarrett D'Amore 		(*mdocs[n->tok].post)(meta, n, h);
462*260e9a87SYuri Pankov 		if (n->end != ENDBODY_NOT)
463*260e9a87SYuri Pankov 			n->body->flags |= MDOC_ENDED;
464*260e9a87SYuri Pankov 		if (n->end == ENDBODY_NOSPACE)
465*260e9a87SYuri Pankov 			h->flags |= HTML_NOSPACE;
46695c635efSGarrett D'Amore 		break;
46795c635efSGarrett D'Amore 	}
46895c635efSGarrett D'Amore }
46995c635efSGarrett D'Amore 
47095c635efSGarrett D'Amore static void
47195c635efSGarrett D'Amore mdoc_root_post(MDOC_ARGS)
47295c635efSGarrett D'Amore {
473*260e9a87SYuri Pankov 	struct htmlpair	 tag;
47495c635efSGarrett D'Amore 	struct tag	*t, *tt;
47595c635efSGarrett D'Amore 
476*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "foot");
477*260e9a87SYuri Pankov 	t = print_otag(h, TAG_TABLE, 1, &tag);
47895c635efSGarrett D'Amore 
47995c635efSGarrett D'Amore 	print_otag(h, TAG_TBODY, 0, NULL);
48095c635efSGarrett D'Amore 
48195c635efSGarrett D'Amore 	tt = print_otag(h, TAG_TR, 0, NULL);
48295c635efSGarrett D'Amore 
483*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "foot-date");
484*260e9a87SYuri Pankov 	print_otag(h, TAG_TD, 1, &tag);
485698f87a4SGarrett D'Amore 	print_text(h, meta->date);
48695c635efSGarrett D'Amore 	print_stagq(h, tt);
48795c635efSGarrett D'Amore 
488*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "foot-os");
489*260e9a87SYuri Pankov 	print_otag(h, TAG_TD, 1, &tag);
490698f87a4SGarrett D'Amore 	print_text(h, meta->os);
49195c635efSGarrett D'Amore 	print_tagq(h, t);
49295c635efSGarrett D'Amore }
49395c635efSGarrett D'Amore 
49495c635efSGarrett D'Amore static int
49595c635efSGarrett D'Amore mdoc_root_pre(MDOC_ARGS)
49695c635efSGarrett D'Amore {
497*260e9a87SYuri Pankov 	struct htmlpair	 tag;
49895c635efSGarrett D'Amore 	struct tag	*t, *tt;
499*260e9a87SYuri Pankov 	char		*volume, *title;
50095c635efSGarrett D'Amore 
501*260e9a87SYuri Pankov 	if (NULL == meta->arch)
502*260e9a87SYuri Pankov 		volume = mandoc_strdup(meta->vol);
503*260e9a87SYuri Pankov 	else
504*260e9a87SYuri Pankov 		mandoc_asprintf(&volume, "%s (%s)",
505*260e9a87SYuri Pankov 		    meta->vol, meta->arch);
50695c635efSGarrett D'Amore 
507*260e9a87SYuri Pankov 	if (NULL == meta->msec)
508*260e9a87SYuri Pankov 		title = mandoc_strdup(meta->title);
509*260e9a87SYuri Pankov 	else
510*260e9a87SYuri Pankov 		mandoc_asprintf(&title, "%s(%s)",
511*260e9a87SYuri Pankov 		    meta->title, meta->msec);
51295c635efSGarrett D'Amore 
513*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "head");
514*260e9a87SYuri Pankov 	t = print_otag(h, TAG_TABLE, 1, &tag);
51595c635efSGarrett D'Amore 
51695c635efSGarrett D'Amore 	print_otag(h, TAG_TBODY, 0, NULL);
51795c635efSGarrett D'Amore 
51895c635efSGarrett D'Amore 	tt = print_otag(h, TAG_TR, 0, NULL);
51995c635efSGarrett D'Amore 
520*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "head-ltitle");
521*260e9a87SYuri Pankov 	print_otag(h, TAG_TD, 1, &tag);
52295c635efSGarrett D'Amore 	print_text(h, title);
52395c635efSGarrett D'Amore 	print_stagq(h, tt);
52495c635efSGarrett D'Amore 
525*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "head-vol");
526*260e9a87SYuri Pankov 	print_otag(h, TAG_TD, 1, &tag);
527*260e9a87SYuri Pankov 	print_text(h, volume);
52895c635efSGarrett D'Amore 	print_stagq(h, tt);
52995c635efSGarrett D'Amore 
530*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "head-rtitle");
531*260e9a87SYuri Pankov 	print_otag(h, TAG_TD, 1, &tag);
53295c635efSGarrett D'Amore 	print_text(h, title);
53395c635efSGarrett D'Amore 	print_tagq(h, t);
534*260e9a87SYuri Pankov 
535*260e9a87SYuri Pankov 	free(title);
536*260e9a87SYuri Pankov 	free(volume);
53795c635efSGarrett D'Amore 	return(1);
53895c635efSGarrett D'Amore }
53995c635efSGarrett D'Amore 
54095c635efSGarrett D'Amore static int
54195c635efSGarrett D'Amore mdoc_sh_pre(MDOC_ARGS)
54295c635efSGarrett D'Amore {
54395c635efSGarrett D'Amore 	struct htmlpair	 tag;
54495c635efSGarrett D'Amore 
545*260e9a87SYuri Pankov 	switch (n->type) {
546*260e9a87SYuri Pankov 	case MDOC_BLOCK:
54795c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag, "section");
54895c635efSGarrett D'Amore 		print_otag(h, TAG_DIV, 1, &tag);
54995c635efSGarrett D'Amore 		return(1);
550*260e9a87SYuri Pankov 	case MDOC_BODY:
551*260e9a87SYuri Pankov 		if (n->sec == SEC_AUTHORS)
552*260e9a87SYuri Pankov 			h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
55395c635efSGarrett D'Amore 		return(1);
554*260e9a87SYuri Pankov 	default:
555*260e9a87SYuri Pankov 		break;
556*260e9a87SYuri Pankov 	}
55795c635efSGarrett D'Amore 
55895c635efSGarrett D'Amore 	bufinit(h);
55995c635efSGarrett D'Amore 	bufcat(h, "x");
56095c635efSGarrett D'Amore 
56195c635efSGarrett D'Amore 	for (n = n->child; n && MDOC_TEXT == n->type; ) {
56295c635efSGarrett D'Amore 		bufcat_id(h, n->string);
56395c635efSGarrett D'Amore 		if (NULL != (n = n->next))
56495c635efSGarrett D'Amore 			bufcat_id(h, " ");
56595c635efSGarrett D'Amore 	}
56695c635efSGarrett D'Amore 
56795c635efSGarrett D'Amore 	if (NULL == n) {
56895c635efSGarrett D'Amore 		PAIR_ID_INIT(&tag, h->buf);
56995c635efSGarrett D'Amore 		print_otag(h, TAG_H1, 1, &tag);
57095c635efSGarrett D'Amore 	} else
57195c635efSGarrett D'Amore 		print_otag(h, TAG_H1, 0, NULL);
57295c635efSGarrett D'Amore 
57395c635efSGarrett D'Amore 	return(1);
57495c635efSGarrett D'Amore }
57595c635efSGarrett D'Amore 
57695c635efSGarrett D'Amore static int
57795c635efSGarrett D'Amore mdoc_ss_pre(MDOC_ARGS)
57895c635efSGarrett D'Amore {
57995c635efSGarrett D'Amore 	struct htmlpair	 tag;
58095c635efSGarrett D'Amore 
58195c635efSGarrett D'Amore 	if (MDOC_BLOCK == n->type) {
58295c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag, "subsection");
58395c635efSGarrett D'Amore 		print_otag(h, TAG_DIV, 1, &tag);
58495c635efSGarrett D'Amore 		return(1);
58595c635efSGarrett D'Amore 	} else if (MDOC_BODY == n->type)
58695c635efSGarrett D'Amore 		return(1);
58795c635efSGarrett D'Amore 
58895c635efSGarrett D'Amore 	bufinit(h);
58995c635efSGarrett D'Amore 	bufcat(h, "x");
59095c635efSGarrett D'Amore 
59195c635efSGarrett D'Amore 	for (n = n->child; n && MDOC_TEXT == n->type; ) {
59295c635efSGarrett D'Amore 		bufcat_id(h, n->string);
59395c635efSGarrett D'Amore 		if (NULL != (n = n->next))
59495c635efSGarrett D'Amore 			bufcat_id(h, " ");
59595c635efSGarrett D'Amore 	}
59695c635efSGarrett D'Amore 
59795c635efSGarrett D'Amore 	if (NULL == n) {
59895c635efSGarrett D'Amore 		PAIR_ID_INIT(&tag, h->buf);
59995c635efSGarrett D'Amore 		print_otag(h, TAG_H2, 1, &tag);
60095c635efSGarrett D'Amore 	} else
60195c635efSGarrett D'Amore 		print_otag(h, TAG_H2, 0, NULL);
60295c635efSGarrett D'Amore 
60395c635efSGarrett D'Amore 	return(1);
60495c635efSGarrett D'Amore }
60595c635efSGarrett D'Amore 
60695c635efSGarrett D'Amore static int
60795c635efSGarrett D'Amore mdoc_fl_pre(MDOC_ARGS)
60895c635efSGarrett D'Amore {
60995c635efSGarrett D'Amore 	struct htmlpair	 tag;
61095c635efSGarrett D'Amore 
61195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "flag");
61295c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, &tag);
61395c635efSGarrett D'Amore 
61495c635efSGarrett D'Amore 	/* `Cm' has no leading hyphen. */
61595c635efSGarrett D'Amore 
61695c635efSGarrett D'Amore 	if (MDOC_Cm == n->tok)
61795c635efSGarrett D'Amore 		return(1);
61895c635efSGarrett D'Amore 
61995c635efSGarrett D'Amore 	print_text(h, "\\-");
62095c635efSGarrett D'Amore 
621*260e9a87SYuri Pankov 	if ( ! (n->nchild == 0 &&
622*260e9a87SYuri Pankov 	    (n->next == NULL ||
623*260e9a87SYuri Pankov 	     n->next->type == MDOC_TEXT ||
624*260e9a87SYuri Pankov 	     n->next->flags & MDOC_LINE)))
62595c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
62695c635efSGarrett D'Amore 
62795c635efSGarrett D'Amore 	return(1);
62895c635efSGarrett D'Amore }
62995c635efSGarrett D'Amore 
63095c635efSGarrett D'Amore static int
63195c635efSGarrett D'Amore mdoc_nd_pre(MDOC_ARGS)
63295c635efSGarrett D'Amore {
63395c635efSGarrett D'Amore 	struct htmlpair	 tag;
63495c635efSGarrett D'Amore 
63595c635efSGarrett D'Amore 	if (MDOC_BODY != n->type)
63695c635efSGarrett D'Amore 		return(1);
63795c635efSGarrett D'Amore 
63895c635efSGarrett D'Amore 	/* XXX: this tag in theory can contain block elements. */
63995c635efSGarrett D'Amore 
64095c635efSGarrett D'Amore 	print_text(h, "\\(em");
64195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "desc");
64295c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
64395c635efSGarrett D'Amore 	return(1);
64495c635efSGarrett D'Amore }
64595c635efSGarrett D'Amore 
64695c635efSGarrett D'Amore static int
64795c635efSGarrett D'Amore mdoc_nm_pre(MDOC_ARGS)
64895c635efSGarrett D'Amore {
64995c635efSGarrett D'Amore 	struct htmlpair	 tag;
65095c635efSGarrett D'Amore 	struct roffsu	 su;
65195c635efSGarrett D'Amore 	int		 len;
65295c635efSGarrett D'Amore 
65395c635efSGarrett D'Amore 	switch (n->type) {
654*260e9a87SYuri Pankov 	case MDOC_ELEM:
65595c635efSGarrett D'Amore 		synopsis_pre(h, n);
65695c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag, "name");
65795c635efSGarrett D'Amore 		print_otag(h, TAG_B, 1, &tag);
658698f87a4SGarrett D'Amore 		if (NULL == n->child && meta->name)
659698f87a4SGarrett D'Amore 			print_text(h, meta->name);
66095c635efSGarrett D'Amore 		return(1);
661*260e9a87SYuri Pankov 	case MDOC_HEAD:
66295c635efSGarrett D'Amore 		print_otag(h, TAG_TD, 0, NULL);
663698f87a4SGarrett D'Amore 		if (NULL == n->child && meta->name)
664698f87a4SGarrett D'Amore 			print_text(h, meta->name);
66595c635efSGarrett D'Amore 		return(1);
666*260e9a87SYuri Pankov 	case MDOC_BODY:
66795c635efSGarrett D'Amore 		print_otag(h, TAG_TD, 0, NULL);
66895c635efSGarrett D'Amore 		return(1);
66995c635efSGarrett D'Amore 	default:
67095c635efSGarrett D'Amore 		break;
67195c635efSGarrett D'Amore 	}
67295c635efSGarrett D'Amore 
67395c635efSGarrett D'Amore 	synopsis_pre(h, n);
67495c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "synopsis");
67595c635efSGarrett D'Amore 	print_otag(h, TAG_TABLE, 1, &tag);
67695c635efSGarrett D'Amore 
67795c635efSGarrett D'Amore 	for (len = 0, n = n->child; n; n = n->next)
67895c635efSGarrett D'Amore 		if (MDOC_TEXT == n->type)
67995c635efSGarrett D'Amore 			len += html_strlen(n->string);
68095c635efSGarrett D'Amore 
681698f87a4SGarrett D'Amore 	if (0 == len && meta->name)
682698f87a4SGarrett D'Amore 		len = html_strlen(meta->name);
68395c635efSGarrett D'Amore 
684*260e9a87SYuri Pankov 	SCALE_HS_INIT(&su, len);
68595c635efSGarrett D'Amore 	bufinit(h);
68695c635efSGarrett D'Amore 	bufcat_su(h, "width", &su);
68795c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag, h);
68895c635efSGarrett D'Amore 	print_otag(h, TAG_COL, 1, &tag);
68995c635efSGarrett D'Amore 	print_otag(h, TAG_COL, 0, NULL);
69095c635efSGarrett D'Amore 	print_otag(h, TAG_TBODY, 0, NULL);
69195c635efSGarrett D'Amore 	print_otag(h, TAG_TR, 0, NULL);
69295c635efSGarrett D'Amore 	return(1);
69395c635efSGarrett D'Amore }
69495c635efSGarrett D'Amore 
69595c635efSGarrett D'Amore static int
69695c635efSGarrett D'Amore mdoc_xr_pre(MDOC_ARGS)
69795c635efSGarrett D'Amore {
69895c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
69995c635efSGarrett D'Amore 
70095c635efSGarrett D'Amore 	if (NULL == n->child)
70195c635efSGarrett D'Amore 		return(0);
70295c635efSGarrett D'Amore 
70395c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "link-man");
70495c635efSGarrett D'Amore 
70595c635efSGarrett D'Amore 	if (h->base_man) {
70695c635efSGarrett D'Amore 		buffmt_man(h, n->child->string,
70795c635efSGarrett D'Amore 		    n->child->next ?
70895c635efSGarrett D'Amore 		    n->child->next->string : NULL);
70995c635efSGarrett D'Amore 		PAIR_HREF_INIT(&tag[1], h->buf);
71095c635efSGarrett D'Amore 		print_otag(h, TAG_A, 2, tag);
71195c635efSGarrett D'Amore 	} else
71295c635efSGarrett D'Amore 		print_otag(h, TAG_A, 1, tag);
71395c635efSGarrett D'Amore 
71495c635efSGarrett D'Amore 	n = n->child;
71595c635efSGarrett D'Amore 	print_text(h, n->string);
71695c635efSGarrett D'Amore 
71795c635efSGarrett D'Amore 	if (NULL == (n = n->next))
71895c635efSGarrett D'Amore 		return(0);
71995c635efSGarrett D'Amore 
72095c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
72195c635efSGarrett D'Amore 	print_text(h, "(");
72295c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
72395c635efSGarrett D'Amore 	print_text(h, n->string);
72495c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
72595c635efSGarrett D'Amore 	print_text(h, ")");
72695c635efSGarrett D'Amore 	return(0);
72795c635efSGarrett D'Amore }
72895c635efSGarrett D'Amore 
72995c635efSGarrett D'Amore static int
73095c635efSGarrett D'Amore mdoc_ns_pre(MDOC_ARGS)
73195c635efSGarrett D'Amore {
73295c635efSGarrett D'Amore 
73395c635efSGarrett D'Amore 	if ( ! (MDOC_LINE & n->flags))
73495c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
73595c635efSGarrett D'Amore 	return(1);
73695c635efSGarrett D'Amore }
73795c635efSGarrett D'Amore 
73895c635efSGarrett D'Amore static int
73995c635efSGarrett D'Amore mdoc_ar_pre(MDOC_ARGS)
74095c635efSGarrett D'Amore {
74195c635efSGarrett D'Amore 	struct htmlpair tag;
74295c635efSGarrett D'Amore 
74395c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "arg");
74495c635efSGarrett D'Amore 	print_otag(h, TAG_I, 1, &tag);
74595c635efSGarrett D'Amore 	return(1);
74695c635efSGarrett D'Amore }
74795c635efSGarrett D'Amore 
74895c635efSGarrett D'Amore static int
74995c635efSGarrett D'Amore mdoc_xx_pre(MDOC_ARGS)
75095c635efSGarrett D'Amore {
75195c635efSGarrett D'Amore 	const char	*pp;
75295c635efSGarrett D'Amore 	struct htmlpair	 tag;
75395c635efSGarrett D'Amore 	int		 flags;
75495c635efSGarrett D'Amore 
75595c635efSGarrett D'Amore 	switch (n->tok) {
756*260e9a87SYuri Pankov 	case MDOC_Bsx:
75795c635efSGarrett D'Amore 		pp = "BSD/OS";
75895c635efSGarrett D'Amore 		break;
759*260e9a87SYuri Pankov 	case MDOC_Dx:
76095c635efSGarrett D'Amore 		pp = "DragonFly";
76195c635efSGarrett D'Amore 		break;
762*260e9a87SYuri Pankov 	case MDOC_Fx:
76395c635efSGarrett D'Amore 		pp = "FreeBSD";
76495c635efSGarrett D'Amore 		break;
765*260e9a87SYuri Pankov 	case MDOC_Nx:
76695c635efSGarrett D'Amore 		pp = "NetBSD";
76795c635efSGarrett D'Amore 		break;
768*260e9a87SYuri Pankov 	case MDOC_Ox:
76995c635efSGarrett D'Amore 		pp = "OpenBSD";
77095c635efSGarrett D'Amore 		break;
771*260e9a87SYuri Pankov 	case MDOC_Ux:
77295c635efSGarrett D'Amore 		pp = "UNIX";
77395c635efSGarrett D'Amore 		break;
77495c635efSGarrett D'Amore 	default:
77595c635efSGarrett D'Amore 		return(1);
77695c635efSGarrett D'Amore 	}
77795c635efSGarrett D'Amore 
77895c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "unix");
77995c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
78095c635efSGarrett D'Amore 
78195c635efSGarrett D'Amore 	print_text(h, pp);
78295c635efSGarrett D'Amore 	if (n->child) {
78395c635efSGarrett D'Amore 		flags = h->flags;
78495c635efSGarrett D'Amore 		h->flags |= HTML_KEEP;
78595c635efSGarrett D'Amore 		print_text(h, n->child->string);
78695c635efSGarrett D'Amore 		h->flags = flags;
78795c635efSGarrett D'Amore 	}
78895c635efSGarrett D'Amore 	return(0);
78995c635efSGarrett D'Amore }
79095c635efSGarrett D'Amore 
79195c635efSGarrett D'Amore static int
79295c635efSGarrett D'Amore mdoc_bx_pre(MDOC_ARGS)
79395c635efSGarrett D'Amore {
79495c635efSGarrett D'Amore 	struct htmlpair	 tag;
79595c635efSGarrett D'Amore 
79695c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "unix");
79795c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
79895c635efSGarrett D'Amore 
79995c635efSGarrett D'Amore 	if (NULL != (n = n->child)) {
80095c635efSGarrett D'Amore 		print_text(h, n->string);
80195c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
80295c635efSGarrett D'Amore 		print_text(h, "BSD");
80395c635efSGarrett D'Amore 	} else {
80495c635efSGarrett D'Amore 		print_text(h, "BSD");
80595c635efSGarrett D'Amore 		return(0);
80695c635efSGarrett D'Amore 	}
80795c635efSGarrett D'Amore 
80895c635efSGarrett D'Amore 	if (NULL != (n = n->next)) {
80995c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
81095c635efSGarrett D'Amore 		print_text(h, "-");
81195c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
81295c635efSGarrett D'Amore 		print_text(h, n->string);
81395c635efSGarrett D'Amore 	}
81495c635efSGarrett D'Amore 
81595c635efSGarrett D'Amore 	return(0);
81695c635efSGarrett D'Amore }
81795c635efSGarrett D'Amore 
81895c635efSGarrett D'Amore static int
81995c635efSGarrett D'Amore mdoc_it_pre(MDOC_ARGS)
82095c635efSGarrett D'Amore {
82195c635efSGarrett D'Amore 	struct roffsu	 su;
82295c635efSGarrett D'Amore 	enum mdoc_list	 type;
82395c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
82495c635efSGarrett D'Amore 	const struct mdoc_node *bl;
82595c635efSGarrett D'Amore 
82695c635efSGarrett D'Amore 	bl = n->parent;
82795c635efSGarrett D'Amore 	while (bl && MDOC_Bl != bl->tok)
82895c635efSGarrett D'Amore 		bl = bl->parent;
82995c635efSGarrett D'Amore 
83095c635efSGarrett D'Amore 	assert(bl);
83195c635efSGarrett D'Amore 
83295c635efSGarrett D'Amore 	type = bl->norm->Bl.type;
83395c635efSGarrett D'Amore 
83495c635efSGarrett D'Amore 	assert(lists[type]);
83595c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], lists[type]);
83695c635efSGarrett D'Amore 
83795c635efSGarrett D'Amore 	bufinit(h);
83895c635efSGarrett D'Amore 
83995c635efSGarrett D'Amore 	if (MDOC_HEAD == n->type) {
84095c635efSGarrett D'Amore 		switch (type) {
841*260e9a87SYuri Pankov 		case LIST_bullet:
84295c635efSGarrett D'Amore 			/* FALLTHROUGH */
843*260e9a87SYuri Pankov 		case LIST_dash:
84495c635efSGarrett D'Amore 			/* FALLTHROUGH */
845*260e9a87SYuri Pankov 		case LIST_item:
84695c635efSGarrett D'Amore 			/* FALLTHROUGH */
847*260e9a87SYuri Pankov 		case LIST_hyphen:
84895c635efSGarrett D'Amore 			/* FALLTHROUGH */
849*260e9a87SYuri Pankov 		case LIST_enum:
85095c635efSGarrett D'Amore 			return(0);
851*260e9a87SYuri Pankov 		case LIST_diag:
85295c635efSGarrett D'Amore 			/* FALLTHROUGH */
853*260e9a87SYuri Pankov 		case LIST_hang:
85495c635efSGarrett D'Amore 			/* FALLTHROUGH */
855*260e9a87SYuri Pankov 		case LIST_inset:
85695c635efSGarrett D'Amore 			/* FALLTHROUGH */
857*260e9a87SYuri Pankov 		case LIST_ohang:
85895c635efSGarrett D'Amore 			/* FALLTHROUGH */
859*260e9a87SYuri Pankov 		case LIST_tag:
86095c635efSGarrett D'Amore 			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
86195c635efSGarrett D'Amore 			bufcat_su(h, "margin-top", &su);
86295c635efSGarrett D'Amore 			PAIR_STYLE_INIT(&tag[1], h);
86395c635efSGarrett D'Amore 			print_otag(h, TAG_DT, 2, tag);
86495c635efSGarrett D'Amore 			if (LIST_diag != type)
86595c635efSGarrett D'Amore 				break;
86695c635efSGarrett D'Amore 			PAIR_CLASS_INIT(&tag[0], "diag");
86795c635efSGarrett D'Amore 			print_otag(h, TAG_B, 1, tag);
86895c635efSGarrett D'Amore 			break;
869*260e9a87SYuri Pankov 		case LIST_column:
87095c635efSGarrett D'Amore 			break;
87195c635efSGarrett D'Amore 		default:
87295c635efSGarrett D'Amore 			break;
87395c635efSGarrett D'Amore 		}
87495c635efSGarrett D'Amore 	} else if (MDOC_BODY == n->type) {
87595c635efSGarrett D'Amore 		switch (type) {
876*260e9a87SYuri Pankov 		case LIST_bullet:
87795c635efSGarrett D'Amore 			/* FALLTHROUGH */
878*260e9a87SYuri Pankov 		case LIST_hyphen:
87995c635efSGarrett D'Amore 			/* FALLTHROUGH */
880*260e9a87SYuri Pankov 		case LIST_dash:
88195c635efSGarrett D'Amore 			/* FALLTHROUGH */
882*260e9a87SYuri Pankov 		case LIST_enum:
88395c635efSGarrett D'Amore 			/* FALLTHROUGH */
884*260e9a87SYuri Pankov 		case LIST_item:
88595c635efSGarrett D'Amore 			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
88695c635efSGarrett D'Amore 			bufcat_su(h, "margin-top", &su);
88795c635efSGarrett D'Amore 			PAIR_STYLE_INIT(&tag[1], h);
88895c635efSGarrett D'Amore 			print_otag(h, TAG_LI, 2, tag);
88995c635efSGarrett D'Amore 			break;
890*260e9a87SYuri Pankov 		case LIST_diag:
89195c635efSGarrett D'Amore 			/* FALLTHROUGH */
892*260e9a87SYuri Pankov 		case LIST_hang:
89395c635efSGarrett D'Amore 			/* FALLTHROUGH */
894*260e9a87SYuri Pankov 		case LIST_inset:
89595c635efSGarrett D'Amore 			/* FALLTHROUGH */
896*260e9a87SYuri Pankov 		case LIST_ohang:
89795c635efSGarrett D'Amore 			/* FALLTHROUGH */
898*260e9a87SYuri Pankov 		case LIST_tag:
89995c635efSGarrett D'Amore 			if (NULL == bl->norm->Bl.width) {
90095c635efSGarrett D'Amore 				print_otag(h, TAG_DD, 1, tag);
90195c635efSGarrett D'Amore 				break;
90295c635efSGarrett D'Amore 			}
90395c635efSGarrett D'Amore 			a2width(bl->norm->Bl.width, &su);
90495c635efSGarrett D'Amore 			bufcat_su(h, "margin-left", &su);
90595c635efSGarrett D'Amore 			PAIR_STYLE_INIT(&tag[1], h);
90695c635efSGarrett D'Amore 			print_otag(h, TAG_DD, 2, tag);
90795c635efSGarrett D'Amore 			break;
908*260e9a87SYuri Pankov 		case LIST_column:
90995c635efSGarrett D'Amore 			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
91095c635efSGarrett D'Amore 			bufcat_su(h, "margin-top", &su);
91195c635efSGarrett D'Amore 			PAIR_STYLE_INIT(&tag[1], h);
91295c635efSGarrett D'Amore 			print_otag(h, TAG_TD, 2, tag);
91395c635efSGarrett D'Amore 			break;
91495c635efSGarrett D'Amore 		default:
91595c635efSGarrett D'Amore 			break;
91695c635efSGarrett D'Amore 		}
91795c635efSGarrett D'Amore 	} else {
91895c635efSGarrett D'Amore 		switch (type) {
919*260e9a87SYuri Pankov 		case LIST_column:
92095c635efSGarrett D'Amore 			print_otag(h, TAG_TR, 1, tag);
92195c635efSGarrett D'Amore 			break;
92295c635efSGarrett D'Amore 		default:
92395c635efSGarrett D'Amore 			break;
92495c635efSGarrett D'Amore 		}
92595c635efSGarrett D'Amore 	}
92695c635efSGarrett D'Amore 
92795c635efSGarrett D'Amore 	return(1);
92895c635efSGarrett D'Amore }
92995c635efSGarrett D'Amore 
93095c635efSGarrett D'Amore static int
93195c635efSGarrett D'Amore mdoc_bl_pre(MDOC_ARGS)
93295c635efSGarrett D'Amore {
93395c635efSGarrett D'Amore 	int		 i;
93495c635efSGarrett D'Amore 	struct htmlpair	 tag[3];
93595c635efSGarrett D'Amore 	struct roffsu	 su;
93695c635efSGarrett D'Amore 	char		 buf[BUFSIZ];
93795c635efSGarrett D'Amore 
93895c635efSGarrett D'Amore 	if (MDOC_BODY == n->type) {
93995c635efSGarrett D'Amore 		if (LIST_column == n->norm->Bl.type)
94095c635efSGarrett D'Amore 			print_otag(h, TAG_TBODY, 0, NULL);
94195c635efSGarrett D'Amore 		return(1);
94295c635efSGarrett D'Amore 	}
94395c635efSGarrett D'Amore 
94495c635efSGarrett D'Amore 	if (MDOC_HEAD == n->type) {
94595c635efSGarrett D'Amore 		if (LIST_column != n->norm->Bl.type)
94695c635efSGarrett D'Amore 			return(0);
94795c635efSGarrett D'Amore 
94895c635efSGarrett D'Amore 		/*
94995c635efSGarrett D'Amore 		 * For each column, print out the <COL> tag with our
95095c635efSGarrett D'Amore 		 * suggested width.  The last column gets min-width, as
95195c635efSGarrett D'Amore 		 * in terminal mode it auto-sizes to the width of the
95295c635efSGarrett D'Amore 		 * screen and we want to preserve that behaviour.
95395c635efSGarrett D'Amore 		 */
95495c635efSGarrett D'Amore 
95595c635efSGarrett D'Amore 		for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
956698f87a4SGarrett D'Amore 			bufinit(h);
95795c635efSGarrett D'Amore 			a2width(n->norm->Bl.cols[i], &su);
95895c635efSGarrett D'Amore 			if (i < (int)n->norm->Bl.ncols - 1)
95995c635efSGarrett D'Amore 				bufcat_su(h, "width", &su);
96095c635efSGarrett D'Amore 			else
96195c635efSGarrett D'Amore 				bufcat_su(h, "min-width", &su);
96295c635efSGarrett D'Amore 			PAIR_STYLE_INIT(&tag[0], h);
96395c635efSGarrett D'Amore 			print_otag(h, TAG_COL, 1, tag);
96495c635efSGarrett D'Amore 		}
96595c635efSGarrett D'Amore 
96695c635efSGarrett D'Amore 		return(0);
96795c635efSGarrett D'Amore 	}
96895c635efSGarrett D'Amore 
96995c635efSGarrett D'Amore 	SCALE_VS_INIT(&su, 0);
970698f87a4SGarrett D'Amore 	bufinit(h);
97195c635efSGarrett D'Amore 	bufcat_su(h, "margin-top", &su);
97295c635efSGarrett D'Amore 	bufcat_su(h, "margin-bottom", &su);
97395c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag[0], h);
97495c635efSGarrett D'Amore 
97595c635efSGarrett D'Amore 	assert(lists[n->norm->Bl.type]);
976*260e9a87SYuri Pankov 	(void)strlcpy(buf, "list ", BUFSIZ);
977*260e9a87SYuri Pankov 	(void)strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
97895c635efSGarrett D'Amore 	PAIR_INIT(&tag[1], ATTR_CLASS, buf);
97995c635efSGarrett D'Amore 
98095c635efSGarrett D'Amore 	/* Set the block's left-hand margin. */
98195c635efSGarrett D'Amore 
98295c635efSGarrett D'Amore 	if (n->norm->Bl.offs) {
983*260e9a87SYuri Pankov 		a2width(n->norm->Bl.offs, &su);
98495c635efSGarrett D'Amore 		bufcat_su(h, "margin-left", &su);
98595c635efSGarrett D'Amore 	}
98695c635efSGarrett D'Amore 
98795c635efSGarrett D'Amore 	switch (n->norm->Bl.type) {
988*260e9a87SYuri Pankov 	case LIST_bullet:
98995c635efSGarrett D'Amore 		/* FALLTHROUGH */
990*260e9a87SYuri Pankov 	case LIST_dash:
99195c635efSGarrett D'Amore 		/* FALLTHROUGH */
992*260e9a87SYuri Pankov 	case LIST_hyphen:
99395c635efSGarrett D'Amore 		/* FALLTHROUGH */
994*260e9a87SYuri Pankov 	case LIST_item:
99595c635efSGarrett D'Amore 		print_otag(h, TAG_UL, 2, tag);
99695c635efSGarrett D'Amore 		break;
997*260e9a87SYuri Pankov 	case LIST_enum:
99895c635efSGarrett D'Amore 		print_otag(h, TAG_OL, 2, tag);
99995c635efSGarrett D'Amore 		break;
1000*260e9a87SYuri Pankov 	case LIST_diag:
100195c635efSGarrett D'Amore 		/* FALLTHROUGH */
1002*260e9a87SYuri Pankov 	case LIST_hang:
100395c635efSGarrett D'Amore 		/* FALLTHROUGH */
1004*260e9a87SYuri Pankov 	case LIST_inset:
100595c635efSGarrett D'Amore 		/* FALLTHROUGH */
1006*260e9a87SYuri Pankov 	case LIST_ohang:
100795c635efSGarrett D'Amore 		/* FALLTHROUGH */
1008*260e9a87SYuri Pankov 	case LIST_tag:
100995c635efSGarrett D'Amore 		print_otag(h, TAG_DL, 2, tag);
101095c635efSGarrett D'Amore 		break;
1011*260e9a87SYuri Pankov 	case LIST_column:
101295c635efSGarrett D'Amore 		print_otag(h, TAG_TABLE, 2, tag);
101395c635efSGarrett D'Amore 		break;
101495c635efSGarrett D'Amore 	default:
101595c635efSGarrett D'Amore 		abort();
101695c635efSGarrett D'Amore 		/* NOTREACHED */
101795c635efSGarrett D'Amore 	}
101895c635efSGarrett D'Amore 
101995c635efSGarrett D'Amore 	return(1);
102095c635efSGarrett D'Amore }
102195c635efSGarrett D'Amore 
102295c635efSGarrett D'Amore static int
102395c635efSGarrett D'Amore mdoc_ex_pre(MDOC_ARGS)
102495c635efSGarrett D'Amore {
102595c635efSGarrett D'Amore 	struct tag	*t;
102695c635efSGarrett D'Amore 	struct htmlpair	 tag;
102795c635efSGarrett D'Amore 	int		 nchild;
102895c635efSGarrett D'Amore 
102995c635efSGarrett D'Amore 	if (n->prev)
103095c635efSGarrett D'Amore 		print_otag(h, TAG_BR, 0, NULL);
103195c635efSGarrett D'Amore 
103295c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "utility");
103395c635efSGarrett D'Amore 
103495c635efSGarrett D'Amore 	print_text(h, "The");
103595c635efSGarrett D'Amore 
103695c635efSGarrett D'Amore 	nchild = n->nchild;
103795c635efSGarrett D'Amore 	for (n = n->child; n; n = n->next) {
103895c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
103995c635efSGarrett D'Amore 
104095c635efSGarrett D'Amore 		t = print_otag(h, TAG_B, 1, &tag);
104195c635efSGarrett D'Amore 		print_text(h, n->string);
104295c635efSGarrett D'Amore 		print_tagq(h, t);
104395c635efSGarrett D'Amore 
104495c635efSGarrett D'Amore 		if (nchild > 2 && n->next) {
104595c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
104695c635efSGarrett D'Amore 			print_text(h, ",");
104795c635efSGarrett D'Amore 		}
104895c635efSGarrett D'Amore 
104995c635efSGarrett D'Amore 		if (n->next && NULL == n->next->next)
105095c635efSGarrett D'Amore 			print_text(h, "and");
105195c635efSGarrett D'Amore 	}
105295c635efSGarrett D'Amore 
105395c635efSGarrett D'Amore 	if (nchild > 1)
1054*260e9a87SYuri Pankov 		print_text(h, "utilities exit\\~0");
105595c635efSGarrett D'Amore 	else
1056*260e9a87SYuri Pankov 		print_text(h, "utility exits\\~0");
105795c635efSGarrett D'Amore 
1058*260e9a87SYuri Pankov 	print_text(h, "on success, and\\~>0 if an error occurs.");
105995c635efSGarrett D'Amore 	return(0);
106095c635efSGarrett D'Amore }
106195c635efSGarrett D'Amore 
106295c635efSGarrett D'Amore static int
106395c635efSGarrett D'Amore mdoc_em_pre(MDOC_ARGS)
106495c635efSGarrett D'Amore {
106595c635efSGarrett D'Amore 	struct htmlpair	tag;
106695c635efSGarrett D'Amore 
106795c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "emph");
106895c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
106995c635efSGarrett D'Amore 	return(1);
107095c635efSGarrett D'Amore }
107195c635efSGarrett D'Amore 
107295c635efSGarrett D'Amore static int
107395c635efSGarrett D'Amore mdoc_d1_pre(MDOC_ARGS)
107495c635efSGarrett D'Amore {
107595c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
107695c635efSGarrett D'Amore 	struct roffsu	 su;
107795c635efSGarrett D'Amore 
107895c635efSGarrett D'Amore 	if (MDOC_BLOCK != n->type)
107995c635efSGarrett D'Amore 		return(1);
108095c635efSGarrett D'Amore 
108195c635efSGarrett D'Amore 	SCALE_VS_INIT(&su, 0);
108295c635efSGarrett D'Amore 	bufinit(h);
108395c635efSGarrett D'Amore 	bufcat_su(h, "margin-top", &su);
108495c635efSGarrett D'Amore 	bufcat_su(h, "margin-bottom", &su);
108595c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag[0], h);
108695c635efSGarrett D'Amore 	print_otag(h, TAG_BLOCKQUOTE, 1, tag);
108795c635efSGarrett D'Amore 
108895c635efSGarrett D'Amore 	/* BLOCKQUOTE needs a block body. */
108995c635efSGarrett D'Amore 
109095c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "display");
109195c635efSGarrett D'Amore 	print_otag(h, TAG_DIV, 1, tag);
109295c635efSGarrett D'Amore 
109395c635efSGarrett D'Amore 	if (MDOC_Dl == n->tok) {
109495c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "lit");
109595c635efSGarrett D'Amore 		print_otag(h, TAG_CODE, 1, tag);
109695c635efSGarrett D'Amore 	}
109795c635efSGarrett D'Amore 
109895c635efSGarrett D'Amore 	return(1);
109995c635efSGarrett D'Amore }
110095c635efSGarrett D'Amore 
110195c635efSGarrett D'Amore static int
110295c635efSGarrett D'Amore mdoc_sx_pre(MDOC_ARGS)
110395c635efSGarrett D'Amore {
110495c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
110595c635efSGarrett D'Amore 
110695c635efSGarrett D'Amore 	bufinit(h);
110795c635efSGarrett D'Amore 	bufcat(h, "#x");
110895c635efSGarrett D'Amore 
110995c635efSGarrett D'Amore 	for (n = n->child; n; ) {
111095c635efSGarrett D'Amore 		bufcat_id(h, n->string);
111195c635efSGarrett D'Amore 		if (NULL != (n = n->next))
111295c635efSGarrett D'Amore 			bufcat_id(h, " ");
111395c635efSGarrett D'Amore 	}
111495c635efSGarrett D'Amore 
111595c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "link-sec");
111695c635efSGarrett D'Amore 	PAIR_HREF_INIT(&tag[1], h->buf);
111795c635efSGarrett D'Amore 
111895c635efSGarrett D'Amore 	print_otag(h, TAG_I, 1, tag);
111995c635efSGarrett D'Amore 	print_otag(h, TAG_A, 2, tag);
112095c635efSGarrett D'Amore 	return(1);
112195c635efSGarrett D'Amore }
112295c635efSGarrett D'Amore 
112395c635efSGarrett D'Amore static int
112495c635efSGarrett D'Amore mdoc_bd_pre(MDOC_ARGS)
112595c635efSGarrett D'Amore {
112695c635efSGarrett D'Amore 	struct htmlpair		 tag[2];
112795c635efSGarrett D'Amore 	int			 comp, sv;
1128*260e9a87SYuri Pankov 	struct mdoc_node	*nn;
112995c635efSGarrett D'Amore 	struct roffsu		 su;
113095c635efSGarrett D'Amore 
113195c635efSGarrett D'Amore 	if (MDOC_HEAD == n->type)
113295c635efSGarrett D'Amore 		return(0);
113395c635efSGarrett D'Amore 
113495c635efSGarrett D'Amore 	if (MDOC_BLOCK == n->type) {
113595c635efSGarrett D'Amore 		comp = n->norm->Bd.comp;
113695c635efSGarrett D'Amore 		for (nn = n; nn && ! comp; nn = nn->parent) {
113795c635efSGarrett D'Amore 			if (MDOC_BLOCK != nn->type)
113895c635efSGarrett D'Amore 				continue;
113995c635efSGarrett D'Amore 			if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
114095c635efSGarrett D'Amore 				comp = 1;
114195c635efSGarrett D'Amore 			if (nn->prev)
114295c635efSGarrett D'Amore 				break;
114395c635efSGarrett D'Amore 		}
114495c635efSGarrett D'Amore 		if ( ! comp)
1145*260e9a87SYuri Pankov 			print_paragraph(h);
114695c635efSGarrett D'Amore 		return(1);
114795c635efSGarrett D'Amore 	}
114895c635efSGarrett D'Amore 
1149*260e9a87SYuri Pankov 	/* Handle the -offset argument. */
1150*260e9a87SYuri Pankov 
1151*260e9a87SYuri Pankov 	if (n->norm->Bd.offs == NULL ||
1152*260e9a87SYuri Pankov 	    ! strcmp(n->norm->Bd.offs, "left"))
115395c635efSGarrett D'Amore 		SCALE_HS_INIT(&su, 0);
1154*260e9a87SYuri Pankov 	else if ( ! strcmp(n->norm->Bd.offs, "indent"))
1155*260e9a87SYuri Pankov 		SCALE_HS_INIT(&su, INDENT);
1156*260e9a87SYuri Pankov 	else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
1157*260e9a87SYuri Pankov 		SCALE_HS_INIT(&su, INDENT * 2);
1158*260e9a87SYuri Pankov 	else
1159*260e9a87SYuri Pankov 		a2width(n->norm->Bd.offs, &su);
116095c635efSGarrett D'Amore 
116195c635efSGarrett D'Amore 	bufinit(h);
116295c635efSGarrett D'Amore 	bufcat_su(h, "margin-left", &su);
116395c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag[0], h);
116495c635efSGarrett D'Amore 
116595c635efSGarrett D'Amore 	if (DISP_unfilled != n->norm->Bd.type &&
116695c635efSGarrett D'Amore 	    DISP_literal != n->norm->Bd.type) {
116795c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[1], "display");
116895c635efSGarrett D'Amore 		print_otag(h, TAG_DIV, 2, tag);
116995c635efSGarrett D'Amore 		return(1);
117095c635efSGarrett D'Amore 	}
117195c635efSGarrett D'Amore 
117295c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[1], "lit display");
117395c635efSGarrett D'Amore 	print_otag(h, TAG_PRE, 2, tag);
117495c635efSGarrett D'Amore 
117595c635efSGarrett D'Amore 	/* This can be recursive: save & set our literal state. */
117695c635efSGarrett D'Amore 
117795c635efSGarrett D'Amore 	sv = h->flags & HTML_LITERAL;
117895c635efSGarrett D'Amore 	h->flags |= HTML_LITERAL;
117995c635efSGarrett D'Amore 
118095c635efSGarrett D'Amore 	for (nn = n->child; nn; nn = nn->next) {
1181698f87a4SGarrett D'Amore 		print_mdoc_node(meta, nn, h);
118295c635efSGarrett D'Amore 		/*
118395c635efSGarrett D'Amore 		 * If the printed node flushes its own line, then we
118495c635efSGarrett D'Amore 		 * needn't do it here as well.  This is hacky, but the
118595c635efSGarrett D'Amore 		 * notion of selective eoln whitespace is pretty dumb
118695c635efSGarrett D'Amore 		 * anyway, so don't sweat it.
118795c635efSGarrett D'Amore 		 */
118895c635efSGarrett D'Amore 		switch (nn->tok) {
1189*260e9a87SYuri Pankov 		case MDOC_Sm:
119095c635efSGarrett D'Amore 			/* FALLTHROUGH */
1191*260e9a87SYuri Pankov 		case MDOC_br:
119295c635efSGarrett D'Amore 			/* FALLTHROUGH */
1193*260e9a87SYuri Pankov 		case MDOC_sp:
119495c635efSGarrett D'Amore 			/* FALLTHROUGH */
1195*260e9a87SYuri Pankov 		case MDOC_Bl:
119695c635efSGarrett D'Amore 			/* FALLTHROUGH */
1197*260e9a87SYuri Pankov 		case MDOC_D1:
119895c635efSGarrett D'Amore 			/* FALLTHROUGH */
1199*260e9a87SYuri Pankov 		case MDOC_Dl:
120095c635efSGarrett D'Amore 			/* FALLTHROUGH */
1201*260e9a87SYuri Pankov 		case MDOC_Lp:
120295c635efSGarrett D'Amore 			/* FALLTHROUGH */
1203*260e9a87SYuri Pankov 		case MDOC_Pp:
120495c635efSGarrett D'Amore 			continue;
120595c635efSGarrett D'Amore 		default:
120695c635efSGarrett D'Amore 			break;
120795c635efSGarrett D'Amore 		}
1208*260e9a87SYuri Pankov 		if (h->flags & HTML_NONEWLINE ||
1209*260e9a87SYuri Pankov 		    (nn->next && ! (nn->next->flags & MDOC_LINE)))
121095c635efSGarrett D'Amore 			continue;
121195c635efSGarrett D'Amore 		else if (nn->next)
121295c635efSGarrett D'Amore 			print_text(h, "\n");
121395c635efSGarrett D'Amore 
121495c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
121595c635efSGarrett D'Amore 	}
121695c635efSGarrett D'Amore 
121795c635efSGarrett D'Amore 	if (0 == sv)
121895c635efSGarrett D'Amore 		h->flags &= ~HTML_LITERAL;
121995c635efSGarrett D'Amore 
122095c635efSGarrett D'Amore 	return(0);
122195c635efSGarrett D'Amore }
122295c635efSGarrett D'Amore 
122395c635efSGarrett D'Amore static int
122495c635efSGarrett D'Amore mdoc_pa_pre(MDOC_ARGS)
122595c635efSGarrett D'Amore {
122695c635efSGarrett D'Amore 	struct htmlpair	tag;
122795c635efSGarrett D'Amore 
122895c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "file");
122995c635efSGarrett D'Amore 	print_otag(h, TAG_I, 1, &tag);
123095c635efSGarrett D'Amore 	return(1);
123195c635efSGarrett D'Amore }
123295c635efSGarrett D'Amore 
123395c635efSGarrett D'Amore static int
123495c635efSGarrett D'Amore mdoc_ad_pre(MDOC_ARGS)
123595c635efSGarrett D'Amore {
123695c635efSGarrett D'Amore 	struct htmlpair	tag;
123795c635efSGarrett D'Amore 
123895c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "addr");
123995c635efSGarrett D'Amore 	print_otag(h, TAG_I, 1, &tag);
124095c635efSGarrett D'Amore 	return(1);
124195c635efSGarrett D'Amore }
124295c635efSGarrett D'Amore 
124395c635efSGarrett D'Amore static int
124495c635efSGarrett D'Amore mdoc_an_pre(MDOC_ARGS)
124595c635efSGarrett D'Amore {
124695c635efSGarrett D'Amore 	struct htmlpair	tag;
124795c635efSGarrett D'Amore 
1248*260e9a87SYuri Pankov 	if (n->norm->An.auth == AUTH_split) {
1249*260e9a87SYuri Pankov 		h->flags &= ~HTML_NOSPLIT;
1250*260e9a87SYuri Pankov 		h->flags |= HTML_SPLIT;
1251*260e9a87SYuri Pankov 		return(0);
1252*260e9a87SYuri Pankov 	}
1253*260e9a87SYuri Pankov 	if (n->norm->An.auth == AUTH_nosplit) {
1254*260e9a87SYuri Pankov 		h->flags &= ~HTML_SPLIT;
1255*260e9a87SYuri Pankov 		h->flags |= HTML_NOSPLIT;
1256*260e9a87SYuri Pankov 		return(0);
1257*260e9a87SYuri Pankov 	}
1258*260e9a87SYuri Pankov 
1259*260e9a87SYuri Pankov 	if (h->flags & HTML_SPLIT)
1260*260e9a87SYuri Pankov 		print_otag(h, TAG_BR, 0, NULL);
1261*260e9a87SYuri Pankov 
1262*260e9a87SYuri Pankov 	if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
1263*260e9a87SYuri Pankov 		h->flags |= HTML_SPLIT;
126495c635efSGarrett D'Amore 
126595c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "author");
126695c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
126795c635efSGarrett D'Amore 	return(1);
126895c635efSGarrett D'Amore }
126995c635efSGarrett D'Amore 
127095c635efSGarrett D'Amore static int
127195c635efSGarrett D'Amore mdoc_cd_pre(MDOC_ARGS)
127295c635efSGarrett D'Amore {
127395c635efSGarrett D'Amore 	struct htmlpair	tag;
127495c635efSGarrett D'Amore 
127595c635efSGarrett D'Amore 	synopsis_pre(h, n);
127695c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "config");
127795c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, &tag);
127895c635efSGarrett D'Amore 	return(1);
127995c635efSGarrett D'Amore }
128095c635efSGarrett D'Amore 
128195c635efSGarrett D'Amore static int
128295c635efSGarrett D'Amore mdoc_dv_pre(MDOC_ARGS)
128395c635efSGarrett D'Amore {
128495c635efSGarrett D'Amore 	struct htmlpair	tag;
128595c635efSGarrett D'Amore 
128695c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "define");
128795c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
128895c635efSGarrett D'Amore 	return(1);
128995c635efSGarrett D'Amore }
129095c635efSGarrett D'Amore 
129195c635efSGarrett D'Amore static int
129295c635efSGarrett D'Amore mdoc_ev_pre(MDOC_ARGS)
129395c635efSGarrett D'Amore {
129495c635efSGarrett D'Amore 	struct htmlpair	tag;
129595c635efSGarrett D'Amore 
129695c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "env");
129795c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
129895c635efSGarrett D'Amore 	return(1);
129995c635efSGarrett D'Amore }
130095c635efSGarrett D'Amore 
130195c635efSGarrett D'Amore static int
130295c635efSGarrett D'Amore mdoc_er_pre(MDOC_ARGS)
130395c635efSGarrett D'Amore {
130495c635efSGarrett D'Amore 	struct htmlpair	tag;
130595c635efSGarrett D'Amore 
130695c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "errno");
130795c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
130895c635efSGarrett D'Amore 	return(1);
130995c635efSGarrett D'Amore }
131095c635efSGarrett D'Amore 
131195c635efSGarrett D'Amore static int
131295c635efSGarrett D'Amore mdoc_fa_pre(MDOC_ARGS)
131395c635efSGarrett D'Amore {
131495c635efSGarrett D'Amore 	const struct mdoc_node	*nn;
131595c635efSGarrett D'Amore 	struct htmlpair		 tag;
131695c635efSGarrett D'Amore 	struct tag		*t;
131795c635efSGarrett D'Amore 
131895c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "farg");
131995c635efSGarrett D'Amore 	if (n->parent->tok != MDOC_Fo) {
132095c635efSGarrett D'Amore 		print_otag(h, TAG_I, 1, &tag);
132195c635efSGarrett D'Amore 		return(1);
132295c635efSGarrett D'Amore 	}
132395c635efSGarrett D'Amore 
132495c635efSGarrett D'Amore 	for (nn = n->child; nn; nn = nn->next) {
132595c635efSGarrett D'Amore 		t = print_otag(h, TAG_I, 1, &tag);
132695c635efSGarrett D'Amore 		print_text(h, nn->string);
132795c635efSGarrett D'Amore 		print_tagq(h, t);
132895c635efSGarrett D'Amore 		if (nn->next) {
132995c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
133095c635efSGarrett D'Amore 			print_text(h, ",");
133195c635efSGarrett D'Amore 		}
133295c635efSGarrett D'Amore 	}
133395c635efSGarrett D'Amore 
133495c635efSGarrett D'Amore 	if (n->child && n->next && n->next->tok == MDOC_Fa) {
133595c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
133695c635efSGarrett D'Amore 		print_text(h, ",");
133795c635efSGarrett D'Amore 	}
133895c635efSGarrett D'Amore 
133995c635efSGarrett D'Amore 	return(0);
134095c635efSGarrett D'Amore }
134195c635efSGarrett D'Amore 
134295c635efSGarrett D'Amore static int
134395c635efSGarrett D'Amore mdoc_fd_pre(MDOC_ARGS)
134495c635efSGarrett D'Amore {
134595c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
134695c635efSGarrett D'Amore 	char		 buf[BUFSIZ];
134795c635efSGarrett D'Amore 	size_t		 sz;
134895c635efSGarrett D'Amore 	int		 i;
134995c635efSGarrett D'Amore 	struct tag	*t;
135095c635efSGarrett D'Amore 
135195c635efSGarrett D'Amore 	synopsis_pre(h, n);
135295c635efSGarrett D'Amore 
135395c635efSGarrett D'Amore 	if (NULL == (n = n->child))
135495c635efSGarrett D'Amore 		return(0);
135595c635efSGarrett D'Amore 
135695c635efSGarrett D'Amore 	assert(MDOC_TEXT == n->type);
135795c635efSGarrett D'Amore 
135895c635efSGarrett D'Amore 	if (strcmp(n->string, "#include")) {
135995c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "macro");
136095c635efSGarrett D'Amore 		print_otag(h, TAG_B, 1, tag);
136195c635efSGarrett D'Amore 		return(1);
136295c635efSGarrett D'Amore 	}
136395c635efSGarrett D'Amore 
136495c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "includes");
136595c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, tag);
136695c635efSGarrett D'Amore 	print_text(h, n->string);
136795c635efSGarrett D'Amore 
136895c635efSGarrett D'Amore 	if (NULL != (n = n->next)) {
136995c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
1370*260e9a87SYuri Pankov 
1371*260e9a87SYuri Pankov 		/*
1372*260e9a87SYuri Pankov 		 * XXX This is broken and not easy to fix.
1373*260e9a87SYuri Pankov 		 * When using -Oincludes, truncation may occur.
1374*260e9a87SYuri Pankov 		 * Dynamic allocation wouldn't help because
1375*260e9a87SYuri Pankov 		 * passing long strings to buffmt_includes()
1376*260e9a87SYuri Pankov 		 * does not work either.
1377*260e9a87SYuri Pankov 		 */
1378*260e9a87SYuri Pankov 
137995c635efSGarrett D'Amore 		strlcpy(buf, '<' == *n->string || '"' == *n->string ?
138095c635efSGarrett D'Amore 		    n->string + 1 : n->string, BUFSIZ);
138195c635efSGarrett D'Amore 
138295c635efSGarrett D'Amore 		sz = strlen(buf);
138395c635efSGarrett D'Amore 		if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1]))
138495c635efSGarrett D'Amore 			buf[sz - 1] = '\0';
138595c635efSGarrett D'Amore 
138695c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "link-includes");
138795c635efSGarrett D'Amore 
138895c635efSGarrett D'Amore 		i = 1;
138995c635efSGarrett D'Amore 		if (h->base_includes) {
139095c635efSGarrett D'Amore 			buffmt_includes(h, buf);
139195c635efSGarrett D'Amore 			PAIR_HREF_INIT(&tag[i], h->buf);
139295c635efSGarrett D'Amore 			i++;
139395c635efSGarrett D'Amore 		}
139495c635efSGarrett D'Amore 
139595c635efSGarrett D'Amore 		t = print_otag(h, TAG_A, i, tag);
139695c635efSGarrett D'Amore 		print_text(h, n->string);
139795c635efSGarrett D'Amore 		print_tagq(h, t);
139895c635efSGarrett D'Amore 
139995c635efSGarrett D'Amore 		n = n->next;
140095c635efSGarrett D'Amore 	}
140195c635efSGarrett D'Amore 
140295c635efSGarrett D'Amore 	for ( ; n; n = n->next) {
140395c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
140495c635efSGarrett D'Amore 		print_text(h, n->string);
140595c635efSGarrett D'Amore 	}
140695c635efSGarrett D'Amore 
140795c635efSGarrett D'Amore 	return(0);
140895c635efSGarrett D'Amore }
140995c635efSGarrett D'Amore 
141095c635efSGarrett D'Amore static int
141195c635efSGarrett D'Amore mdoc_vt_pre(MDOC_ARGS)
141295c635efSGarrett D'Amore {
141395c635efSGarrett D'Amore 	struct htmlpair	 tag;
141495c635efSGarrett D'Amore 
141595c635efSGarrett D'Amore 	if (MDOC_BLOCK == n->type) {
141695c635efSGarrett D'Amore 		synopsis_pre(h, n);
141795c635efSGarrett D'Amore 		return(1);
141895c635efSGarrett D'Amore 	} else if (MDOC_ELEM == n->type) {
141995c635efSGarrett D'Amore 		synopsis_pre(h, n);
142095c635efSGarrett D'Amore 	} else if (MDOC_HEAD == n->type)
142195c635efSGarrett D'Amore 		return(0);
142295c635efSGarrett D'Amore 
142395c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "type");
142495c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
142595c635efSGarrett D'Amore 	return(1);
142695c635efSGarrett D'Amore }
142795c635efSGarrett D'Amore 
142895c635efSGarrett D'Amore static int
142995c635efSGarrett D'Amore mdoc_ft_pre(MDOC_ARGS)
143095c635efSGarrett D'Amore {
143195c635efSGarrett D'Amore 	struct htmlpair	 tag;
143295c635efSGarrett D'Amore 
143395c635efSGarrett D'Amore 	synopsis_pre(h, n);
143495c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "ftype");
143595c635efSGarrett D'Amore 	print_otag(h, TAG_I, 1, &tag);
143695c635efSGarrett D'Amore 	return(1);
143795c635efSGarrett D'Amore }
143895c635efSGarrett D'Amore 
143995c635efSGarrett D'Amore static int
144095c635efSGarrett D'Amore mdoc_fn_pre(MDOC_ARGS)
144195c635efSGarrett D'Amore {
144295c635efSGarrett D'Amore 	struct tag	*t;
144395c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
144495c635efSGarrett D'Amore 	char		 nbuf[BUFSIZ];
144595c635efSGarrett D'Amore 	const char	*sp, *ep;
144695c635efSGarrett D'Amore 	int		 sz, i, pretty;
144795c635efSGarrett D'Amore 
144895c635efSGarrett D'Amore 	pretty = MDOC_SYNPRETTY & n->flags;
144995c635efSGarrett D'Amore 	synopsis_pre(h, n);
145095c635efSGarrett D'Amore 
145195c635efSGarrett D'Amore 	/* Split apart into type and name. */
145295c635efSGarrett D'Amore 	assert(n->child->string);
145395c635efSGarrett D'Amore 	sp = n->child->string;
145495c635efSGarrett D'Amore 
145595c635efSGarrett D'Amore 	ep = strchr(sp, ' ');
145695c635efSGarrett D'Amore 	if (NULL != ep) {
145795c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ftype");
145895c635efSGarrett D'Amore 		t = print_otag(h, TAG_I, 1, tag);
145995c635efSGarrett D'Amore 
146095c635efSGarrett D'Amore 		while (ep) {
146195c635efSGarrett D'Amore 			sz = MIN((int)(ep - sp), BUFSIZ - 1);
146295c635efSGarrett D'Amore 			(void)memcpy(nbuf, sp, (size_t)sz);
146395c635efSGarrett D'Amore 			nbuf[sz] = '\0';
146495c635efSGarrett D'Amore 			print_text(h, nbuf);
146595c635efSGarrett D'Amore 			sp = ++ep;
146695c635efSGarrett D'Amore 			ep = strchr(sp, ' ');
146795c635efSGarrett D'Amore 		}
146895c635efSGarrett D'Amore 		print_tagq(h, t);
146995c635efSGarrett D'Amore 	}
147095c635efSGarrett D'Amore 
147195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "fname");
147295c635efSGarrett D'Amore 
147395c635efSGarrett D'Amore 	/*
147495c635efSGarrett D'Amore 	 * FIXME: only refer to IDs that we know exist.
147595c635efSGarrett D'Amore 	 */
147695c635efSGarrett D'Amore 
147795c635efSGarrett D'Amore #if 0
147895c635efSGarrett D'Amore 	if (MDOC_SYNPRETTY & n->flags) {
147995c635efSGarrett D'Amore 		nbuf[0] = '\0';
148095c635efSGarrett D'Amore 		html_idcat(nbuf, sp, BUFSIZ);
148195c635efSGarrett D'Amore 		PAIR_ID_INIT(&tag[1], nbuf);
148295c635efSGarrett D'Amore 	} else {
148395c635efSGarrett D'Amore 		strlcpy(nbuf, "#", BUFSIZ);
148495c635efSGarrett D'Amore 		html_idcat(nbuf, sp, BUFSIZ);
148595c635efSGarrett D'Amore 		PAIR_HREF_INIT(&tag[1], nbuf);
148695c635efSGarrett D'Amore 	}
148795c635efSGarrett D'Amore #endif
148895c635efSGarrett D'Amore 
148995c635efSGarrett D'Amore 	t = print_otag(h, TAG_B, 1, tag);
149095c635efSGarrett D'Amore 
1491*260e9a87SYuri Pankov 	if (sp)
1492*260e9a87SYuri Pankov 		print_text(h, sp);
149395c635efSGarrett D'Amore 
149495c635efSGarrett D'Amore 	print_tagq(h, t);
149595c635efSGarrett D'Amore 
149695c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
149795c635efSGarrett D'Amore 	print_text(h, "(");
149895c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
149995c635efSGarrett D'Amore 
150095c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "farg");
150195c635efSGarrett D'Amore 	bufinit(h);
150295c635efSGarrett D'Amore 	bufcat_style(h, "white-space", "nowrap");
150395c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag[1], h);
150495c635efSGarrett D'Amore 
150595c635efSGarrett D'Amore 	for (n = n->child->next; n; n = n->next) {
150695c635efSGarrett D'Amore 		i = 1;
150795c635efSGarrett D'Amore 		if (MDOC_SYNPRETTY & n->flags)
150895c635efSGarrett D'Amore 			i = 2;
150995c635efSGarrett D'Amore 		t = print_otag(h, TAG_I, i, tag);
151095c635efSGarrett D'Amore 		print_text(h, n->string);
151195c635efSGarrett D'Amore 		print_tagq(h, t);
151295c635efSGarrett D'Amore 		if (n->next) {
151395c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
151495c635efSGarrett D'Amore 			print_text(h, ",");
151595c635efSGarrett D'Amore 		}
151695c635efSGarrett D'Amore 	}
151795c635efSGarrett D'Amore 
151895c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
151995c635efSGarrett D'Amore 	print_text(h, ")");
152095c635efSGarrett D'Amore 
152195c635efSGarrett D'Amore 	if (pretty) {
152295c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
152395c635efSGarrett D'Amore 		print_text(h, ";");
152495c635efSGarrett D'Amore 	}
152595c635efSGarrett D'Amore 
152695c635efSGarrett D'Amore 	return(0);
152795c635efSGarrett D'Amore }
152895c635efSGarrett D'Amore 
152995c635efSGarrett D'Amore static int
153095c635efSGarrett D'Amore mdoc_sm_pre(MDOC_ARGS)
153195c635efSGarrett D'Amore {
153295c635efSGarrett D'Amore 
1533*260e9a87SYuri Pankov 	if (NULL == n->child)
1534*260e9a87SYuri Pankov 		h->flags ^= HTML_NONOSPACE;
1535*260e9a87SYuri Pankov 	else if (0 == strcmp("on", n->child->string))
153695c635efSGarrett D'Amore 		h->flags &= ~HTML_NONOSPACE;
1537*260e9a87SYuri Pankov 	else
153895c635efSGarrett D'Amore 		h->flags |= HTML_NONOSPACE;
153995c635efSGarrett D'Amore 
1540*260e9a87SYuri Pankov 	if ( ! (HTML_NONOSPACE & h->flags))
1541*260e9a87SYuri Pankov 		h->flags &= ~HTML_NOSPACE;
1542*260e9a87SYuri Pankov 
154395c635efSGarrett D'Amore 	return(0);
154495c635efSGarrett D'Amore }
154595c635efSGarrett D'Amore 
1546*260e9a87SYuri Pankov static int
1547*260e9a87SYuri Pankov mdoc_skip_pre(MDOC_ARGS)
1548*260e9a87SYuri Pankov {
1549*260e9a87SYuri Pankov 
1550*260e9a87SYuri Pankov 	return(0);
1551*260e9a87SYuri Pankov }
1552*260e9a87SYuri Pankov 
155395c635efSGarrett D'Amore static int
155495c635efSGarrett D'Amore mdoc_pp_pre(MDOC_ARGS)
155595c635efSGarrett D'Amore {
155695c635efSGarrett D'Amore 
1557*260e9a87SYuri Pankov 	print_paragraph(h);
155895c635efSGarrett D'Amore 	return(0);
155995c635efSGarrett D'Amore }
156095c635efSGarrett D'Amore 
156195c635efSGarrett D'Amore static int
156295c635efSGarrett D'Amore mdoc_sp_pre(MDOC_ARGS)
156395c635efSGarrett D'Amore {
156495c635efSGarrett D'Amore 	struct roffsu	 su;
156595c635efSGarrett D'Amore 	struct htmlpair	 tag;
156695c635efSGarrett D'Amore 
156795c635efSGarrett D'Amore 	SCALE_VS_INIT(&su, 1);
156895c635efSGarrett D'Amore 
156995c635efSGarrett D'Amore 	if (MDOC_sp == n->tok) {
1570*260e9a87SYuri Pankov 		if (NULL != (n = n->child)) {
157195c635efSGarrett D'Amore 			if ( ! a2roffsu(n->string, &su, SCALE_VS))
1572*260e9a87SYuri Pankov 				su.scale = 1.0;
1573*260e9a87SYuri Pankov 			else if (su.scale < 0.0)
1574*260e9a87SYuri Pankov 				su.scale = 0.0;
1575*260e9a87SYuri Pankov 		}
157695c635efSGarrett D'Amore 	} else
1577*260e9a87SYuri Pankov 		su.scale = 0.0;
157895c635efSGarrett D'Amore 
157995c635efSGarrett D'Amore 	bufinit(h);
158095c635efSGarrett D'Amore 	bufcat_su(h, "height", &su);
158195c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag, h);
158295c635efSGarrett D'Amore 	print_otag(h, TAG_DIV, 1, &tag);
158395c635efSGarrett D'Amore 
158495c635efSGarrett D'Amore 	/* So the div isn't empty: */
158595c635efSGarrett D'Amore 	print_text(h, "\\~");
158695c635efSGarrett D'Amore 
158795c635efSGarrett D'Amore 	return(0);
158895c635efSGarrett D'Amore 
158995c635efSGarrett D'Amore }
159095c635efSGarrett D'Amore 
159195c635efSGarrett D'Amore static int
159295c635efSGarrett D'Amore mdoc_lk_pre(MDOC_ARGS)
159395c635efSGarrett D'Amore {
159495c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
159595c635efSGarrett D'Amore 
159695c635efSGarrett D'Amore 	if (NULL == (n = n->child))
159795c635efSGarrett D'Amore 		return(0);
159895c635efSGarrett D'Amore 
159995c635efSGarrett D'Amore 	assert(MDOC_TEXT == n->type);
160095c635efSGarrett D'Amore 
160195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "link-ext");
160295c635efSGarrett D'Amore 	PAIR_HREF_INIT(&tag[1], n->string);
160395c635efSGarrett D'Amore 
160495c635efSGarrett D'Amore 	print_otag(h, TAG_A, 2, tag);
160595c635efSGarrett D'Amore 
160695c635efSGarrett D'Amore 	if (NULL == n->next)
160795c635efSGarrett D'Amore 		print_text(h, n->string);
160895c635efSGarrett D'Amore 
160995c635efSGarrett D'Amore 	for (n = n->next; n; n = n->next)
161095c635efSGarrett D'Amore 		print_text(h, n->string);
161195c635efSGarrett D'Amore 
161295c635efSGarrett D'Amore 	return(0);
161395c635efSGarrett D'Amore }
161495c635efSGarrett D'Amore 
161595c635efSGarrett D'Amore static int
161695c635efSGarrett D'Amore mdoc_mt_pre(MDOC_ARGS)
161795c635efSGarrett D'Amore {
161895c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
161995c635efSGarrett D'Amore 	struct tag	*t;
162095c635efSGarrett D'Amore 
162195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "link-mail");
162295c635efSGarrett D'Amore 
162395c635efSGarrett D'Amore 	for (n = n->child; n; n = n->next) {
162495c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
162595c635efSGarrett D'Amore 
162695c635efSGarrett D'Amore 		bufinit(h);
162795c635efSGarrett D'Amore 		bufcat(h, "mailto:");
162895c635efSGarrett D'Amore 		bufcat(h, n->string);
162995c635efSGarrett D'Amore 
163095c635efSGarrett D'Amore 		PAIR_HREF_INIT(&tag[1], h->buf);
163195c635efSGarrett D'Amore 		t = print_otag(h, TAG_A, 2, tag);
163295c635efSGarrett D'Amore 		print_text(h, n->string);
163395c635efSGarrett D'Amore 		print_tagq(h, t);
163495c635efSGarrett D'Amore 	}
163595c635efSGarrett D'Amore 
163695c635efSGarrett D'Amore 	return(0);
163795c635efSGarrett D'Amore }
163895c635efSGarrett D'Amore 
163995c635efSGarrett D'Amore static int
164095c635efSGarrett D'Amore mdoc_fo_pre(MDOC_ARGS)
164195c635efSGarrett D'Amore {
164295c635efSGarrett D'Amore 	struct htmlpair	 tag;
164395c635efSGarrett D'Amore 	struct tag	*t;
164495c635efSGarrett D'Amore 
164595c635efSGarrett D'Amore 	if (MDOC_BODY == n->type) {
164695c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
164795c635efSGarrett D'Amore 		print_text(h, "(");
164895c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
164995c635efSGarrett D'Amore 		return(1);
165095c635efSGarrett D'Amore 	} else if (MDOC_BLOCK == n->type) {
165195c635efSGarrett D'Amore 		synopsis_pre(h, n);
165295c635efSGarrett D'Amore 		return(1);
165395c635efSGarrett D'Amore 	}
165495c635efSGarrett D'Amore 
165595c635efSGarrett D'Amore 	/* XXX: we drop non-initial arguments as per groff. */
165695c635efSGarrett D'Amore 
165795c635efSGarrett D'Amore 	assert(n->child);
165895c635efSGarrett D'Amore 	assert(n->child->string);
165995c635efSGarrett D'Amore 
166095c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "fname");
166195c635efSGarrett D'Amore 	t = print_otag(h, TAG_B, 1, &tag);
166295c635efSGarrett D'Amore 	print_text(h, n->child->string);
166395c635efSGarrett D'Amore 	print_tagq(h, t);
166495c635efSGarrett D'Amore 	return(0);
166595c635efSGarrett D'Amore }
166695c635efSGarrett D'Amore 
166795c635efSGarrett D'Amore static void
166895c635efSGarrett D'Amore mdoc_fo_post(MDOC_ARGS)
166995c635efSGarrett D'Amore {
167095c635efSGarrett D'Amore 
167195c635efSGarrett D'Amore 	if (MDOC_BODY != n->type)
167295c635efSGarrett D'Amore 		return;
167395c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
167495c635efSGarrett D'Amore 	print_text(h, ")");
167595c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
167695c635efSGarrett D'Amore 	print_text(h, ";");
167795c635efSGarrett D'Amore }
167895c635efSGarrett D'Amore 
167995c635efSGarrett D'Amore static int
168095c635efSGarrett D'Amore mdoc_in_pre(MDOC_ARGS)
168195c635efSGarrett D'Amore {
168295c635efSGarrett D'Amore 	struct tag	*t;
168395c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
168495c635efSGarrett D'Amore 	int		 i;
168595c635efSGarrett D'Amore 
168695c635efSGarrett D'Amore 	synopsis_pre(h, n);
168795c635efSGarrett D'Amore 
168895c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag[0], "includes");
168995c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, tag);
169095c635efSGarrett D'Amore 
169195c635efSGarrett D'Amore 	/*
169295c635efSGarrett D'Amore 	 * The first argument of the `In' gets special treatment as
169395c635efSGarrett D'Amore 	 * being a linked value.  Subsequent values are printed
169495c635efSGarrett D'Amore 	 * afterward.  groff does similarly.  This also handles the case
169595c635efSGarrett D'Amore 	 * of no children.
169695c635efSGarrett D'Amore 	 */
169795c635efSGarrett D'Amore 
169895c635efSGarrett D'Amore 	if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
169995c635efSGarrett D'Amore 		print_text(h, "#include");
170095c635efSGarrett D'Amore 
170195c635efSGarrett D'Amore 	print_text(h, "<");
170295c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
170395c635efSGarrett D'Amore 
170495c635efSGarrett D'Amore 	if (NULL != (n = n->child)) {
170595c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
170695c635efSGarrett D'Amore 
170795c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "link-includes");
170895c635efSGarrett D'Amore 
170995c635efSGarrett D'Amore 		i = 1;
171095c635efSGarrett D'Amore 		if (h->base_includes) {
171195c635efSGarrett D'Amore 			buffmt_includes(h, n->string);
171295c635efSGarrett D'Amore 			PAIR_HREF_INIT(&tag[i], h->buf);
171395c635efSGarrett D'Amore 			i++;
171495c635efSGarrett D'Amore 		}
171595c635efSGarrett D'Amore 
171695c635efSGarrett D'Amore 		t = print_otag(h, TAG_A, i, tag);
171795c635efSGarrett D'Amore 		print_text(h, n->string);
171895c635efSGarrett D'Amore 		print_tagq(h, t);
171995c635efSGarrett D'Amore 
172095c635efSGarrett D'Amore 		n = n->next;
172195c635efSGarrett D'Amore 	}
172295c635efSGarrett D'Amore 
172395c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
172495c635efSGarrett D'Amore 	print_text(h, ">");
172595c635efSGarrett D'Amore 
172695c635efSGarrett D'Amore 	for ( ; n; n = n->next) {
172795c635efSGarrett D'Amore 		assert(MDOC_TEXT == n->type);
172895c635efSGarrett D'Amore 		print_text(h, n->string);
172995c635efSGarrett D'Amore 	}
173095c635efSGarrett D'Amore 
173195c635efSGarrett D'Amore 	return(0);
173295c635efSGarrett D'Amore }
173395c635efSGarrett D'Amore 
173495c635efSGarrett D'Amore static int
173595c635efSGarrett D'Amore mdoc_ic_pre(MDOC_ARGS)
173695c635efSGarrett D'Amore {
173795c635efSGarrett D'Amore 	struct htmlpair	tag;
173895c635efSGarrett D'Amore 
173995c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "cmd");
174095c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, &tag);
174195c635efSGarrett D'Amore 	return(1);
174295c635efSGarrett D'Amore }
174395c635efSGarrett D'Amore 
174495c635efSGarrett D'Amore static int
174595c635efSGarrett D'Amore mdoc_rv_pre(MDOC_ARGS)
174695c635efSGarrett D'Amore {
174795c635efSGarrett D'Amore 	struct htmlpair	 tag;
174895c635efSGarrett D'Amore 	struct tag	*t;
174995c635efSGarrett D'Amore 	int		 nchild;
175095c635efSGarrett D'Amore 
175195c635efSGarrett D'Amore 	if (n->prev)
175295c635efSGarrett D'Amore 		print_otag(h, TAG_BR, 0, NULL);
175395c635efSGarrett D'Amore 
175495c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "fname");
175595c635efSGarrett D'Amore 
1756*260e9a87SYuri Pankov 	nchild = n->nchild;
1757*260e9a87SYuri Pankov 	if (nchild > 0) {
175895c635efSGarrett D'Amore 		print_text(h, "The");
175995c635efSGarrett D'Amore 
176095c635efSGarrett D'Amore 		for (n = n->child; n; n = n->next) {
176195c635efSGarrett D'Amore 			t = print_otag(h, TAG_B, 1, &tag);
176295c635efSGarrett D'Amore 			print_text(h, n->string);
176395c635efSGarrett D'Amore 			print_tagq(h, t);
176495c635efSGarrett D'Amore 
176595c635efSGarrett D'Amore 			h->flags |= HTML_NOSPACE;
176695c635efSGarrett D'Amore 			print_text(h, "()");
176795c635efSGarrett D'Amore 
1768*260e9a87SYuri Pankov 			if (n->next == NULL)
1769*260e9a87SYuri Pankov 				continue;
1770*260e9a87SYuri Pankov 
1771*260e9a87SYuri Pankov 			if (nchild > 2) {
177295c635efSGarrett D'Amore 				h->flags |= HTML_NOSPACE;
177395c635efSGarrett D'Amore 				print_text(h, ",");
177495c635efSGarrett D'Amore 			}
1775*260e9a87SYuri Pankov 			if (n->next->next == NULL)
177695c635efSGarrett D'Amore 				print_text(h, "and");
177795c635efSGarrett D'Amore 		}
177895c635efSGarrett D'Amore 
177995c635efSGarrett D'Amore 		if (nchild > 1)
178095c635efSGarrett D'Amore 			print_text(h, "functions return");
178195c635efSGarrett D'Amore 		else
178295c635efSGarrett D'Amore 			print_text(h, "function returns");
178395c635efSGarrett D'Amore 
1784*260e9a87SYuri Pankov 		print_text(h, "the value\\~0 if successful;");
1785*260e9a87SYuri Pankov 	} else
1786*260e9a87SYuri Pankov 		print_text(h, "Upon successful completion,"
1787*260e9a87SYuri Pankov                     " the value\\~0 is returned;");
1788*260e9a87SYuri Pankov 
1789*260e9a87SYuri Pankov 	print_text(h, "otherwise the value\\~\\-1 is returned"
1790*260e9a87SYuri Pankov 	   " and the global variable");
179195c635efSGarrett D'Amore 
179295c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "var");
179395c635efSGarrett D'Amore 	t = print_otag(h, TAG_B, 1, &tag);
179495c635efSGarrett D'Amore 	print_text(h, "errno");
179595c635efSGarrett D'Amore 	print_tagq(h, t);
179695c635efSGarrett D'Amore 	print_text(h, "is set to indicate the error.");
179795c635efSGarrett D'Amore 	return(0);
179895c635efSGarrett D'Amore }
179995c635efSGarrett D'Amore 
180095c635efSGarrett D'Amore static int
180195c635efSGarrett D'Amore mdoc_va_pre(MDOC_ARGS)
180295c635efSGarrett D'Amore {
180395c635efSGarrett D'Amore 	struct htmlpair	tag;
180495c635efSGarrett D'Amore 
180595c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "var");
180695c635efSGarrett D'Amore 	print_otag(h, TAG_B, 1, &tag);
180795c635efSGarrett D'Amore 	return(1);
180895c635efSGarrett D'Amore }
180995c635efSGarrett D'Amore 
181095c635efSGarrett D'Amore static int
181195c635efSGarrett D'Amore mdoc_ap_pre(MDOC_ARGS)
181295c635efSGarrett D'Amore {
181395c635efSGarrett D'Amore 
181495c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
181595c635efSGarrett D'Amore 	print_text(h, "\\(aq");
181695c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
181795c635efSGarrett D'Amore 	return(1);
181895c635efSGarrett D'Amore }
181995c635efSGarrett D'Amore 
182095c635efSGarrett D'Amore static int
182195c635efSGarrett D'Amore mdoc_bf_pre(MDOC_ARGS)
182295c635efSGarrett D'Amore {
182395c635efSGarrett D'Amore 	struct htmlpair	 tag[2];
182495c635efSGarrett D'Amore 	struct roffsu	 su;
182595c635efSGarrett D'Amore 
182695c635efSGarrett D'Amore 	if (MDOC_HEAD == n->type)
182795c635efSGarrett D'Amore 		return(0);
182895c635efSGarrett D'Amore 	else if (MDOC_BODY != n->type)
182995c635efSGarrett D'Amore 		return(1);
183095c635efSGarrett D'Amore 
183195c635efSGarrett D'Amore 	if (FONT_Em == n->norm->Bf.font)
183295c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "emph");
183395c635efSGarrett D'Amore 	else if (FONT_Sy == n->norm->Bf.font)
183495c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "symb");
183595c635efSGarrett D'Amore 	else if (FONT_Li == n->norm->Bf.font)
183695c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "lit");
183795c635efSGarrett D'Amore 	else
183895c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "none");
183995c635efSGarrett D'Amore 
184095c635efSGarrett D'Amore 	/*
184195c635efSGarrett D'Amore 	 * We want this to be inline-formatted, but needs to be div to
184295c635efSGarrett D'Amore 	 * accept block children.
184395c635efSGarrett D'Amore 	 */
184495c635efSGarrett D'Amore 	bufinit(h);
184595c635efSGarrett D'Amore 	bufcat_style(h, "display", "inline");
184695c635efSGarrett D'Amore 	SCALE_HS_INIT(&su, 1);
184795c635efSGarrett D'Amore 	/* Needs a left-margin for spacing. */
184895c635efSGarrett D'Amore 	bufcat_su(h, "margin-left", &su);
184995c635efSGarrett D'Amore 	PAIR_STYLE_INIT(&tag[1], h);
185095c635efSGarrett D'Amore 	print_otag(h, TAG_DIV, 2, tag);
185195c635efSGarrett D'Amore 	return(1);
185295c635efSGarrett D'Amore }
185395c635efSGarrett D'Amore 
185495c635efSGarrett D'Amore static int
185595c635efSGarrett D'Amore mdoc_ms_pre(MDOC_ARGS)
185695c635efSGarrett D'Amore {
185795c635efSGarrett D'Amore 	struct htmlpair	tag;
185895c635efSGarrett D'Amore 
185995c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "symb");
186095c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
186195c635efSGarrett D'Amore 	return(1);
186295c635efSGarrett D'Amore }
186395c635efSGarrett D'Amore 
186495c635efSGarrett D'Amore static int
186595c635efSGarrett D'Amore mdoc_igndelim_pre(MDOC_ARGS)
186695c635efSGarrett D'Amore {
186795c635efSGarrett D'Amore 
186895c635efSGarrett D'Amore 	h->flags |= HTML_IGNDELIM;
186995c635efSGarrett D'Amore 	return(1);
187095c635efSGarrett D'Amore }
187195c635efSGarrett D'Amore 
187295c635efSGarrett D'Amore static void
187395c635efSGarrett D'Amore mdoc_pf_post(MDOC_ARGS)
187495c635efSGarrett D'Amore {
187595c635efSGarrett D'Amore 
1876*260e9a87SYuri Pankov 	if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
187795c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
187895c635efSGarrett D'Amore }
187995c635efSGarrett D'Amore 
188095c635efSGarrett D'Amore static int
188195c635efSGarrett D'Amore mdoc_rs_pre(MDOC_ARGS)
188295c635efSGarrett D'Amore {
188395c635efSGarrett D'Amore 	struct htmlpair	 tag;
188495c635efSGarrett D'Amore 
188595c635efSGarrett D'Amore 	if (MDOC_BLOCK != n->type)
188695c635efSGarrett D'Amore 		return(1);
188795c635efSGarrett D'Amore 
188895c635efSGarrett D'Amore 	if (n->prev && SEC_SEE_ALSO == n->sec)
1889*260e9a87SYuri Pankov 		print_paragraph(h);
189095c635efSGarrett D'Amore 
189195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "ref");
189295c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
189395c635efSGarrett D'Amore 	return(1);
189495c635efSGarrett D'Amore }
189595c635efSGarrett D'Amore 
1896*260e9a87SYuri Pankov static int
1897*260e9a87SYuri Pankov mdoc_no_pre(MDOC_ARGS)
1898*260e9a87SYuri Pankov {
1899*260e9a87SYuri Pankov 	struct htmlpair	tag;
190095c635efSGarrett D'Amore 
1901*260e9a87SYuri Pankov 	PAIR_CLASS_INIT(&tag, "none");
1902*260e9a87SYuri Pankov 	print_otag(h, TAG_CODE, 1, &tag);
1903*260e9a87SYuri Pankov 	return(1);
1904*260e9a87SYuri Pankov }
190595c635efSGarrett D'Amore 
190695c635efSGarrett D'Amore static int
190795c635efSGarrett D'Amore mdoc_li_pre(MDOC_ARGS)
190895c635efSGarrett D'Amore {
190995c635efSGarrett D'Amore 	struct htmlpair	tag;
191095c635efSGarrett D'Amore 
191195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "lit");
191295c635efSGarrett D'Amore 	print_otag(h, TAG_CODE, 1, &tag);
191395c635efSGarrett D'Amore 	return(1);
191495c635efSGarrett D'Amore }
191595c635efSGarrett D'Amore 
191695c635efSGarrett D'Amore static int
191795c635efSGarrett D'Amore mdoc_sy_pre(MDOC_ARGS)
191895c635efSGarrett D'Amore {
191995c635efSGarrett D'Amore 	struct htmlpair	tag;
192095c635efSGarrett D'Amore 
192195c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "symb");
192295c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
192395c635efSGarrett D'Amore 	return(1);
192495c635efSGarrett D'Amore }
192595c635efSGarrett D'Amore 
192695c635efSGarrett D'Amore static int
192795c635efSGarrett D'Amore mdoc_bt_pre(MDOC_ARGS)
192895c635efSGarrett D'Amore {
192995c635efSGarrett D'Amore 
193095c635efSGarrett D'Amore 	print_text(h, "is currently in beta test.");
193195c635efSGarrett D'Amore 	return(0);
193295c635efSGarrett D'Amore }
193395c635efSGarrett D'Amore 
193495c635efSGarrett D'Amore static int
193595c635efSGarrett D'Amore mdoc_ud_pre(MDOC_ARGS)
193695c635efSGarrett D'Amore {
193795c635efSGarrett D'Amore 
193895c635efSGarrett D'Amore 	print_text(h, "currently under development.");
193995c635efSGarrett D'Amore 	return(0);
194095c635efSGarrett D'Amore }
194195c635efSGarrett D'Amore 
194295c635efSGarrett D'Amore static int
194395c635efSGarrett D'Amore mdoc_lb_pre(MDOC_ARGS)
194495c635efSGarrett D'Amore {
194595c635efSGarrett D'Amore 	struct htmlpair	tag;
194695c635efSGarrett D'Amore 
194795c635efSGarrett D'Amore 	if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
194895c635efSGarrett D'Amore 		print_otag(h, TAG_BR, 0, NULL);
194995c635efSGarrett D'Amore 
195095c635efSGarrett D'Amore 	PAIR_CLASS_INIT(&tag, "lib");
195195c635efSGarrett D'Amore 	print_otag(h, TAG_SPAN, 1, &tag);
195295c635efSGarrett D'Amore 	return(1);
195395c635efSGarrett D'Amore }
195495c635efSGarrett D'Amore 
195595c635efSGarrett D'Amore static int
195695c635efSGarrett D'Amore mdoc__x_pre(MDOC_ARGS)
195795c635efSGarrett D'Amore {
195895c635efSGarrett D'Amore 	struct htmlpair	tag[2];
195995c635efSGarrett D'Amore 	enum htmltag	t;
196095c635efSGarrett D'Amore 
196195c635efSGarrett D'Amore 	t = TAG_SPAN;
196295c635efSGarrett D'Amore 
196395c635efSGarrett D'Amore 	switch (n->tok) {
1964*260e9a87SYuri Pankov 	case MDOC__A:
196595c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-auth");
196695c635efSGarrett D'Amore 		if (n->prev && MDOC__A == n->prev->tok)
196795c635efSGarrett D'Amore 			if (NULL == n->next || MDOC__A != n->next->tok)
196895c635efSGarrett D'Amore 				print_text(h, "and");
196995c635efSGarrett D'Amore 		break;
1970*260e9a87SYuri Pankov 	case MDOC__B:
197195c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-book");
197295c635efSGarrett D'Amore 		t = TAG_I;
197395c635efSGarrett D'Amore 		break;
1974*260e9a87SYuri Pankov 	case MDOC__C:
197595c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-city");
197695c635efSGarrett D'Amore 		break;
1977*260e9a87SYuri Pankov 	case MDOC__D:
197895c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-date");
197995c635efSGarrett D'Amore 		break;
1980*260e9a87SYuri Pankov 	case MDOC__I:
198195c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-issue");
198295c635efSGarrett D'Amore 		t = TAG_I;
198395c635efSGarrett D'Amore 		break;
1984*260e9a87SYuri Pankov 	case MDOC__J:
198595c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
198695c635efSGarrett D'Amore 		t = TAG_I;
198795c635efSGarrett D'Amore 		break;
1988*260e9a87SYuri Pankov 	case MDOC__N:
198995c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-num");
199095c635efSGarrett D'Amore 		break;
1991*260e9a87SYuri Pankov 	case MDOC__O:
199295c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-opt");
199395c635efSGarrett D'Amore 		break;
1994*260e9a87SYuri Pankov 	case MDOC__P:
199595c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-page");
199695c635efSGarrett D'Amore 		break;
1997*260e9a87SYuri Pankov 	case MDOC__Q:
199895c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-corp");
199995c635efSGarrett D'Amore 		break;
2000*260e9a87SYuri Pankov 	case MDOC__R:
200195c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-rep");
200295c635efSGarrett D'Amore 		break;
2003*260e9a87SYuri Pankov 	case MDOC__T:
200495c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-title");
200595c635efSGarrett D'Amore 		break;
2006*260e9a87SYuri Pankov 	case MDOC__U:
200795c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "link-ref");
200895c635efSGarrett D'Amore 		break;
2009*260e9a87SYuri Pankov 	case MDOC__V:
201095c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag[0], "ref-vol");
201195c635efSGarrett D'Amore 		break;
201295c635efSGarrett D'Amore 	default:
201395c635efSGarrett D'Amore 		abort();
201495c635efSGarrett D'Amore 		/* NOTREACHED */
201595c635efSGarrett D'Amore 	}
201695c635efSGarrett D'Amore 
201795c635efSGarrett D'Amore 	if (MDOC__U != n->tok) {
201895c635efSGarrett D'Amore 		print_otag(h, t, 1, tag);
201995c635efSGarrett D'Amore 		return(1);
202095c635efSGarrett D'Amore 	}
202195c635efSGarrett D'Amore 
202295c635efSGarrett D'Amore 	PAIR_HREF_INIT(&tag[1], n->child->string);
202395c635efSGarrett D'Amore 	print_otag(h, TAG_A, 2, tag);
202495c635efSGarrett D'Amore 
202595c635efSGarrett D'Amore 	return(1);
202695c635efSGarrett D'Amore }
202795c635efSGarrett D'Amore 
202895c635efSGarrett D'Amore static void
202995c635efSGarrett D'Amore mdoc__x_post(MDOC_ARGS)
203095c635efSGarrett D'Amore {
203195c635efSGarrett D'Amore 
203295c635efSGarrett D'Amore 	if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
203395c635efSGarrett D'Amore 		if (NULL == n->next->next || MDOC__A != n->next->next->tok)
203495c635efSGarrett D'Amore 			if (NULL == n->prev || MDOC__A != n->prev->tok)
203595c635efSGarrett D'Amore 				return;
203695c635efSGarrett D'Amore 
203795c635efSGarrett D'Amore 	/* TODO: %U */
203895c635efSGarrett D'Amore 
203995c635efSGarrett D'Amore 	if (NULL == n->parent || MDOC_Rs != n->parent->tok)
204095c635efSGarrett D'Amore 		return;
204195c635efSGarrett D'Amore 
204295c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
204395c635efSGarrett D'Amore 	print_text(h, n->next ? "," : ".");
204495c635efSGarrett D'Amore }
204595c635efSGarrett D'Amore 
204695c635efSGarrett D'Amore static int
204795c635efSGarrett D'Amore mdoc_bk_pre(MDOC_ARGS)
204895c635efSGarrett D'Amore {
204995c635efSGarrett D'Amore 
205095c635efSGarrett D'Amore 	switch (n->type) {
2051*260e9a87SYuri Pankov 	case MDOC_BLOCK:
205295c635efSGarrett D'Amore 		break;
2053*260e9a87SYuri Pankov 	case MDOC_HEAD:
205495c635efSGarrett D'Amore 		return(0);
2055*260e9a87SYuri Pankov 	case MDOC_BODY:
205695c635efSGarrett D'Amore 		if (n->parent->args || 0 == n->prev->nchild)
205795c635efSGarrett D'Amore 			h->flags |= HTML_PREKEEP;
205895c635efSGarrett D'Amore 		break;
205995c635efSGarrett D'Amore 	default:
206095c635efSGarrett D'Amore 		abort();
206195c635efSGarrett D'Amore 		/* NOTREACHED */
206295c635efSGarrett D'Amore 	}
206395c635efSGarrett D'Amore 
206495c635efSGarrett D'Amore 	return(1);
206595c635efSGarrett D'Amore }
206695c635efSGarrett D'Amore 
206795c635efSGarrett D'Amore static void
206895c635efSGarrett D'Amore mdoc_bk_post(MDOC_ARGS)
206995c635efSGarrett D'Amore {
207095c635efSGarrett D'Amore 
207195c635efSGarrett D'Amore 	if (MDOC_BODY == n->type)
207295c635efSGarrett D'Amore 		h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
207395c635efSGarrett D'Amore }
207495c635efSGarrett D'Amore 
207595c635efSGarrett D'Amore static int
207695c635efSGarrett D'Amore mdoc_quote_pre(MDOC_ARGS)
207795c635efSGarrett D'Amore {
207895c635efSGarrett D'Amore 	struct htmlpair	tag;
207995c635efSGarrett D'Amore 
208095c635efSGarrett D'Amore 	if (MDOC_BODY != n->type)
208195c635efSGarrett D'Amore 		return(1);
208295c635efSGarrett D'Amore 
208395c635efSGarrett D'Amore 	switch (n->tok) {
2084*260e9a87SYuri Pankov 	case MDOC_Ao:
208595c635efSGarrett D'Amore 		/* FALLTHROUGH */
2086*260e9a87SYuri Pankov 	case MDOC_Aq:
2087*260e9a87SYuri Pankov 		print_text(h, n->nchild == 1 &&
2088*260e9a87SYuri Pankov 		    n->child->tok == MDOC_Mt ?  "<" : "\\(la");
208995c635efSGarrett D'Amore 		break;
2090*260e9a87SYuri Pankov 	case MDOC_Bro:
209195c635efSGarrett D'Amore 		/* FALLTHROUGH */
2092*260e9a87SYuri Pankov 	case MDOC_Brq:
209395c635efSGarrett D'Amore 		print_text(h, "\\(lC");
209495c635efSGarrett D'Amore 		break;
2095*260e9a87SYuri Pankov 	case MDOC_Bo:
209695c635efSGarrett D'Amore 		/* FALLTHROUGH */
2097*260e9a87SYuri Pankov 	case MDOC_Bq:
209895c635efSGarrett D'Amore 		print_text(h, "\\(lB");
209995c635efSGarrett D'Amore 		break;
2100*260e9a87SYuri Pankov 	case MDOC_Oo:
210195c635efSGarrett D'Amore 		/* FALLTHROUGH */
2102*260e9a87SYuri Pankov 	case MDOC_Op:
210395c635efSGarrett D'Amore 		print_text(h, "\\(lB");
210495c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
210595c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag, "opt");
210695c635efSGarrett D'Amore 		print_otag(h, TAG_SPAN, 1, &tag);
210795c635efSGarrett D'Amore 		break;
2108*260e9a87SYuri Pankov 	case MDOC_En:
2109*260e9a87SYuri Pankov 		if (NULL == n->norm->Es ||
2110*260e9a87SYuri Pankov 		    NULL == n->norm->Es->child)
2111*260e9a87SYuri Pankov 			return(1);
2112*260e9a87SYuri Pankov 		print_text(h, n->norm->Es->child->string);
211395c635efSGarrett D'Amore 		break;
2114*260e9a87SYuri Pankov 	case MDOC_Do:
211595c635efSGarrett D'Amore 		/* FALLTHROUGH */
2116*260e9a87SYuri Pankov 	case MDOC_Dq:
211795c635efSGarrett D'Amore 		/* FALLTHROUGH */
2118*260e9a87SYuri Pankov 	case MDOC_Qo:
211995c635efSGarrett D'Amore 		/* FALLTHROUGH */
2120*260e9a87SYuri Pankov 	case MDOC_Qq:
212195c635efSGarrett D'Amore 		print_text(h, "\\(lq");
212295c635efSGarrett D'Amore 		break;
2123*260e9a87SYuri Pankov 	case MDOC_Po:
212495c635efSGarrett D'Amore 		/* FALLTHROUGH */
2125*260e9a87SYuri Pankov 	case MDOC_Pq:
212695c635efSGarrett D'Amore 		print_text(h, "(");
212795c635efSGarrett D'Amore 		break;
2128*260e9a87SYuri Pankov 	case MDOC_Ql:
212995c635efSGarrett D'Amore 		print_text(h, "\\(oq");
213095c635efSGarrett D'Amore 		h->flags |= HTML_NOSPACE;
213195c635efSGarrett D'Amore 		PAIR_CLASS_INIT(&tag, "lit");
213295c635efSGarrett D'Amore 		print_otag(h, TAG_CODE, 1, &tag);
213395c635efSGarrett D'Amore 		break;
2134*260e9a87SYuri Pankov 	case MDOC_So:
213595c635efSGarrett D'Amore 		/* FALLTHROUGH */
2136*260e9a87SYuri Pankov 	case MDOC_Sq:
213795c635efSGarrett D'Amore 		print_text(h, "\\(oq");
213895c635efSGarrett D'Amore 		break;
213995c635efSGarrett D'Amore 	default:
214095c635efSGarrett D'Amore 		abort();
214195c635efSGarrett D'Amore 		/* NOTREACHED */
214295c635efSGarrett D'Amore 	}
214395c635efSGarrett D'Amore 
214495c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
214595c635efSGarrett D'Amore 	return(1);
214695c635efSGarrett D'Amore }
214795c635efSGarrett D'Amore 
214895c635efSGarrett D'Amore static void
214995c635efSGarrett D'Amore mdoc_quote_post(MDOC_ARGS)
215095c635efSGarrett D'Amore {
215195c635efSGarrett D'Amore 
2152*260e9a87SYuri Pankov 	if (n->type != MDOC_BODY && n->type != MDOC_ELEM)
215395c635efSGarrett D'Amore 		return;
215495c635efSGarrett D'Amore 
215595c635efSGarrett D'Amore 	h->flags |= HTML_NOSPACE;
215695c635efSGarrett D'Amore 
215795c635efSGarrett D'Amore 	switch (n->tok) {
2158*260e9a87SYuri Pankov 	case MDOC_Ao:
215995c635efSGarrett D'Amore 		/* FALLTHROUGH */
2160*260e9a87SYuri Pankov 	case MDOC_Aq:
2161*260e9a87SYuri Pankov 		print_text(h, n->nchild == 1 &&
2162*260e9a87SYuri Pankov 		    n->child->tok == MDOC_Mt ?  ">" : "\\(ra");
216395c635efSGarrett D'Amore 		break;
2164*260e9a87SYuri Pankov 	case MDOC_Bro:
216595c635efSGarrett D'Amore 		/* FALLTHROUGH */
2166*260e9a87SYuri Pankov 	case MDOC_Brq:
216795c635efSGarrett D'Amore 		print_text(h, "\\(rC");
216895c635efSGarrett D'Amore 		break;
2169*260e9a87SYuri Pankov 	case MDOC_Oo:
217095c635efSGarrett D'Amore 		/* FALLTHROUGH */
2171*260e9a87SYuri Pankov 	case MDOC_Op:
217295c635efSGarrett D'Amore 		/* FALLTHROUGH */
2173*260e9a87SYuri Pankov 	case MDOC_Bo:
217495c635efSGarrett D'Amore 		/* FALLTHROUGH */
2175*260e9a87SYuri Pankov 	case MDOC_Bq:
217695c635efSGarrett D'Amore 		print_text(h, "\\(rB");
217795c635efSGarrett D'Amore 		break;
2178*260e9a87SYuri Pankov 	case MDOC_En:
2179*260e9a87SYuri Pankov 		if (n->norm->Es == NULL ||
2180*260e9a87SYuri Pankov 		    n->norm->Es->child == NULL ||
2181*260e9a87SYuri Pankov 		    n->norm->Es->child->next == NULL)
2182*260e9a87SYuri Pankov 			h->flags &= ~HTML_NOSPACE;
2183*260e9a87SYuri Pankov 		else
2184*260e9a87SYuri Pankov 			print_text(h, n->norm->Es->child->next->string);
218595c635efSGarrett D'Amore 		break;
2186*260e9a87SYuri Pankov 	case MDOC_Qo:
218795c635efSGarrett D'Amore 		/* FALLTHROUGH */
2188*260e9a87SYuri Pankov 	case MDOC_Qq:
218995c635efSGarrett D'Amore 		/* FALLTHROUGH */
2190*260e9a87SYuri Pankov 	case MDOC_Do:
219195c635efSGarrett D'Amore 		/* FALLTHROUGH */
2192*260e9a87SYuri Pankov 	case MDOC_Dq:
219395c635efSGarrett D'Amore 		print_text(h, "\\(rq");
219495c635efSGarrett D'Amore 		break;
2195*260e9a87SYuri Pankov 	case MDOC_Po:
219695c635efSGarrett D'Amore 		/* FALLTHROUGH */
2197*260e9a87SYuri Pankov 	case MDOC_Pq:
219895c635efSGarrett D'Amore 		print_text(h, ")");
219995c635efSGarrett D'Amore 		break;
2200*260e9a87SYuri Pankov 	case MDOC_Ql:
220195c635efSGarrett D'Amore 		/* FALLTHROUGH */
2202*260e9a87SYuri Pankov 	case MDOC_So:
220395c635efSGarrett D'Amore 		/* FALLTHROUGH */
2204*260e9a87SYuri Pankov 	case MDOC_Sq:
2205698f87a4SGarrett D'Amore 		print_text(h, "\\(cq");
220695c635efSGarrett D'Amore 		break;
220795c635efSGarrett D'Amore 	default:
220895c635efSGarrett D'Amore 		abort();
220995c635efSGarrett D'Amore 		/* NOTREACHED */
221095c635efSGarrett D'Amore 	}
221195c635efSGarrett D'Amore }
221295c635efSGarrett D'Amore 
2213*260e9a87SYuri Pankov static int
2214*260e9a87SYuri Pankov mdoc_eo_pre(MDOC_ARGS)
2215*260e9a87SYuri Pankov {
221695c635efSGarrett D'Amore 
2217*260e9a87SYuri Pankov 	if (n->type != MDOC_BODY)
2218*260e9a87SYuri Pankov 		return(1);
2219*260e9a87SYuri Pankov 
2220*260e9a87SYuri Pankov 	if (n->end == ENDBODY_NOT &&
2221*260e9a87SYuri Pankov 	    n->parent->head->child == NULL &&
2222*260e9a87SYuri Pankov 	    n->child != NULL &&
2223*260e9a87SYuri Pankov 	    n->child->end != ENDBODY_NOT)
2224*260e9a87SYuri Pankov 		print_text(h, "\\&");
2225*260e9a87SYuri Pankov 	else if (n->end != ENDBODY_NOT ? n->child != NULL :
2226*260e9a87SYuri Pankov 	    n->parent->head->child != NULL && (n->child != NULL ||
2227*260e9a87SYuri Pankov 	    (n->parent->tail != NULL && n->parent->tail->child != NULL)))
2228*260e9a87SYuri Pankov 		h->flags |= HTML_NOSPACE;
2229*260e9a87SYuri Pankov 	return(1);
2230*260e9a87SYuri Pankov }
2231*260e9a87SYuri Pankov 
2232*260e9a87SYuri Pankov static void
2233*260e9a87SYuri Pankov mdoc_eo_post(MDOC_ARGS)
2234*260e9a87SYuri Pankov {
2235*260e9a87SYuri Pankov 	int	 body, tail;
2236*260e9a87SYuri Pankov 
2237*260e9a87SYuri Pankov 	if (n->type != MDOC_BODY)
2238*260e9a87SYuri Pankov 		return;
2239*260e9a87SYuri Pankov 
2240*260e9a87SYuri Pankov 	if (n->end != ENDBODY_NOT) {
2241*260e9a87SYuri Pankov 		h->flags &= ~HTML_NOSPACE;
2242*260e9a87SYuri Pankov 		return;
2243*260e9a87SYuri Pankov 	}
2244*260e9a87SYuri Pankov 
2245*260e9a87SYuri Pankov 	body = n->child != NULL || n->parent->head->child != NULL;
2246*260e9a87SYuri Pankov 	tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
2247*260e9a87SYuri Pankov 
2248*260e9a87SYuri Pankov 	if (body && tail)
2249*260e9a87SYuri Pankov 		h->flags |= HTML_NOSPACE;
2250*260e9a87SYuri Pankov 	else if ( ! tail)
2251*260e9a87SYuri Pankov 		h->flags &= ~HTML_NOSPACE;
2252*260e9a87SYuri Pankov }
2253