]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.253 2017/01/19 15:27:34 schwarze Exp $ */
3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2016, 2017 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"
38 #define MDOC_ARGS const struct roff_meta *meta, \
39 struct roff_node *n, \
43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
47 int (*pre
)(MDOC_ARGS
);
48 void (*post
)(MDOC_ARGS
);
51 static void print_mdoc_head(MDOC_ARGS
);
52 static void print_mdoc_node(MDOC_ARGS
);
53 static void print_mdoc_nodelist(MDOC_ARGS
);
54 static void synopsis_pre(struct html
*,
55 const struct roff_node
*);
57 static void mdoc_root_post(MDOC_ARGS
);
58 static int mdoc_root_pre(MDOC_ARGS
);
60 static void mdoc__x_post(MDOC_ARGS
);
61 static int mdoc__x_pre(MDOC_ARGS
);
62 static int mdoc_ad_pre(MDOC_ARGS
);
63 static int mdoc_an_pre(MDOC_ARGS
);
64 static int mdoc_ap_pre(MDOC_ARGS
);
65 static int mdoc_ar_pre(MDOC_ARGS
);
66 static int mdoc_bd_pre(MDOC_ARGS
);
67 static int mdoc_bf_pre(MDOC_ARGS
);
68 static void mdoc_bk_post(MDOC_ARGS
);
69 static int mdoc_bk_pre(MDOC_ARGS
);
70 static int mdoc_bl_pre(MDOC_ARGS
);
71 static int mdoc_cd_pre(MDOC_ARGS
);
72 static int mdoc_d1_pre(MDOC_ARGS
);
73 static int mdoc_dv_pre(MDOC_ARGS
);
74 static int mdoc_fa_pre(MDOC_ARGS
);
75 static int mdoc_fd_pre(MDOC_ARGS
);
76 static int mdoc_fl_pre(MDOC_ARGS
);
77 static int mdoc_fn_pre(MDOC_ARGS
);
78 static int mdoc_ft_pre(MDOC_ARGS
);
79 static int mdoc_em_pre(MDOC_ARGS
);
80 static void mdoc_eo_post(MDOC_ARGS
);
81 static int mdoc_eo_pre(MDOC_ARGS
);
82 static int mdoc_er_pre(MDOC_ARGS
);
83 static int mdoc_ev_pre(MDOC_ARGS
);
84 static int mdoc_ex_pre(MDOC_ARGS
);
85 static void mdoc_fo_post(MDOC_ARGS
);
86 static int mdoc_fo_pre(MDOC_ARGS
);
87 static int mdoc_ic_pre(MDOC_ARGS
);
88 static int mdoc_igndelim_pre(MDOC_ARGS
);
89 static int mdoc_in_pre(MDOC_ARGS
);
90 static int mdoc_it_pre(MDOC_ARGS
);
91 static int mdoc_lb_pre(MDOC_ARGS
);
92 static int mdoc_li_pre(MDOC_ARGS
);
93 static int mdoc_lk_pre(MDOC_ARGS
);
94 static int mdoc_mt_pre(MDOC_ARGS
);
95 static int mdoc_ms_pre(MDOC_ARGS
);
96 static int mdoc_nd_pre(MDOC_ARGS
);
97 static int mdoc_nm_pre(MDOC_ARGS
);
98 static int mdoc_no_pre(MDOC_ARGS
);
99 static int mdoc_ns_pre(MDOC_ARGS
);
100 static int mdoc_pa_pre(MDOC_ARGS
);
101 static void mdoc_pf_post(MDOC_ARGS
);
102 static int mdoc_pp_pre(MDOC_ARGS
);
103 static void mdoc_quote_post(MDOC_ARGS
);
104 static int mdoc_quote_pre(MDOC_ARGS
);
105 static int mdoc_rs_pre(MDOC_ARGS
);
106 static int mdoc_sh_pre(MDOC_ARGS
);
107 static int mdoc_skip_pre(MDOC_ARGS
);
108 static int mdoc_sm_pre(MDOC_ARGS
);
109 static int mdoc_sp_pre(MDOC_ARGS
);
110 static int mdoc_ss_pre(MDOC_ARGS
);
111 static int mdoc_sx_pre(MDOC_ARGS
);
112 static int mdoc_sy_pre(MDOC_ARGS
);
113 static int mdoc_va_pre(MDOC_ARGS
);
114 static int mdoc_vt_pre(MDOC_ARGS
);
115 static int mdoc_xr_pre(MDOC_ARGS
);
116 static int mdoc_xx_pre(MDOC_ARGS
);
118 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
119 {mdoc_ap_pre
, NULL
}, /* Ap */
120 {NULL
, NULL
}, /* Dd */
121 {NULL
, NULL
}, /* Dt */
122 {NULL
, NULL
}, /* Os */
123 {mdoc_sh_pre
, NULL
}, /* Sh */
124 {mdoc_ss_pre
, NULL
}, /* Ss */
125 {mdoc_pp_pre
, NULL
}, /* Pp */
126 {mdoc_d1_pre
, NULL
}, /* D1 */
127 {mdoc_d1_pre
, NULL
}, /* Dl */
128 {mdoc_bd_pre
, NULL
}, /* Bd */
129 {NULL
, NULL
}, /* Ed */
130 {mdoc_bl_pre
, NULL
}, /* Bl */
131 {NULL
, NULL
}, /* El */
132 {mdoc_it_pre
, NULL
}, /* It */
133 {mdoc_ad_pre
, NULL
}, /* Ad */
134 {mdoc_an_pre
, NULL
}, /* An */
135 {mdoc_ar_pre
, NULL
}, /* Ar */
136 {mdoc_cd_pre
, NULL
}, /* Cd */
137 {mdoc_fl_pre
, NULL
}, /* Cm */
138 {mdoc_dv_pre
, NULL
}, /* Dv */
139 {mdoc_er_pre
, NULL
}, /* Er */
140 {mdoc_ev_pre
, NULL
}, /* Ev */
141 {mdoc_ex_pre
, NULL
}, /* Ex */
142 {mdoc_fa_pre
, NULL
}, /* Fa */
143 {mdoc_fd_pre
, NULL
}, /* Fd */
144 {mdoc_fl_pre
, NULL
}, /* Fl */
145 {mdoc_fn_pre
, NULL
}, /* Fn */
146 {mdoc_ft_pre
, NULL
}, /* Ft */
147 {mdoc_ic_pre
, NULL
}, /* Ic */
148 {mdoc_in_pre
, NULL
}, /* In */
149 {mdoc_li_pre
, NULL
}, /* Li */
150 {mdoc_nd_pre
, NULL
}, /* Nd */
151 {mdoc_nm_pre
, NULL
}, /* Nm */
152 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
153 {mdoc_ft_pre
, NULL
}, /* Ot */
154 {mdoc_pa_pre
, NULL
}, /* Pa */
155 {mdoc_ex_pre
, NULL
}, /* Rv */
156 {NULL
, NULL
}, /* St */
157 {mdoc_va_pre
, NULL
}, /* Va */
158 {mdoc_vt_pre
, NULL
}, /* Vt */
159 {mdoc_xr_pre
, NULL
}, /* Xr */
160 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
161 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
162 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
163 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
171 {NULL
, NULL
}, /* Ac */
172 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
173 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
174 {NULL
, NULL
}, /* At */
175 {NULL
, NULL
}, /* Bc */
176 {mdoc_bf_pre
, NULL
}, /* Bf */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
179 {mdoc_xx_pre
, NULL
}, /* Bsx */
180 {mdoc_xx_pre
, NULL
}, /* Bx */
181 {mdoc_skip_pre
, NULL
}, /* Db */
182 {NULL
, NULL
}, /* Dc */
183 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
185 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
186 {NULL
, NULL
}, /* Ef */
187 {mdoc_em_pre
, NULL
}, /* Em */
188 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
189 {mdoc_xx_pre
, NULL
}, /* Fx */
190 {mdoc_ms_pre
, NULL
}, /* Ms */
191 {mdoc_no_pre
, NULL
}, /* No */
192 {mdoc_ns_pre
, NULL
}, /* Ns */
193 {mdoc_xx_pre
, NULL
}, /* Nx */
194 {mdoc_xx_pre
, NULL
}, /* Ox */
195 {NULL
, NULL
}, /* Pc */
196 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
197 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
198 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
199 {NULL
, NULL
}, /* Qc */
200 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
203 {NULL
, NULL
}, /* Re */
204 {mdoc_rs_pre
, NULL
}, /* Rs */
205 {NULL
, NULL
}, /* Sc */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
208 {mdoc_sm_pre
, NULL
}, /* Sm */
209 {mdoc_sx_pre
, NULL
}, /* Sx */
210 {mdoc_sy_pre
, NULL
}, /* Sy */
211 {NULL
, NULL
}, /* Tn */
212 {mdoc_xx_pre
, NULL
}, /* Ux */
213 {NULL
, NULL
}, /* Xc */
214 {NULL
, NULL
}, /* Xo */
215 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
216 {NULL
, NULL
}, /* Fc */
217 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
218 {NULL
, NULL
}, /* Oc */
219 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
220 {NULL
, NULL
}, /* Ek */
221 {NULL
, NULL
}, /* Bt */
222 {NULL
, NULL
}, /* Hf */
223 {mdoc_em_pre
, NULL
}, /* Fr */
224 {NULL
, NULL
}, /* Ud */
225 {mdoc_lb_pre
, NULL
}, /* Lb */
226 {mdoc_pp_pre
, NULL
}, /* Lp */
227 {mdoc_lk_pre
, NULL
}, /* Lk */
228 {mdoc_mt_pre
, NULL
}, /* Mt */
229 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
230 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
231 {NULL
, NULL
}, /* Brc */
232 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
233 {mdoc_skip_pre
, NULL
}, /* Es */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
235 {mdoc_xx_pre
, NULL
}, /* Dx */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
237 {mdoc_sp_pre
, NULL
}, /* br */
238 {mdoc_sp_pre
, NULL
}, /* sp */
239 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
240 {NULL
, NULL
}, /* Ta */
241 {mdoc_skip_pre
, NULL
}, /* ll */
244 static const char * const lists
[LIST_MAX
] = {
261 * See the same function in mdoc_term.c for documentation.
264 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
267 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
270 if (n
->prev
->tok
== n
->tok
&&
274 print_otag(h
, TAG_BR
, "");
278 switch (n
->prev
->tok
) {
287 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
293 print_otag(h
, TAG_BR
, "");
299 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
304 h
= (struct html
*)arg
;
306 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
308 print_otag(h
, TAG_HTML
, "");
309 t
= print_otag(h
, TAG_HEAD
, "");
310 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
312 print_otag(h
, TAG_BODY
, "");
315 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
316 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
317 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
319 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
324 print_mdoc_head(MDOC_ARGS
)
330 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
331 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
332 meta
->msec
, meta
->arch
);
333 else if (meta
->msec
!= NULL
)
334 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
335 else if (meta
->arch
!= NULL
)
336 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
338 cp
= mandoc_strdup(meta
->title
);
340 print_otag(h
, TAG_TITLE
, "");
346 print_mdoc_nodelist(MDOC_ARGS
)
350 print_mdoc_node(meta
, n
, h
);
356 print_mdoc_node(MDOC_ARGS
)
361 if (n
->flags
& NODE_NOPRT
)
366 n
->flags
&= ~NODE_ENDED
;
370 /* No tables in this mode... */
371 assert(NULL
== h
->tblt
);
374 * Make sure that if we're in a literal mode already
375 * (i.e., within a <PRE>) don't print the newline.
377 if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
378 if ( ! (HTML_LITERAL
& h
->flags
))
379 print_otag(h
, TAG_BR
, "");
380 if (NODE_DELIMC
& n
->flags
)
381 h
->flags
|= HTML_NOSPACE
;
382 print_text(h
, n
->string
);
383 if (NODE_DELIMO
& n
->flags
)
384 h
->flags
|= HTML_NOSPACE
;
387 print_eqn(h
, n
->eqn
);
391 * This will take care of initialising all of the table
392 * state data for the first table, then tearing it down
395 print_tbl(h
, n
->span
);
399 * Close out the current table, if it's open, and unset
400 * the "meta" table state. This will be reopened on the
401 * next table element.
403 if (h
->tblt
!= NULL
) {
407 assert(h
->tblt
== NULL
);
408 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
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 ( ! mdocs
[n
->tok
].post
|| n
->flags
& NODE_ENDED
)
429 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
430 if (n
->end
!= ENDBODY_NOT
)
431 n
->body
->flags
|= NODE_ENDED
;
432 if (n
->end
== ENDBODY_NOSPACE
)
433 h
->flags
|= HTML_NOSPACE
;
439 mdoc_root_post(MDOC_ARGS
)
443 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
444 print_otag(h
, TAG_TBODY
, "");
445 tt
= print_otag(h
, TAG_TR
, "");
447 print_otag(h
, TAG_TD
, "c", "foot-date");
448 print_text(h
, meta
->date
);
451 print_otag(h
, TAG_TD
, "c", "foot-os");
452 print_text(h
, meta
->os
);
457 mdoc_root_pre(MDOC_ARGS
)
460 char *volume
, *title
;
462 if (NULL
== meta
->arch
)
463 volume
= mandoc_strdup(meta
->vol
);
465 mandoc_asprintf(&volume
, "%s (%s)",
466 meta
->vol
, meta
->arch
);
468 if (NULL
== meta
->msec
)
469 title
= mandoc_strdup(meta
->title
);
471 mandoc_asprintf(&title
, "%s(%s)",
472 meta
->title
, meta
->msec
);
474 t
= print_otag(h
, TAG_TABLE
, "c", "head");
475 print_otag(h
, TAG_TBODY
, "");
476 tt
= print_otag(h
, TAG_TR
, "");
478 print_otag(h
, TAG_TD
, "c", "head-ltitle");
479 print_text(h
, title
);
482 print_otag(h
, TAG_TD
, "c", "head-vol");
483 print_text(h
, volume
);
486 print_otag(h
, TAG_TD
, "c", "head-rtitle");
487 print_text(h
, title
);
496 make_id(const struct roff_node
*n
)
498 const struct roff_node
*nch
;
501 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
)
502 if (nch
->type
!= ROFFT_TEXT
)
508 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
510 for (cp
= buf
; *cp
!= '\0'; cp
++)
518 mdoc_sh_pre(MDOC_ARGS
)
526 if (n
->sec
== SEC_AUTHORS
)
527 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
533 if ((id
= make_id(n
)) != NULL
) {
534 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
537 print_otag(h
, TAG_H1
, "c", "Sh");
543 mdoc_ss_pre(MDOC_ARGS
)
547 if (n
->type
!= ROFFT_HEAD
)
550 if ((id
= make_id(n
)) != NULL
) {
551 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
554 print_otag(h
, TAG_H2
, "c", "Ss");
560 mdoc_fl_pre(MDOC_ARGS
)
562 print_otag(h
, TAG_B
, "c", "flag");
564 /* `Cm' has no leading hyphen. */
566 if (MDOC_Cm
== n
->tok
)
569 print_text(h
, "\\-");
571 if (!(n
->child
== NULL
&&
573 n
->next
->type
== ROFFT_TEXT
||
574 n
->next
->flags
& NODE_LINE
)))
575 h
->flags
|= HTML_NOSPACE
;
581 mdoc_nd_pre(MDOC_ARGS
)
583 if (n
->type
!= ROFFT_BODY
)
586 /* XXX: this tag in theory can contain block elements. */
588 print_text(h
, "\\(em");
589 print_otag(h
, TAG_SPAN
, "c", "desc");
594 mdoc_nm_pre(MDOC_ARGS
)
600 print_otag(h
, TAG_TD
, "");
603 print_otag(h
, TAG_B
, "c", "name");
604 if (n
->child
== NULL
&& meta
->name
!= NULL
)
605 print_text(h
, meta
->name
);
608 print_otag(h
, TAG_TD
, "");
615 print_otag(h
, TAG_TABLE
, "c", "synopsis");
617 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
618 if (n
->type
== ROFFT_TEXT
)
619 len
+= html_strlen(n
->string
);
621 if (len
== 0 && meta
->name
!= NULL
)
622 len
= html_strlen(meta
->name
);
624 print_otag(h
, TAG_COL
, "shw", len
);
625 print_otag(h
, TAG_COL
, "");
626 print_otag(h
, TAG_TBODY
, "");
627 print_otag(h
, TAG_TR
, "");
632 mdoc_xr_pre(MDOC_ARGS
)
634 if (NULL
== n
->child
)
638 print_otag(h
, TAG_A
, "chM", "link-man",
639 n
->child
->string
, n
->child
->next
== NULL
?
640 NULL
: n
->child
->next
->string
);
642 print_otag(h
, TAG_A
, "c", "link-man");
645 print_text(h
, n
->string
);
647 if (NULL
== (n
= n
->next
))
650 h
->flags
|= HTML_NOSPACE
;
652 h
->flags
|= HTML_NOSPACE
;
653 print_text(h
, n
->string
);
654 h
->flags
|= HTML_NOSPACE
;
660 mdoc_ns_pre(MDOC_ARGS
)
663 if ( ! (NODE_LINE
& n
->flags
))
664 h
->flags
|= HTML_NOSPACE
;
669 mdoc_ar_pre(MDOC_ARGS
)
671 print_otag(h
, TAG_I
, "c", "arg");
676 mdoc_xx_pre(MDOC_ARGS
)
678 print_otag(h
, TAG_SPAN
, "c", "unix");
683 mdoc_it_pre(MDOC_ARGS
)
686 const struct roff_node
*bl
;
689 while (bl
&& MDOC_Bl
!= bl
->tok
)
691 type
= bl
->norm
->Bl
.type
;
693 if (n
->type
== ROFFT_HEAD
) {
706 print_otag(h
, TAG_DT
, "csvt", lists
[type
],
708 if (LIST_diag
!= type
)
710 print_otag(h
, TAG_B
, "c", "diag");
717 } else if (n
->type
== ROFFT_BODY
) {
724 print_otag(h
, TAG_LI
, "csvt", lists
[type
],
732 if (NULL
== bl
->norm
->Bl
.width
) {
733 print_otag(h
, TAG_DD
, "c", lists
[type
]);
736 print_otag(h
, TAG_DD
, "cswl", lists
[type
],
740 print_otag(h
, TAG_TD
, "csvt", lists
[type
],
749 print_otag(h
, TAG_TR
, "c", lists
[type
]);
760 mdoc_bl_pre(MDOC_ARGS
)
764 enum htmltag elemtype
;
766 if (n
->type
== ROFFT_BODY
) {
767 if (LIST_column
== n
->norm
->Bl
.type
)
768 print_otag(h
, TAG_TBODY
, "");
772 if (n
->type
== ROFFT_HEAD
) {
773 if (LIST_column
!= n
->norm
->Bl
.type
)
777 * For each column, print out the <COL> tag with our
778 * suggested width. The last column gets min-width, as
779 * in terminal mode it auto-sizes to the width of the
780 * screen and we want to preserve that behaviour.
783 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
- 1; i
++)
784 print_otag(h
, TAG_COL
, "sww", n
->norm
->Bl
.cols
[i
]);
785 print_otag(h
, TAG_COL
, "swW", n
->norm
->Bl
.cols
[i
]);
790 assert(lists
[n
->norm
->Bl
.type
]);
791 (void)strlcpy(buf
, "list ", BUFSIZ
);
792 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
794 switch (n
->norm
->Bl
.type
) {
812 elemtype
= TAG_TABLE
;
818 if (n
->norm
->Bl
.offs
)
819 print_otag(h
, elemtype
, "csvtvbwl", buf
, 0, 0,
822 print_otag(h
, elemtype
, "csvtvb", buf
, 0, 0);
828 mdoc_ex_pre(MDOC_ARGS
)
831 print_otag(h
, TAG_BR
, "");
836 mdoc_em_pre(MDOC_ARGS
)
838 print_otag(h
, TAG_SPAN
, "c", "emph");
843 mdoc_d1_pre(MDOC_ARGS
)
845 if (n
->type
!= ROFFT_BLOCK
)
848 print_otag(h
, TAG_BLOCKQUOTE
, "svtvb", 0, 0);
850 /* BLOCKQUOTE needs a block body. */
852 print_otag(h
, TAG_DIV
, "c", "display");
854 if (MDOC_Dl
== n
->tok
)
855 print_otag(h
, TAG_CODE
, "c", "lit");
861 mdoc_sx_pre(MDOC_ARGS
)
865 print_otag(h
, TAG_I
, "c", "link-sec");
866 if ((id
= make_id(n
)) != NULL
) {
867 print_otag(h
, TAG_A
, "chR", "link-sec", id
);
870 print_otag(h
, TAG_A
, "c", "link-sec");
876 mdoc_bd_pre(MDOC_ARGS
)
879 struct roff_node
*nn
;
881 if (n
->type
== ROFFT_HEAD
)
884 if (n
->type
== ROFFT_BLOCK
) {
885 comp
= n
->norm
->Bd
.comp
;
886 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
887 if (nn
->type
!= ROFFT_BLOCK
)
889 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
899 /* Handle the -offset argument. */
901 if (n
->norm
->Bd
.offs
== NULL
||
902 ! strcmp(n
->norm
->Bd
.offs
, "left"))
904 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
906 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
912 print_otag(h
, TAG_DIV
, "cswl", "display", n
->norm
->Bd
.offs
);
914 print_otag(h
, TAG_DIV
, "cshl", "display", offs
);
916 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
917 n
->norm
->Bd
.type
!= DISP_literal
)
920 print_otag(h
, TAG_PRE
, "c", "lit");
922 /* This can be recursive: save & set our literal state. */
924 sv
= h
->flags
& HTML_LITERAL
;
925 h
->flags
|= HTML_LITERAL
;
927 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
928 print_mdoc_node(meta
, nn
, h
);
930 * If the printed node flushes its own line, then we
931 * needn't do it here as well. This is hacky, but the
932 * notion of selective eoln whitespace is pretty dumb
933 * anyway, so don't sweat it.
948 if (h
->flags
& HTML_NONEWLINE
||
949 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
954 h
->flags
|= HTML_NOSPACE
;
958 h
->flags
&= ~HTML_LITERAL
;
964 mdoc_pa_pre(MDOC_ARGS
)
966 print_otag(h
, TAG_I
, "c", "file");
971 mdoc_ad_pre(MDOC_ARGS
)
973 print_otag(h
, TAG_I
, "c", "addr");
978 mdoc_an_pre(MDOC_ARGS
)
980 if (n
->norm
->An
.auth
== AUTH_split
) {
981 h
->flags
&= ~HTML_NOSPLIT
;
982 h
->flags
|= HTML_SPLIT
;
985 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
986 h
->flags
&= ~HTML_SPLIT
;
987 h
->flags
|= HTML_NOSPLIT
;
991 if (h
->flags
& HTML_SPLIT
)
992 print_otag(h
, TAG_BR
, "");
994 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
995 h
->flags
|= HTML_SPLIT
;
997 print_otag(h
, TAG_SPAN
, "c", "author");
1002 mdoc_cd_pre(MDOC_ARGS
)
1005 print_otag(h
, TAG_B
, "c", "config");
1010 mdoc_dv_pre(MDOC_ARGS
)
1012 print_otag(h
, TAG_SPAN
, "c", "define");
1017 mdoc_ev_pre(MDOC_ARGS
)
1019 print_otag(h
, TAG_SPAN
, "c", "env");
1024 mdoc_er_pre(MDOC_ARGS
)
1026 print_otag(h
, TAG_SPAN
, "c", "errno");
1031 mdoc_fa_pre(MDOC_ARGS
)
1033 const struct roff_node
*nn
;
1036 if (n
->parent
->tok
!= MDOC_Fo
) {
1037 print_otag(h
, TAG_I
, "c", "farg");
1041 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1042 t
= print_otag(h
, TAG_I
, "c", "farg");
1043 print_text(h
, nn
->string
);
1046 h
->flags
|= HTML_NOSPACE
;
1051 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1052 h
->flags
|= HTML_NOSPACE
;
1060 mdoc_fd_pre(MDOC_ARGS
)
1067 if (NULL
== (n
= n
->child
))
1070 assert(n
->type
== ROFFT_TEXT
);
1072 if (strcmp(n
->string
, "#include")) {
1073 print_otag(h
, TAG_B
, "c", "macro");
1077 print_otag(h
, TAG_B
, "c", "includes");
1078 print_text(h
, n
->string
);
1080 if (NULL
!= (n
= n
->next
)) {
1081 assert(n
->type
== ROFFT_TEXT
);
1083 if (h
->base_includes
) {
1085 if (*cp
== '<' || *cp
== '"')
1087 buf
= mandoc_strdup(cp
);
1088 cp
= strchr(buf
, '\0') - 1;
1089 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1091 t
= print_otag(h
, TAG_A
, "chI", "link-includes", buf
);
1094 t
= print_otag(h
, TAG_A
, "c", "link-includes");
1096 print_text(h
, n
->string
);
1102 for ( ; n
; n
= n
->next
) {
1103 assert(n
->type
== ROFFT_TEXT
);
1104 print_text(h
, n
->string
);
1111 mdoc_vt_pre(MDOC_ARGS
)
1113 if (n
->type
== ROFFT_BLOCK
) {
1116 } else if (n
->type
== ROFFT_ELEM
) {
1118 } else if (n
->type
== ROFFT_HEAD
)
1121 print_otag(h
, TAG_SPAN
, "c", "type");
1126 mdoc_ft_pre(MDOC_ARGS
)
1129 print_otag(h
, TAG_I
, "c", "ftype");
1134 mdoc_fn_pre(MDOC_ARGS
)
1138 const char *sp
, *ep
;
1141 pretty
= NODE_SYNPRETTY
& n
->flags
;
1144 /* Split apart into type and name. */
1145 assert(n
->child
->string
);
1146 sp
= n
->child
->string
;
1148 ep
= strchr(sp
, ' ');
1150 t
= print_otag(h
, TAG_I
, "c", "ftype");
1153 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1154 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1156 print_text(h
, nbuf
);
1158 ep
= strchr(sp
, ' ');
1163 t
= print_otag(h
, TAG_B
, "c", "fname");
1170 h
->flags
|= HTML_NOSPACE
;
1172 h
->flags
|= HTML_NOSPACE
;
1174 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1175 if (NODE_SYNPRETTY
& n
->flags
)
1176 t
= print_otag(h
, TAG_I
, "css?", "farg",
1177 "white-space", "nowrap");
1179 t
= print_otag(h
, TAG_I
, "c", "farg");
1180 print_text(h
, n
->string
);
1183 h
->flags
|= HTML_NOSPACE
;
1188 h
->flags
|= HTML_NOSPACE
;
1192 h
->flags
|= HTML_NOSPACE
;
1200 mdoc_sm_pre(MDOC_ARGS
)
1203 if (NULL
== n
->child
)
1204 h
->flags
^= HTML_NONOSPACE
;
1205 else if (0 == strcmp("on", n
->child
->string
))
1206 h
->flags
&= ~HTML_NONOSPACE
;
1208 h
->flags
|= HTML_NONOSPACE
;
1210 if ( ! (HTML_NONOSPACE
& h
->flags
))
1211 h
->flags
&= ~HTML_NOSPACE
;
1217 mdoc_skip_pre(MDOC_ARGS
)
1224 mdoc_pp_pre(MDOC_ARGS
)
1232 mdoc_sp_pre(MDOC_ARGS
)
1236 SCALE_VS_INIT(&su
, 1);
1238 if (MDOC_sp
== n
->tok
) {
1239 if (NULL
!= (n
= n
->child
)) {
1240 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1242 else if (su
.scale
< 0.0)
1248 print_otag(h
, TAG_DIV
, "suh", &su
);
1250 /* So the div isn't empty: */
1251 print_text(h
, "\\~");
1258 mdoc_lk_pre(MDOC_ARGS
)
1260 if (NULL
== (n
= n
->child
))
1263 assert(n
->type
== ROFFT_TEXT
);
1265 print_otag(h
, TAG_A
, "ch", "link-ext", n
->string
);
1267 if (NULL
== n
->next
)
1268 print_text(h
, n
->string
);
1270 for (n
= n
->next
; n
; n
= n
->next
)
1271 print_text(h
, n
->string
);
1277 mdoc_mt_pre(MDOC_ARGS
)
1282 for (n
= n
->child
; n
; n
= n
->next
) {
1283 assert(n
->type
== ROFFT_TEXT
);
1285 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1286 t
= print_otag(h
, TAG_A
, "ch", "link-mail", cp
);
1287 print_text(h
, n
->string
);
1296 mdoc_fo_pre(MDOC_ARGS
)
1300 if (n
->type
== ROFFT_BODY
) {
1301 h
->flags
|= HTML_NOSPACE
;
1303 h
->flags
|= HTML_NOSPACE
;
1305 } else if (n
->type
== ROFFT_BLOCK
) {
1310 if (n
->child
== NULL
)
1313 assert(n
->child
->string
);
1314 t
= print_otag(h
, TAG_B
, "c", "fname");
1315 print_text(h
, n
->child
->string
);
1321 mdoc_fo_post(MDOC_ARGS
)
1324 if (n
->type
!= ROFFT_BODY
)
1326 h
->flags
|= HTML_NOSPACE
;
1328 h
->flags
|= HTML_NOSPACE
;
1333 mdoc_in_pre(MDOC_ARGS
)
1338 print_otag(h
, TAG_B
, "c", "includes");
1341 * The first argument of the `In' gets special treatment as
1342 * being a linked value. Subsequent values are printed
1343 * afterward. groff does similarly. This also handles the case
1347 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1348 print_text(h
, "#include");
1351 h
->flags
|= HTML_NOSPACE
;
1353 if (NULL
!= (n
= n
->child
)) {
1354 assert(n
->type
== ROFFT_TEXT
);
1356 if (h
->base_includes
)
1357 t
= print_otag(h
, TAG_A
, "chI", "link-includes",
1360 t
= print_otag(h
, TAG_A
, "c", "link-includes");
1361 print_text(h
, n
->string
);
1367 h
->flags
|= HTML_NOSPACE
;
1370 for ( ; n
; n
= n
->next
) {
1371 assert(n
->type
== ROFFT_TEXT
);
1372 print_text(h
, n
->string
);
1379 mdoc_ic_pre(MDOC_ARGS
)
1381 print_otag(h
, TAG_B
, "c", "cmd");
1386 mdoc_va_pre(MDOC_ARGS
)
1388 print_otag(h
, TAG_B
, "c", "var");
1393 mdoc_ap_pre(MDOC_ARGS
)
1396 h
->flags
|= HTML_NOSPACE
;
1397 print_text(h
, "\\(aq");
1398 h
->flags
|= HTML_NOSPACE
;
1403 mdoc_bf_pre(MDOC_ARGS
)
1407 if (n
->type
== ROFFT_HEAD
)
1409 else if (n
->type
!= ROFFT_BODY
)
1412 if (FONT_Em
== n
->norm
->Bf
.font
)
1414 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1416 else if (FONT_Li
== n
->norm
->Bf
.font
)
1422 * We want this to be inline-formatted, but needs to be div to
1423 * accept block children.
1426 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1431 mdoc_ms_pre(MDOC_ARGS
)
1433 print_otag(h
, TAG_SPAN
, "c", "symb");
1438 mdoc_igndelim_pre(MDOC_ARGS
)
1441 h
->flags
|= HTML_IGNDELIM
;
1446 mdoc_pf_post(MDOC_ARGS
)
1449 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1450 h
->flags
|= HTML_NOSPACE
;
1454 mdoc_rs_pre(MDOC_ARGS
)
1456 if (n
->type
!= ROFFT_BLOCK
)
1459 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1462 print_otag(h
, TAG_SPAN
, "c", "ref");
1467 mdoc_no_pre(MDOC_ARGS
)
1469 print_otag(h
, TAG_SPAN
, "c", "none");
1474 mdoc_li_pre(MDOC_ARGS
)
1476 print_otag(h
, TAG_CODE
, "c", "lit");
1481 mdoc_sy_pre(MDOC_ARGS
)
1483 print_otag(h
, TAG_SPAN
, "c", "symb");
1488 mdoc_lb_pre(MDOC_ARGS
)
1490 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1491 print_otag(h
, TAG_BR
, "");
1493 print_otag(h
, TAG_SPAN
, "c", "lib");
1498 mdoc__x_pre(MDOC_ARGS
)
1508 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1509 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1510 print_text(h
, "and");
1523 cattr
= "ref-issue";
1546 cattr
= "ref-title";
1558 if (MDOC__U
!= n
->tok
) {
1559 print_otag(h
, t
, "c", cattr
);
1563 print_otag(h
, TAG_A
, "ch", cattr
, n
->child
->string
);
1569 mdoc__x_post(MDOC_ARGS
)
1572 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1573 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1574 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1579 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1582 h
->flags
|= HTML_NOSPACE
;
1583 print_text(h
, n
->next
? "," : ".");
1587 mdoc_bk_pre(MDOC_ARGS
)
1596 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1597 h
->flags
|= HTML_PREKEEP
;
1607 mdoc_bk_post(MDOC_ARGS
)
1610 if (n
->type
== ROFFT_BODY
)
1611 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1615 mdoc_quote_pre(MDOC_ARGS
)
1617 if (n
->type
!= ROFFT_BODY
)
1623 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1624 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1628 print_text(h
, "\\(lC");
1632 print_text(h
, "\\(lB");
1636 print_text(h
, "\\(lB");
1637 h
->flags
|= HTML_NOSPACE
;
1638 print_otag(h
, TAG_SPAN
, "c", "opt");
1641 if (NULL
== n
->norm
->Es
||
1642 NULL
== n
->norm
->Es
->child
)
1644 print_text(h
, n
->norm
->Es
->child
->string
);
1650 print_text(h
, "\\(lq");
1657 print_text(h
, "\\(oq");
1658 h
->flags
|= HTML_NOSPACE
;
1659 print_otag(h
, TAG_CODE
, "c", "lit");
1663 print_text(h
, "\\(oq");
1669 h
->flags
|= HTML_NOSPACE
;
1674 mdoc_quote_post(MDOC_ARGS
)
1677 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1680 h
->flags
|= HTML_NOSPACE
;
1685 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1686 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1690 print_text(h
, "\\(rC");
1696 print_text(h
, "\\(rB");
1699 if (n
->norm
->Es
== NULL
||
1700 n
->norm
->Es
->child
== NULL
||
1701 n
->norm
->Es
->child
->next
== NULL
)
1702 h
->flags
&= ~HTML_NOSPACE
;
1704 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1710 print_text(h
, "\\(rq");
1719 print_text(h
, "\\(cq");
1727 mdoc_eo_pre(MDOC_ARGS
)
1730 if (n
->type
!= ROFFT_BODY
)
1733 if (n
->end
== ENDBODY_NOT
&&
1734 n
->parent
->head
->child
== NULL
&&
1736 n
->child
->end
!= ENDBODY_NOT
)
1737 print_text(h
, "\\&");
1738 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1739 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1740 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1741 h
->flags
|= HTML_NOSPACE
;
1746 mdoc_eo_post(MDOC_ARGS
)
1750 if (n
->type
!= ROFFT_BODY
)
1753 if (n
->end
!= ENDBODY_NOT
) {
1754 h
->flags
&= ~HTML_NOSPACE
;
1758 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1759 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1762 h
->flags
|= HTML_NOSPACE
;
1764 h
->flags
&= ~HTML_NOSPACE
;