]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.255 2017/01/19 16:59:30 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 char *make_id(const struct roff_node
*);
52 static void print_mdoc_head(MDOC_ARGS
);
53 static void print_mdoc_node(MDOC_ARGS
);
54 static void print_mdoc_nodelist(MDOC_ARGS
);
55 static void synopsis_pre(struct html
*,
56 const struct roff_node
*);
58 static void mdoc_root_post(MDOC_ARGS
);
59 static int mdoc_root_pre(MDOC_ARGS
);
61 static void mdoc__x_post(MDOC_ARGS
);
62 static int mdoc__x_pre(MDOC_ARGS
);
63 static int mdoc_ad_pre(MDOC_ARGS
);
64 static int mdoc_an_pre(MDOC_ARGS
);
65 static int mdoc_ap_pre(MDOC_ARGS
);
66 static int mdoc_ar_pre(MDOC_ARGS
);
67 static int mdoc_bd_pre(MDOC_ARGS
);
68 static int mdoc_bf_pre(MDOC_ARGS
);
69 static void mdoc_bk_post(MDOC_ARGS
);
70 static int mdoc_bk_pre(MDOC_ARGS
);
71 static int mdoc_bl_pre(MDOC_ARGS
);
72 static int mdoc_cd_pre(MDOC_ARGS
);
73 static int mdoc_d1_pre(MDOC_ARGS
);
74 static int mdoc_dv_pre(MDOC_ARGS
);
75 static int mdoc_fa_pre(MDOC_ARGS
);
76 static int mdoc_fd_pre(MDOC_ARGS
);
77 static int mdoc_fl_pre(MDOC_ARGS
);
78 static int mdoc_fn_pre(MDOC_ARGS
);
79 static int mdoc_ft_pre(MDOC_ARGS
);
80 static int mdoc_em_pre(MDOC_ARGS
);
81 static void mdoc_eo_post(MDOC_ARGS
);
82 static int mdoc_eo_pre(MDOC_ARGS
);
83 static int mdoc_er_pre(MDOC_ARGS
);
84 static int mdoc_ev_pre(MDOC_ARGS
);
85 static int mdoc_ex_pre(MDOC_ARGS
);
86 static void mdoc_fo_post(MDOC_ARGS
);
87 static int mdoc_fo_pre(MDOC_ARGS
);
88 static int mdoc_ic_pre(MDOC_ARGS
);
89 static int mdoc_igndelim_pre(MDOC_ARGS
);
90 static int mdoc_in_pre(MDOC_ARGS
);
91 static int mdoc_it_pre(MDOC_ARGS
);
92 static int mdoc_lb_pre(MDOC_ARGS
);
93 static int mdoc_li_pre(MDOC_ARGS
);
94 static int mdoc_lk_pre(MDOC_ARGS
);
95 static int mdoc_mt_pre(MDOC_ARGS
);
96 static int mdoc_ms_pre(MDOC_ARGS
);
97 static int mdoc_nd_pre(MDOC_ARGS
);
98 static int mdoc_nm_pre(MDOC_ARGS
);
99 static int mdoc_no_pre(MDOC_ARGS
);
100 static int mdoc_ns_pre(MDOC_ARGS
);
101 static int mdoc_pa_pre(MDOC_ARGS
);
102 static void mdoc_pf_post(MDOC_ARGS
);
103 static int mdoc_pp_pre(MDOC_ARGS
);
104 static void mdoc_quote_post(MDOC_ARGS
);
105 static int mdoc_quote_pre(MDOC_ARGS
);
106 static int mdoc_rs_pre(MDOC_ARGS
);
107 static int mdoc_sh_pre(MDOC_ARGS
);
108 static int mdoc_skip_pre(MDOC_ARGS
);
109 static int mdoc_sm_pre(MDOC_ARGS
);
110 static int mdoc_sp_pre(MDOC_ARGS
);
111 static int mdoc_ss_pre(MDOC_ARGS
);
112 static int mdoc_sx_pre(MDOC_ARGS
);
113 static int mdoc_sy_pre(MDOC_ARGS
);
114 static int mdoc_va_pre(MDOC_ARGS
);
115 static int mdoc_vt_pre(MDOC_ARGS
);
116 static int mdoc_xr_pre(MDOC_ARGS
);
117 static int mdoc_xx_pre(MDOC_ARGS
);
119 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
120 {mdoc_ap_pre
, NULL
}, /* Ap */
121 {NULL
, NULL
}, /* Dd */
122 {NULL
, NULL
}, /* Dt */
123 {NULL
, NULL
}, /* Os */
124 {mdoc_sh_pre
, NULL
}, /* Sh */
125 {mdoc_ss_pre
, NULL
}, /* Ss */
126 {mdoc_pp_pre
, NULL
}, /* Pp */
127 {mdoc_d1_pre
, NULL
}, /* D1 */
128 {mdoc_d1_pre
, NULL
}, /* Dl */
129 {mdoc_bd_pre
, NULL
}, /* Bd */
130 {NULL
, NULL
}, /* Ed */
131 {mdoc_bl_pre
, NULL
}, /* Bl */
132 {NULL
, NULL
}, /* El */
133 {mdoc_it_pre
, NULL
}, /* It */
134 {mdoc_ad_pre
, NULL
}, /* Ad */
135 {mdoc_an_pre
, NULL
}, /* An */
136 {mdoc_ar_pre
, NULL
}, /* Ar */
137 {mdoc_cd_pre
, NULL
}, /* Cd */
138 {mdoc_fl_pre
, NULL
}, /* Cm */
139 {mdoc_dv_pre
, NULL
}, /* Dv */
140 {mdoc_er_pre
, NULL
}, /* Er */
141 {mdoc_ev_pre
, NULL
}, /* Ev */
142 {mdoc_ex_pre
, NULL
}, /* Ex */
143 {mdoc_fa_pre
, NULL
}, /* Fa */
144 {mdoc_fd_pre
, NULL
}, /* Fd */
145 {mdoc_fl_pre
, NULL
}, /* Fl */
146 {mdoc_fn_pre
, NULL
}, /* Fn */
147 {mdoc_ft_pre
, NULL
}, /* Ft */
148 {mdoc_ic_pre
, NULL
}, /* Ic */
149 {mdoc_in_pre
, NULL
}, /* In */
150 {mdoc_li_pre
, NULL
}, /* Li */
151 {mdoc_nd_pre
, NULL
}, /* Nd */
152 {mdoc_nm_pre
, NULL
}, /* Nm */
153 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
154 {mdoc_ft_pre
, NULL
}, /* Ot */
155 {mdoc_pa_pre
, NULL
}, /* Pa */
156 {mdoc_ex_pre
, NULL
}, /* Rv */
157 {NULL
, NULL
}, /* St */
158 {mdoc_va_pre
, NULL
}, /* Va */
159 {mdoc_vt_pre
, NULL
}, /* Vt */
160 {mdoc_xr_pre
, NULL
}, /* Xr */
161 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
162 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
163 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
172 {NULL
, NULL
}, /* Ac */
173 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
174 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
175 {NULL
, NULL
}, /* At */
176 {NULL
, NULL
}, /* Bc */
177 {mdoc_bf_pre
, NULL
}, /* Bf */
178 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
179 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
180 {mdoc_xx_pre
, NULL
}, /* Bsx */
181 {mdoc_xx_pre
, NULL
}, /* Bx */
182 {mdoc_skip_pre
, NULL
}, /* Db */
183 {NULL
, NULL
}, /* Dc */
184 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
185 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
186 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
187 {NULL
, NULL
}, /* Ef */
188 {mdoc_em_pre
, NULL
}, /* Em */
189 {mdoc_eo_pre
, mdoc_eo_post
}, /* Eo */
190 {mdoc_xx_pre
, NULL
}, /* Fx */
191 {mdoc_ms_pre
, NULL
}, /* Ms */
192 {mdoc_no_pre
, NULL
}, /* No */
193 {mdoc_ns_pre
, NULL
}, /* Ns */
194 {mdoc_xx_pre
, NULL
}, /* Nx */
195 {mdoc_xx_pre
, NULL
}, /* Ox */
196 {NULL
, NULL
}, /* Pc */
197 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
198 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
199 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
200 {NULL
, NULL
}, /* Qc */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
203 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
204 {NULL
, NULL
}, /* Re */
205 {mdoc_rs_pre
, NULL
}, /* Rs */
206 {NULL
, NULL
}, /* Sc */
207 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
208 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
209 {mdoc_sm_pre
, NULL
}, /* Sm */
210 {mdoc_sx_pre
, NULL
}, /* Sx */
211 {mdoc_sy_pre
, NULL
}, /* Sy */
212 {NULL
, NULL
}, /* Tn */
213 {mdoc_xx_pre
, NULL
}, /* Ux */
214 {NULL
, NULL
}, /* Xc */
215 {NULL
, NULL
}, /* Xo */
216 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
217 {NULL
, NULL
}, /* Fc */
218 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
219 {NULL
, NULL
}, /* Oc */
220 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
221 {NULL
, NULL
}, /* Ek */
222 {NULL
, NULL
}, /* Bt */
223 {NULL
, NULL
}, /* Hf */
224 {mdoc_em_pre
, NULL
}, /* Fr */
225 {NULL
, NULL
}, /* Ud */
226 {mdoc_lb_pre
, NULL
}, /* Lb */
227 {mdoc_pp_pre
, NULL
}, /* Lp */
228 {mdoc_lk_pre
, NULL
}, /* Lk */
229 {mdoc_mt_pre
, NULL
}, /* Mt */
230 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
231 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
232 {NULL
, NULL
}, /* Brc */
233 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
234 {mdoc_skip_pre
, NULL
}, /* Es */
235 {mdoc_quote_pre
, mdoc_quote_post
}, /* En */
236 {mdoc_xx_pre
, NULL
}, /* Dx */
237 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
238 {mdoc_sp_pre
, NULL
}, /* br */
239 {mdoc_sp_pre
, NULL
}, /* sp */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
241 {NULL
, NULL
}, /* Ta */
242 {mdoc_skip_pre
, NULL
}, /* ll */
245 static const char * const lists
[LIST_MAX
] = {
262 * See the same function in mdoc_term.c for documentation.
265 synopsis_pre(struct html
*h
, const struct roff_node
*n
)
268 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
271 if (n
->prev
->tok
== n
->tok
&&
275 print_otag(h
, TAG_BR
, "");
279 switch (n
->prev
->tok
) {
288 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
294 print_otag(h
, TAG_BR
, "");
300 html_mdoc(void *arg
, const struct roff_man
*mdoc
)
305 h
= (struct html
*)arg
;
307 if ((h
->oflags
& HTML_FRAGMENT
) == 0) {
309 print_otag(h
, TAG_HTML
, "");
310 t
= print_otag(h
, TAG_HEAD
, "");
311 print_mdoc_head(&mdoc
->meta
, mdoc
->first
->child
, h
);
313 print_otag(h
, TAG_BODY
, "");
316 mdoc_root_pre(&mdoc
->meta
, mdoc
->first
->child
, h
);
317 t
= print_otag(h
, TAG_DIV
, "c", "manual-text");
318 print_mdoc_nodelist(&mdoc
->meta
, mdoc
->first
->child
, h
);
320 mdoc_root_post(&mdoc
->meta
, mdoc
->first
->child
, h
);
325 print_mdoc_head(MDOC_ARGS
)
331 if (meta
->arch
!= NULL
&& meta
->msec
!= NULL
)
332 mandoc_asprintf(&cp
, "%s(%s) (%s)", meta
->title
,
333 meta
->msec
, meta
->arch
);
334 else if (meta
->msec
!= NULL
)
335 mandoc_asprintf(&cp
, "%s(%s)", meta
->title
, meta
->msec
);
336 else if (meta
->arch
!= NULL
)
337 mandoc_asprintf(&cp
, "%s (%s)", meta
->title
, meta
->arch
);
339 cp
= mandoc_strdup(meta
->title
);
341 print_otag(h
, TAG_TITLE
, "");
347 print_mdoc_nodelist(MDOC_ARGS
)
351 print_mdoc_node(meta
, n
, h
);
357 print_mdoc_node(MDOC_ARGS
)
362 if (n
->flags
& NODE_NOPRT
)
367 n
->flags
&= ~NODE_ENDED
;
371 /* No tables in this mode... */
372 assert(NULL
== h
->tblt
);
375 * Make sure that if we're in a literal mode already
376 * (i.e., within a <PRE>) don't print the newline.
378 if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
379 if ( ! (HTML_LITERAL
& h
->flags
))
380 print_otag(h
, TAG_BR
, "");
381 if (NODE_DELIMC
& n
->flags
)
382 h
->flags
|= HTML_NOSPACE
;
383 print_text(h
, n
->string
);
384 if (NODE_DELIMO
& n
->flags
)
385 h
->flags
|= HTML_NOSPACE
;
388 print_eqn(h
, n
->eqn
);
392 * This will take care of initialising all of the table
393 * state data for the first table, then tearing it down
396 print_tbl(h
, n
->span
);
400 * Close out the current table, if it's open, and unset
401 * the "meta" table state. This will be reopened on the
402 * next table element.
404 if (h
->tblt
!= NULL
) {
408 assert(h
->tblt
== NULL
);
409 if (mdocs
[n
->tok
].pre
&& (n
->end
== ENDBODY_NOT
|| n
->child
))
410 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
414 if (h
->flags
& HTML_KEEP
&& n
->flags
& NODE_LINE
) {
415 h
->flags
&= ~HTML_KEEP
;
416 h
->flags
|= HTML_PREKEEP
;
419 if (child
&& n
->child
)
420 print_mdoc_nodelist(meta
, n
->child
, h
);
428 if ( ! mdocs
[n
->tok
].post
|| n
->flags
& NODE_ENDED
)
430 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
431 if (n
->end
!= ENDBODY_NOT
)
432 n
->body
->flags
|= NODE_ENDED
;
433 if (n
->end
== ENDBODY_NOSPACE
)
434 h
->flags
|= HTML_NOSPACE
;
440 mdoc_root_post(MDOC_ARGS
)
444 t
= print_otag(h
, TAG_TABLE
, "c", "foot");
445 print_otag(h
, TAG_TBODY
, "");
446 tt
= print_otag(h
, TAG_TR
, "");
448 print_otag(h
, TAG_TD
, "c", "foot-date");
449 print_text(h
, meta
->date
);
452 print_otag(h
, TAG_TD
, "c", "foot-os");
453 print_text(h
, meta
->os
);
458 mdoc_root_pre(MDOC_ARGS
)
461 char *volume
, *title
;
463 if (NULL
== meta
->arch
)
464 volume
= mandoc_strdup(meta
->vol
);
466 mandoc_asprintf(&volume
, "%s (%s)",
467 meta
->vol
, meta
->arch
);
469 if (NULL
== meta
->msec
)
470 title
= mandoc_strdup(meta
->title
);
472 mandoc_asprintf(&title
, "%s(%s)",
473 meta
->title
, meta
->msec
);
475 t
= print_otag(h
, TAG_TABLE
, "c", "head");
476 print_otag(h
, TAG_TBODY
, "");
477 tt
= print_otag(h
, TAG_TR
, "");
479 print_otag(h
, TAG_TD
, "c", "head-ltitle");
480 print_text(h
, title
);
483 print_otag(h
, TAG_TD
, "c", "head-vol");
484 print_text(h
, volume
);
487 print_otag(h
, TAG_TD
, "c", "head-rtitle");
488 print_text(h
, title
);
497 make_id(const struct roff_node
*n
)
499 const struct roff_node
*nch
;
502 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
)
503 if (nch
->type
!= ROFFT_TEXT
)
509 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
511 for (cp
= buf
; *cp
!= '\0'; cp
++)
519 mdoc_sh_pre(MDOC_ARGS
)
527 if (n
->sec
== SEC_AUTHORS
)
528 h
->flags
&= ~(HTML_SPLIT
|HTML_NOSPLIT
);
534 if ((id
= make_id(n
)) != NULL
) {
535 print_otag(h
, TAG_H1
, "ci", "Sh", id
);
538 print_otag(h
, TAG_H1
, "c", "Sh");
544 mdoc_ss_pre(MDOC_ARGS
)
548 if (n
->type
!= ROFFT_HEAD
)
551 if ((id
= make_id(n
)) != NULL
) {
552 print_otag(h
, TAG_H2
, "ci", "Ss", id
);
555 print_otag(h
, TAG_H2
, "c", "Ss");
561 mdoc_fl_pre(MDOC_ARGS
)
563 print_otag(h
, TAG_B
, "c", "flag");
565 /* `Cm' has no leading hyphen. */
567 if (MDOC_Cm
== n
->tok
)
570 print_text(h
, "\\-");
572 if (!(n
->child
== NULL
&&
574 n
->next
->type
== ROFFT_TEXT
||
575 n
->next
->flags
& NODE_LINE
)))
576 h
->flags
|= HTML_NOSPACE
;
582 mdoc_nd_pre(MDOC_ARGS
)
584 if (n
->type
!= ROFFT_BODY
)
587 /* XXX: this tag in theory can contain block elements. */
589 print_text(h
, "\\(em");
590 print_otag(h
, TAG_SPAN
, "c", "desc");
595 mdoc_nm_pre(MDOC_ARGS
)
601 print_otag(h
, TAG_TD
, "");
604 print_otag(h
, TAG_B
, "c", "name");
605 if (n
->child
== NULL
&& meta
->name
!= NULL
)
606 print_text(h
, meta
->name
);
609 print_otag(h
, TAG_TD
, "");
616 print_otag(h
, TAG_TABLE
, "c", "synopsis");
618 for (len
= 0, n
= n
->head
->child
; n
; n
= n
->next
)
619 if (n
->type
== ROFFT_TEXT
)
620 len
+= html_strlen(n
->string
);
622 if (len
== 0 && meta
->name
!= NULL
)
623 len
= html_strlen(meta
->name
);
625 print_otag(h
, TAG_COL
, "shw", len
);
626 print_otag(h
, TAG_COL
, "");
627 print_otag(h
, TAG_TBODY
, "");
628 print_otag(h
, TAG_TR
, "");
633 mdoc_xr_pre(MDOC_ARGS
)
635 if (NULL
== n
->child
)
639 print_otag(h
, TAG_A
, "chM", "Xr",
640 n
->child
->string
, n
->child
->next
== NULL
?
641 NULL
: n
->child
->next
->string
);
643 print_otag(h
, TAG_A
, "c", "Xr");
646 print_text(h
, n
->string
);
648 if (NULL
== (n
= n
->next
))
651 h
->flags
|= HTML_NOSPACE
;
653 h
->flags
|= HTML_NOSPACE
;
654 print_text(h
, n
->string
);
655 h
->flags
|= HTML_NOSPACE
;
661 mdoc_ns_pre(MDOC_ARGS
)
664 if ( ! (NODE_LINE
& n
->flags
))
665 h
->flags
|= HTML_NOSPACE
;
670 mdoc_ar_pre(MDOC_ARGS
)
672 print_otag(h
, TAG_I
, "c", "arg");
677 mdoc_xx_pre(MDOC_ARGS
)
679 print_otag(h
, TAG_SPAN
, "c", "unix");
684 mdoc_it_pre(MDOC_ARGS
)
687 const struct roff_node
*bl
;
690 while (bl
&& MDOC_Bl
!= bl
->tok
)
692 type
= bl
->norm
->Bl
.type
;
694 if (n
->type
== ROFFT_HEAD
) {
707 print_otag(h
, TAG_DT
, "csvt", lists
[type
],
709 if (LIST_diag
!= type
)
711 print_otag(h
, TAG_B
, "c", "diag");
718 } else if (n
->type
== ROFFT_BODY
) {
725 print_otag(h
, TAG_LI
, "csvt", lists
[type
],
733 if (NULL
== bl
->norm
->Bl
.width
) {
734 print_otag(h
, TAG_DD
, "c", lists
[type
]);
737 print_otag(h
, TAG_DD
, "cswl", lists
[type
],
741 print_otag(h
, TAG_TD
, "csvt", lists
[type
],
750 print_otag(h
, TAG_TR
, "c", lists
[type
]);
761 mdoc_bl_pre(MDOC_ARGS
)
765 enum htmltag elemtype
;
767 if (n
->type
== ROFFT_BODY
) {
768 if (LIST_column
== n
->norm
->Bl
.type
)
769 print_otag(h
, TAG_TBODY
, "");
773 if (n
->type
== ROFFT_HEAD
) {
774 if (LIST_column
!= n
->norm
->Bl
.type
)
778 * For each column, print out the <COL> tag with our
779 * suggested width. The last column gets min-width, as
780 * in terminal mode it auto-sizes to the width of the
781 * screen and we want to preserve that behaviour.
784 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
- 1; i
++)
785 print_otag(h
, TAG_COL
, "sww", n
->norm
->Bl
.cols
[i
]);
786 print_otag(h
, TAG_COL
, "swW", n
->norm
->Bl
.cols
[i
]);
791 assert(lists
[n
->norm
->Bl
.type
]);
792 (void)strlcpy(buf
, "list ", BUFSIZ
);
793 (void)strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
795 switch (n
->norm
->Bl
.type
) {
813 elemtype
= TAG_TABLE
;
819 if (n
->norm
->Bl
.offs
)
820 print_otag(h
, elemtype
, "csvtvbwl", buf
, 0, 0,
823 print_otag(h
, elemtype
, "csvtvb", buf
, 0, 0);
829 mdoc_ex_pre(MDOC_ARGS
)
832 print_otag(h
, TAG_BR
, "");
837 mdoc_em_pre(MDOC_ARGS
)
839 print_otag(h
, TAG_SPAN
, "c", "emph");
844 mdoc_d1_pre(MDOC_ARGS
)
846 if (n
->type
!= ROFFT_BLOCK
)
849 print_otag(h
, TAG_DIV
, "c", "D1");
851 if (n
->tok
== MDOC_Dl
)
852 print_otag(h
, TAG_CODE
, "c", "Li");
858 mdoc_sx_pre(MDOC_ARGS
)
862 if ((id
= make_id(n
)) != NULL
) {
863 print_otag(h
, TAG_A
, "chR", "Sx", id
);
866 print_otag(h
, TAG_A
, "c", "Sx");
872 mdoc_bd_pre(MDOC_ARGS
)
875 struct roff_node
*nn
;
877 if (n
->type
== ROFFT_HEAD
)
880 if (n
->type
== ROFFT_BLOCK
) {
881 comp
= n
->norm
->Bd
.comp
;
882 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
883 if (nn
->type
!= ROFFT_BLOCK
)
885 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
895 /* Handle the -offset argument. */
897 if (n
->norm
->Bd
.offs
== NULL
||
898 ! strcmp(n
->norm
->Bd
.offs
, "left"))
900 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
902 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
908 print_otag(h
, TAG_DIV
, "cswl", "Bd", n
->norm
->Bd
.offs
);
910 print_otag(h
, TAG_DIV
, "cshl", "Bd", offs
);
912 if (n
->norm
->Bd
.type
!= DISP_unfilled
&&
913 n
->norm
->Bd
.type
!= DISP_literal
)
916 print_otag(h
, TAG_PRE
, "c", "Li");
918 /* This can be recursive: save & set our literal state. */
920 sv
= h
->flags
& HTML_LITERAL
;
921 h
->flags
|= HTML_LITERAL
;
923 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
924 print_mdoc_node(meta
, nn
, h
);
926 * If the printed node flushes its own line, then we
927 * needn't do it here as well. This is hacky, but the
928 * notion of selective eoln whitespace is pretty dumb
929 * anyway, so don't sweat it.
944 if (h
->flags
& HTML_NONEWLINE
||
945 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
950 h
->flags
|= HTML_NOSPACE
;
954 h
->flags
&= ~HTML_LITERAL
;
960 mdoc_pa_pre(MDOC_ARGS
)
962 print_otag(h
, TAG_I
, "c", "file");
967 mdoc_ad_pre(MDOC_ARGS
)
969 print_otag(h
, TAG_I
, "c", "addr");
974 mdoc_an_pre(MDOC_ARGS
)
976 if (n
->norm
->An
.auth
== AUTH_split
) {
977 h
->flags
&= ~HTML_NOSPLIT
;
978 h
->flags
|= HTML_SPLIT
;
981 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
982 h
->flags
&= ~HTML_SPLIT
;
983 h
->flags
|= HTML_NOSPLIT
;
987 if (h
->flags
& HTML_SPLIT
)
988 print_otag(h
, TAG_BR
, "");
990 if (n
->sec
== SEC_AUTHORS
&& ! (h
->flags
& HTML_NOSPLIT
))
991 h
->flags
|= HTML_SPLIT
;
993 print_otag(h
, TAG_SPAN
, "c", "author");
998 mdoc_cd_pre(MDOC_ARGS
)
1001 print_otag(h
, TAG_B
, "c", "config");
1006 mdoc_dv_pre(MDOC_ARGS
)
1008 print_otag(h
, TAG_SPAN
, "c", "define");
1013 mdoc_ev_pre(MDOC_ARGS
)
1015 print_otag(h
, TAG_SPAN
, "c", "env");
1020 mdoc_er_pre(MDOC_ARGS
)
1022 print_otag(h
, TAG_SPAN
, "c", "errno");
1027 mdoc_fa_pre(MDOC_ARGS
)
1029 const struct roff_node
*nn
;
1032 if (n
->parent
->tok
!= MDOC_Fo
) {
1033 print_otag(h
, TAG_I
, "c", "farg");
1037 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1038 t
= print_otag(h
, TAG_I
, "c", "farg");
1039 print_text(h
, nn
->string
);
1042 h
->flags
|= HTML_NOSPACE
;
1047 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1048 h
->flags
|= HTML_NOSPACE
;
1056 mdoc_fd_pre(MDOC_ARGS
)
1063 if (NULL
== (n
= n
->child
))
1066 assert(n
->type
== ROFFT_TEXT
);
1068 if (strcmp(n
->string
, "#include")) {
1069 print_otag(h
, TAG_B
, "c", "macro");
1073 print_otag(h
, TAG_B
, "c", "includes");
1074 print_text(h
, n
->string
);
1076 if (NULL
!= (n
= n
->next
)) {
1077 assert(n
->type
== ROFFT_TEXT
);
1079 if (h
->base_includes
) {
1081 if (*cp
== '<' || *cp
== '"')
1083 buf
= mandoc_strdup(cp
);
1084 cp
= strchr(buf
, '\0') - 1;
1085 if (cp
>= buf
&& (*cp
== '>' || *cp
== '"'))
1087 t
= print_otag(h
, TAG_A
, "chI", "link-includes", buf
);
1090 t
= print_otag(h
, TAG_A
, "c", "link-includes");
1092 print_text(h
, n
->string
);
1098 for ( ; n
; n
= n
->next
) {
1099 assert(n
->type
== ROFFT_TEXT
);
1100 print_text(h
, n
->string
);
1107 mdoc_vt_pre(MDOC_ARGS
)
1109 if (n
->type
== ROFFT_BLOCK
) {
1112 } else if (n
->type
== ROFFT_ELEM
) {
1114 } else if (n
->type
== ROFFT_HEAD
)
1117 print_otag(h
, TAG_SPAN
, "c", "type");
1122 mdoc_ft_pre(MDOC_ARGS
)
1125 print_otag(h
, TAG_I
, "c", "ftype");
1130 mdoc_fn_pre(MDOC_ARGS
)
1134 const char *sp
, *ep
;
1137 pretty
= NODE_SYNPRETTY
& n
->flags
;
1140 /* Split apart into type and name. */
1141 assert(n
->child
->string
);
1142 sp
= n
->child
->string
;
1144 ep
= strchr(sp
, ' ');
1146 t
= print_otag(h
, TAG_I
, "c", "ftype");
1149 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1150 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1152 print_text(h
, nbuf
);
1154 ep
= strchr(sp
, ' ');
1159 t
= print_otag(h
, TAG_B
, "c", "fname");
1166 h
->flags
|= HTML_NOSPACE
;
1168 h
->flags
|= HTML_NOSPACE
;
1170 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1171 if (NODE_SYNPRETTY
& n
->flags
)
1172 t
= print_otag(h
, TAG_I
, "css?", "farg",
1173 "white-space", "nowrap");
1175 t
= print_otag(h
, TAG_I
, "c", "farg");
1176 print_text(h
, n
->string
);
1179 h
->flags
|= HTML_NOSPACE
;
1184 h
->flags
|= HTML_NOSPACE
;
1188 h
->flags
|= HTML_NOSPACE
;
1196 mdoc_sm_pre(MDOC_ARGS
)
1199 if (NULL
== n
->child
)
1200 h
->flags
^= HTML_NONOSPACE
;
1201 else if (0 == strcmp("on", n
->child
->string
))
1202 h
->flags
&= ~HTML_NONOSPACE
;
1204 h
->flags
|= HTML_NONOSPACE
;
1206 if ( ! (HTML_NONOSPACE
& h
->flags
))
1207 h
->flags
&= ~HTML_NOSPACE
;
1213 mdoc_skip_pre(MDOC_ARGS
)
1220 mdoc_pp_pre(MDOC_ARGS
)
1228 mdoc_sp_pre(MDOC_ARGS
)
1232 SCALE_VS_INIT(&su
, 1);
1234 if (MDOC_sp
== n
->tok
) {
1235 if (NULL
!= (n
= n
->child
)) {
1236 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1238 else if (su
.scale
< 0.0)
1244 print_otag(h
, TAG_DIV
, "suh", &su
);
1246 /* So the div isn't empty: */
1247 print_text(h
, "\\~");
1254 mdoc_lk_pre(MDOC_ARGS
)
1256 if (NULL
== (n
= n
->child
))
1259 assert(n
->type
== ROFFT_TEXT
);
1261 print_otag(h
, TAG_A
, "ch", "link-ext", n
->string
);
1263 if (NULL
== n
->next
)
1264 print_text(h
, n
->string
);
1266 for (n
= n
->next
; n
; n
= n
->next
)
1267 print_text(h
, n
->string
);
1273 mdoc_mt_pre(MDOC_ARGS
)
1278 for (n
= n
->child
; n
; n
= n
->next
) {
1279 assert(n
->type
== ROFFT_TEXT
);
1281 mandoc_asprintf(&cp
, "mailto:%s", n
->string
);
1282 t
= print_otag(h
, TAG_A
, "ch", "link-mail", cp
);
1283 print_text(h
, n
->string
);
1292 mdoc_fo_pre(MDOC_ARGS
)
1296 if (n
->type
== ROFFT_BODY
) {
1297 h
->flags
|= HTML_NOSPACE
;
1299 h
->flags
|= HTML_NOSPACE
;
1301 } else if (n
->type
== ROFFT_BLOCK
) {
1306 if (n
->child
== NULL
)
1309 assert(n
->child
->string
);
1310 t
= print_otag(h
, TAG_B
, "c", "fname");
1311 print_text(h
, n
->child
->string
);
1317 mdoc_fo_post(MDOC_ARGS
)
1320 if (n
->type
!= ROFFT_BODY
)
1322 h
->flags
|= HTML_NOSPACE
;
1324 h
->flags
|= HTML_NOSPACE
;
1329 mdoc_in_pre(MDOC_ARGS
)
1334 print_otag(h
, TAG_B
, "c", "includes");
1337 * The first argument of the `In' gets special treatment as
1338 * being a linked value. Subsequent values are printed
1339 * afterward. groff does similarly. This also handles the case
1343 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
)
1344 print_text(h
, "#include");
1347 h
->flags
|= HTML_NOSPACE
;
1349 if (NULL
!= (n
= n
->child
)) {
1350 assert(n
->type
== ROFFT_TEXT
);
1352 if (h
->base_includes
)
1353 t
= print_otag(h
, TAG_A
, "chI", "link-includes",
1356 t
= print_otag(h
, TAG_A
, "c", "link-includes");
1357 print_text(h
, n
->string
);
1363 h
->flags
|= HTML_NOSPACE
;
1366 for ( ; n
; n
= n
->next
) {
1367 assert(n
->type
== ROFFT_TEXT
);
1368 print_text(h
, n
->string
);
1375 mdoc_ic_pre(MDOC_ARGS
)
1377 print_otag(h
, TAG_B
, "c", "cmd");
1382 mdoc_va_pre(MDOC_ARGS
)
1384 print_otag(h
, TAG_B
, "c", "var");
1389 mdoc_ap_pre(MDOC_ARGS
)
1392 h
->flags
|= HTML_NOSPACE
;
1393 print_text(h
, "\\(aq");
1394 h
->flags
|= HTML_NOSPACE
;
1399 mdoc_bf_pre(MDOC_ARGS
)
1403 if (n
->type
== ROFFT_HEAD
)
1405 else if (n
->type
!= ROFFT_BODY
)
1408 if (FONT_Em
== n
->norm
->Bf
.font
)
1410 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1412 else if (FONT_Li
== n
->norm
->Bf
.font
)
1418 * We want this to be inline-formatted, but needs to be div to
1419 * accept block children.
1422 print_otag(h
, TAG_DIV
, "css?hl", cattr
, "display", "inline", 1);
1427 mdoc_ms_pre(MDOC_ARGS
)
1429 print_otag(h
, TAG_SPAN
, "c", "symb");
1434 mdoc_igndelim_pre(MDOC_ARGS
)
1437 h
->flags
|= HTML_IGNDELIM
;
1442 mdoc_pf_post(MDOC_ARGS
)
1445 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1446 h
->flags
|= HTML_NOSPACE
;
1450 mdoc_rs_pre(MDOC_ARGS
)
1452 if (n
->type
!= ROFFT_BLOCK
)
1455 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1458 print_otag(h
, TAG_SPAN
, "c", "ref");
1463 mdoc_no_pre(MDOC_ARGS
)
1465 print_otag(h
, TAG_SPAN
, "c", "none");
1470 mdoc_li_pre(MDOC_ARGS
)
1472 print_otag(h
, TAG_CODE
, "c", "Li");
1477 mdoc_sy_pre(MDOC_ARGS
)
1479 print_otag(h
, TAG_SPAN
, "c", "symb");
1484 mdoc_lb_pre(MDOC_ARGS
)
1486 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
&& n
->prev
)
1487 print_otag(h
, TAG_BR
, "");
1489 print_otag(h
, TAG_SPAN
, "c", "lib");
1494 mdoc__x_pre(MDOC_ARGS
)
1504 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1505 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1506 print_text(h
, "and");
1519 cattr
= "ref-issue";
1542 cattr
= "ref-title";
1554 if (MDOC__U
!= n
->tok
) {
1555 print_otag(h
, t
, "c", cattr
);
1559 print_otag(h
, TAG_A
, "ch", cattr
, n
->child
->string
);
1565 mdoc__x_post(MDOC_ARGS
)
1568 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1569 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1570 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1575 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1578 h
->flags
|= HTML_NOSPACE
;
1579 print_text(h
, n
->next
? "," : ".");
1583 mdoc_bk_pre(MDOC_ARGS
)
1592 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1593 h
->flags
|= HTML_PREKEEP
;
1603 mdoc_bk_post(MDOC_ARGS
)
1606 if (n
->type
== ROFFT_BODY
)
1607 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
1611 mdoc_quote_pre(MDOC_ARGS
)
1613 if (n
->type
!= ROFFT_BODY
)
1619 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1620 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1624 print_text(h
, "\\(lC");
1628 print_text(h
, "\\(lB");
1632 print_text(h
, "\\(lB");
1633 h
->flags
|= HTML_NOSPACE
;
1634 print_otag(h
, TAG_SPAN
, "c", "opt");
1637 if (NULL
== n
->norm
->Es
||
1638 NULL
== n
->norm
->Es
->child
)
1640 print_text(h
, n
->norm
->Es
->child
->string
);
1646 print_text(h
, "\\(lq");
1653 print_text(h
, "\\(oq");
1654 h
->flags
|= HTML_NOSPACE
;
1655 print_otag(h
, TAG_CODE
, "c", "Li");
1659 print_text(h
, "\\(oq");
1665 h
->flags
|= HTML_NOSPACE
;
1670 mdoc_quote_post(MDOC_ARGS
)
1673 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1676 h
->flags
|= HTML_NOSPACE
;
1681 print_text(h
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1682 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1686 print_text(h
, "\\(rC");
1692 print_text(h
, "\\(rB");
1695 if (n
->norm
->Es
== NULL
||
1696 n
->norm
->Es
->child
== NULL
||
1697 n
->norm
->Es
->child
->next
== NULL
)
1698 h
->flags
&= ~HTML_NOSPACE
;
1700 print_text(h
, n
->norm
->Es
->child
->next
->string
);
1706 print_text(h
, "\\(rq");
1715 print_text(h
, "\\(cq");
1723 mdoc_eo_pre(MDOC_ARGS
)
1726 if (n
->type
!= ROFFT_BODY
)
1729 if (n
->end
== ENDBODY_NOT
&&
1730 n
->parent
->head
->child
== NULL
&&
1732 n
->child
->end
!= ENDBODY_NOT
)
1733 print_text(h
, "\\&");
1734 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1735 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1736 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1737 h
->flags
|= HTML_NOSPACE
;
1742 mdoc_eo_post(MDOC_ARGS
)
1746 if (n
->type
!= ROFFT_BODY
)
1749 if (n
->end
!= ENDBODY_NOT
) {
1750 h
->flags
&= ~HTML_NOSPACE
;
1754 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1755 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1758 h
->flags
|= HTML_NOSPACE
;
1760 h
->flags
&= ~HTML_NOSPACE
;