]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_html.c
1 /* $Id: mdoc_html.c,v 1.1 2009/09/21 14:56:57 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/types.h>
18 #include <sys/queue.h>
34 #define MDOC_ARGS const struct mdoc_meta *m, \
35 const struct mdoc_node *n, \
37 #define MAN_ARGS const struct man_meta *m, \
38 const struct man_node *n, \
42 int (*pre
)(MDOC_ARGS
);
43 void (*post
)(MDOC_ARGS
);
46 static void print_mdoc(MDOC_ARGS
);
47 static void print_mdoc_head(MDOC_ARGS
);
48 static void print_mdoc_node(MDOC_ARGS
);
49 static void print_mdoc_nodelist(MDOC_ARGS
);
51 static int a2width(const char *);
52 static int a2offs(const char *);
53 static int a2list(const struct mdoc_node
*);
55 static void mdoc_root_post(MDOC_ARGS
);
56 static int mdoc_root_pre(MDOC_ARGS
);
57 static int mdoc_tbl_pre(MDOC_ARGS
, int);
58 static int mdoc_tbl_block_pre(MDOC_ARGS
, int, int, int, int);
59 static int mdoc_tbl_body_pre(MDOC_ARGS
, int, int);
60 static int mdoc_tbl_head_pre(MDOC_ARGS
, int, int);
62 static int mdoc_ad_pre(MDOC_ARGS
);
63 static int mdoc_an_pre(MDOC_ARGS
);
64 static void mdoc_aq_post(MDOC_ARGS
);
65 static int mdoc_aq_pre(MDOC_ARGS
);
66 static int mdoc_ar_pre(MDOC_ARGS
);
67 static int mdoc_bd_pre(MDOC_ARGS
);
68 static void mdoc_bl_post(MDOC_ARGS
);
69 static int mdoc_bl_pre(MDOC_ARGS
);
70 static int mdoc_cd_pre(MDOC_ARGS
);
71 static int mdoc_d1_pre(MDOC_ARGS
);
72 static void mdoc_dq_post(MDOC_ARGS
);
73 static int mdoc_dq_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 int mdoc_er_pre(MDOC_ARGS
);
82 static int mdoc_ev_pre(MDOC_ARGS
);
83 static int mdoc_ex_pre(MDOC_ARGS
);
84 static int mdoc_it_pre(MDOC_ARGS
);
85 static int mdoc_nd_pre(MDOC_ARGS
);
86 static int mdoc_nm_pre(MDOC_ARGS
);
87 static int mdoc_ns_pre(MDOC_ARGS
);
88 static void mdoc_op_post(MDOC_ARGS
);
89 static int mdoc_op_pre(MDOC_ARGS
);
90 static int mdoc_pa_pre(MDOC_ARGS
);
91 static void mdoc_pq_post(MDOC_ARGS
);
92 static int mdoc_pq_pre(MDOC_ARGS
);
93 static void mdoc_qq_post(MDOC_ARGS
);
94 static int mdoc_qq_pre(MDOC_ARGS
);
95 static int mdoc_sh_pre(MDOC_ARGS
);
96 static int mdoc_sp_pre(MDOC_ARGS
);
97 static void mdoc_sq_post(MDOC_ARGS
);
98 static int mdoc_sq_pre(MDOC_ARGS
);
99 static int mdoc_ss_pre(MDOC_ARGS
);
100 static int mdoc_sx_pre(MDOC_ARGS
);
101 static int mdoc_vt_pre(MDOC_ARGS
);
102 static int mdoc_xr_pre(MDOC_ARGS
);
103 static int mdoc_xx_pre(MDOC_ARGS
);
106 extern size_t strlcpy(char *, const char *, size_t);
107 extern size_t strlcat(char *, const char *, size_t);
110 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
111 {NULL
, NULL
}, /* Ap */
112 {NULL
, NULL
}, /* Dd */
113 {NULL
, NULL
}, /* Dt */
114 {NULL
, NULL
}, /* Os */
115 {mdoc_sh_pre
, NULL
}, /* Sh */
116 {mdoc_ss_pre
, NULL
}, /* Ss */
117 {mdoc_sp_pre
, NULL
}, /* Pp */
118 {mdoc_d1_pre
, NULL
}, /* D1 */
119 {mdoc_d1_pre
, NULL
}, /* Dl */
120 {mdoc_bd_pre
, NULL
}, /* Bd */
121 {NULL
, NULL
}, /* Ed */
122 {mdoc_bl_pre
, mdoc_bl_post
}, /* Bl */
123 {NULL
, NULL
}, /* El */
124 {mdoc_it_pre
, NULL
}, /* It */
125 {mdoc_ad_pre
, NULL
}, /* Ad */
126 {mdoc_an_pre
, NULL
}, /* An */
127 {mdoc_ar_pre
, NULL
}, /* Ar */
128 {mdoc_cd_pre
, NULL
}, /* Cd */
129 {mdoc_fl_pre
, NULL
}, /* Cm */
130 {mdoc_dv_pre
, NULL
}, /* Dv */
131 {mdoc_er_pre
, NULL
}, /* Er */
132 {mdoc_ev_pre
, NULL
}, /* Ev */
133 {mdoc_ex_pre
, NULL
}, /* Ex */
134 {mdoc_fa_pre
, NULL
}, /* Fa */
135 {mdoc_fd_pre
, NULL
}, /* Fd */
136 {mdoc_fl_pre
, NULL
}, /* Fl */
137 {mdoc_fn_pre
, NULL
}, /* Fn */
138 {mdoc_ft_pre
, NULL
}, /* Ft */
139 {NULL
, NULL
}, /* Ic */
140 {NULL
, NULL
}, /* In */
141 {NULL
, NULL
}, /* Li */
142 {mdoc_nd_pre
, NULL
}, /* Nd */
143 {mdoc_nm_pre
, NULL
}, /* Nm */
144 {mdoc_op_pre
, mdoc_op_post
}, /* Op */
145 {NULL
, NULL
}, /* Ot */
146 {mdoc_pa_pre
, NULL
}, /* Pa */
147 {NULL
, NULL
}, /* Rv */
148 {NULL
, NULL
}, /* St */
149 {NULL
, NULL
}, /* Va */
150 {mdoc_vt_pre
, NULL
}, /* Vt */
151 {mdoc_xr_pre
, NULL
}, /* Xr */
152 {NULL
, NULL
}, /* %A */
153 {NULL
, NULL
}, /* %B */
154 {NULL
, NULL
}, /* %D */
155 {NULL
, NULL
}, /* %I */
156 {NULL
, NULL
}, /* %J */
157 {NULL
, NULL
}, /* %N */
158 {NULL
, NULL
}, /* %O */
159 {NULL
, NULL
}, /* %P */
160 {NULL
, NULL
}, /* %R */
161 {NULL
, NULL
}, /* %T */
162 {NULL
, NULL
}, /* %V */
163 {NULL
, NULL
}, /* Ac */
164 {mdoc_aq_pre
, mdoc_aq_post
}, /* Ao */
165 {mdoc_aq_pre
, mdoc_aq_post
}, /* Aq */
166 {NULL
, NULL
}, /* At */
167 {NULL
, NULL
}, /* Bc */
168 {NULL
, NULL
}, /* Bf */
169 {NULL
, NULL
}, /* Bo */
170 {NULL
, NULL
}, /* Bq */
171 {mdoc_xx_pre
, NULL
}, /* Bsx */
172 {NULL
, NULL
}, /* Bx */
173 {NULL
, NULL
}, /* Db */
174 {NULL
, NULL
}, /* Dc */
175 {NULL
, NULL
}, /* Do */
176 {mdoc_dq_pre
, mdoc_dq_post
}, /* Dq */
177 {NULL
, NULL
}, /* Ec */
178 {NULL
, NULL
}, /* Ef */
179 {mdoc_em_pre
, NULL
}, /* Em */
180 {NULL
, NULL
}, /* Eo */
181 {mdoc_xx_pre
, NULL
}, /* Fx */
182 {NULL
, NULL
}, /* Ms */
183 {NULL
, NULL
}, /* No */
184 {mdoc_ns_pre
, NULL
}, /* Ns */
185 {mdoc_xx_pre
, NULL
}, /* Nx */
186 {mdoc_xx_pre
, NULL
}, /* Ox */
187 {NULL
, NULL
}, /* Pc */
188 {NULL
, NULL
}, /* Pf */
189 {mdoc_pq_pre
, mdoc_pq_post
}, /* Po */
190 {mdoc_pq_pre
, mdoc_pq_post
}, /* Pq */
191 {NULL
, NULL
}, /* Qc */
192 {NULL
, NULL
}, /* Ql */
193 {mdoc_qq_pre
, mdoc_qq_post
}, /* Qo */
194 {mdoc_qq_pre
, mdoc_qq_post
}, /* Qq */
195 {NULL
, NULL
}, /* Re */
196 {NULL
, NULL
}, /* Rs */
197 {NULL
, NULL
}, /* Sc */
198 {mdoc_sq_pre
, mdoc_sq_post
}, /* So */
199 {mdoc_sq_pre
, mdoc_sq_post
}, /* Sq */
200 {NULL
, NULL
}, /* Sm */
201 {mdoc_sx_pre
, NULL
}, /* Sx */
202 {NULL
, NULL
}, /* Sy */
203 {NULL
, NULL
}, /* Tn */
204 {mdoc_xx_pre
, NULL
}, /* Ux */
205 {NULL
, NULL
}, /* Xc */
206 {NULL
, NULL
}, /* Xo */
207 {NULL
, NULL
}, /* Fo */
208 {NULL
, NULL
}, /* Fc */
209 {NULL
, NULL
}, /* Oo */
210 {NULL
, NULL
}, /* Oc */
211 {NULL
, NULL
}, /* Bk */
212 {NULL
, NULL
}, /* Ek */
213 {NULL
, NULL
}, /* Bt */
214 {NULL
, NULL
}, /* Hf */
215 {NULL
, NULL
}, /* Fr */
216 {NULL
, NULL
}, /* Ud */
217 {NULL
, NULL
}, /* Lb */
218 {mdoc_sp_pre
, NULL
}, /* Lp */
219 {NULL
, NULL
}, /* Lk */
220 {NULL
, NULL
}, /* Mt */
221 {NULL
, NULL
}, /* Brq */
222 {NULL
, NULL
}, /* Bro */
223 {NULL
, NULL
}, /* Brc */
224 {NULL
, NULL
}, /* %C */
225 {NULL
, NULL
}, /* Es */
226 {NULL
, NULL
}, /* En */
227 {mdoc_xx_pre
, NULL
}, /* Dx */
228 {NULL
, NULL
}, /* %Q */
229 {mdoc_sp_pre
, NULL
}, /* br */
230 {mdoc_sp_pre
, NULL
}, /* sp */
233 static char buf
[BUFSIZ
]; /* XXX */
235 #define bufcat(x) (void)strlcat(buf, (x), BUFSIZ)
236 #define bufinit() buf[0] = 0
237 #define buffmt(...) (void)snprintf(buf, BUFSIZ - 1, __VA_ARGS__)
240 html_mdoc(void *arg
, const struct mdoc
*m
)
245 h
= (struct html
*)arg
;
247 print_gen_doctype(h
);
248 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
249 print_mdoc(mdoc_meta(m
), mdoc_node(m
), h
);
257 a2list(const struct mdoc_node
*n
)
261 assert(MDOC_BLOCK
== n
->type
&& MDOC_Bl
== n
->tok
);
264 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
265 switch (n
->args
->argv
[i
].arg
) {
287 return(n
->args
->argv
[i
].arg
);
298 a2width(const char *p
)
302 if (0 == (len
= (int)strlen(p
)))
304 for (i
= 0; i
< len
- 1; i
++)
305 if ( ! isdigit((u_char
)p
[i
]))
309 if ('n' == p
[len
- 1] || 'm' == p
[len
- 1])
317 a2offs(const char *p
)
321 if (0 == strcmp(p
, "left"))
323 if (0 == strcmp(p
, "indent"))
325 if (0 == strcmp(p
, "indent-two"))
326 return((INDENT
+ 1) * 2);
328 if (0 == (len
= (int)strlen(p
)))
331 for (i
= 0; i
< len
- 1; i
++)
332 if ( ! isdigit((u_char
)p
[i
]))
336 if ('n' == p
[len
- 1] || 'm' == p
[len
- 1])
344 print_mdoc(MDOC_ARGS
)
349 t
= print_otag(h
, TAG_HEAD
, 0, NULL
);
350 print_mdoc_head(m
, n
, h
);
353 t
= print_otag(h
, TAG_BODY
, 0, NULL
);
355 tag
.key
= ATTR_CLASS
;
357 print_otag(h
, TAG_DIV
, 1, &tag
);
359 print_mdoc_nodelist(m
, n
, h
);
366 print_mdoc_head(MDOC_ARGS
)
372 (void)snprintf(b
, BUFSIZ
- 1,
373 "%s(%d)", m
->title
, m
->msec
);
376 (void)strlcat(b
, " (", BUFSIZ
);
377 (void)strlcat(b
, m
->arch
, BUFSIZ
);
378 (void)strlcat(b
, ")", BUFSIZ
);
381 print_otag(h
, TAG_TITLE
, 0, NULL
);
387 print_mdoc_nodelist(MDOC_ARGS
)
390 print_mdoc_node(m
, n
, h
);
392 print_mdoc_nodelist(m
, n
->next
, h
);
397 print_mdoc_node(MDOC_ARGS
)
403 t
= SLIST_FIRST(&h
->tags
);
409 child
= mdoc_root_pre(m
, n
, h
);
412 print_text(h
, n
->string
);
415 if (mdocs
[n
->tok
].pre
)
416 child
= (*mdocs
[n
->tok
].pre
)(m
, n
, h
);
420 if (child
&& n
->child
)
421 print_mdoc_nodelist(m
, n
->child
, h
);
429 mdoc_root_post(m
, n
, h
);
434 if (mdocs
[n
->tok
].post
)
435 (*mdocs
[n
->tok
].post
)(m
, n
, h
);
443 mdoc_root_post(MDOC_ARGS
)
446 struct htmlpair tag
[2];
450 (void)localtime_r(&m
->date
, &tm
);
452 if (0 == strftime(b
, BUFSIZ
- 1, "%B %e, %Y", &tm
))
453 err(EXIT_FAILURE
, "strftime");
455 tag
[0].key
= ATTR_CLASS
;
456 tag
[0].val
= "footer";
457 tag
[1].key
= ATTR_STYLE
;
458 tag
[1].val
= "width: 100%;";
459 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
460 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
462 tag
[0].key
= ATTR_STYLE
;
463 tag
[0].val
= "width: 50%;";
464 print_otag(h
, TAG_TD
, 1, tag
);
468 tag
[0].key
= ATTR_STYLE
;
469 tag
[0].val
= "width: 50%; text-align: right;";
470 print_otag(h
, TAG_TD
, 1, tag
);
471 print_text(h
, m
->os
);
478 mdoc_root_pre(MDOC_ARGS
)
480 struct htmlpair tag
[2];
482 char b
[BUFSIZ
], title
[BUFSIZ
];
484 (void)strlcpy(b
, m
->vol
, BUFSIZ
);
487 (void)strlcat(b
, " (", BUFSIZ
);
488 (void)strlcat(b
, m
->arch
, BUFSIZ
);
489 (void)strlcat(b
, ")", BUFSIZ
);
492 (void)snprintf(title
, BUFSIZ
- 1,
493 "%s(%d)", m
->title
, m
->msec
);
495 tag
[0].key
= ATTR_CLASS
;
496 tag
[0].val
= "header";
497 tag
[1].key
= ATTR_STYLE
;
498 tag
[1].val
= "width: 100%;";
499 t
= print_otag(h
, TAG_TABLE
, 2, tag
);
500 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
502 tag
[0].key
= ATTR_STYLE
;
503 tag
[0].val
= "width: 33%;";
504 print_otag(h
, TAG_TD
, 1, tag
);
508 tag
[0].key
= ATTR_STYLE
;
509 tag
[0].val
= "width: 33%; text-align: center;";
510 print_otag(h
, TAG_TD
, 1, tag
);
511 print_text(h
, title
);
514 tag
[0].key
= ATTR_STYLE
;
515 tag
[0].val
= "width: 33%; text-align: right;";
516 print_otag(h
, TAG_TD
, 1, tag
);
526 mdoc_sh_pre(MDOC_ARGS
)
528 struct htmlpair tag
[2];
529 const struct mdoc_node
*nn
;
531 if (MDOC_HEAD
== n
->type
) {
532 tag
[0].key
= ATTR_CLASS
;
533 tag
[0].val
= "sec-head";
534 print_otag(h
, TAG_DIV
, 1, tag
);
535 print_otag(h
, TAG_SPAN
, 1, tag
);
537 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
542 tag
[0].key
= ATTR_NAME
;
544 print_otag(h
, TAG_A
, 1, tag
);
546 } else if (MDOC_BLOCK
== n
->type
) {
547 tag
[0].key
= ATTR_CLASS
;
548 tag
[0].val
= "sec-block";
550 if (n
->prev
&& NULL
== n
->prev
->body
->child
) {
551 print_otag(h
, TAG_DIV
, 1, tag
);
555 bufcat("margin-top: 1em;");
557 bufcat("margin-bottom: 1em;");
559 tag
[1].key
= ATTR_STYLE
;
562 print_otag(h
, TAG_DIV
, 2, tag
);
566 buffmt("margin-left: %dem;", INDENT
);
568 tag
[0].key
= ATTR_CLASS
;
569 tag
[0].val
= "sec-body";
570 tag
[1].key
= ATTR_STYLE
;
573 print_otag(h
, TAG_DIV
, 2, tag
);
580 mdoc_ss_pre(MDOC_ARGS
)
582 struct htmlpair tag
[2];
584 const struct mdoc_node
*nn
;
588 if (MDOC_BODY
== n
->type
) {
589 tag
[i
].key
= ATTR_CLASS
;
590 tag
[i
++].val
= "ssec-body";
591 if (n
->parent
->next
&& n
->child
) {
592 bufcat("margin-bottom: 1em;");
593 tag
[i
].key
= ATTR_STYLE
;
596 print_otag(h
, TAG_DIV
, i
, tag
);
598 } else if (MDOC_BLOCK
== n
->type
) {
599 tag
[i
].key
= ATTR_CLASS
;
600 tag
[i
++].val
= "ssec-block";
602 bufcat("margin-top: 1em;");
603 tag
[i
].key
= ATTR_STYLE
;
606 print_otag(h
, TAG_DIV
, i
, tag
);
610 buffmt("margin-left: -%dem;", INDENT
- HALFINDENT
);
612 tag
[0].key
= ATTR_CLASS
;
613 tag
[0].val
= "ssec-head";
614 tag
[1].key
= ATTR_STYLE
;
617 print_otag(h
, TAG_DIV
, 2, tag
);
618 print_otag(h
, TAG_SPAN
, 1, tag
);
621 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
626 tag
[0].key
= ATTR_NAME
;
628 print_otag(h
, TAG_A
, 1, tag
);
636 mdoc_fl_pre(MDOC_ARGS
)
640 tag
.key
= ATTR_CLASS
;
643 print_otag(h
, TAG_SPAN
, 1, &tag
);
644 if (MDOC_Fl
== n
->tok
) {
645 print_text(h
, "\\-");
646 h
->flags
|= HTML_NOSPACE
;
654 mdoc_nd_pre(MDOC_ARGS
)
658 if (MDOC_BODY
!= n
->type
)
661 /* XXX - this can contain block elements! */
662 print_text(h
, "\\(em");
663 tag
.key
= ATTR_CLASS
;
664 tag
.val
= "desc-body";
665 print_otag(h
, TAG_SPAN
, 1, &tag
);
672 mdoc_op_pre(MDOC_ARGS
)
676 if (MDOC_BODY
!= n
->type
)
679 /* XXX - this can contain block elements! */
680 print_text(h
, "\\(lB");
681 h
->flags
|= HTML_NOSPACE
;
682 tag
.key
= ATTR_CLASS
;
684 print_otag(h
, TAG_SPAN
, 1, &tag
);
691 mdoc_op_post(MDOC_ARGS
)
694 if (MDOC_BODY
!= n
->type
)
696 h
->flags
|= HTML_NOSPACE
;
697 print_text(h
, "\\(rB");
702 mdoc_nm_pre(MDOC_ARGS
)
706 if ( ! (HTML_NEWLINE
& h
->flags
))
707 if (SEC_SYNOPSIS
== n
->sec
) {
708 tag
.key
= ATTR_STYLE
;
709 tag
.val
= "clear: both;";
710 print_otag(h
, TAG_BR
, 1, &tag
);
713 tag
.key
= ATTR_CLASS
;
716 print_otag(h
, TAG_SPAN
, 1, &tag
);
717 if (NULL
== n
->child
)
718 print_text(h
, m
->name
);
726 mdoc_xr_pre(MDOC_ARGS
)
728 struct htmlpair tag
[2];
729 const char *name
, *sec
;
730 const struct mdoc_node
*nn
;
733 name
= nn
&& nn
->string
? nn
->string
: "";
734 nn
= nn
? nn
->next
: NULL
;
735 sec
= nn
&& nn
->string
? nn
->string
: "";
737 buffmt("%s%s%s.html", name
, name
&& sec
? "." : "", sec
);
739 tag
[0].key
= ATTR_CLASS
;
740 tag
[0].val
= "link-man";
741 tag
[1].key
= ATTR_HREF
;
743 print_otag(h
, TAG_A
, 2, tag
);
746 print_text(h
, nn
->string
);
747 if (NULL
== (nn
= nn
->next
))
750 h
->flags
|= HTML_NOSPACE
;
752 h
->flags
|= HTML_NOSPACE
;
753 print_text(h
, nn
->string
);
754 h
->flags
|= HTML_NOSPACE
;
763 mdoc_ns_pre(MDOC_ARGS
)
766 h
->flags
|= HTML_NOSPACE
;
773 mdoc_ar_pre(MDOC_ARGS
)
777 tag
.key
= ATTR_CLASS
;
780 print_otag(h
, TAG_SPAN
, 1, &tag
);
787 mdoc_xx_pre(MDOC_ARGS
)
815 tag
.key
= ATTR_CLASS
;
818 print_otag(h
, TAG_SPAN
, 1, &tag
);
826 mdoc_tbl_block_pre(MDOC_ARGS
, int t
, int w
, int o
, int c
)
836 buffmt("margin-left: %dem; clear: both;", o
);
839 buffmt("margin-left: %dem; clear: both;", w
+ o
);
843 if ( ! c
&& MDOC_Column
!= t
) {
844 if (n
->prev
&& n
->prev
->body
->child
)
845 bufcat("padding-top: 1em;");
846 else if (NULL
== n
->prev
)
847 bufcat("padding-top: 1em;");
850 tag
.key
= ATTR_STYLE
;
852 print_otag(h
, TAG_DIV
, 1, &tag
);
859 mdoc_tbl_body_pre(MDOC_ARGS
, int t
, int w
)
862 print_otag(h
, TAG_DIV
, 0, NULL
);
869 mdoc_tbl_head_pre(MDOC_ARGS
, int t
, int w
)
879 print_otag(h
, TAG_DIV
, 0, NULL
);
882 buffmt("min-width: %dem;", w
);
883 bufcat("clear: none;");
884 if (n
->next
&& MDOC_HEAD
== n
->next
->type
)
885 bufcat("float: left;");
886 tag
.key
= ATTR_STYLE
;
888 print_otag(h
, TAG_DIV
, 1, &tag
);
891 buffmt("margin-left: -%dem;", w
);
892 bufcat("clear: left;");
893 bufcat("float: left;");
894 bufcat("padding-right: 1em;");
895 tag
.key
= ATTR_STYLE
;
897 print_otag(h
, TAG_DIV
, 1, &tag
);
903 tag
.key
= ATTR_CLASS
;
905 print_otag(h
, TAG_SPAN
, 1, &tag
);
908 ord
= SLIST_FIRST(&h
->ords
);
910 nbuf
[BUFSIZ
- 1] = 0;
911 (void)snprintf(nbuf
, BUFSIZ
- 1, "%d.", ord
->pos
++);
915 print_text(h
, "\\(en");
918 print_text(h
, "\\-");
921 print_text(h
, "\\(bu");
932 mdoc_tbl_pre(MDOC_ARGS
, int type
)
935 const struct mdoc_node
*bl
, *nn
;
937 bl
= n
->parent
->parent
;
938 if (MDOC_BLOCK
!= n
->type
)
941 /* FIXME: fmt_vspace() equivalent. */
948 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
949 if (MDOC_Width
== bl
->args
->argv
[i
].arg
) {
950 assert(bl
->args
->argv
[i
].sz
);
952 w
= a2width(bl
->args
->argv
[i
].value
[0]);
953 } else if (MDOC_Offset
== bl
->args
->argv
[i
].arg
) {
954 assert(bl
->args
->argv
[i
].sz
);
955 o
= a2offs(bl
->args
->argv
[i
].value
[0]);
956 } else if (MDOC_Compact
== bl
->args
->argv
[i
].arg
)
959 if (MDOC_HEAD
== n
->type
&& MDOC_Column
== type
) {
960 nn
= n
->parent
->child
;
961 assert(nn
&& MDOC_HEAD
== nn
->type
);
962 for (i
= 0; nn
&& nn
!= n
; nn
= nn
->next
, i
++)
965 if (wp
>= 0 && i
< (int)bl
->args
[wp
].argv
->sz
)
966 w
= a2width(bl
->args
->argv
[wp
].value
[i
]);
995 return(mdoc_tbl_head_pre(m
, n
, h
, type
, w
));
997 return(mdoc_tbl_body_pre(m
, n
, h
, type
, w
));
1003 return(mdoc_tbl_block_pre(m
, n
, h
, type
, w
, o
, c
));
1009 mdoc_bl_pre(MDOC_ARGS
)
1013 if (MDOC_BLOCK
!= n
->type
)
1015 if (MDOC_Enum
!= a2list(n
))
1018 ord
= malloc(sizeof(struct ord
));
1020 err(EXIT_FAILURE
, "malloc");
1023 SLIST_INSERT_HEAD(&h
->ords
, ord
, entry
);
1031 mdoc_bl_post(MDOC_ARGS
)
1035 if (MDOC_BLOCK
!= n
->type
)
1037 if (MDOC_Enum
!= a2list(n
))
1040 ord
= SLIST_FIRST(&h
->ords
);
1042 SLIST_REMOVE_HEAD(&h
->ords
, entry
);
1048 mdoc_it_pre(MDOC_ARGS
)
1052 if (MDOC_BLOCK
== n
->type
)
1053 type
= a2list(n
->parent
->parent
);
1055 type
= a2list(n
->parent
->parent
->parent
);
1057 return(mdoc_tbl_pre(m
, n
, h
, type
));
1063 mdoc_ex_pre(MDOC_ARGS
)
1065 const struct mdoc_node
*nn
;
1067 struct htmlpair tag
;
1069 print_text(h
, "The");
1071 tag
.key
= ATTR_CLASS
;
1072 tag
.val
= "utility";
1074 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1075 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1076 print_text(h
, nn
->string
);
1079 h
->flags
|= HTML_NOSPACE
;
1081 if (nn
->next
&& NULL
== nn
->next
->next
)
1082 print_text(h
, ", and");
1086 h
->flags
&= ~HTML_NOSPACE
;
1090 print_text(h
, "utilities exit");
1092 print_text(h
, "utility exits");
1094 print_text(h
, "0 on success, and >0 if an error occurs.");
1101 mdoc_dq_pre(MDOC_ARGS
)
1104 if (MDOC_BODY
!= n
->type
)
1106 print_text(h
, "\\(lq");
1107 h
->flags
|= HTML_NOSPACE
;
1114 mdoc_dq_post(MDOC_ARGS
)
1117 if (MDOC_BODY
!= n
->type
)
1119 h
->flags
|= HTML_NOSPACE
;
1120 print_text(h
, "\\(rq");
1126 mdoc_pq_pre(MDOC_ARGS
)
1129 if (MDOC_BODY
!= n
->type
)
1131 print_text(h
, "\\&(");
1132 h
->flags
|= HTML_NOSPACE
;
1139 mdoc_pq_post(MDOC_ARGS
)
1142 if (MDOC_BODY
!= n
->type
)
1150 mdoc_sq_pre(MDOC_ARGS
)
1153 if (MDOC_BODY
!= n
->type
)
1155 print_text(h
, "\\(oq");
1156 h
->flags
|= HTML_NOSPACE
;
1163 mdoc_sq_post(MDOC_ARGS
)
1166 if (MDOC_BODY
!= n
->type
)
1168 h
->flags
|= HTML_NOSPACE
;
1169 print_text(h
, "\\(aq");
1175 mdoc_em_pre(MDOC_ARGS
)
1177 struct htmlpair tag
;
1179 tag
.key
= ATTR_CLASS
;
1182 print_otag(h
, TAG_SPAN
, 1, &tag
);
1189 mdoc_d1_pre(MDOC_ARGS
)
1191 struct htmlpair tag
[2];
1193 if (MDOC_BLOCK
!= n
->type
)
1196 buffmt("margin-left: %dem;", INDENT
);
1198 tag
[0].key
= ATTR_CLASS
;
1199 tag
[0].val
= "lit-block";
1200 tag
[1].key
= ATTR_STYLE
;
1203 print_otag(h
, TAG_DIV
, 2, tag
);
1210 mdoc_sx_pre(MDOC_ARGS
)
1212 struct htmlpair tag
[2];
1213 const struct mdoc_node
*nn
;
1216 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1222 tag
[0].key
= ATTR_HREF
;
1224 tag
[1].key
= ATTR_CLASS
;
1225 tag
[1].val
= "link-sec";
1227 print_otag(h
, TAG_A
, 2, tag
);
1234 mdoc_aq_pre(MDOC_ARGS
)
1237 if (MDOC_BODY
!= n
->type
)
1239 print_text(h
, "\\(la");
1240 h
->flags
|= HTML_NOSPACE
;
1247 mdoc_aq_post(MDOC_ARGS
)
1250 if (MDOC_BODY
!= n
->type
)
1252 h
->flags
|= HTML_NOSPACE
;
1253 print_text(h
, "\\(ra");
1259 mdoc_bd_pre(MDOC_ARGS
)
1261 struct htmlpair tag
[2];
1263 const struct mdoc_node
*bl
;
1265 /* FIXME: fmt_vspace() shit. */
1267 if (MDOC_BLOCK
== n
->type
)
1269 else if (MDOC_HEAD
== n
->type
)
1276 for (i
= 0; i
< (int)bl
->args
->argc
; i
++)
1277 switch (bl
->args
->argv
[i
].arg
) {
1279 assert(bl
->args
->argv
[i
].sz
);
1280 o
= a2offs (bl
->args
->argv
[i
].value
[0]);
1282 case (MDOC_Compact
):
1289 case (MDOC_Unfilled
):
1291 case (MDOC_Literal
):
1292 t
= bl
->args
->argv
[i
].arg
;
1296 if (MDOC_BLOCK
== n
->type
) {
1298 buffmt("margin-left: %dem;", o
);
1299 bufcat("margin-top: 1em;");
1300 tag
[0].key
= ATTR_STYLE
;
1302 print_otag(h
, TAG_DIV
, 1, tag
);
1307 case (MDOC_Unfilled
):
1308 case (MDOC_Literal
):
1314 bufcat("white-space: pre;");
1315 tag
[0].key
= ATTR_STYLE
;
1317 tag
[1].key
= ATTR_CLASS
;
1318 tag
[1].val
= "lit-block";
1320 print_otag(h
, TAG_DIV
, 2, tag
);
1322 for (n
= n
->child
; n
; n
= n
->next
) {
1323 h
->flags
|= HTML_NOSPACE
;
1324 print_mdoc_node(m
, n
, h
);
1326 print_text(h
, "\n");
1335 mdoc_pa_pre(MDOC_ARGS
)
1337 struct htmlpair tag
;
1339 tag
.key
= ATTR_CLASS
;
1342 print_otag(h
, TAG_SPAN
, 1, &tag
);
1349 mdoc_qq_pre(MDOC_ARGS
)
1352 if (MDOC_BODY
!= n
->type
)
1354 print_text(h
, "\\*q");
1355 h
->flags
|= HTML_NOSPACE
;
1362 mdoc_qq_post(MDOC_ARGS
)
1365 if (MDOC_BODY
!= n
->type
)
1367 h
->flags
|= HTML_NOSPACE
;
1368 print_text(h
, "\\*q");
1374 mdoc_ad_pre(MDOC_ARGS
)
1376 struct htmlpair tag
;
1378 tag
.key
= ATTR_CLASS
;
1380 print_otag(h
, TAG_SPAN
, 1, &tag
);
1387 mdoc_an_pre(MDOC_ARGS
)
1389 struct htmlpair tag
;
1391 tag
.key
= ATTR_CLASS
;
1393 print_otag(h
, TAG_SPAN
, 1, &tag
);
1400 mdoc_cd_pre(MDOC_ARGS
)
1402 struct htmlpair tag
;
1404 tag
.key
= ATTR_CLASS
;
1406 print_otag(h
, TAG_SPAN
, 1, &tag
);
1413 mdoc_dv_pre(MDOC_ARGS
)
1415 struct htmlpair tag
;
1417 tag
.key
= ATTR_CLASS
;
1419 print_otag(h
, TAG_SPAN
, 1, &tag
);
1426 mdoc_ev_pre(MDOC_ARGS
)
1428 struct htmlpair tag
;
1430 tag
.key
= ATTR_CLASS
;
1432 print_otag(h
, TAG_SPAN
, 1, &tag
);
1439 mdoc_er_pre(MDOC_ARGS
)
1441 struct htmlpair tag
;
1443 tag
.key
= ATTR_CLASS
;
1445 print_otag(h
, TAG_SPAN
, 1, &tag
);
1452 mdoc_fa_pre(MDOC_ARGS
)
1454 const struct mdoc_node
*nn
;
1455 struct htmlpair tag
;
1458 tag
.key
= ATTR_CLASS
;
1461 if (n
->parent
->tok
!= MDOC_Fo
) {
1462 print_otag(h
, TAG_SPAN
, 1, &tag
);
1466 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1467 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1468 print_text(h
, nn
->string
);
1474 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1483 mdoc_fd_pre(MDOC_ARGS
)
1485 struct htmlpair tag
;
1487 if (SEC_SYNOPSIS
== n
->sec
) {
1488 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
) {
1489 tag
.key
= ATTR_STYLE
;
1490 tag
.val
= "margin-bottom: 1em;";
1491 print_otag(h
, TAG_DIV
, 1, &tag
);
1493 print_otag(h
, TAG_DIV
, 0, NULL
);
1496 tag
.key
= ATTR_CLASS
;
1498 print_otag(h
, TAG_SPAN
, 1, &tag
);
1505 mdoc_vt_pre(MDOC_ARGS
)
1507 struct htmlpair tag
;
1509 if (SEC_SYNOPSIS
== n
->sec
) {
1510 if (n
->next
&& MDOC_Vt
!= n
->next
->tok
) {
1511 tag
.key
= ATTR_STYLE
;
1512 tag
.val
= "margin-bottom: 1em;";
1513 print_otag(h
, TAG_DIV
, 1, &tag
);
1515 print_otag(h
, TAG_DIV
, 0, NULL
);
1518 tag
.key
= ATTR_CLASS
;
1520 print_otag(h
, TAG_SPAN
, 1, &tag
);
1526 mdoc_ft_pre(MDOC_ARGS
)
1528 struct htmlpair tag
;
1530 if (SEC_SYNOPSIS
== n
->sec
) {
1531 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
) {
1532 tag
.key
= ATTR_STYLE
;
1533 tag
.val
= "magin-bottom: 1em;";
1534 print_otag(h
, TAG_DIV
, 1, &tag
);
1536 print_otag(h
, TAG_DIV
, 0, NULL
);
1539 tag
.key
= ATTR_CLASS
;
1541 print_otag(h
, TAG_SPAN
, 1, &tag
);
1548 mdoc_fn_pre(MDOC_ARGS
)
1551 struct htmlpair tag
;
1552 const struct mdoc_node
*nn
;
1554 if (SEC_SYNOPSIS
== n
->sec
) {
1556 tag
.key
= ATTR_STYLE
;
1557 tag
.val
= "margin-bottom: 1em";
1558 print_otag(h
, TAG_DIV
, 1, &tag
);
1560 print_otag(h
, TAG_DIV
, 0, NULL
);
1563 tag
.key
= ATTR_CLASS
;
1566 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1567 print_text(h
, n
->child
->string
);
1570 h
->flags
|= HTML_NOSPACE
;
1573 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1574 tag
.key
= ATTR_CLASS
;
1576 t
= print_otag(h
, TAG_SPAN
, 1, &tag
);
1577 print_text(h
, nn
->string
);
1585 if (SEC_SYNOPSIS
== n
->sec
)
1594 mdoc_sp_pre(MDOC_ARGS
)
1597 struct htmlpair tag
;
1601 len
= n
->child
? atoi(n
->child
->string
) : 1;
1611 buffmt("height: %dem", len
);
1612 tag
.key
= ATTR_STYLE
;
1614 print_otag(h
, TAG_DIV
, 1, &tag
);