1 /* $Id: mdoc_html.c,v 1.260 2017/01/21 02:09:51 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_cm_pre(MDOC_ARGS);
74 static int mdoc_d1_pre(MDOC_ARGS);
75 static int mdoc_dv_pre(MDOC_ARGS);
76 static int mdoc_fa_pre(MDOC_ARGS);
77 static int mdoc_fd_pre(MDOC_ARGS);
78 static int mdoc_fl_pre(MDOC_ARGS);
79 static int mdoc_fn_pre(MDOC_ARGS);
80 static int mdoc_ft_pre(MDOC_ARGS);
81 static int mdoc_em_pre(MDOC_ARGS);
82 static void mdoc_eo_post(MDOC_ARGS);
83 static int mdoc_eo_pre(MDOC_ARGS);
84 static int mdoc_er_pre(MDOC_ARGS);
85 static int mdoc_ev_pre(MDOC_ARGS);
86 static int mdoc_ex_pre(MDOC_ARGS);
87 static void mdoc_fo_post(MDOC_ARGS);
88 static int mdoc_fo_pre(MDOC_ARGS);
89 static int mdoc_ic_pre(MDOC_ARGS);
90 static int mdoc_igndelim_pre(MDOC_ARGS);
91 static int mdoc_in_pre(MDOC_ARGS);
92 static int mdoc_it_pre(MDOC_ARGS);
93 static int mdoc_lb_pre(MDOC_ARGS);
94 static int mdoc_li_pre(MDOC_ARGS);
95 static int mdoc_lk_pre(MDOC_ARGS);
96 static int mdoc_mt_pre(MDOC_ARGS);
97 static int mdoc_ms_pre(MDOC_ARGS);
98 static int mdoc_nd_pre(MDOC_ARGS);
99 static int mdoc_nm_pre(MDOC_ARGS);
100 static int mdoc_no_pre(MDOC_ARGS);
101 static int mdoc_ns_pre(MDOC_ARGS);
102 static int mdoc_pa_pre(MDOC_ARGS);
103 static void mdoc_pf_post(MDOC_ARGS);
104 static int mdoc_pp_pre(MDOC_ARGS);
105 static void mdoc_quote_post(MDOC_ARGS);
106 static int mdoc_quote_pre(MDOC_ARGS);
107 static int mdoc_rs_pre(MDOC_ARGS);
108 static int mdoc_sh_pre(MDOC_ARGS);
109 static int mdoc_skip_pre(MDOC_ARGS);
110 static int mdoc_sm_pre(MDOC_ARGS);
111 static int mdoc_sp_pre(MDOC_ARGS);
112 static int mdoc_ss_pre(MDOC_ARGS);
113 static int mdoc_sx_pre(MDOC_ARGS);
114 static int mdoc_sy_pre(MDOC_ARGS);
115 static int mdoc_va_pre(MDOC_ARGS);
116 static int mdoc_vt_pre(MDOC_ARGS);
117 static int mdoc_xr_pre(MDOC_ARGS);
118 static int mdoc_xx_pre(MDOC_ARGS);
120 static const struct htmlmdoc mdocs[MDOC_MAX] = {
121 {mdoc_ap_pre, NULL}, /* Ap */
122 {NULL, NULL}, /* Dd */
123 {NULL, NULL}, /* Dt */
124 {NULL, NULL}, /* Os */
125 {mdoc_sh_pre, NULL }, /* Sh */
126 {mdoc_ss_pre, NULL }, /* Ss */
127 {mdoc_pp_pre, NULL}, /* Pp */
128 {mdoc_d1_pre, NULL}, /* D1 */
129 {mdoc_d1_pre, NULL}, /* Dl */
130 {mdoc_bd_pre, NULL}, /* Bd */
131 {NULL, NULL}, /* Ed */
132 {mdoc_bl_pre, NULL}, /* Bl */
133 {NULL, NULL}, /* El */
134 {mdoc_it_pre, NULL}, /* It */
135 {mdoc_ad_pre, NULL}, /* Ad */
136 {mdoc_an_pre, NULL}, /* An */
137 {mdoc_ar_pre, NULL}, /* Ar */
138 {mdoc_cd_pre, NULL}, /* Cd */
139 {mdoc_cm_pre, NULL}, /* Cm */
140 {mdoc_dv_pre, NULL}, /* Dv */
141 {mdoc_er_pre, NULL}, /* Er */
142 {mdoc_ev_pre, NULL}, /* Ev */
143 {mdoc_ex_pre, NULL}, /* Ex */
144 {mdoc_fa_pre, NULL}, /* Fa */
145 {mdoc_fd_pre, NULL}, /* Fd */
146 {mdoc_fl_pre, NULL}, /* Fl */
147 {mdoc_fn_pre, NULL}, /* Fn */
148 {mdoc_ft_pre, NULL}, /* Ft */
149 {mdoc_ic_pre, NULL}, /* Ic */
150 {mdoc_in_pre, NULL}, /* In */
151 {mdoc_li_pre, NULL}, /* Li */
152 {mdoc_nd_pre, NULL}, /* Nd */
153 {mdoc_nm_pre, NULL}, /* Nm */
154 {mdoc_quote_pre, mdoc_quote_post}, /* Op */
155 {mdoc_ft_pre, NULL}, /* Ot */
156 {mdoc_pa_pre, NULL}, /* Pa */
157 {mdoc_ex_pre, NULL}, /* Rv */
158 {NULL, NULL}, /* St */
159 {mdoc_va_pre, NULL}, /* Va */
160 {mdoc_vt_pre, NULL}, /* Vt */
161 {mdoc_xr_pre, NULL}, /* Xr */
162 {mdoc__x_pre, mdoc__x_post}, /* %A */
163 {mdoc__x_pre, mdoc__x_post}, /* %B */
164 {mdoc__x_pre, mdoc__x_post}, /* %D */
165 {mdoc__x_pre, mdoc__x_post}, /* %I */
166 {mdoc__x_pre, mdoc__x_post}, /* %J */
167 {mdoc__x_pre, mdoc__x_post}, /* %N */
168 {mdoc__x_pre, mdoc__x_post}, /* %O */
169 {mdoc__x_pre, mdoc__x_post}, /* %P */
170 {mdoc__x_pre, mdoc__x_post}, /* %R */
171 {mdoc__x_pre, mdoc__x_post}, /* %T */
172 {mdoc__x_pre, mdoc__x_post}, /* %V */
173 {NULL, NULL}, /* Ac */
174 {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
175 {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
176 {NULL, NULL}, /* At */
177 {NULL, NULL}, /* Bc */
178 {mdoc_bf_pre, NULL}, /* Bf */
179 {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
180 {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
181 {mdoc_xx_pre, NULL}, /* Bsx */
182 {mdoc_xx_pre, NULL}, /* Bx */
183 {mdoc_skip_pre, NULL}, /* Db */
184 {NULL, NULL}, /* Dc */
185 {mdoc_quote_pre, mdoc_quote_post}, /* Do */
186 {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
187 {NULL, NULL}, /* Ec */ /* FIXME: no space */
188 {NULL, NULL}, /* Ef */
189 {mdoc_em_pre, NULL}, /* Em */
190 {mdoc_eo_pre, mdoc_eo_post}, /* Eo */
191 {mdoc_xx_pre, NULL}, /* Fx */
192 {mdoc_ms_pre, NULL}, /* Ms */
193 {mdoc_no_pre, NULL}, /* No */
194 {mdoc_ns_pre, NULL}, /* Ns */
195 {mdoc_xx_pre, NULL}, /* Nx */
196 {mdoc_xx_pre, NULL}, /* Ox */
197 {NULL, NULL}, /* Pc */
198 {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
199 {mdoc_quote_pre, mdoc_quote_post}, /* Po */
200 {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
201 {NULL, NULL}, /* Qc */
202 {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
203 {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
204 {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
205 {NULL, NULL}, /* Re */
206 {mdoc_rs_pre, NULL}, /* Rs */
207 {NULL, NULL}, /* Sc */
208 {mdoc_quote_pre, mdoc_quote_post}, /* So */
209 {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
210 {mdoc_sm_pre, NULL}, /* Sm */
211 {mdoc_sx_pre, NULL}, /* Sx */
212 {mdoc_sy_pre, NULL}, /* Sy */
213 {NULL, NULL}, /* Tn */
214 {mdoc_xx_pre, NULL}, /* Ux */
215 {NULL, NULL}, /* Xc */
216 {NULL, NULL}, /* Xo */
217 {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
218 {NULL, NULL}, /* Fc */
219 {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
220 {NULL, NULL}, /* Oc */
221 {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
222 {NULL, NULL}, /* Ek */
223 {NULL, NULL}, /* Bt */
224 {NULL, NULL}, /* Hf */
225 {mdoc_em_pre, NULL}, /* Fr */
226 {NULL, NULL}, /* Ud */
227 {mdoc_lb_pre, NULL}, /* Lb */
228 {mdoc_pp_pre, NULL}, /* Lp */
229 {mdoc_lk_pre, NULL}, /* Lk */
230 {mdoc_mt_pre, NULL}, /* Mt */
231 {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
232 {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
233 {NULL, NULL}, /* Brc */
234 {mdoc__x_pre, mdoc__x_post}, /* %C */
235 {mdoc_skip_pre, NULL}, /* Es */
236 {mdoc_quote_pre, mdoc_quote_post}, /* En */
237 {mdoc_xx_pre, NULL}, /* Dx */
238 {mdoc__x_pre, mdoc__x_post}, /* %Q */
239 {mdoc_sp_pre, NULL}, /* br */
240 {mdoc_sp_pre, NULL}, /* sp */
241 {mdoc__x_pre, mdoc__x_post}, /* %U */
242 {NULL, NULL}, /* Ta */
243 {mdoc_skip_pre, NULL}, /* ll */
248 * See the same function in mdoc_term.c for documentation.
251 synopsis_pre(struct html *h, const struct roff_node *n)
254 if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
257 if (n->prev->tok == n->tok &&
261 print_otag(h, TAG_BR, "");
265 switch (n->prev->tok) {
274 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
280 print_otag(h, TAG_BR, "");
286 html_mdoc(void *arg, const struct roff_man *mdoc)
291 h = (struct html *)arg;
293 if ((h->oflags & HTML_FRAGMENT) == 0) {
295 print_otag(h, TAG_HTML, "");
296 t = print_otag(h, TAG_HEAD, "");
297 print_mdoc_head(&mdoc->meta, mdoc->first->child, h);
299 print_otag(h, TAG_BODY, "");
302 mdoc_root_pre(&mdoc->meta, mdoc->first->child, h);
303 t = print_otag(h, TAG_DIV, "c", "manual-text");
304 print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h);
306 mdoc_root_post(&mdoc->meta, mdoc->first->child, h);
311 print_mdoc_head(MDOC_ARGS)
317 if (meta->arch != NULL && meta->msec != NULL)
318 mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title,
319 meta->msec, meta->arch);
320 else if (meta->msec != NULL)
321 mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec);
322 else if (meta->arch != NULL)
323 mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch);
325 cp = mandoc_strdup(meta->title);
327 print_otag(h, TAG_TITLE, "");
333 print_mdoc_nodelist(MDOC_ARGS)
337 print_mdoc_node(meta, n, h);
343 print_mdoc_node(MDOC_ARGS)
348 if (n->flags & NODE_NOPRT)
353 n->flags &= ~NODE_ENDED;
357 /* No tables in this mode... */
358 assert(NULL == h->tblt);
361 * Make sure that if we're in a literal mode already
362 * (i.e., within a <PRE>) don't print the newline.
364 if (' ' == *n->string && NODE_LINE & n->flags)
365 if ( ! (HTML_LITERAL & h->flags))
366 print_otag(h, TAG_BR, "");
367 if (NODE_DELIMC & n->flags)
368 h->flags |= HTML_NOSPACE;
369 print_text(h, n->string);
370 if (NODE_DELIMO & n->flags)
371 h->flags |= HTML_NOSPACE;
374 print_eqn(h, n->eqn);
378 * This will take care of initialising all of the table
379 * state data for the first table, then tearing it down
382 print_tbl(h, n->span);
386 * Close out the current table, if it's open, and unset
387 * the "meta" table state. This will be reopened on the
388 * next table element.
390 if (h->tblt != NULL) {
394 assert(h->tblt == NULL);
395 if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
396 child = (*mdocs[n->tok].pre)(meta, n, h);
400 if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
401 h->flags &= ~HTML_KEEP;
402 h->flags |= HTML_PREKEEP;
405 if (child && n->child)
406 print_mdoc_nodelist(meta, n->child, h);
414 if ( ! mdocs[n->tok].post || n->flags & NODE_ENDED)
416 (*mdocs[n->tok].post)(meta, n, h);
417 if (n->end != ENDBODY_NOT)
418 n->body->flags |= NODE_ENDED;
419 if (n->end == ENDBODY_NOSPACE)
420 h->flags |= HTML_NOSPACE;
426 mdoc_root_post(MDOC_ARGS)
430 t = print_otag(h, TAG_TABLE, "c", "foot");
431 print_otag(h, TAG_TBODY, "");
432 tt = print_otag(h, TAG_TR, "");
434 print_otag(h, TAG_TD, "c", "foot-date");
435 print_text(h, meta->date);
438 print_otag(h, TAG_TD, "c", "foot-os");
439 print_text(h, meta->os);
444 mdoc_root_pre(MDOC_ARGS)
447 char *volume, *title;
449 if (NULL == meta->arch)
450 volume = mandoc_strdup(meta->vol);
452 mandoc_asprintf(&volume, "%s (%s)",
453 meta->vol, meta->arch);
455 if (NULL == meta->msec)
456 title = mandoc_strdup(meta->title);
458 mandoc_asprintf(&title, "%s(%s)",
459 meta->title, meta->msec);
461 t = print_otag(h, TAG_TABLE, "c", "head");
462 print_otag(h, TAG_TBODY, "");
463 tt = print_otag(h, TAG_TR, "");
465 print_otag(h, TAG_TD, "c", "head-ltitle");
466 print_text(h, title);
469 print_otag(h, TAG_TD, "c", "head-vol");
470 print_text(h, volume);
473 print_otag(h, TAG_TD, "c", "head-rtitle");
474 print_text(h, title);
483 make_id(const struct roff_node *n)
485 const struct roff_node *nch;
488 for (nch = n->child; nch != NULL; nch = nch->next)
489 if (nch->type != ROFFT_TEXT)
495 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
497 for (cp = buf; *cp != '\0'; cp++)
505 mdoc_sh_pre(MDOC_ARGS)
513 if (n->sec == SEC_AUTHORS)
514 h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
520 if ((id = make_id(n)) != NULL) {
521 print_otag(h, TAG_H1, "ci", "Sh", id);
524 print_otag(h, TAG_H1, "c", "Sh");
530 mdoc_ss_pre(MDOC_ARGS)
534 if (n->type != ROFFT_HEAD)
537 if ((id = make_id(n)) != NULL) {
538 print_otag(h, TAG_H2, "ci", "Ss", id);
541 print_otag(h, TAG_H2, "c", "Ss");
547 mdoc_fl_pre(MDOC_ARGS)
549 print_otag(h, TAG_B, "c", "Fl");
550 print_text(h, "\\-");
552 if (!(n->child == NULL &&
554 n->next->type == ROFFT_TEXT ||
555 n->next->flags & NODE_LINE)))
556 h->flags |= HTML_NOSPACE;
562 mdoc_cm_pre(MDOC_ARGS)
564 print_otag(h, TAG_B, "c", "Cm");
569 mdoc_nd_pre(MDOC_ARGS)
571 if (n->type != ROFFT_BODY)
574 /* XXX: this tag in theory can contain block elements. */
576 print_text(h, "\\(em");
577 print_otag(h, TAG_SPAN, "c", "Nd");
582 mdoc_nm_pre(MDOC_ARGS)
588 print_otag(h, TAG_TD, "");
591 print_otag(h, TAG_B, "c", "Nm");
592 if (n->child == NULL && meta->name != NULL)
593 print_text(h, meta->name);
596 print_otag(h, TAG_TD, "");
603 print_otag(h, TAG_TABLE, "c", "Nm");
605 for (len = 0, n = n->head->child; n; n = n->next)
606 if (n->type == ROFFT_TEXT)
607 len += html_strlen(n->string);
609 if (len == 0 && meta->name != NULL)
610 len = html_strlen(meta->name);
612 print_otag(h, TAG_COL, "shw", len);
613 print_otag(h, TAG_COL, "");
614 print_otag(h, TAG_TBODY, "");
615 print_otag(h, TAG_TR, "");
620 mdoc_xr_pre(MDOC_ARGS)
622 if (NULL == n->child)
626 print_otag(h, TAG_A, "chM", "Xr",
627 n->child->string, n->child->next == NULL ?
628 NULL : n->child->next->string);
630 print_otag(h, TAG_A, "c", "Xr");
633 print_text(h, n->string);
635 if (NULL == (n = n->next))
638 h->flags |= HTML_NOSPACE;
640 h->flags |= HTML_NOSPACE;
641 print_text(h, n->string);
642 h->flags |= HTML_NOSPACE;
648 mdoc_ns_pre(MDOC_ARGS)
651 if ( ! (NODE_LINE & n->flags))
652 h->flags |= HTML_NOSPACE;
657 mdoc_ar_pre(MDOC_ARGS)
659 print_otag(h, TAG_I, "c", "Ar");
664 mdoc_xx_pre(MDOC_ARGS)
666 print_otag(h, TAG_SPAN, "c", "Ux");
671 mdoc_it_pre(MDOC_ARGS)
673 const struct roff_node *bl;
678 while (bl != NULL && bl->tok != MDOC_Bl)
680 type = bl->norm->Bl.type;
728 if (bl->norm->Bl.comp)
729 print_otag(h, TAG_LI, "csvt", cattr, 0);
731 print_otag(h, TAG_LI, "c", cattr);
744 if (bl->norm->Bl.comp)
745 print_otag(h, TAG_DT, "csvt", cattr, 0);
747 print_otag(h, TAG_DT, "c", cattr);
748 if (type == LIST_diag)
749 print_otag(h, TAG_B, "c", cattr);
752 if (bl->norm->Bl.width == NULL)
753 print_otag(h, TAG_DD, "c", cattr);
755 print_otag(h, TAG_DD, "cswl", cattr,
767 if (bl->norm->Bl.comp)
768 print_otag(h, TAG_TD, "csvt", cattr, 0);
770 print_otag(h, TAG_TD, "c", cattr);
773 print_otag(h, TAG_TR, "c", cattr);
783 mdoc_bl_pre(MDOC_ARGS)
787 enum htmltag elemtype;
789 if (n->type == ROFFT_BODY) {
790 if (LIST_column == n->norm->Bl.type)
791 print_otag(h, TAG_TBODY, "");
795 if (n->type == ROFFT_HEAD) {
796 if (LIST_column != n->norm->Bl.type)
800 * For each column, print out the <COL> tag with our
801 * suggested width. The last column gets min-width, as
802 * in terminal mode it auto-sizes to the width of the
803 * screen and we want to preserve that behaviour.
806 for (i = 0; i < (int)n->norm->Bl.ncols - 1; i++)
807 print_otag(h, TAG_COL, "sww", n->norm->Bl.cols[i]);
808 print_otag(h, TAG_COL, "swW", n->norm->Bl.cols[i]);
813 switch (n->norm->Bl.type) {
852 elemtype = TAG_TABLE;
859 if (n->norm->Bl.offs)
860 print_otag(h, elemtype, "cswl", cattr, n->norm->Bl.offs);
862 print_otag(h, elemtype, "c", cattr);
868 mdoc_ex_pre(MDOC_ARGS)
871 print_otag(h, TAG_BR, "");
876 mdoc_em_pre(MDOC_ARGS)
878 print_otag(h, TAG_I, "c", "Em");
883 mdoc_d1_pre(MDOC_ARGS)
885 if (n->type != ROFFT_BLOCK)
888 print_otag(h, TAG_DIV, "c", "D1");
890 if (n->tok == MDOC_Dl)
891 print_otag(h, TAG_CODE, "c", "Li");
897 mdoc_sx_pre(MDOC_ARGS)
901 if ((id = make_id(n)) != NULL) {
902 print_otag(h, TAG_A, "chR", "Sx", id);
905 print_otag(h, TAG_A, "c", "Sx");
911 mdoc_bd_pre(MDOC_ARGS)
914 struct roff_node *nn;
916 if (n->type == ROFFT_HEAD)
919 if (n->type == ROFFT_BLOCK) {
920 comp = n->norm->Bd.comp;
921 for (nn = n; nn && ! comp; nn = nn->parent) {
922 if (nn->type != ROFFT_BLOCK)
924 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
934 /* Handle the -offset argument. */
936 if (n->norm->Bd.offs == NULL ||
937 ! strcmp(n->norm->Bd.offs, "left"))
939 else if ( ! strcmp(n->norm->Bd.offs, "indent"))
941 else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
947 print_otag(h, TAG_DIV, "cswl", "Bd", n->norm->Bd.offs);
949 print_otag(h, TAG_DIV, "cshl", "Bd", offs);
951 if (n->norm->Bd.type != DISP_unfilled &&
952 n->norm->Bd.type != DISP_literal)
955 print_otag(h, TAG_PRE, "c", "Li");
957 /* This can be recursive: save & set our literal state. */
959 sv = h->flags & HTML_LITERAL;
960 h->flags |= HTML_LITERAL;
962 for (nn = n->child; nn; nn = nn->next) {
963 print_mdoc_node(meta, nn, h);
965 * If the printed node flushes its own line, then we
966 * needn't do it here as well. This is hacky, but the
967 * notion of selective eoln whitespace is pretty dumb
968 * anyway, so don't sweat it.
983 if (h->flags & HTML_NONEWLINE ||
984 (nn->next && ! (nn->next->flags & NODE_LINE)))
989 h->flags |= HTML_NOSPACE;
993 h->flags &= ~HTML_LITERAL;
999 mdoc_pa_pre(MDOC_ARGS)
1001 print_otag(h, TAG_I, "c", "Pa");
1006 mdoc_ad_pre(MDOC_ARGS)
1008 print_otag(h, TAG_I, "c", "Ad");
1013 mdoc_an_pre(MDOC_ARGS)
1015 if (n->norm->An.auth == AUTH_split) {
1016 h->flags &= ~HTML_NOSPLIT;
1017 h->flags |= HTML_SPLIT;
1020 if (n->norm->An.auth == AUTH_nosplit) {
1021 h->flags &= ~HTML_SPLIT;
1022 h->flags |= HTML_NOSPLIT;
1026 if (h->flags & HTML_SPLIT)
1027 print_otag(h, TAG_BR, "");
1029 if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
1030 h->flags |= HTML_SPLIT;
1032 print_otag(h, TAG_SPAN, "c", "An");
1037 mdoc_cd_pre(MDOC_ARGS)
1040 print_otag(h, TAG_B, "c", "Cd");
1045 mdoc_dv_pre(MDOC_ARGS)
1047 print_otag(h, TAG_CODE, "c", "Dv");
1052 mdoc_ev_pre(MDOC_ARGS)
1054 print_otag(h, TAG_CODE, "c", "Ev");
1059 mdoc_er_pre(MDOC_ARGS)
1061 print_otag(h, TAG_CODE, "c", "Er");
1066 mdoc_fa_pre(MDOC_ARGS)
1068 const struct roff_node *nn;
1071 if (n->parent->tok != MDOC_Fo) {
1072 print_otag(h, TAG_I, "c", "Fa");
1076 for (nn = n->child; nn; nn = nn->next) {
1077 t = print_otag(h, TAG_I, "c", "Fa");
1078 print_text(h, nn->string);
1081 h->flags |= HTML_NOSPACE;
1086 if (n->child && n->next && n->next->tok == MDOC_Fa) {
1087 h->flags |= HTML_NOSPACE;
1095 mdoc_fd_pre(MDOC_ARGS)
1102 if (NULL == (n = n->child))
1105 assert(n->type == ROFFT_TEXT);
1107 if (strcmp(n->string, "#include")) {
1108 print_otag(h, TAG_B, "c", "Fd");
1112 print_otag(h, TAG_B, "c", "In");
1113 print_text(h, n->string);
1115 if (NULL != (n = n->next)) {
1116 assert(n->type == ROFFT_TEXT);
1118 if (h->base_includes) {
1120 if (*cp == '<' || *cp == '"')
1122 buf = mandoc_strdup(cp);
1123 cp = strchr(buf, '\0') - 1;
1124 if (cp >= buf && (*cp == '>' || *cp == '"'))
1126 t = print_otag(h, TAG_A, "chI", "In", buf);
1129 t = print_otag(h, TAG_A, "c", "In");
1131 print_text(h, n->string);
1137 for ( ; n; n = n->next) {
1138 assert(n->type == ROFFT_TEXT);
1139 print_text(h, n->string);
1146 mdoc_vt_pre(MDOC_ARGS)
1148 if (n->type == ROFFT_BLOCK) {
1151 } else if (n->type == ROFFT_ELEM) {
1153 } else if (n->type == ROFFT_HEAD)
1156 print_otag(h, TAG_I, "c", "Vt");
1161 mdoc_ft_pre(MDOC_ARGS)
1164 print_otag(h, TAG_I, "c", "Ft");
1169 mdoc_fn_pre(MDOC_ARGS)
1173 const char *sp, *ep;
1176 pretty = NODE_SYNPRETTY & n->flags;
1179 /* Split apart into type and name. */
1180 assert(n->child->string);
1181 sp = n->child->string;
1183 ep = strchr(sp, ' ');
1185 t = print_otag(h, TAG_I, "c", "Ft");
1188 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1189 (void)memcpy(nbuf, sp, (size_t)sz);
1191 print_text(h, nbuf);
1193 ep = strchr(sp, ' ');
1198 t = print_otag(h, TAG_B, "c", "Fn");
1205 h->flags |= HTML_NOSPACE;
1207 h->flags |= HTML_NOSPACE;
1209 for (n = n->child->next; n; n = n->next) {
1210 if (NODE_SYNPRETTY & n->flags)
1211 t = print_otag(h, TAG_I, "css?", "Fa",
1212 "white-space", "nowrap");
1214 t = print_otag(h, TAG_I, "c", "Fa");
1215 print_text(h, n->string);
1218 h->flags |= HTML_NOSPACE;
1223 h->flags |= HTML_NOSPACE;
1227 h->flags |= HTML_NOSPACE;
1235 mdoc_sm_pre(MDOC_ARGS)
1238 if (NULL == n->child)
1239 h->flags ^= HTML_NONOSPACE;
1240 else if (0 == strcmp("on", n->child->string))
1241 h->flags &= ~HTML_NONOSPACE;
1243 h->flags |= HTML_NONOSPACE;
1245 if ( ! (HTML_NONOSPACE & h->flags))
1246 h->flags &= ~HTML_NOSPACE;
1252 mdoc_skip_pre(MDOC_ARGS)
1259 mdoc_pp_pre(MDOC_ARGS)
1267 mdoc_sp_pre(MDOC_ARGS)
1271 SCALE_VS_INIT(&su, 1);
1273 if (MDOC_sp == n->tok) {
1274 if (NULL != (n = n->child)) {
1275 if ( ! a2roffsu(n->string, &su, SCALE_VS))
1277 else if (su.scale < 0.0)
1283 print_otag(h, TAG_DIV, "suh", &su);
1285 /* So the div isn't empty: */
1286 print_text(h, "\\~");
1293 mdoc_lk_pre(MDOC_ARGS)
1295 if (NULL == (n = n->child))
1298 assert(n->type == ROFFT_TEXT);
1300 print_otag(h, TAG_A, "ch", "Lk", n->string);
1302 if (NULL == n->next)
1303 print_text(h, n->string);
1305 for (n = n->next; n; n = n->next)
1306 print_text(h, n->string);
1312 mdoc_mt_pre(MDOC_ARGS)
1317 for (n = n->child; n; n = n->next) {
1318 assert(n->type == ROFFT_TEXT);
1320 mandoc_asprintf(&cp, "mailto:%s", n->string);
1321 t = print_otag(h, TAG_A, "ch", "Mt", cp);
1322 print_text(h, n->string);
1331 mdoc_fo_pre(MDOC_ARGS)
1335 if (n->type == ROFFT_BODY) {
1336 h->flags |= HTML_NOSPACE;
1338 h->flags |= HTML_NOSPACE;
1340 } else if (n->type == ROFFT_BLOCK) {
1345 if (n->child == NULL)
1348 assert(n->child->string);
1349 t = print_otag(h, TAG_B, "c", "Fn");
1350 print_text(h, n->child->string);
1356 mdoc_fo_post(MDOC_ARGS)
1359 if (n->type != ROFFT_BODY)
1361 h->flags |= HTML_NOSPACE;
1363 h->flags |= HTML_NOSPACE;
1368 mdoc_in_pre(MDOC_ARGS)
1373 print_otag(h, TAG_B, "c", "In");
1376 * The first argument of the `In' gets special treatment as
1377 * being a linked value. Subsequent values are printed
1378 * afterward. groff does similarly. This also handles the case
1382 if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
1383 print_text(h, "#include");
1386 h->flags |= HTML_NOSPACE;
1388 if (NULL != (n = n->child)) {
1389 assert(n->type == ROFFT_TEXT);
1391 if (h->base_includes)
1392 t = print_otag(h, TAG_A, "chI", "In", n->string);
1394 t = print_otag(h, TAG_A, "c", "In");
1395 print_text(h, n->string);
1401 h->flags |= HTML_NOSPACE;
1404 for ( ; n; n = n->next) {
1405 assert(n->type == ROFFT_TEXT);
1406 print_text(h, n->string);
1413 mdoc_ic_pre(MDOC_ARGS)
1415 print_otag(h, TAG_B, "c", "Ic");
1420 mdoc_va_pre(MDOC_ARGS)
1422 print_otag(h, TAG_I, "c", "Va");
1427 mdoc_ap_pre(MDOC_ARGS)
1430 h->flags |= HTML_NOSPACE;
1431 print_text(h, "\\(aq");
1432 h->flags |= HTML_NOSPACE;
1437 mdoc_bf_pre(MDOC_ARGS)
1441 if (n->type == ROFFT_HEAD)
1443 else if (n->type != ROFFT_BODY)
1446 if (FONT_Em == n->norm->Bf.font)
1448 else if (FONT_Sy == n->norm->Bf.font)
1450 else if (FONT_Li == n->norm->Bf.font)
1456 * We want this to be inline-formatted, but needs to be div to
1457 * accept block children.
1460 print_otag(h, TAG_DIV, "css?hl", cattr, "display", "inline", 1);
1465 mdoc_ms_pre(MDOC_ARGS)
1467 print_otag(h, TAG_B, "c", "Ms");
1472 mdoc_igndelim_pre(MDOC_ARGS)
1475 h->flags |= HTML_IGNDELIM;
1480 mdoc_pf_post(MDOC_ARGS)
1483 if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1484 h->flags |= HTML_NOSPACE;
1488 mdoc_rs_pre(MDOC_ARGS)
1490 if (n->type != ROFFT_BLOCK)
1493 if (n->prev && SEC_SEE_ALSO == n->sec)
1496 print_otag(h, TAG_SPAN, "c", "Rs");
1501 mdoc_no_pre(MDOC_ARGS)
1503 print_otag(h, TAG_SPAN, "c", "No");
1508 mdoc_li_pre(MDOC_ARGS)
1510 print_otag(h, TAG_CODE, "c", "Li");
1515 mdoc_sy_pre(MDOC_ARGS)
1517 print_otag(h, TAG_B, "c", "Sy");
1522 mdoc_lb_pre(MDOC_ARGS)
1524 if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
1525 print_otag(h, TAG_BR, "");
1527 print_otag(h, TAG_SPAN, "c", "Lb");
1532 mdoc__x_pre(MDOC_ARGS)
1542 if (n->prev && MDOC__A == n->prev->tok)
1543 if (NULL == n->next || MDOC__A != n->next->tok)
1544 print_text(h, "and");
1583 print_otag(h, TAG_A, "ch", "RsU", n->child->string);
1592 print_otag(h, t, "c", cattr);
1597 mdoc__x_post(MDOC_ARGS)
1600 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1601 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1602 if (NULL == n->prev || MDOC__A != n->prev->tok)
1607 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1610 h->flags |= HTML_NOSPACE;
1611 print_text(h, n->next ? "," : ".");
1615 mdoc_bk_pre(MDOC_ARGS)
1624 if (n->parent->args != NULL || n->prev->child == NULL)
1625 h->flags |= HTML_PREKEEP;
1635 mdoc_bk_post(MDOC_ARGS)
1638 if (n->type == ROFFT_BODY)
1639 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1643 mdoc_quote_pre(MDOC_ARGS)
1645 if (n->type != ROFFT_BODY)
1651 print_text(h, n->child != NULL && n->child->next == NULL &&
1652 n->child->tok == MDOC_Mt ? "<" : "\\(la");
1656 print_text(h, "\\(lC");
1660 print_text(h, "\\(lB");
1664 print_text(h, "\\(lB");
1665 h->flags |= HTML_NOSPACE;
1666 print_otag(h, TAG_SPAN, "c", "Op");
1669 if (NULL == n->norm->Es ||
1670 NULL == n->norm->Es->child)
1672 print_text(h, n->norm->Es->child->string);
1678 print_text(h, "\\(lq");
1685 print_text(h, "\\(oq");
1686 h->flags |= HTML_NOSPACE;
1687 print_otag(h, TAG_CODE, "c", "Li");
1691 print_text(h, "\\(oq");
1697 h->flags |= HTML_NOSPACE;
1702 mdoc_quote_post(MDOC_ARGS)
1705 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1708 h->flags |= HTML_NOSPACE;
1713 print_text(h, n->child != NULL && n->child->next == NULL &&
1714 n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1718 print_text(h, "\\(rC");
1724 print_text(h, "\\(rB");
1727 if (n->norm->Es == NULL ||
1728 n->norm->Es->child == NULL ||
1729 n->norm->Es->child->next == NULL)
1730 h->flags &= ~HTML_NOSPACE;
1732 print_text(h, n->norm->Es->child->next->string);
1738 print_text(h, "\\(rq");
1747 print_text(h, "\\(cq");
1755 mdoc_eo_pre(MDOC_ARGS)
1758 if (n->type != ROFFT_BODY)
1761 if (n->end == ENDBODY_NOT &&
1762 n->parent->head->child == NULL &&
1764 n->child->end != ENDBODY_NOT)
1765 print_text(h, "\\&");
1766 else if (n->end != ENDBODY_NOT ? n->child != NULL :
1767 n->parent->head->child != NULL && (n->child != NULL ||
1768 (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1769 h->flags |= HTML_NOSPACE;
1774 mdoc_eo_post(MDOC_ARGS)
1778 if (n->type != ROFFT_BODY)
1781 if (n->end != ENDBODY_NOT) {
1782 h->flags &= ~HTML_NOSPACE;
1786 body = n->child != NULL || n->parent->head->child != NULL;
1787 tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1790 h->flags |= HTML_NOSPACE;
1792 h->flags &= ~HTML_NOSPACE;