1 /* Id: mdoc_html.c,v 1.186 2013/12/24 20:45:27 schwarze Exp */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
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.
21 #include <sys/types.h>
38 #define MDOC_ARGS const struct mdoc_meta *meta, \
39 const struct mdoc_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(MDOC_ARGS
);
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 mdoc_node
*);
58 static void a2width(const char *, struct roffsu
*);
59 static void a2offs(const char *, struct roffsu
*);
61 static void mdoc_root_post(MDOC_ARGS
);
62 static int mdoc_root_pre(MDOC_ARGS
);
64 static void mdoc__x_post(MDOC_ARGS
);
65 static int mdoc__x_pre(MDOC_ARGS
);
66 static int mdoc_ad_pre(MDOC_ARGS
);
67 static int mdoc_an_pre(MDOC_ARGS
);
68 static int mdoc_ap_pre(MDOC_ARGS
);
69 static int mdoc_ar_pre(MDOC_ARGS
);
70 static int mdoc_bd_pre(MDOC_ARGS
);
71 static int mdoc_bf_pre(MDOC_ARGS
);
72 static void mdoc_bk_post(MDOC_ARGS
);
73 static int mdoc_bk_pre(MDOC_ARGS
);
74 static int mdoc_bl_pre(MDOC_ARGS
);
75 static int mdoc_bt_pre(MDOC_ARGS
);
76 static int mdoc_bx_pre(MDOC_ARGS
);
77 static int mdoc_cd_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 int mdoc_er_pre(MDOC_ARGS
);
87 static int mdoc_ev_pre(MDOC_ARGS
);
88 static int mdoc_ex_pre(MDOC_ARGS
);
89 static void mdoc_fo_post(MDOC_ARGS
);
90 static int mdoc_fo_pre(MDOC_ARGS
);
91 static int mdoc_ic_pre(MDOC_ARGS
);
92 static int mdoc_igndelim_pre(MDOC_ARGS
);
93 static int mdoc_in_pre(MDOC_ARGS
);
94 static int mdoc_it_pre(MDOC_ARGS
);
95 static int mdoc_lb_pre(MDOC_ARGS
);
96 static int mdoc_li_pre(MDOC_ARGS
);
97 static int mdoc_lk_pre(MDOC_ARGS
);
98 static int mdoc_mt_pre(MDOC_ARGS
);
99 static int mdoc_ms_pre(MDOC_ARGS
);
100 static int mdoc_nd_pre(MDOC_ARGS
);
101 static int mdoc_nm_pre(MDOC_ARGS
);
102 static int mdoc_ns_pre(MDOC_ARGS
);
103 static int mdoc_pa_pre(MDOC_ARGS
);
104 static void mdoc_pf_post(MDOC_ARGS
);
105 static int mdoc_pp_pre(MDOC_ARGS
);
106 static void mdoc_quote_post(MDOC_ARGS
);
107 static int mdoc_quote_pre(MDOC_ARGS
);
108 static int mdoc_rs_pre(MDOC_ARGS
);
109 static int mdoc_rv_pre(MDOC_ARGS
);
110 static int mdoc_sh_pre(MDOC_ARGS
);
111 static int mdoc_sm_pre(MDOC_ARGS
);
112 static int mdoc_sp_pre(MDOC_ARGS
);
113 static int mdoc_ss_pre(MDOC_ARGS
);
114 static int mdoc_sx_pre(MDOC_ARGS
);
115 static int mdoc_sy_pre(MDOC_ARGS
);
116 static int mdoc_ud_pre(MDOC_ARGS
);
117 static int mdoc_va_pre(MDOC_ARGS
);
118 static int mdoc_vt_pre(MDOC_ARGS
);
119 static int mdoc_xr_pre(MDOC_ARGS
);
120 static int mdoc_xx_pre(MDOC_ARGS
);
122 static const struct htmlmdoc mdocs
[MDOC_MAX
] = {
123 {mdoc_ap_pre
, NULL
}, /* Ap */
124 {NULL
, NULL
}, /* Dd */
125 {NULL
, NULL
}, /* Dt */
126 {NULL
, NULL
}, /* Os */
127 {mdoc_sh_pre
, NULL
}, /* Sh */
128 {mdoc_ss_pre
, NULL
}, /* Ss */
129 {mdoc_pp_pre
, NULL
}, /* Pp */
130 {mdoc_d1_pre
, NULL
}, /* D1 */
131 {mdoc_d1_pre
, NULL
}, /* Dl */
132 {mdoc_bd_pre
, NULL
}, /* Bd */
133 {NULL
, NULL
}, /* Ed */
134 {mdoc_bl_pre
, NULL
}, /* Bl */
135 {NULL
, NULL
}, /* El */
136 {mdoc_it_pre
, NULL
}, /* It */
137 {mdoc_ad_pre
, NULL
}, /* Ad */
138 {mdoc_an_pre
, NULL
}, /* An */
139 {mdoc_ar_pre
, NULL
}, /* Ar */
140 {mdoc_cd_pre
, NULL
}, /* Cd */
141 {mdoc_fl_pre
, NULL
}, /* Cm */
142 {mdoc_dv_pre
, NULL
}, /* Dv */
143 {mdoc_er_pre
, NULL
}, /* Er */
144 {mdoc_ev_pre
, NULL
}, /* Ev */
145 {mdoc_ex_pre
, NULL
}, /* Ex */
146 {mdoc_fa_pre
, NULL
}, /* Fa */
147 {mdoc_fd_pre
, NULL
}, /* Fd */
148 {mdoc_fl_pre
, NULL
}, /* Fl */
149 {mdoc_fn_pre
, NULL
}, /* Fn */
150 {mdoc_ft_pre
, NULL
}, /* Ft */
151 {mdoc_ic_pre
, NULL
}, /* Ic */
152 {mdoc_in_pre
, NULL
}, /* In */
153 {mdoc_li_pre
, NULL
}, /* Li */
154 {mdoc_nd_pre
, NULL
}, /* Nd */
155 {mdoc_nm_pre
, NULL
}, /* Nm */
156 {mdoc_quote_pre
, mdoc_quote_post
}, /* Op */
157 {NULL
, NULL
}, /* Ot */
158 {mdoc_pa_pre
, NULL
}, /* Pa */
159 {mdoc_rv_pre
, NULL
}, /* Rv */
160 {NULL
, NULL
}, /* St */
161 {mdoc_va_pre
, NULL
}, /* Va */
162 {mdoc_vt_pre
, NULL
}, /* Vt */
163 {mdoc_xr_pre
, NULL
}, /* Xr */
164 {mdoc__x_pre
, mdoc__x_post
}, /* %A */
165 {mdoc__x_pre
, mdoc__x_post
}, /* %B */
166 {mdoc__x_pre
, mdoc__x_post
}, /* %D */
167 {mdoc__x_pre
, mdoc__x_post
}, /* %I */
168 {mdoc__x_pre
, mdoc__x_post
}, /* %J */
169 {mdoc__x_pre
, mdoc__x_post
}, /* %N */
170 {mdoc__x_pre
, mdoc__x_post
}, /* %O */
171 {mdoc__x_pre
, mdoc__x_post
}, /* %P */
172 {mdoc__x_pre
, mdoc__x_post
}, /* %R */
173 {mdoc__x_pre
, mdoc__x_post
}, /* %T */
174 {mdoc__x_pre
, mdoc__x_post
}, /* %V */
175 {NULL
, NULL
}, /* Ac */
176 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ao */
177 {mdoc_quote_pre
, mdoc_quote_post
}, /* Aq */
178 {NULL
, NULL
}, /* At */
179 {NULL
, NULL
}, /* Bc */
180 {mdoc_bf_pre
, NULL
}, /* Bf */
181 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bo */
182 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bq */
183 {mdoc_xx_pre
, NULL
}, /* Bsx */
184 {mdoc_bx_pre
, NULL
}, /* Bx */
185 {NULL
, NULL
}, /* Db */
186 {NULL
, NULL
}, /* Dc */
187 {mdoc_quote_pre
, mdoc_quote_post
}, /* Do */
188 {mdoc_quote_pre
, mdoc_quote_post
}, /* Dq */
189 {NULL
, NULL
}, /* Ec */ /* FIXME: no space */
190 {NULL
, NULL
}, /* Ef */
191 {mdoc_em_pre
, NULL
}, /* Em */
192 {mdoc_quote_pre
, mdoc_quote_post
}, /* Eo */
193 {mdoc_xx_pre
, NULL
}, /* Fx */
194 {mdoc_ms_pre
, NULL
}, /* Ms */
195 {mdoc_igndelim_pre
, NULL
}, /* No */
196 {mdoc_ns_pre
, NULL
}, /* Ns */
197 {mdoc_xx_pre
, NULL
}, /* Nx */
198 {mdoc_xx_pre
, NULL
}, /* Ox */
199 {NULL
, NULL
}, /* Pc */
200 {mdoc_igndelim_pre
, mdoc_pf_post
}, /* Pf */
201 {mdoc_quote_pre
, mdoc_quote_post
}, /* Po */
202 {mdoc_quote_pre
, mdoc_quote_post
}, /* Pq */
203 {NULL
, NULL
}, /* Qc */
204 {mdoc_quote_pre
, mdoc_quote_post
}, /* Ql */
205 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qo */
206 {mdoc_quote_pre
, mdoc_quote_post
}, /* Qq */
207 {NULL
, NULL
}, /* Re */
208 {mdoc_rs_pre
, NULL
}, /* Rs */
209 {NULL
, NULL
}, /* Sc */
210 {mdoc_quote_pre
, mdoc_quote_post
}, /* So */
211 {mdoc_quote_pre
, mdoc_quote_post
}, /* Sq */
212 {mdoc_sm_pre
, NULL
}, /* Sm */
213 {mdoc_sx_pre
, NULL
}, /* Sx */
214 {mdoc_sy_pre
, NULL
}, /* Sy */
215 {NULL
, NULL
}, /* Tn */
216 {mdoc_xx_pre
, NULL
}, /* Ux */
217 {NULL
, NULL
}, /* Xc */
218 {NULL
, NULL
}, /* Xo */
219 {mdoc_fo_pre
, mdoc_fo_post
}, /* Fo */
220 {NULL
, NULL
}, /* Fc */
221 {mdoc_quote_pre
, mdoc_quote_post
}, /* Oo */
222 {NULL
, NULL
}, /* Oc */
223 {mdoc_bk_pre
, mdoc_bk_post
}, /* Bk */
224 {NULL
, NULL
}, /* Ek */
225 {mdoc_bt_pre
, NULL
}, /* Bt */
226 {NULL
, NULL
}, /* Hf */
227 {NULL
, NULL
}, /* Fr */
228 {mdoc_ud_pre
, NULL
}, /* Ud */
229 {mdoc_lb_pre
, NULL
}, /* Lb */
230 {mdoc_pp_pre
, NULL
}, /* Lp */
231 {mdoc_lk_pre
, NULL
}, /* Lk */
232 {mdoc_mt_pre
, NULL
}, /* Mt */
233 {mdoc_quote_pre
, mdoc_quote_post
}, /* Brq */
234 {mdoc_quote_pre
, mdoc_quote_post
}, /* Bro */
235 {NULL
, NULL
}, /* Brc */
236 {mdoc__x_pre
, mdoc__x_post
}, /* %C */
237 {NULL
, NULL
}, /* Es */ /* TODO */
238 {NULL
, NULL
}, /* En */ /* TODO */
239 {mdoc_xx_pre
, NULL
}, /* Dx */
240 {mdoc__x_pre
, mdoc__x_post
}, /* %Q */
241 {mdoc_sp_pre
, NULL
}, /* br */
242 {mdoc_sp_pre
, NULL
}, /* sp */
243 {mdoc__x_pre
, mdoc__x_post
}, /* %U */
244 {NULL
, NULL
}, /* Ta */
247 static const char * const lists
[LIST_MAX
] = {
263 html_mdoc(void *arg
, const struct mdoc
*mdoc
)
266 print_mdoc(mdoc_meta(mdoc
), mdoc_node(mdoc
),
273 * Calculate the scaling unit passed in a `-width' argument. This uses
274 * either a native scaling unit (e.g., 1i, 2m) or the string length of
278 a2width(const char *p
, struct roffsu
*su
)
281 if ( ! a2roffsu(p
, su
, SCALE_MAX
)) {
283 su
->scale
= html_strlen(p
);
289 * See the same function in mdoc_term.c for documentation.
292 synopsis_pre(struct html
*h
, const struct mdoc_node
*n
)
295 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
298 if (n
->prev
->tok
== n
->tok
&&
302 print_otag(h
, TAG_BR
, 0, NULL
);
306 switch (n
->prev
->tok
) {
316 print_otag(h
, TAG_P
, 0, NULL
);
319 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
320 print_otag(h
, TAG_P
, 0, NULL
);
325 print_otag(h
, TAG_BR
, 0, NULL
);
332 * Calculate the scaling unit passed in an `-offset' argument. This
333 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
334 * predefined strings (indent, etc.), or the string length of the value.
337 a2offs(const char *p
, struct roffsu
*su
)
340 /* FIXME: "right"? */
342 if (0 == strcmp(p
, "left"))
343 SCALE_HS_INIT(su
, 0);
344 else if (0 == strcmp(p
, "indent"))
345 SCALE_HS_INIT(su
, INDENT
);
346 else if (0 == strcmp(p
, "indent-two"))
347 SCALE_HS_INIT(su
, INDENT
* 2);
348 else if ( ! a2roffsu(p
, su
, SCALE_MAX
))
349 SCALE_HS_INIT(su
, html_strlen(p
));
354 print_mdoc(MDOC_ARGS
)
359 PAIR_CLASS_INIT(&tag
, "mandoc");
361 if ( ! (HTML_FRAGMENT
& h
->oflags
)) {
363 t
= print_otag(h
, TAG_HTML
, 0, NULL
);
364 tt
= print_otag(h
, TAG_HEAD
, 0, NULL
);
365 print_mdoc_head(meta
, n
, h
);
367 print_otag(h
, TAG_BODY
, 0, NULL
);
368 print_otag(h
, TAG_DIV
, 1, &tag
);
370 t
= print_otag(h
, TAG_DIV
, 1, &tag
);
372 print_mdoc_nodelist(meta
, n
, h
);
379 print_mdoc_head(MDOC_ARGS
)
384 bufcat_fmt(h
, "%s(%s)", meta
->title
, meta
->msec
);
387 bufcat_fmt(h
, " (%s)", meta
->arch
);
389 print_otag(h
, TAG_TITLE
, 0, NULL
);
390 print_text(h
, h
->buf
);
395 print_mdoc_nodelist(MDOC_ARGS
)
398 print_mdoc_node(meta
, n
, h
);
400 print_mdoc_nodelist(meta
, n
->next
, h
);
405 print_mdoc_node(MDOC_ARGS
)
415 child
= mdoc_root_pre(meta
, n
, h
);
418 /* No tables in this mode... */
419 assert(NULL
== h
->tblt
);
422 * Make sure that if we're in a literal mode already
423 * (i.e., within a <PRE>) don't print the newline.
425 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
426 if ( ! (HTML_LITERAL
& h
->flags
))
427 print_otag(h
, TAG_BR
, 0, NULL
);
428 if (MDOC_DELIMC
& n
->flags
)
429 h
->flags
|= HTML_NOSPACE
;
430 print_text(h
, n
->string
);
431 if (MDOC_DELIMO
& n
->flags
)
432 h
->flags
|= HTML_NOSPACE
;
435 print_eqn(h
, n
->eqn
);
439 * This will take care of initialising all of the table
440 * state data for the first table, then tearing it down
443 print_tbl(h
, n
->span
);
447 * Close out the current table, if it's open, and unset
448 * the "meta" table state. This will be reopened on the
449 * next table element.
456 assert(NULL
== h
->tblt
);
457 if (mdocs
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
458 child
= (*mdocs
[n
->tok
].pre
)(meta
, n
, h
);
462 if (HTML_KEEP
& h
->flags
) {
463 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
464 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
465 h
->flags
&= ~HTML_KEEP
;
466 h
->flags
|= HTML_PREKEEP
;
470 if (child
&& n
->child
)
471 print_mdoc_nodelist(meta
, n
->child
, h
);
477 mdoc_root_post(meta
, n
, h
);
482 if (mdocs
[n
->tok
].post
&& ENDBODY_NOT
== n
->end
)
483 (*mdocs
[n
->tok
].post
)(meta
, n
, h
);
490 mdoc_root_post(MDOC_ARGS
)
492 struct htmlpair tag
[3];
495 PAIR_SUMMARY_INIT(&tag
[0], "Document Footer");
496 PAIR_CLASS_INIT(&tag
[1], "foot");
497 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
498 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
499 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "50%");
500 print_otag(h
, TAG_COL
, 1, tag
);
501 print_otag(h
, TAG_COL
, 1, tag
);
503 print_otag(h
, TAG_TBODY
, 0, NULL
);
505 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
507 PAIR_CLASS_INIT(&tag
[0], "foot-date");
508 print_otag(h
, TAG_TD
, 1, tag
);
509 print_text(h
, meta
->date
);
512 PAIR_CLASS_INIT(&tag
[0], "foot-os");
513 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
514 print_otag(h
, TAG_TD
, 2, tag
);
515 print_text(h
, meta
->os
);
522 mdoc_root_pre(MDOC_ARGS
)
524 struct htmlpair tag
[3];
526 char b
[BUFSIZ
], title
[BUFSIZ
];
528 strlcpy(b
, meta
->vol
, BUFSIZ
);
531 strlcat(b
, " (", BUFSIZ
);
532 strlcat(b
, meta
->arch
, BUFSIZ
);
533 strlcat(b
, ")", BUFSIZ
);
536 snprintf(title
, BUFSIZ
- 1, "%s(%s)", meta
->title
, meta
->msec
);
538 PAIR_SUMMARY_INIT(&tag
[0], "Document Header");
539 PAIR_CLASS_INIT(&tag
[1], "head");
540 PAIR_INIT(&tag
[2], ATTR_WIDTH
, "100%");
541 t
= print_otag(h
, TAG_TABLE
, 3, tag
);
542 PAIR_INIT(&tag
[0], ATTR_WIDTH
, "30%");
543 print_otag(h
, TAG_COL
, 1, tag
);
544 print_otag(h
, TAG_COL
, 1, tag
);
545 print_otag(h
, TAG_COL
, 1, tag
);
547 print_otag(h
, TAG_TBODY
, 0, NULL
);
549 tt
= print_otag(h
, TAG_TR
, 0, NULL
);
551 PAIR_CLASS_INIT(&tag
[0], "head-ltitle");
552 print_otag(h
, TAG_TD
, 1, tag
);
553 print_text(h
, title
);
556 PAIR_CLASS_INIT(&tag
[0], "head-vol");
557 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "center");
558 print_otag(h
, TAG_TD
, 2, tag
);
562 PAIR_CLASS_INIT(&tag
[0], "head-rtitle");
563 PAIR_INIT(&tag
[1], ATTR_ALIGN
, "right");
564 print_otag(h
, TAG_TD
, 2, tag
);
565 print_text(h
, title
);
573 mdoc_sh_pre(MDOC_ARGS
)
577 if (MDOC_BLOCK
== n
->type
) {
578 PAIR_CLASS_INIT(&tag
, "section");
579 print_otag(h
, TAG_DIV
, 1, &tag
);
581 } else if (MDOC_BODY
== n
->type
)
587 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
588 bufcat_id(h
, n
->string
);
589 if (NULL
!= (n
= n
->next
))
594 PAIR_ID_INIT(&tag
, h
->buf
);
595 print_otag(h
, TAG_H1
, 1, &tag
);
597 print_otag(h
, TAG_H1
, 0, NULL
);
604 mdoc_ss_pre(MDOC_ARGS
)
608 if (MDOC_BLOCK
== n
->type
) {
609 PAIR_CLASS_INIT(&tag
, "subsection");
610 print_otag(h
, TAG_DIV
, 1, &tag
);
612 } else if (MDOC_BODY
== n
->type
)
618 for (n
= n
->child
; n
&& MDOC_TEXT
== n
->type
; ) {
619 bufcat_id(h
, n
->string
);
620 if (NULL
!= (n
= n
->next
))
625 PAIR_ID_INIT(&tag
, h
->buf
);
626 print_otag(h
, TAG_H2
, 1, &tag
);
628 print_otag(h
, TAG_H2
, 0, NULL
);
636 mdoc_fl_pre(MDOC_ARGS
)
640 PAIR_CLASS_INIT(&tag
, "flag");
641 print_otag(h
, TAG_B
, 1, &tag
);
643 /* `Cm' has no leading hyphen. */
645 if (MDOC_Cm
== n
->tok
)
648 print_text(h
, "\\-");
651 h
->flags
|= HTML_NOSPACE
;
652 else if (n
->next
&& n
->next
->line
== n
->line
)
653 h
->flags
|= HTML_NOSPACE
;
661 mdoc_nd_pre(MDOC_ARGS
)
665 if (MDOC_BODY
!= n
->type
)
668 /* XXX: this tag in theory can contain block elements. */
670 print_text(h
, "\\(em");
671 PAIR_CLASS_INIT(&tag
, "desc");
672 print_otag(h
, TAG_SPAN
, 1, &tag
);
678 mdoc_nm_pre(MDOC_ARGS
)
687 PAIR_CLASS_INIT(&tag
, "name");
688 print_otag(h
, TAG_B
, 1, &tag
);
689 if (NULL
== n
->child
&& meta
->name
)
690 print_text(h
, meta
->name
);
693 print_otag(h
, TAG_TD
, 0, NULL
);
694 if (NULL
== n
->child
&& meta
->name
)
695 print_text(h
, meta
->name
);
698 print_otag(h
, TAG_TD
, 0, NULL
);
705 PAIR_CLASS_INIT(&tag
, "synopsis");
706 print_otag(h
, TAG_TABLE
, 1, &tag
);
708 for (len
= 0, n
= n
->child
; n
; n
= n
->next
)
709 if (MDOC_TEXT
== n
->type
)
710 len
+= html_strlen(n
->string
);
712 if (0 == len
&& meta
->name
)
713 len
= html_strlen(meta
->name
);
715 SCALE_HS_INIT(&su
, (double)len
);
717 bufcat_su(h
, "width", &su
);
718 PAIR_STYLE_INIT(&tag
, h
);
719 print_otag(h
, TAG_COL
, 1, &tag
);
720 print_otag(h
, TAG_COL
, 0, NULL
);
721 print_otag(h
, TAG_TBODY
, 0, NULL
);
722 print_otag(h
, TAG_TR
, 0, NULL
);
729 mdoc_xr_pre(MDOC_ARGS
)
731 struct htmlpair tag
[2];
733 if (NULL
== n
->child
)
736 PAIR_CLASS_INIT(&tag
[0], "link-man");
739 buffmt_man(h
, n
->child
->string
,
741 n
->child
->next
->string
: NULL
);
742 PAIR_HREF_INIT(&tag
[1], h
->buf
);
743 print_otag(h
, TAG_A
, 2, tag
);
745 print_otag(h
, TAG_A
, 1, tag
);
748 print_text(h
, n
->string
);
750 if (NULL
== (n
= n
->next
))
753 h
->flags
|= HTML_NOSPACE
;
755 h
->flags
|= HTML_NOSPACE
;
756 print_text(h
, n
->string
);
757 h
->flags
|= HTML_NOSPACE
;
765 mdoc_ns_pre(MDOC_ARGS
)
768 if ( ! (MDOC_LINE
& n
->flags
))
769 h
->flags
|= HTML_NOSPACE
;
776 mdoc_ar_pre(MDOC_ARGS
)
780 PAIR_CLASS_INIT(&tag
, "arg");
781 print_otag(h
, TAG_I
, 1, &tag
);
788 mdoc_xx_pre(MDOC_ARGS
)
817 PAIR_CLASS_INIT(&tag
, "unix");
818 print_otag(h
, TAG_SPAN
, 1, &tag
);
823 h
->flags
|= HTML_KEEP
;
824 print_text(h
, n
->child
->string
);
833 mdoc_bx_pre(MDOC_ARGS
)
837 PAIR_CLASS_INIT(&tag
, "unix");
838 print_otag(h
, TAG_SPAN
, 1, &tag
);
840 if (NULL
!= (n
= n
->child
)) {
841 print_text(h
, n
->string
);
842 h
->flags
|= HTML_NOSPACE
;
843 print_text(h
, "BSD");
845 print_text(h
, "BSD");
849 if (NULL
!= (n
= n
->next
)) {
850 h
->flags
|= HTML_NOSPACE
;
852 h
->flags
|= HTML_NOSPACE
;
853 print_text(h
, n
->string
);
861 mdoc_it_pre(MDOC_ARGS
)
865 struct htmlpair tag
[2];
866 const struct mdoc_node
*bl
;
869 while (bl
&& MDOC_Bl
!= bl
->tok
)
874 type
= bl
->norm
->Bl
.type
;
877 PAIR_CLASS_INIT(&tag
[0], lists
[type
]);
881 if (MDOC_HEAD
== n
->type
) {
902 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
903 bufcat_su(h
, "margin-top", &su
);
904 PAIR_STYLE_INIT(&tag
[1], h
);
905 print_otag(h
, TAG_DT
, 2, tag
);
906 if (LIST_diag
!= type
)
908 PAIR_CLASS_INIT(&tag
[0], "diag");
909 print_otag(h
, TAG_B
, 1, tag
);
916 } else if (MDOC_BODY
== n
->type
) {
927 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
928 bufcat_su(h
, "margin-top", &su
);
929 PAIR_STYLE_INIT(&tag
[1], h
);
930 print_otag(h
, TAG_LI
, 2, tag
);
941 if (NULL
== bl
->norm
->Bl
.width
) {
942 print_otag(h
, TAG_DD
, 1, tag
);
945 a2width(bl
->norm
->Bl
.width
, &su
);
946 bufcat_su(h
, "margin-left", &su
);
947 PAIR_STYLE_INIT(&tag
[1], h
);
948 print_otag(h
, TAG_DD
, 2, tag
);
951 SCALE_VS_INIT(&su
, ! bl
->norm
->Bl
.comp
);
952 bufcat_su(h
, "margin-top", &su
);
953 PAIR_STYLE_INIT(&tag
[1], h
);
954 print_otag(h
, TAG_TD
, 2, tag
);
962 print_otag(h
, TAG_TR
, 1, tag
);
974 mdoc_bl_pre(MDOC_ARGS
)
977 struct htmlpair tag
[3];
981 if (MDOC_BODY
== n
->type
) {
982 if (LIST_column
== n
->norm
->Bl
.type
)
983 print_otag(h
, TAG_TBODY
, 0, NULL
);
987 if (MDOC_HEAD
== n
->type
) {
988 if (LIST_column
!= n
->norm
->Bl
.type
)
992 * For each column, print out the <COL> tag with our
993 * suggested width. The last column gets min-width, as
994 * in terminal mode it auto-sizes to the width of the
995 * screen and we want to preserve that behaviour.
998 for (i
= 0; i
< (int)n
->norm
->Bl
.ncols
; i
++) {
1000 a2width(n
->norm
->Bl
.cols
[i
], &su
);
1001 if (i
< (int)n
->norm
->Bl
.ncols
- 1)
1002 bufcat_su(h
, "width", &su
);
1004 bufcat_su(h
, "min-width", &su
);
1005 PAIR_STYLE_INIT(&tag
[0], h
);
1006 print_otag(h
, TAG_COL
, 1, tag
);
1012 SCALE_VS_INIT(&su
, 0);
1014 bufcat_su(h
, "margin-top", &su
);
1015 bufcat_su(h
, "margin-bottom", &su
);
1016 PAIR_STYLE_INIT(&tag
[0], h
);
1018 assert(lists
[n
->norm
->Bl
.type
]);
1019 strlcpy(buf
, "list ", BUFSIZ
);
1020 strlcat(buf
, lists
[n
->norm
->Bl
.type
], BUFSIZ
);
1021 PAIR_INIT(&tag
[1], ATTR_CLASS
, buf
);
1023 /* Set the block's left-hand margin. */
1025 if (n
->norm
->Bl
.offs
) {
1026 a2offs(n
->norm
->Bl
.offs
, &su
);
1027 bufcat_su(h
, "margin-left", &su
);
1030 switch (n
->norm
->Bl
.type
) {
1038 print_otag(h
, TAG_UL
, 2, tag
);
1041 print_otag(h
, TAG_OL
, 2, tag
);
1052 print_otag(h
, TAG_DL
, 2, tag
);
1055 print_otag(h
, TAG_TABLE
, 2, tag
);
1067 mdoc_ex_pre(MDOC_ARGS
)
1070 struct htmlpair tag
;
1074 print_otag(h
, TAG_BR
, 0, NULL
);
1076 PAIR_CLASS_INIT(&tag
, "utility");
1078 print_text(h
, "The");
1081 for (n
= n
->child
; n
; n
= n
->next
) {
1082 assert(MDOC_TEXT
== n
->type
);
1084 t
= print_otag(h
, TAG_B
, 1, &tag
);
1085 print_text(h
, n
->string
);
1088 if (nchild
> 2 && n
->next
) {
1089 h
->flags
|= HTML_NOSPACE
;
1093 if (n
->next
&& NULL
== n
->next
->next
)
1094 print_text(h
, "and");
1098 print_text(h
, "utilities exit");
1100 print_text(h
, "utility exits");
1102 print_text(h
, "0 on success, and >0 if an error occurs.");
1109 mdoc_em_pre(MDOC_ARGS
)
1111 struct htmlpair tag
;
1113 PAIR_CLASS_INIT(&tag
, "emph");
1114 print_otag(h
, TAG_SPAN
, 1, &tag
);
1121 mdoc_d1_pre(MDOC_ARGS
)
1123 struct htmlpair tag
[2];
1126 if (MDOC_BLOCK
!= n
->type
)
1129 SCALE_VS_INIT(&su
, 0);
1131 bufcat_su(h
, "margin-top", &su
);
1132 bufcat_su(h
, "margin-bottom", &su
);
1133 PAIR_STYLE_INIT(&tag
[0], h
);
1134 print_otag(h
, TAG_BLOCKQUOTE
, 1, tag
);
1136 /* BLOCKQUOTE needs a block body. */
1138 PAIR_CLASS_INIT(&tag
[0], "display");
1139 print_otag(h
, TAG_DIV
, 1, tag
);
1141 if (MDOC_Dl
== n
->tok
) {
1142 PAIR_CLASS_INIT(&tag
[0], "lit");
1143 print_otag(h
, TAG_CODE
, 1, tag
);
1152 mdoc_sx_pre(MDOC_ARGS
)
1154 struct htmlpair tag
[2];
1159 for (n
= n
->child
; n
; ) {
1160 bufcat_id(h
, n
->string
);
1161 if (NULL
!= (n
= n
->next
))
1165 PAIR_CLASS_INIT(&tag
[0], "link-sec");
1166 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1168 print_otag(h
, TAG_I
, 1, tag
);
1169 print_otag(h
, TAG_A
, 2, tag
);
1176 mdoc_bd_pre(MDOC_ARGS
)
1178 struct htmlpair tag
[2];
1180 const struct mdoc_node
*nn
;
1183 if (MDOC_HEAD
== n
->type
)
1186 if (MDOC_BLOCK
== n
->type
) {
1187 comp
= n
->norm
->Bd
.comp
;
1188 for (nn
= n
; nn
&& ! comp
; nn
= nn
->parent
) {
1189 if (MDOC_BLOCK
!= nn
->type
)
1191 if (MDOC_Ss
== nn
->tok
|| MDOC_Sh
== nn
->tok
)
1197 print_otag(h
, TAG_P
, 0, NULL
);
1201 SCALE_HS_INIT(&su
, 0);
1202 if (n
->norm
->Bd
.offs
)
1203 a2offs(n
->norm
->Bd
.offs
, &su
);
1206 bufcat_su(h
, "margin-left", &su
);
1207 PAIR_STYLE_INIT(&tag
[0], h
);
1209 if (DISP_unfilled
!= n
->norm
->Bd
.type
&&
1210 DISP_literal
!= n
->norm
->Bd
.type
) {
1211 PAIR_CLASS_INIT(&tag
[1], "display");
1212 print_otag(h
, TAG_DIV
, 2, tag
);
1216 PAIR_CLASS_INIT(&tag
[1], "lit display");
1217 print_otag(h
, TAG_PRE
, 2, tag
);
1219 /* This can be recursive: save & set our literal state. */
1221 sv
= h
->flags
& HTML_LITERAL
;
1222 h
->flags
|= HTML_LITERAL
;
1224 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1225 print_mdoc_node(meta
, nn
, h
);
1227 * If the printed node flushes its own line, then we
1228 * needn't do it here as well. This is hacky, but the
1229 * notion of selective eoln whitespace is pretty dumb
1230 * anyway, so don't sweat it.
1252 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1255 print_text(h
, "\n");
1257 h
->flags
|= HTML_NOSPACE
;
1261 h
->flags
&= ~HTML_LITERAL
;
1269 mdoc_pa_pre(MDOC_ARGS
)
1271 struct htmlpair tag
;
1273 PAIR_CLASS_INIT(&tag
, "file");
1274 print_otag(h
, TAG_I
, 1, &tag
);
1281 mdoc_ad_pre(MDOC_ARGS
)
1283 struct htmlpair tag
;
1285 PAIR_CLASS_INIT(&tag
, "addr");
1286 print_otag(h
, TAG_I
, 1, &tag
);
1293 mdoc_an_pre(MDOC_ARGS
)
1295 struct htmlpair tag
;
1297 /* TODO: -split and -nosplit (see termp_an_pre()). */
1299 PAIR_CLASS_INIT(&tag
, "author");
1300 print_otag(h
, TAG_SPAN
, 1, &tag
);
1307 mdoc_cd_pre(MDOC_ARGS
)
1309 struct htmlpair tag
;
1312 PAIR_CLASS_INIT(&tag
, "config");
1313 print_otag(h
, TAG_B
, 1, &tag
);
1320 mdoc_dv_pre(MDOC_ARGS
)
1322 struct htmlpair tag
;
1324 PAIR_CLASS_INIT(&tag
, "define");
1325 print_otag(h
, TAG_SPAN
, 1, &tag
);
1332 mdoc_ev_pre(MDOC_ARGS
)
1334 struct htmlpair tag
;
1336 PAIR_CLASS_INIT(&tag
, "env");
1337 print_otag(h
, TAG_SPAN
, 1, &tag
);
1344 mdoc_er_pre(MDOC_ARGS
)
1346 struct htmlpair tag
;
1348 PAIR_CLASS_INIT(&tag
, "errno");
1349 print_otag(h
, TAG_SPAN
, 1, &tag
);
1356 mdoc_fa_pre(MDOC_ARGS
)
1358 const struct mdoc_node
*nn
;
1359 struct htmlpair tag
;
1362 PAIR_CLASS_INIT(&tag
, "farg");
1363 if (n
->parent
->tok
!= MDOC_Fo
) {
1364 print_otag(h
, TAG_I
, 1, &tag
);
1368 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1369 t
= print_otag(h
, TAG_I
, 1, &tag
);
1370 print_text(h
, nn
->string
);
1373 h
->flags
|= HTML_NOSPACE
;
1378 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
) {
1379 h
->flags
|= HTML_NOSPACE
;
1389 mdoc_fd_pre(MDOC_ARGS
)
1391 struct htmlpair tag
[2];
1399 if (NULL
== (n
= n
->child
))
1402 assert(MDOC_TEXT
== n
->type
);
1404 if (strcmp(n
->string
, "#include")) {
1405 PAIR_CLASS_INIT(&tag
[0], "macro");
1406 print_otag(h
, TAG_B
, 1, tag
);
1410 PAIR_CLASS_INIT(&tag
[0], "includes");
1411 print_otag(h
, TAG_B
, 1, tag
);
1412 print_text(h
, n
->string
);
1414 if (NULL
!= (n
= n
->next
)) {
1415 assert(MDOC_TEXT
== n
->type
);
1416 strlcpy(buf
, '<' == *n
->string
|| '"' == *n
->string
?
1417 n
->string
+ 1 : n
->string
, BUFSIZ
);
1420 if (sz
&& ('>' == buf
[sz
- 1] || '"' == buf
[sz
- 1]))
1423 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1426 if (h
->base_includes
) {
1427 buffmt_includes(h
, buf
);
1428 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1432 t
= print_otag(h
, TAG_A
, i
, tag
);
1433 print_text(h
, n
->string
);
1439 for ( ; n
; n
= n
->next
) {
1440 assert(MDOC_TEXT
== n
->type
);
1441 print_text(h
, n
->string
);
1450 mdoc_vt_pre(MDOC_ARGS
)
1452 struct htmlpair tag
;
1454 if (MDOC_BLOCK
== n
->type
) {
1457 } else if (MDOC_ELEM
== n
->type
) {
1459 } else if (MDOC_HEAD
== n
->type
)
1462 PAIR_CLASS_INIT(&tag
, "type");
1463 print_otag(h
, TAG_SPAN
, 1, &tag
);
1470 mdoc_ft_pre(MDOC_ARGS
)
1472 struct htmlpair tag
;
1475 PAIR_CLASS_INIT(&tag
, "ftype");
1476 print_otag(h
, TAG_I
, 1, &tag
);
1483 mdoc_fn_pre(MDOC_ARGS
)
1486 struct htmlpair tag
[2];
1488 const char *sp
, *ep
;
1491 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1494 /* Split apart into type and name. */
1495 assert(n
->child
->string
);
1496 sp
= n
->child
->string
;
1498 ep
= strchr(sp
, ' ');
1500 PAIR_CLASS_INIT(&tag
[0], "ftype");
1501 t
= print_otag(h
, TAG_I
, 1, tag
);
1504 sz
= MIN((int)(ep
- sp
), BUFSIZ
- 1);
1505 (void)memcpy(nbuf
, sp
, (size_t)sz
);
1507 print_text(h
, nbuf
);
1509 ep
= strchr(sp
, ' ');
1514 PAIR_CLASS_INIT(&tag
[0], "fname");
1517 * FIXME: only refer to IDs that we know exist.
1521 if (MDOC_SYNPRETTY
& n
->flags
) {
1523 html_idcat(nbuf
, sp
, BUFSIZ
);
1524 PAIR_ID_INIT(&tag
[1], nbuf
);
1526 strlcpy(nbuf
, "#", BUFSIZ
);
1527 html_idcat(nbuf
, sp
, BUFSIZ
);
1528 PAIR_HREF_INIT(&tag
[1], nbuf
);
1532 t
= print_otag(h
, TAG_B
, 1, tag
);
1535 strlcpy(nbuf
, sp
, BUFSIZ
);
1536 print_text(h
, nbuf
);
1541 h
->flags
|= HTML_NOSPACE
;
1543 h
->flags
|= HTML_NOSPACE
;
1545 PAIR_CLASS_INIT(&tag
[0], "farg");
1547 bufcat_style(h
, "white-space", "nowrap");
1548 PAIR_STYLE_INIT(&tag
[1], h
);
1550 for (n
= n
->child
->next
; n
; n
= n
->next
) {
1552 if (MDOC_SYNPRETTY
& n
->flags
)
1554 t
= print_otag(h
, TAG_I
, i
, tag
);
1555 print_text(h
, n
->string
);
1558 h
->flags
|= HTML_NOSPACE
;
1563 h
->flags
|= HTML_NOSPACE
;
1567 h
->flags
|= HTML_NOSPACE
;
1577 mdoc_sm_pre(MDOC_ARGS
)
1580 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1581 if (0 == strcmp("on", n
->child
->string
)) {
1583 * FIXME: no p->col to check. Thus, if we have
1590 * the "3" is preceded by a space.
1592 h
->flags
&= ~HTML_NOSPACE
;
1593 h
->flags
&= ~HTML_NONOSPACE
;
1595 h
->flags
|= HTML_NONOSPACE
;
1602 mdoc_pp_pre(MDOC_ARGS
)
1605 print_otag(h
, TAG_P
, 0, NULL
);
1612 mdoc_sp_pre(MDOC_ARGS
)
1615 struct htmlpair tag
;
1617 SCALE_VS_INIT(&su
, 1);
1619 if (MDOC_sp
== n
->tok
) {
1620 if (NULL
!= (n
= n
->child
))
1621 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
1622 SCALE_VS_INIT(&su
, atoi(n
->string
));
1627 bufcat_su(h
, "height", &su
);
1628 PAIR_STYLE_INIT(&tag
, h
);
1629 print_otag(h
, TAG_DIV
, 1, &tag
);
1631 /* So the div isn't empty: */
1632 print_text(h
, "\\~");
1640 mdoc_lk_pre(MDOC_ARGS
)
1642 struct htmlpair tag
[2];
1644 if (NULL
== (n
= n
->child
))
1647 assert(MDOC_TEXT
== n
->type
);
1649 PAIR_CLASS_INIT(&tag
[0], "link-ext");
1650 PAIR_HREF_INIT(&tag
[1], n
->string
);
1652 print_otag(h
, TAG_A
, 2, tag
);
1654 if (NULL
== n
->next
)
1655 print_text(h
, n
->string
);
1657 for (n
= n
->next
; n
; n
= n
->next
)
1658 print_text(h
, n
->string
);
1666 mdoc_mt_pre(MDOC_ARGS
)
1668 struct htmlpair tag
[2];
1671 PAIR_CLASS_INIT(&tag
[0], "link-mail");
1673 for (n
= n
->child
; n
; n
= n
->next
) {
1674 assert(MDOC_TEXT
== n
->type
);
1677 bufcat(h
, "mailto:");
1678 bufcat(h
, n
->string
);
1680 PAIR_HREF_INIT(&tag
[1], h
->buf
);
1681 t
= print_otag(h
, TAG_A
, 2, tag
);
1682 print_text(h
, n
->string
);
1692 mdoc_fo_pre(MDOC_ARGS
)
1694 struct htmlpair tag
;
1697 if (MDOC_BODY
== n
->type
) {
1698 h
->flags
|= HTML_NOSPACE
;
1700 h
->flags
|= HTML_NOSPACE
;
1702 } else if (MDOC_BLOCK
== n
->type
) {
1707 /* XXX: we drop non-initial arguments as per groff. */
1710 assert(n
->child
->string
);
1712 PAIR_CLASS_INIT(&tag
, "fname");
1713 t
= print_otag(h
, TAG_B
, 1, &tag
);
1714 print_text(h
, n
->child
->string
);
1722 mdoc_fo_post(MDOC_ARGS
)
1725 if (MDOC_BODY
!= n
->type
)
1727 h
->flags
|= HTML_NOSPACE
;
1729 h
->flags
|= HTML_NOSPACE
;
1736 mdoc_in_pre(MDOC_ARGS
)
1739 struct htmlpair tag
[2];
1744 PAIR_CLASS_INIT(&tag
[0], "includes");
1745 print_otag(h
, TAG_B
, 1, tag
);
1748 * The first argument of the `In' gets special treatment as
1749 * being a linked value. Subsequent values are printed
1750 * afterward. groff does similarly. This also handles the case
1754 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
)
1755 print_text(h
, "#include");
1758 h
->flags
|= HTML_NOSPACE
;
1760 if (NULL
!= (n
= n
->child
)) {
1761 assert(MDOC_TEXT
== n
->type
);
1763 PAIR_CLASS_INIT(&tag
[0], "link-includes");
1766 if (h
->base_includes
) {
1767 buffmt_includes(h
, n
->string
);
1768 PAIR_HREF_INIT(&tag
[i
], h
->buf
);
1772 t
= print_otag(h
, TAG_A
, i
, tag
);
1773 print_text(h
, n
->string
);
1779 h
->flags
|= HTML_NOSPACE
;
1782 for ( ; n
; n
= n
->next
) {
1783 assert(MDOC_TEXT
== n
->type
);
1784 print_text(h
, n
->string
);
1793 mdoc_ic_pre(MDOC_ARGS
)
1795 struct htmlpair tag
;
1797 PAIR_CLASS_INIT(&tag
, "cmd");
1798 print_otag(h
, TAG_B
, 1, &tag
);
1805 mdoc_rv_pre(MDOC_ARGS
)
1807 struct htmlpair tag
;
1812 print_otag(h
, TAG_BR
, 0, NULL
);
1814 PAIR_CLASS_INIT(&tag
, "fname");
1816 print_text(h
, "The");
1819 for (n
= n
->child
; n
; n
= n
->next
) {
1820 assert(MDOC_TEXT
== n
->type
);
1822 t
= print_otag(h
, TAG_B
, 1, &tag
);
1823 print_text(h
, n
->string
);
1826 h
->flags
|= HTML_NOSPACE
;
1827 print_text(h
, "()");
1829 if (nchild
> 2 && n
->next
) {
1830 h
->flags
|= HTML_NOSPACE
;
1834 if (n
->next
&& NULL
== n
->next
->next
)
1835 print_text(h
, "and");
1839 print_text(h
, "functions return");
1841 print_text(h
, "function returns");
1843 print_text(h
, "the value 0 if successful; otherwise the value "
1844 "-1 is returned and the global variable");
1846 PAIR_CLASS_INIT(&tag
, "var");
1847 t
= print_otag(h
, TAG_B
, 1, &tag
);
1848 print_text(h
, "errno");
1850 print_text(h
, "is set to indicate the error.");
1857 mdoc_va_pre(MDOC_ARGS
)
1859 struct htmlpair tag
;
1861 PAIR_CLASS_INIT(&tag
, "var");
1862 print_otag(h
, TAG_B
, 1, &tag
);
1869 mdoc_ap_pre(MDOC_ARGS
)
1872 h
->flags
|= HTML_NOSPACE
;
1873 print_text(h
, "\\(aq");
1874 h
->flags
|= HTML_NOSPACE
;
1881 mdoc_bf_pre(MDOC_ARGS
)
1883 struct htmlpair tag
[2];
1886 if (MDOC_HEAD
== n
->type
)
1888 else if (MDOC_BODY
!= n
->type
)
1891 if (FONT_Em
== n
->norm
->Bf
.font
)
1892 PAIR_CLASS_INIT(&tag
[0], "emph");
1893 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1894 PAIR_CLASS_INIT(&tag
[0], "symb");
1895 else if (FONT_Li
== n
->norm
->Bf
.font
)
1896 PAIR_CLASS_INIT(&tag
[0], "lit");
1898 PAIR_CLASS_INIT(&tag
[0], "none");
1901 * We want this to be inline-formatted, but needs to be div to
1902 * accept block children.
1905 bufcat_style(h
, "display", "inline");
1906 SCALE_HS_INIT(&su
, 1);
1907 /* Needs a left-margin for spacing. */
1908 bufcat_su(h
, "margin-left", &su
);
1909 PAIR_STYLE_INIT(&tag
[1], h
);
1910 print_otag(h
, TAG_DIV
, 2, tag
);
1917 mdoc_ms_pre(MDOC_ARGS
)
1919 struct htmlpair tag
;
1921 PAIR_CLASS_INIT(&tag
, "symb");
1922 print_otag(h
, TAG_SPAN
, 1, &tag
);
1929 mdoc_igndelim_pre(MDOC_ARGS
)
1932 h
->flags
|= HTML_IGNDELIM
;
1939 mdoc_pf_post(MDOC_ARGS
)
1942 h
->flags
|= HTML_NOSPACE
;
1948 mdoc_rs_pre(MDOC_ARGS
)
1950 struct htmlpair tag
;
1952 if (MDOC_BLOCK
!= n
->type
)
1955 if (n
->prev
&& SEC_SEE_ALSO
== n
->sec
)
1956 print_otag(h
, TAG_P
, 0, NULL
);
1958 PAIR_CLASS_INIT(&tag
, "ref");
1959 print_otag(h
, TAG_SPAN
, 1, &tag
);
1967 mdoc_li_pre(MDOC_ARGS
)
1969 struct htmlpair tag
;
1971 PAIR_CLASS_INIT(&tag
, "lit");
1972 print_otag(h
, TAG_CODE
, 1, &tag
);
1979 mdoc_sy_pre(MDOC_ARGS
)
1981 struct htmlpair tag
;
1983 PAIR_CLASS_INIT(&tag
, "symb");
1984 print_otag(h
, TAG_SPAN
, 1, &tag
);
1991 mdoc_bt_pre(MDOC_ARGS
)
1994 print_text(h
, "is currently in beta test.");
2001 mdoc_ud_pre(MDOC_ARGS
)
2004 print_text(h
, "currently under development.");
2011 mdoc_lb_pre(MDOC_ARGS
)
2013 struct htmlpair tag
;
2015 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
&& n
->prev
)
2016 print_otag(h
, TAG_BR
, 0, NULL
);
2018 PAIR_CLASS_INIT(&tag
, "lib");
2019 print_otag(h
, TAG_SPAN
, 1, &tag
);
2026 mdoc__x_pre(MDOC_ARGS
)
2028 struct htmlpair tag
[2];
2035 PAIR_CLASS_INIT(&tag
[0], "ref-auth");
2036 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
2037 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
2038 print_text(h
, "and");
2041 PAIR_CLASS_INIT(&tag
[0], "ref-book");
2045 PAIR_CLASS_INIT(&tag
[0], "ref-city");
2048 PAIR_CLASS_INIT(&tag
[0], "ref-date");
2051 PAIR_CLASS_INIT(&tag
[0], "ref-issue");
2055 PAIR_CLASS_INIT(&tag
[0], "ref-jrnl");
2059 PAIR_CLASS_INIT(&tag
[0], "ref-num");
2062 PAIR_CLASS_INIT(&tag
[0], "ref-opt");
2065 PAIR_CLASS_INIT(&tag
[0], "ref-page");
2068 PAIR_CLASS_INIT(&tag
[0], "ref-corp");
2071 PAIR_CLASS_INIT(&tag
[0], "ref-rep");
2074 PAIR_CLASS_INIT(&tag
[0], "ref-title");
2077 PAIR_CLASS_INIT(&tag
[0], "link-ref");
2080 PAIR_CLASS_INIT(&tag
[0], "ref-vol");
2087 if (MDOC__U
!= n
->tok
) {
2088 print_otag(h
, t
, 1, tag
);
2092 PAIR_HREF_INIT(&tag
[1], n
->child
->string
);
2093 print_otag(h
, TAG_A
, 2, tag
);
2101 mdoc__x_post(MDOC_ARGS
)
2104 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2105 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2106 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2111 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2114 h
->flags
|= HTML_NOSPACE
;
2115 print_text(h
, n
->next
? "," : ".");
2121 mdoc_bk_pre(MDOC_ARGS
)
2130 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2131 h
->flags
|= HTML_PREKEEP
;
2144 mdoc_bk_post(MDOC_ARGS
)
2147 if (MDOC_BODY
== n
->type
)
2148 h
->flags
&= ~(HTML_KEEP
| HTML_PREKEEP
);
2154 mdoc_quote_pre(MDOC_ARGS
)
2156 struct htmlpair tag
;
2158 if (MDOC_BODY
!= n
->type
)
2165 print_text(h
, "\\(la");
2170 print_text(h
, "\\(lC");
2175 print_text(h
, "\\(lB");
2180 print_text(h
, "\\(lB");
2181 h
->flags
|= HTML_NOSPACE
;
2182 PAIR_CLASS_INIT(&tag
, "opt");
2183 print_otag(h
, TAG_SPAN
, 1, &tag
);
2194 print_text(h
, "\\(lq");
2202 print_text(h
, "\\(oq");
2203 h
->flags
|= HTML_NOSPACE
;
2204 PAIR_CLASS_INIT(&tag
, "lit");
2205 print_otag(h
, TAG_CODE
, 1, &tag
);
2210 print_text(h
, "\\(oq");
2217 h
->flags
|= HTML_NOSPACE
;
2224 mdoc_quote_post(MDOC_ARGS
)
2227 if (MDOC_BODY
!= n
->type
)
2230 h
->flags
|= HTML_NOSPACE
;
2236 print_text(h
, "\\(ra");
2241 print_text(h
, "\\(rC");
2250 print_text(h
, "\\(rB");
2261 print_text(h
, "\\(rq");
2273 print_text(h
, "\\(cq");