]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.306 2018/06/10 16:15:43 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
39 #define MDOC_ARGS const struct roff_meta *meta, \
40 struct roff_node *n, \
44 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
48 int (*pre
)(MDOC_ARGS
);
49 void (*post
)(MDOC_ARGS
);
52 static char *cond_id(const struct roff_node
*);
53 static void print_mdoc_head(const struct roff_meta
*,
55 static void print_mdoc_node(MDOC_ARGS
);
56 static void print_mdoc_nodelist(MDOC_ARGS
);
57 static void synopsis_pre(struct html
*,
58 const struct roff_node
*);
60 static void mdoc_root_post(const struct roff_meta
*,
62 static int mdoc_root_pre(const struct roff_meta
*,
65 static void mdoc__x_post(MDOC_ARGS
);
66 static int mdoc__x_pre(MDOC_ARGS
);
67 static int mdoc_ad_pre(MDOC_ARGS
);
68 static int mdoc_an_pre(MDOC_ARGS
);
69 static int mdoc_ap_pre(MDOC_ARGS
);
70 static int mdoc_ar_pre(MDOC_ARGS
);
71 static int mdoc_bd_pre(MDOC_ARGS
);
72 static int mdoc_bf_pre(MDOC_ARGS
);
73 static void mdoc_bk_post(MDOC_ARGS
);
74 static int mdoc_bk_pre(MDOC_ARGS
);
75 static int mdoc_bl_pre(MDOC_ARGS
);
76 static int mdoc_cd_pre(MDOC_ARGS
);
77 static int mdoc_cm_pre(MDOC_ARGS
);
78 static int mdoc_d1_pre(MDOC_ARGS
);
79 static int mdoc_dv_pre(MDOC_ARGS
);
80 static int mdoc_fa_pre(MDOC_ARGS
);
81 static int mdoc_fd_pre(MDOC_ARGS
);
82 static int mdoc_fl_pre(MDOC_ARGS
);
83 static int mdoc_fn_pre(MDOC_ARGS
);
84 static int mdoc_ft_pre(MDOC_ARGS
);
85 static int mdoc_em_pre(MDOC_ARGS
);
86 static void mdoc_eo_post(MDOC_ARGS
);
87 static int mdoc_eo_pre(MDOC_ARGS
);
88 static int mdoc_er_pre(MDOC_ARGS
);
89 static int mdoc_ev_pre(MDOC_ARGS
);
90 static int mdoc_ex_pre(MDOC_ARGS
);
91 static void mdoc_fo_post(MDOC_ARGS
);
92 static int mdoc_fo_pre(MDOC_ARGS
);
93 static int mdoc_ic_pre(MDOC_ARGS
);
94 static int mdoc_igndelim_pre(MDOC_ARGS
);
95 static int mdoc_in_pre(MDOC_ARGS
);
96 static int mdoc_it_pre(MDOC_ARGS
);
97 static int mdoc_lb_pre(MDOC_ARGS
);
98 static int mdoc_li_pre(MDOC_ARGS
);
99 static int mdoc_lk_pre(MDOC_ARGS
);
100 static int mdoc_mt_pre(MDOC_ARGS
);
101 static int mdoc_ms_pre(MDOC_ARGS
);
102 static int mdoc_nd_pre(MDOC_ARGS
);
103 static int mdoc_nm_pre(MDOC_ARGS
);
104 static int mdoc_no_pre(MDOC_ARGS
);
105 static int mdoc_ns_pre(MDOC_ARGS
);
106 static int mdoc_pa_pre(MDOC_ARGS
);
107 static void mdoc_pf_post(MDOC_ARGS
);
108 static int mdoc_pp_pre(MDOC_ARGS
);
109 static void mdoc_quote_post(MDOC_ARGS
);
110 static int mdoc_quote_pre(MDOC_ARGS
);
111 static int mdoc_rs_pre(MDOC_ARGS
);
112 static int mdoc_sh_pre(MDOC_ARGS
);
113 static int mdoc_skip_pre(MDOC_ARGS
);
114 static int mdoc_sm_pre(MDOC_ARGS
);
115 static int mdoc_ss_pre(MDOC_ARGS
);
116 static int mdoc_st_pre(MDOC_ARGS
);
117 static int mdoc_sx_pre(MDOC_ARGS
);
118 static int mdoc_sy_pre(MDOC_ARGS
);
119 static int mdoc_va_pre(MDOC_ARGS
);
120 static int mdoc_vt_pre(MDOC_ARGS
);
121 static int mdoc_xr_pre(MDOC_ARGS
);
122 static int mdoc_xx_pre(MDOC_ARGS
);
124 static const struct htmlmdoc __mdocs
[MDOC_MAX
- MDOC_Dd
] = {
125 {NULL
, NULL
}, /* Dd */
126 {NULL
, NULL
}, /* Dt */
127 {NULL
, NULL
}, /* Os */
128 {mdoc_sh_pre
, NULL
}, /* Sh */
129 {mdoc_ss_pre
, NULL
}, /* Ss */
130 {mdoc_pp_pre
, NULL
}, /* Pp */
131 {mdoc_d1_pre
, NULL
}, /* D1 */
132 {mdoc_d1_pre
, NULL
}, /* Dl */
133 {mdoc_bd_pre
, NULL
}, /* Bd */
134 {NULL
, NULL
}, /* Ed */
135 {mdoc_bl_pre
, NULL
}, /* Bl */
136 {NULL
, NULL
}, /* El */
137 {mdoc_it_pre
, NULL
}, /* It */
138 {mdoc_ad_pre
, NULL
}, /* Ad */
139 {mdoc_an_pre
, NULL
}, /* An */
140 {mdoc_ap_pre
, NULL
}, /* Ap */
141 {mdoc_ar_pre
, NULL
}, /* Ar */
142 {mdoc_cd_pre
, NULL
}, /* Cd */
143 {mdoc_cm_pre
, NULL
}, /* Cm */
144 {mdoc_dv_pre
, NULL
}, /* Dv */
145 {mdoc_er_pre
, NULL
}, /* Er */
146 {mdoc_ev_pre
, NULL
}, /* Ev */
147 {mdoc_ex_pre
, NULL
}, /* Ex */
148 {mdoc_fa_pre
, NULL
}, /* Fa */
149 {mdoc_fd_pre
, NULL
}, /* Fd */
150 {mdoc_fl_pre
, NULL
}, /* Fl */
151 {mdoc_fn_pre
, NULL
}, /* Fn */
152 {mdoc_ft_pre
, NULL
}, /* Ft */
153 {mdoc_ic_pre
, NULL
}, /* Ic */
154 {mdoc_in_pre
, NULL
}, /* In */
155 {mdoc_li_pre
, NULL
}, /* Li */
156 {mdoc_nd_pre
, NULL
}, /* Nd */
157 {mdoc_nm_pre
, NULL
}, /* Nm */
158 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
159 {mdoc_ft_pre
, NULL
}, /* Ot */
160 {mdoc_pa_pre
, NULL
}, /* Pa */
161 {mdoc_ex_pre
, NULL
}, /* Rv */
162 {mdoc_st_pre
, NULL
}, /* St */
163 {mdoc_va_pre
, NULL
}, /* Va */
164 {mdoc_vt_pre
, NULL
}, /* Vt */
165 {mdoc_xr_pre
, NULL
}, /* Xr */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
175 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
176 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
177 {NULL
, NULL
}, /* Ac */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
180 {mdoc_xx_pre
, NULL
}, /* At */
181 {NULL
, NULL
}, /* Bc */
182 {mdoc_bf_pre
, NULL
}, /* Bf */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
185 {mdoc_xx_pre
, NULL
}, /* Bsx */
186 {mdoc_xx_pre
, NULL
}, /* Bx */
187 {mdoc_skip_pre
, NULL
}, /* Db */
188 {NULL
, NULL
}, /* Dc */
189 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
190 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
191 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
192 {NULL
, NULL
}, /* Ef */
193 {mdoc_em_pre
, NULL
}, /* Em */
194 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
195 {mdoc_xx_pre
, NULL
}, /* Fx */
196 {mdoc_ms_pre
, NULL
}, /* Ms */
197 {mdoc_no_pre
, NULL
}, /* No */
198 {mdoc_ns_pre
, NULL
}, /* Ns */
199 {mdoc_xx_pre
, NULL
}, /* Nx */
200 {mdoc_xx_pre
, NULL
}, /* Ox */
201 {NULL
, NULL
}, /* Pc */
202 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
205 {NULL
, NULL
}, /* Qc */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
209 {NULL
, NULL
}, /* Re */
210 {mdoc_rs_pre
, NULL
}, /* Rs */
211 {NULL
, NULL
}, /* Sc */
212 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
213 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
214 {mdoc_sm_pre
, NULL
}, /* Sm */
215 {mdoc_sx_pre
, NULL
}, /* Sx */
216 {mdoc_sy_pre
, NULL
}, /* Sy */
217 {NULL
, NULL
}, /* Tn */
218 {mdoc_xx_pre
, NULL
}, /* Ux */
219 {NULL
, NULL
}, /* Xc */
220 {NULL
, NULL
}, /* Xo */
221 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
222 {NULL
, NULL
}, /* Fc */
223 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
224 {NULL
, NULL
}, /* Oc */
225 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
226 {NULL
, NULL
}, /* Ek */
227 {NULL
, NULL
}, /* Bt */
228 {NULL
, NULL
}, /* Hf */
229 {mdoc_em_pre
, NULL
}, /* Fr */
230 {NULL
, NULL
}, /* Ud */
231 {mdoc_lb_pre
, NULL
}, /* Lb */
232 {mdoc_pp_pre
, NULL
}, /* Lp */
233 {mdoc_lk_pre
, NULL
}, /* Lk */
234 {mdoc_mt_pre
, NULL
}, /* Mt */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
236 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
237 {NULL
, NULL
}, /* Brc */
238 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
239 {mdoc_skip_pre
, NULL
}, /* Es */
240 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
241 {mdoc_xx_pre
, NULL
}, /* Dx */
242 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
246 static const struct htmlmdoc
*const mdocs
= __mdocs
- MDOC_Dd
;
250 * See the same function in mdoc_term.c for documentation.
253 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
256 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
259 if (n
->prev
->tok
== n
->tok
&&
263 print_otag(h
, TAG_BR
, "");
267 switch (n
->prev
->tok
) {
276 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
282 print_otag(h
, TAG_BR
, "");
288 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
294 h
= (struct html
*)arg
;
295 n
= mdoc
->first
->child
;
297 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
299 print_otag(h
, TAG_HTML
, "");
300 if (n
->type
== ROFFT_COMMENT
)
301 print_gen_comment(h
, n
);
302 t
= print_otag(h
, TAG_HEAD
, "");
303 print_mdoc_head(&mdoc
->meta
, h
);
305 print_otag(h
, TAG_BODY
, "");
308 mdoc_root_pre(&mdoc
->meta
, h
);
309 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
310 print_mdoc_nodelist(&mdoc
->meta
, n
, h
);
312 mdoc_root_post(&mdoc
->meta
, h
);
317 print_mdoc_head(const struct roff_meta
*meta
, struct html
*h
)
323 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
324 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
325 meta
->msec
, meta
->arch
);
326 else if (meta
->msec
!= NULL
)
327 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
328 else if (meta
->arch
!= NULL
)
329 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
331 cp
= mandoc_strdup(meta
->title
);
333 print_otag(h
, TAG_TITLE
, "");
339 print_mdoc_nodelist(MDOC_ARGS
)
343 print_mdoc_node(meta
, n
, h
);
349 print_mdoc_node(MDOC_ARGS
)
354 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
359 n
->flags
&= ~NODE_ENDED
;
363 /* No tables in this mode... */
364 assert(NULL
== h
->tblt
);
367 * Make sure that if we're in a literal mode already
368 * (i.e., within a <PRE>) don't print the newline.
370 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
371 (h
->flags
& (HTML_LITERAL
| HTML_NONEWLINE
)) == 0)
372 print_otag(h
, TAG_BR
, "");
373 if (NODE_DELIMC
& n
->flags
)
374 h
->flags
|= HTML_NOSPACE
;
375 print_text(h
, n
->string
);
376 if (NODE_DELIMO
& n
->flags
)
377 h
->flags
|= HTML_NOSPACE
;
380 print_eqn(h
, n
->eqn
);
384 * This will take care of initialising all of the table
385 * state data for the first table, then tearing it down
388 print_tbl(h
, n
->span
);
392 * Close out the current table, if it's open, and unset
393 * the "meta" table state. This will be reopened on the
394 * next table element.
396 if (h
->tblt
!= NULL
) {
400 assert(h
->tblt
== NULL
);
401 if (n
->tok
< ROFF_MAX
) {
406 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
407 if (mdocs
[n
->tok
].pre
!= NULL
&&
408 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
409 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
413 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
414 h
->flags
&= ~HTML_KEEP
;
415 h
->flags
|= HTML_PREKEEP
;
418 if (child
&& n
->child
)
419 print_mdoc_nodelist(meta
, n
->child
, h
);
427 if (n
->tok
< ROFF_MAX
||
428 mdocs
[n
->tok
].post
== NULL
||
429 n
->flags
& NODE_ENDED
)
431 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
432 if (n
->end
!= ENDBODY_NOT
)
433 n
->body
->flags
|= NODE_ENDED
;
439 mdoc_root_post(const struct roff_meta
*meta
, struct html
*h
)
443 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
444 tt
= print_otag(h
, TAG_TR
, "");
446 print_otag(h
, TAG_TD
, "c", "foot-date");
447 print_text(h
, meta
->date
);
450 print_otag(h
, TAG_TD
, "c", "foot-os");
451 print_text(h
, meta
->os
);
456 mdoc_root_pre(const struct roff_meta
*meta
, struct html
*h
)
459 char *volume
, *title
;
461 if (NULL
== meta
->arch
)
462 volume
= mandoc_strdup(meta
->vol
);
464 mandoc_asprintf(&volume
, "%s (%s)",
465 meta
->vol
, meta
->arch
);
467 if (NULL
== meta
->msec
)
468 title
= mandoc_strdup(meta
->title
);
470 mandoc_asprintf(&title
, "%s(%s)",
471 meta
->title
, meta
->msec
);
473 t
= print_otag(h
, TAG_TABLE
, "c", "head");
474 tt
= print_otag(h
, TAG_TR
, "");
476 print_otag(h
, TAG_TD
, "c", "head-ltitle");
477 print_text(h
, title
);
480 print_otag(h
, TAG_TD
, "c", "head-vol");
481 print_text(h
, volume
);
484 print_otag(h
, TAG_TD
, "c", "head-rtitle");
485 print_text(h
, title
);
494 cond_id(const struct roff_node
*n
)
496 if (n
->child
!= NULL
&&
497 n
->child
->type
== ROFFT_TEXT
&&
499 (n
->prev
->type
== ROFFT_TEXT
&&
500 strcmp(n
->prev
->string
, "|") == 0)) &&
501 (n
->parent
->tok
== MDOC_It
||
502 (n
->parent
->tok
== MDOC_Xo
&&
503 n
->parent
->parent
->prev
== NULL
&&
504 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
505 return html_make_id(n
, 1);
510 mdoc_sh_pre(MDOC_ARGS
)
516 id
= html_make_id(n
, 1);
517 print_otag(h
, TAG_H1
, "cTi", "Sh", id
);
519 print_otag(h
, TAG_A
, "chR", "permalink", id
);
522 if (n
->sec
== SEC_AUTHORS
)
523 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
532 mdoc_ss_pre(MDOC_ARGS
)
536 if (n
->type
!= ROFFT_HEAD
)
539 id
= html_make_id(n
, 1);
540 print_otag(h
, TAG_H2
, "cTi", "Ss", id
);
542 print_otag(h
, TAG_A
, "chR", "permalink", id
);
547 mdoc_fl_pre(MDOC_ARGS
)
551 if ((id
= cond_id(n
)) != NULL
)
552 print_otag(h
, TAG_A
, "chR", "permalink", id
);
553 print_otag(h
, TAG_CODE
, "cTi", "Fl", id
);
555 print_text(h
, "\\-");
556 if (!(n
->child
== NULL
&&
558 n
->next
->type
== ROFFT_TEXT
||
559 n
->next
->flags
& NODE_LINE
)))
560 h
->flags
|= HTML_NOSPACE
;
566 mdoc_cm_pre(MDOC_ARGS
)
570 if ((id
= cond_id(n
)) != NULL
)
571 print_otag(h
, TAG_A
, "chR", "permalink", id
);
572 print_otag(h
, TAG_CODE
, "cTi", "Cm", id
);
577 mdoc_nd_pre(MDOC_ARGS
)
579 if (n
->type
!= ROFFT_BODY
)
582 print_text(h
, "\\(em");
583 /* Cannot use TAG_SPAN because it may contain blocks. */
584 print_otag(h
, TAG_DIV
, "cT", "Nd");
589 mdoc_nm_pre(MDOC_ARGS
)
593 print_otag(h
, TAG_TD
, "");
596 print_otag(h
, TAG_CODE
, "cT", "Nm");
599 print_otag(h
, TAG_TD
, "");
605 print_otag(h
, TAG_TABLE
, "c", "Nm");
606 print_otag(h
, TAG_TR
, "");
611 mdoc_xr_pre(MDOC_ARGS
)
613 if (NULL
== n
->child
)
617 print_otag(h
, TAG_A
, "cThM", "Xr",
618 n
->child
->string
, n
->child
->next
== NULL
?
619 NULL
: n
->child
->next
->string
);
621 print_otag(h
, TAG_A
, "cT", "Xr");
624 print_text(h
, n
->string
);
626 if (NULL
== (n
= n
->next
))
629 h
->flags
|= HTML_NOSPACE
;
631 h
->flags
|= HTML_NOSPACE
;
632 print_text(h
, n
->string
);
633 h
->flags
|= HTML_NOSPACE
;
639 mdoc_ns_pre(MDOC_ARGS
)
642 if ( ! (NODE_LINE
& n
->flags
))
643 h
->flags
|= HTML_NOSPACE
;
648 mdoc_ar_pre(MDOC_ARGS
)
650 print_otag(h
, TAG_VAR
, "cT", "Ar");
655 mdoc_xx_pre(MDOC_ARGS
)
657 print_otag(h
, TAG_SPAN
, "c", "Ux");
662 mdoc_it_pre(MDOC_ARGS
)
664 const struct roff_node
*bl
;
669 while (bl
->tok
!= MDOC_Bl
)
671 type
= bl
->norm
->Bl
.type
;
683 print_otag(h
, TAG_LI
, "");
695 print_otag(h
, TAG_DT
, "");
698 print_otag(h
, TAG_DD
, "");
707 if (h
->style
!= NULL
&& !bl
->norm
->Bl
.comp
&&
708 (n
->parent
->prev
== NULL
||
709 n
->parent
->prev
->body
== NULL
||
710 n
->parent
->prev
->body
->child
!= NULL
)) {
711 t
= print_otag(h
, TAG_DT
, "");
712 print_text(h
, "\\ ");
714 t
= print_otag(h
, TAG_DD
, "");
715 print_text(h
, "\\ ");
718 print_otag(h
, TAG_DT
, "");
721 if (n
->child
== NULL
) {
722 print_otag(h
, TAG_DD
, "ss?",
724 print_text(h
, "\\ ");
726 print_otag(h
, TAG_DD
, "");
737 print_otag(h
, TAG_TD
, "");
740 print_otag(h
, TAG_TR
, "");
750 mdoc_bl_pre(MDOC_ARGS
)
756 enum htmltag elemtype
;
765 if (bl
->type
!= LIST_column
|| bl
->ncols
== 0)
769 * For each column, print out the <COL> tag with our
770 * suggested width. The last column gets min-width, as
771 * in terminal mode it auto-sizes to the width of the
772 * screen and we want to preserve that behaviour.
775 t
= print_otag(h
, TAG_COLGROUP
, "");
776 for (i
= 0; i
< bl
->ncols
- 1; i
++)
777 print_otag(h
, TAG_COL
, "sw+w", bl
->cols
[i
]);
778 print_otag(h
, TAG_COL
, "swW", bl
->cols
[i
]);
789 (void)strlcpy(cattr
, "Bl-bullet", sizeof(cattr
));
794 (void)strlcpy(cattr
, "Bl-dash", sizeof(cattr
));
798 (void)strlcpy(cattr
, "Bl-item", sizeof(cattr
));
802 (void)strlcpy(cattr
, "Bl-enum", sizeof(cattr
));
806 (void)strlcpy(cattr
, "Bl-diag", sizeof(cattr
));
810 (void)strlcpy(cattr
, "Bl-hang", sizeof(cattr
));
814 (void)strlcpy(cattr
, "Bl-inset", sizeof(cattr
));
818 (void)strlcpy(cattr
, "Bl-ohang", sizeof(cattr
));
822 print_otag(h
, TAG_DIV
, "c", "Bd-indent");
823 print_otag(h
, TAG_DL
, "c", bl
->comp
?
824 "Bl-tag Bl-compact" : "Bl-tag");
827 elemtype
= TAG_TABLE
;
828 (void)strlcpy(cattr
, "Bl-column", sizeof(cattr
));
833 if (bl
->offs
!= NULL
)
834 (void)strlcat(cattr
, " Bd-indent", sizeof(cattr
));
836 (void)strlcat(cattr
, " Bl-compact", sizeof(cattr
));
837 print_otag(h
, elemtype
, "c", cattr
);
842 mdoc_ex_pre(MDOC_ARGS
)
845 print_otag(h
, TAG_BR
, "");
850 mdoc_st_pre(MDOC_ARGS
)
852 print_otag(h
, TAG_SPAN
, "cT", "St");
857 mdoc_em_pre(MDOC_ARGS
)
859 print_otag(h
, TAG_I
, "cT", "Em");
864 mdoc_d1_pre(MDOC_ARGS
)
866 if (n
->type
!= ROFFT_BLOCK
)
869 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
871 if (n
->tok
== MDOC_Dl
)
872 print_otag(h
, TAG_CODE
, "c", "Li");
878 mdoc_sx_pre(MDOC_ARGS
)
882 id
= html_make_id(n
, 0);
883 print_otag(h
, TAG_A
, "cThR", "Sx", id
);
889 mdoc_bd_pre(MDOC_ARGS
)
892 struct roff_node
*nn
;
894 if (n
->type
== ROFFT_HEAD
)
897 if (n
->type
== ROFFT_BLOCK
) {
898 comp
= n
->norm
->Bd
.comp
;
899 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
900 if (nn
->type
!= ROFFT_BLOCK
)
902 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
912 /* Handle the -offset argument. */
914 if (n
->norm
->Bd
.offs
== NULL
||
915 ! strcmp(n
->norm
->Bd
.offs
, "left"))
916 print_otag(h
, TAG_DIV
, "c", "Bd");
918 print_otag(h
, TAG_DIV
, "c", "Bd Bd-indent");
920 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
921 n
->norm
->Bd
.type
!= DISP_literal
)
924 print_otag(h
, TAG_PRE
, "c", "Li");
926 /* This can be recursive: save & set our literal state. */
928 sv
= h
->flags
& HTML_LITERAL
;
929 h
->flags
|= HTML_LITERAL
;
931 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
932 print_mdoc_node(meta
, nn
, h
);
934 * If the printed node flushes its own line, then we
935 * needn't do it here as well. This is hacky, but the
936 * notion of selective eoln whitespace is pretty dumb
937 * anyway, so don't sweat it.
952 if (h
->flags
& HTML_NONEWLINE
||
953 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
958 h
->flags
|= HTML_NOSPACE
;
962 h
->flags
&= ~HTML_LITERAL
;
968 mdoc_pa_pre(MDOC_ARGS
)
970 print_otag(h
, TAG_SPAN
, "cT", "Pa");
975 mdoc_ad_pre(MDOC_ARGS
)
977 print_otag(h
, TAG_SPAN
, "c", "Ad");
982 mdoc_an_pre(MDOC_ARGS
)
984 if (n
->norm
->An
.auth
== AUTH_split
) {
985 h
->flags
&= ~HTML_NOSPLIT
;
986 h
->flags
|= HTML_SPLIT
;
989 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
990 h
->flags
&= ~HTML_SPLIT
;
991 h
->flags
|= HTML_NOSPLIT
;
995 if (h
->flags
& HTML_SPLIT
)
996 print_otag(h
, TAG_BR
, "");
998 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
999 h
->flags
|= HTML_SPLIT
;
1001 print_otag(h
, TAG_SPAN
, "cT", "An");
1006 mdoc_cd_pre(MDOC_ARGS
)
1009 print_otag(h
, TAG_CODE
, "cT", "Cd");
1014 mdoc_dv_pre(MDOC_ARGS
)
1018 if ((id
= cond_id(n
)) != NULL
)
1019 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1020 print_otag(h
, TAG_CODE
, "cTi", "Dv", id
);
1025 mdoc_ev_pre(MDOC_ARGS
)
1029 if ((id
= cond_id(n
)) != NULL
)
1030 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1031 print_otag(h
, TAG_CODE
, "cTi", "Ev", id
);
1036 mdoc_er_pre(MDOC_ARGS
)
1040 id
= n
->sec
== SEC_ERRORS
&&
1041 (n
->parent
->tok
== MDOC_It
||
1042 (n
->parent
->tok
== MDOC_Bq
&&
1043 n
->parent
->parent
->parent
->tok
== MDOC_It
)) ?
1044 html_make_id(n
, 1) : NULL
;
1047 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1048 print_otag(h
, TAG_CODE
, "cTi", "Er", id
);
1053 mdoc_fa_pre(MDOC_ARGS
)
1055 const struct roff_node
*nn
;
1058 if (n
->parent
->tok
!= MDOC_Fo
) {
1059 print_otag(h
, TAG_VAR
, "cT", "Fa");
1063 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1064 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1065 print_text(h
, nn
->string
);
1068 h
->flags
|= HTML_NOSPACE
;
1073 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1074 h
->flags
|= HTML_NOSPACE
;
1082 mdoc_fd_pre(MDOC_ARGS
)
1089 if (NULL
== (n
= n
->child
))
1092 assert(n
->type
== ROFFT_TEXT
);
1094 if (strcmp(n
->string
, "#include")) {
1095 print_otag(h
, TAG_CODE
, "cT", "Fd");
1099 print_otag(h
, TAG_CODE
, "cT", "In");
1100 print_text(h
, n
->string
);
1102 if (NULL
!= (n
= n
->next
)) {
1103 assert(n
->type
== ROFFT_TEXT
);
1105 if (h
->base_includes
) {
1107 if (*cp
== '<' || *cp
== '"')
1109 buf
= mandoc_strdup(cp
);
1110 cp
= strchr(buf
, '\0') - 1;
1111 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1113 t
= print_otag(h
, TAG_A
, "cThI", "In", buf
);
1116 t
= print_otag(h
, TAG_A
, "cT", "In");
1118 print_text(h
, n
->string
);
1124 for ( ; n
; n
= n
->next
) {
1125 assert(n
->type
== ROFFT_TEXT
);
1126 print_text(h
, n
->string
);
1133 mdoc_vt_pre(MDOC_ARGS
)
1135 if (n
->type
== ROFFT_BLOCK
) {
1138 } else if (n
->type
== ROFFT_ELEM
) {
1140 } else if (n
->type
== ROFFT_HEAD
)
1143 print_otag(h
, TAG_VAR
, "cT", "Vt");
1148 mdoc_ft_pre(MDOC_ARGS
)
1151 print_otag(h
, TAG_VAR
, "cT", "Ft");
1156 mdoc_fn_pre(MDOC_ARGS
)
1160 const char *sp
, *ep
;
1163 pretty
= NODE_SYNPRETTY
& n
->flags
;
1166 /* Split apart into type and name. */
1167 assert(n
->child
->string
);
1168 sp
= n
->child
->string
;
1170 ep
= strchr(sp
, ' ');
1172 t
= print_otag(h
, TAG_VAR
, "cT", "Ft");
1175 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1176 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1178 print_text(h
, nbuf
);
1180 ep
= strchr(sp
, ' ');
1185 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1192 h
->flags
|= HTML_NOSPACE
;
1194 h
->flags
|= HTML_NOSPACE
;
1196 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1197 if (NODE_SYNPRETTY
& n
->flags
)
1198 t
= print_otag(h
, TAG_VAR
, "cTss?", "Fa",
1199 "white-space", "nowrap");
1201 t
= print_otag(h
, TAG_VAR
, "cT", "Fa");
1202 print_text(h
, n
->string
);
1205 h
->flags
|= HTML_NOSPACE
;
1210 h
->flags
|= HTML_NOSPACE
;
1214 h
->flags
|= HTML_NOSPACE
;
1222 mdoc_sm_pre(MDOC_ARGS
)
1225 if (NULL
== n
->child
)
1226 h
->flags
^= HTML_NONOSPACE
;
1227 else if (0 == strcmp("on", n
->child
->string
))
1228 h
->flags
&= ~HTML_NONOSPACE
;
1230 h
->flags
|= HTML_NONOSPACE
;
1232 if ( ! (HTML_NONOSPACE
& h
->flags
))
1233 h
->flags
&= ~HTML_NOSPACE
;
1239 mdoc_skip_pre(MDOC_ARGS
)
1246 mdoc_pp_pre(MDOC_ARGS
)
1254 mdoc_lk_pre(MDOC_ARGS
)
1256 const struct roff_node
*link
, *descr
, *punct
;
1259 if ((link
= n
->child
) == NULL
)
1262 /* Find beginning of trailing punctuation. */
1264 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1265 punct
= punct
->prev
;
1266 punct
= punct
->next
;
1268 /* Link target and link text. */
1271 descr
= link
; /* no text */
1272 t
= print_otag(h
, TAG_A
, "cTh", "Lk", link
->string
);
1274 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1275 h
->flags
|= HTML_NOSPACE
;
1276 print_text(h
, descr
->string
);
1277 descr
= descr
->next
;
1278 } while (descr
!= punct
);
1281 /* Trailing punctuation. */
1282 while (punct
!= NULL
) {
1283 h
->flags
|= HTML_NOSPACE
;
1284 print_text(h
, punct
->string
);
1285 punct
= punct
->next
;
1291 mdoc_mt_pre(MDOC_ARGS
)
1296 for (n
= n
->child
; n
; n
= n
->next
) {
1297 assert(n
->type
== ROFFT_TEXT
);
1299 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1300 t
= print_otag(h
, TAG_A
, "cTh", "Mt", cp
);
1301 print_text(h
, n
->string
);
1310 mdoc_fo_pre(MDOC_ARGS
)
1314 if (n
->type
== ROFFT_BODY
) {
1315 h
->flags
|= HTML_NOSPACE
;
1317 h
->flags
|= HTML_NOSPACE
;
1319 } else if (n
->type
== ROFFT_BLOCK
) {
1324 if (n
->child
== NULL
)
1327 assert(n
->child
->string
);
1328 t
= print_otag(h
, TAG_CODE
, "cT", "Fn");
1329 print_text(h
, n
->child
->string
);
1335 mdoc_fo_post(MDOC_ARGS
)
1338 if (n
->type
!= ROFFT_BODY
)
1340 h
->flags
|= HTML_NOSPACE
;
1342 h
->flags
|= HTML_NOSPACE
;
1347 mdoc_in_pre(MDOC_ARGS
)
1352 print_otag(h
, TAG_CODE
, "cT", "In");
1355 * The first argument of the `In' gets special treatment as
1356 * being a linked value. Subsequent values are printed
1357 * afterward. groff does similarly. This also handles the case
1361 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1362 print_text(h
, "#include");
1365 h
->flags
|= HTML_NOSPACE
;
1367 if (NULL
!= (n
= n
->child
)) {
1368 assert(n
->type
== ROFFT_TEXT
);
1370 if (h
->base_includes
)
1371 t
= print_otag(h
, TAG_A
, "cThI", "In", n
->string
);
1373 t
= print_otag(h
, TAG_A
, "cT", "In");
1374 print_text(h
, n
->string
);
1380 h
->flags
|= HTML_NOSPACE
;
1383 for ( ; n
; n
= n
->next
) {
1384 assert(n
->type
== ROFFT_TEXT
);
1385 print_text(h
, n
->string
);
1392 mdoc_ic_pre(MDOC_ARGS
)
1396 if ((id
= cond_id(n
)) != NULL
)
1397 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1398 print_otag(h
, TAG_CODE
, "cTi", "Ic", id
);
1403 mdoc_va_pre(MDOC_ARGS
)
1405 print_otag(h
, TAG_VAR
, "cT", "Va");
1410 mdoc_ap_pre(MDOC_ARGS
)
1413 h
->flags
|= HTML_NOSPACE
;
1414 print_text(h
, "\\(aq");
1415 h
->flags
|= HTML_NOSPACE
;
1420 mdoc_bf_pre(MDOC_ARGS
)
1424 if (n
->type
== ROFFT_HEAD
)
1426 else if (n
->type
!= ROFFT_BODY
)
1429 if (FONT_Em
== n
->norm
->Bf
.font
)
1431 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1433 else if (FONT_Li
== n
->norm
->Bf
.font
)
1438 /* Cannot use TAG_SPAN because it may contain blocks. */
1439 print_otag(h
, TAG_DIV
, "cshl", cattr
, 1);
1444 mdoc_ms_pre(MDOC_ARGS
)
1448 if ((id
= cond_id(n
)) != NULL
)
1449 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1450 print_otag(h
, TAG_SPAN
, "cTi", "Ms", id
);
1455 mdoc_igndelim_pre(MDOC_ARGS
)
1458 h
->flags
|= HTML_IGNDELIM
;
1463 mdoc_pf_post(MDOC_ARGS
)
1466 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1467 h
->flags
|= HTML_NOSPACE
;
1471 mdoc_rs_pre(MDOC_ARGS
)
1473 if (n
->type
!= ROFFT_BLOCK
)
1476 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1479 print_otag(h
, TAG_CITE
, "cT", "Rs");
1484 mdoc_no_pre(MDOC_ARGS
)
1488 if ((id
= cond_id(n
)) != NULL
)
1489 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1490 print_otag(h
, TAG_SPAN
, "ci", "No", id
);
1495 mdoc_li_pre(MDOC_ARGS
)
1499 if ((id
= cond_id(n
)) != NULL
)
1500 print_otag(h
, TAG_A
, "chR", "permalink", id
);
1501 print_otag(h
, TAG_CODE
, "ci", "Li", id
);
1506 mdoc_sy_pre(MDOC_ARGS
)
1508 print_otag(h
, TAG_B
, "cT", "Sy");
1513 mdoc_lb_pre(MDOC_ARGS
)
1515 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1516 print_otag(h
, TAG_BR
, "");
1518 print_otag(h
, TAG_SPAN
, "cT", "Lb");
1523 mdoc__x_pre(MDOC_ARGS
)
1533 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1534 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1535 print_text(h
, "and");
1574 print_otag(h
, TAG_A
, "ch", "RsU", n
->child
->string
);
1583 print_otag(h
, t
, "c", cattr
);
1588 mdoc__x_post(MDOC_ARGS
)
1591 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1592 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1593 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1598 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1601 h
->flags
|= HTML_NOSPACE
;
1602 print_text(h
, n
->next
? "," : ".");
1606 mdoc_bk_pre(MDOC_ARGS
)
1615 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1616 h
->flags
|= HTML_PREKEEP
;
1626 mdoc_bk_post(MDOC_ARGS
)
1629 if (n
->type
== ROFFT_BODY
)
1630 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1634 mdoc_quote_pre(MDOC_ARGS
)
1636 if (n
->type
!= ROFFT_BODY
)
1642 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1643 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1647 print_text(h
, "\\(lC");
1651 print_text(h
, "\\(lB");
1655 print_text(h
, "\\(lB");
1656 h
->flags
|= HTML_NOSPACE
;
1657 /* Cannot use TAG_SPAN because it may contain blocks. */
1658 print_otag(h
, TAG_IDIV
, "c", "Op");
1661 if (NULL
== n
->norm
->Es
||
1662 NULL
== n
->norm
->Es
->child
)
1664 print_text(h
, n
->norm
->Es
->child
->string
);
1670 print_text(h
, "\\(lq");
1677 print_text(h
, "\\(oq");
1678 h
->flags
|= HTML_NOSPACE
;
1679 print_otag(h
, TAG_CODE
, "c", "Li");
1683 print_text(h
, "\\(oq");
1689 h
->flags
|= HTML_NOSPACE
;
1694 mdoc_quote_post(MDOC_ARGS
)
1697 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1700 h
->flags
|= HTML_NOSPACE
;
1705 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1706 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1710 print_text(h
, "\\(rC");
1716 print_text(h
, "\\(rB");
1719 if (n
->norm
->Es
== NULL
||
1720 n
->norm
->Es
->child
== NULL
||
1721 n
->norm
->Es
->child
->next
== NULL
)
1722 h
->flags
&= ~HTML_NOSPACE
;
1724 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1730 print_text(h
, "\\(rq");
1739 print_text(h
, "\\(cq");
1747 mdoc_eo_pre(MDOC_ARGS
)
1750 if (n
->type
!= ROFFT_BODY
)
1753 if (n
->end
== ENDBODY_NOT
&&
1754 n
->parent
->head
->child
== NULL
&&
1756 n
->child
->end
!= ENDBODY_NOT
)
1757 print_text(h
, "\\&");
1758 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1759 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1760 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1761 h
->flags
|= HTML_NOSPACE
;
1766 mdoc_eo_post(MDOC_ARGS
)
1770 if (n
->type
!= ROFFT_BODY
)
1773 if (n
->end
!= ENDBODY_NOT
) {
1774 h
->flags
&= ~HTML_NOSPACE
;
1778 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1779 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1782 h
->flags
|= HTML_NOSPACE
;
1784 h
->flags
&= ~HTML_NOSPACE
;