1 /* $Id: mdoc_html.c,v 1.271 2017/02/16 03:00:23 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_st_pre(MDOC_ARGS);
114 static int mdoc_sx_pre(MDOC_ARGS);
115 static int mdoc_sy_pre(MDOC_ARGS);
116 static int mdoc_va_pre(MDOC_ARGS);
117 static int mdoc_vt_pre(MDOC_ARGS);
118 static int mdoc_xr_pre(MDOC_ARGS);
119 static int mdoc_xx_pre(MDOC_ARGS);
121 static const struct htmlmdoc mdocs[MDOC_MAX] = {
122 {mdoc_ap_pre, NULL}, /* Ap */
123 {NULL, NULL}, /* Dd */
124 {NULL, NULL}, /* Dt */
125 {NULL, NULL}, /* Os */
126 {mdoc_sh_pre, NULL }, /* Sh */
127 {mdoc_ss_pre, NULL }, /* Ss */
128 {mdoc_pp_pre, NULL}, /* Pp */
129 {mdoc_d1_pre, NULL}, /* D1 */
130 {mdoc_d1_pre, NULL}, /* Dl */
131 {mdoc_bd_pre, NULL}, /* Bd */
132 {NULL, NULL}, /* Ed */
133 {mdoc_bl_pre, NULL}, /* Bl */
134 {NULL, NULL}, /* El */
135 {mdoc_it_pre, NULL}, /* It */
136 {mdoc_ad_pre, NULL}, /* Ad */
137 {mdoc_an_pre, NULL}, /* An */
138 {mdoc_ar_pre, NULL}, /* Ar */
139 {mdoc_cd_pre, NULL}, /* Cd */
140 {mdoc_cm_pre, NULL}, /* Cm */
141 {mdoc_dv_pre, NULL}, /* Dv */
142 {mdoc_er_pre, NULL}, /* Er */
143 {mdoc_ev_pre, NULL}, /* Ev */
144 {mdoc_ex_pre, NULL}, /* Ex */
145 {mdoc_fa_pre, NULL}, /* Fa */
146 {mdoc_fd_pre, NULL}, /* Fd */
147 {mdoc_fl_pre, NULL}, /* Fl */
148 {mdoc_fn_pre, NULL}, /* Fn */
149 {mdoc_ft_pre, NULL}, /* Ft */
150 {mdoc_ic_pre, NULL}, /* Ic */
151 {mdoc_in_pre, NULL}, /* In */
152 {mdoc_li_pre, NULL}, /* Li */
153 {mdoc_nd_pre, NULL}, /* Nd */
154 {mdoc_nm_pre, NULL}, /* Nm */
155 {mdoc_quote_pre, mdoc_quote_post}, /* Op */
156 {mdoc_ft_pre, NULL}, /* Ot */
157 {mdoc_pa_pre, NULL}, /* Pa */
158 {mdoc_ex_pre, NULL}, /* Rv */
159 {mdoc_st_pre, NULL}, /* St */
160 {mdoc_va_pre, NULL}, /* Va */
161 {mdoc_vt_pre, NULL}, /* Vt */
162 {mdoc_xr_pre, NULL}, /* Xr */
163 {mdoc__x_pre, mdoc__x_post}, /* %A */
164 {mdoc__x_pre, mdoc__x_post}, /* %B */
165 {mdoc__x_pre, mdoc__x_post}, /* %D */
166 {mdoc__x_pre, mdoc__x_post}, /* %I */
167 {mdoc__x_pre, mdoc__x_post}, /* %J */
168 {mdoc__x_pre, mdoc__x_post}, /* %N */
169 {mdoc__x_pre, mdoc__x_post}, /* %O */
170 {mdoc__x_pre, mdoc__x_post}, /* %P */
171 {mdoc__x_pre, mdoc__x_post}, /* %R */
172 {mdoc__x_pre, mdoc__x_post}, /* %T */
173 {mdoc__x_pre, mdoc__x_post}, /* %V */
174 {NULL, NULL}, /* Ac */
175 {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
176 {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
177 {mdoc_xx_pre, NULL}, /* At */
178 {NULL, NULL}, /* Bc */
179 {mdoc_bf_pre, NULL}, /* Bf */
180 {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
181 {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
182 {mdoc_xx_pre, NULL}, /* Bsx */
183 {mdoc_xx_pre, NULL}, /* Bx */
184 {mdoc_skip_pre, NULL}, /* Db */
185 {NULL, NULL}, /* Dc */
186 {mdoc_quote_pre, mdoc_quote_post}, /* Do */
187 {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
188 {NULL, NULL}, /* Ec */ /* FIXME: no space */
189 {NULL, NULL}, /* Ef */
190 {mdoc_em_pre, NULL}, /* Em */
191 {mdoc_eo_pre, mdoc_eo_post}, /* Eo */
192 {mdoc_xx_pre, NULL}, /* Fx */
193 {mdoc_ms_pre, NULL}, /* Ms */
194 {mdoc_no_pre, NULL}, /* No */
195 {mdoc_ns_pre, NULL}, /* Ns */
196 {mdoc_xx_pre, NULL}, /* Nx */
197 {mdoc_xx_pre, NULL}, /* Ox */
198 {NULL, NULL}, /* Pc */
199 {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
200 {mdoc_quote_pre, mdoc_quote_post}, /* Po */
201 {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
202 {NULL, NULL}, /* Qc */
203 {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
204 {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
205 {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
206 {NULL, NULL}, /* Re */
207 {mdoc_rs_pre, NULL}, /* Rs */
208 {NULL, NULL}, /* Sc */
209 {mdoc_quote_pre, mdoc_quote_post}, /* So */
210 {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
211 {mdoc_sm_pre, NULL}, /* Sm */
212 {mdoc_sx_pre, NULL}, /* Sx */
213 {mdoc_sy_pre, NULL}, /* Sy */
214 {NULL, NULL}, /* Tn */
215 {mdoc_xx_pre, NULL}, /* Ux */
216 {NULL, NULL}, /* Xc */
217 {NULL, NULL}, /* Xo */
218 {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
219 {NULL, NULL}, /* Fc */
220 {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
221 {NULL, NULL}, /* Oc */
222 {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
223 {NULL, NULL}, /* Ek */
224 {NULL, NULL}, /* Bt */
225 {NULL, NULL}, /* Hf */
226 {mdoc_em_pre, NULL}, /* Fr */
227 {NULL, NULL}, /* Ud */
228 {mdoc_lb_pre, NULL}, /* Lb */
229 {mdoc_pp_pre, NULL}, /* Lp */
230 {mdoc_lk_pre, NULL}, /* Lk */
231 {mdoc_mt_pre, NULL}, /* Mt */
232 {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
233 {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
234 {NULL, NULL}, /* Brc */
235 {mdoc__x_pre, mdoc__x_post}, /* %C */
236 {mdoc_skip_pre, NULL}, /* Es */
237 {mdoc_quote_pre, mdoc_quote_post}, /* En */
238 {mdoc_xx_pre, NULL}, /* Dx */
239 {mdoc__x_pre, mdoc__x_post}, /* %Q */
240 {mdoc_sp_pre, NULL}, /* br */
241 {mdoc_sp_pre, NULL}, /* sp */
242 {mdoc__x_pre, mdoc__x_post}, /* %U */
243 {NULL, NULL}, /* Ta */
244 {mdoc_skip_pre, NULL}, /* ll */
249 * See the same function in mdoc_term.c for documentation.
252 synopsis_pre(struct html *h, const struct roff_node *n)
255 if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
258 if (n->prev->tok == n->tok &&
262 print_otag(h, TAG_BR, "");
266 switch (n->prev->tok) {
275 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
281 print_otag(h, TAG_BR, "");
287 html_mdoc(void *arg, const struct roff_man *mdoc)
292 h = (struct html *)arg;
294 if ((h->oflags & HTML_FRAGMENT) == 0) {
296 print_otag(h, TAG_HTML, "");
297 t = print_otag(h, TAG_HEAD, "");
298 print_mdoc_head(&mdoc->meta, mdoc->first->child, h);
300 print_otag(h, TAG_BODY, "");
303 mdoc_root_pre(&mdoc->meta, mdoc->first->child, h);
304 t = print_otag(h, TAG_DIV, "c", "manual-text");
305 print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h);
307 mdoc_root_post(&mdoc->meta, mdoc->first->child, h);
312 print_mdoc_head(MDOC_ARGS)
318 if (meta->arch != NULL && meta->msec != NULL)
319 mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title,
320 meta->msec, meta->arch);
321 else if (meta->msec != NULL)
322 mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec);
323 else if (meta->arch != NULL)
324 mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch);
326 cp = mandoc_strdup(meta->title);
328 print_otag(h, TAG_TITLE, "");
334 print_mdoc_nodelist(MDOC_ARGS)
338 print_mdoc_node(meta, n, h);
344 print_mdoc_node(MDOC_ARGS)
349 if (n->flags & NODE_NOPRT)
354 n->flags &= ~NODE_ENDED;
358 /* No tables in this mode... */
359 assert(NULL == h->tblt);
362 * Make sure that if we're in a literal mode already
363 * (i.e., within a <PRE>) don't print the newline.
365 if (' ' == *n->string && NODE_LINE & n->flags)
366 if ( ! (HTML_LITERAL & h->flags))
367 print_otag(h, TAG_BR, "");
368 if (NODE_DELIMC & n->flags)
369 h->flags |= HTML_NOSPACE;
370 print_text(h, n->string);
371 if (NODE_DELIMO & n->flags)
372 h->flags |= HTML_NOSPACE;
375 print_eqn(h, n->eqn);
379 * This will take care of initialising all of the table
380 * state data for the first table, then tearing it down
383 print_tbl(h, n->span);
387 * Close out the current table, if it's open, and unset
388 * the "meta" table state. This will be reopened on the
389 * next table element.
391 if (h->tblt != NULL) {
395 assert(h->tblt == NULL);
396 if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
397 child = (*mdocs[n->tok].pre)(meta, n, h);
401 if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
402 h->flags &= ~HTML_KEEP;
403 h->flags |= HTML_PREKEEP;
406 if (child && n->child)
407 print_mdoc_nodelist(meta, n->child, h);
415 if ( ! mdocs[n->tok].post || n->flags & NODE_ENDED)
417 (*mdocs[n->tok].post)(meta, n, h);
418 if (n->end != ENDBODY_NOT)
419 n->body->flags |= NODE_ENDED;
425 mdoc_root_post(MDOC_ARGS)
429 t = print_otag(h, TAG_TABLE, "c", "foot");
430 tt = print_otag(h, TAG_TR, "");
432 print_otag(h, TAG_TD, "c", "foot-date");
433 print_text(h, meta->date);
436 print_otag(h, TAG_TD, "c", "foot-os");
437 print_text(h, meta->os);
442 mdoc_root_pre(MDOC_ARGS)
445 char *volume, *title;
447 if (NULL == meta->arch)
448 volume = mandoc_strdup(meta->vol);
450 mandoc_asprintf(&volume, "%s (%s)",
451 meta->vol, meta->arch);
453 if (NULL == meta->msec)
454 title = mandoc_strdup(meta->title);
456 mandoc_asprintf(&title, "%s(%s)",
457 meta->title, meta->msec);
459 t = print_otag(h, TAG_TABLE, "c", "head");
460 tt = print_otag(h, TAG_TR, "");
462 print_otag(h, TAG_TD, "c", "head-ltitle");
463 print_text(h, title);
466 print_otag(h, TAG_TD, "c", "head-vol");
467 print_text(h, volume);
470 print_otag(h, TAG_TD, "c", "head-rtitle");
471 print_text(h, title);
480 make_id(const struct roff_node *n)
482 const struct roff_node *nch;
485 for (nch = n->child; nch != NULL; nch = nch->next)
486 if (nch->type != ROFFT_TEXT)
492 /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
494 for (cp = buf; *cp != '\0'; cp++)
502 mdoc_sh_pre(MDOC_ARGS)
509 print_otag(h, TAG_H1, "ci", "Sh", id);
513 if (n->sec == SEC_AUTHORS)
514 h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
523 mdoc_ss_pre(MDOC_ARGS)
527 if (n->type != ROFFT_HEAD)
531 print_otag(h, TAG_H2, "ci", "Ss", id);
537 mdoc_fl_pre(MDOC_ARGS)
539 print_otag(h, TAG_B, "c", "Fl");
540 print_text(h, "\\-");
542 if (!(n->child == NULL &&
544 n->next->type == ROFFT_TEXT ||
545 n->next->flags & NODE_LINE)))
546 h->flags |= HTML_NOSPACE;
552 mdoc_cm_pre(MDOC_ARGS)
554 print_otag(h, TAG_B, "c", "Cm");
559 mdoc_nd_pre(MDOC_ARGS)
561 if (n->type != ROFFT_BODY)
564 /* XXX: this tag in theory can contain block elements. */
566 print_text(h, "\\(em");
567 print_otag(h, TAG_SPAN, "c", "Nd");
572 mdoc_nm_pre(MDOC_ARGS)
579 print_otag(h, TAG_TD, "");
582 print_otag(h, TAG_B, "c", "Nm");
585 print_otag(h, TAG_TD, "");
592 print_otag(h, TAG_TABLE, "c", "Nm");
594 for (len = 0, n = n->head->child; n; n = n->next)
595 if (n->type == ROFFT_TEXT)
596 len += html_strlen(n->string);
598 if (len == 0 && meta->name != NULL)
599 len = html_strlen(meta->name);
601 t = print_otag(h, TAG_COLGROUP, "");
602 print_otag(h, TAG_COL, "shw", len);
603 print_otag(h, TAG_COL, "");
605 print_otag(h, TAG_TR, "");
610 mdoc_xr_pre(MDOC_ARGS)
612 if (NULL == n->child)
616 print_otag(h, TAG_A, "chM", "Xr",
617 n->child->string, n->child->next == NULL ?
618 NULL : n->child->next->string);
620 print_otag(h, TAG_A, "c", "Xr");
623 print_text(h, n->string);
625 if (NULL == (n = n->next))
628 h->flags |= HTML_NOSPACE;
630 h->flags |= HTML_NOSPACE;
631 print_text(h, n->string);
632 h->flags |= HTML_NOSPACE;
638 mdoc_ns_pre(MDOC_ARGS)
641 if ( ! (NODE_LINE & n->flags))
642 h->flags |= HTML_NOSPACE;
647 mdoc_ar_pre(MDOC_ARGS)
649 print_otag(h, TAG_VAR, "c", "Ar");
654 mdoc_xx_pre(MDOC_ARGS)
656 print_otag(h, TAG_SPAN, "c", "Ux");
661 mdoc_it_pre(MDOC_ARGS)
663 const struct roff_node *bl;
669 while (bl != NULL && bl->tok != MDOC_Bl)
671 type = bl->norm->Bl.type;
719 if (bl->norm->Bl.comp)
720 print_otag(h, TAG_LI, "csvt", cattr, 0);
722 print_otag(h, TAG_LI, "c", cattr);
734 if (bl->norm->Bl.comp)
735 print_otag(h, TAG_DT, "csvt", cattr, 0);
737 print_otag(h, TAG_DT, "c", cattr);
738 if (type == LIST_diag)
739 print_otag(h, TAG_B, "c", cattr);
742 print_otag(h, TAG_DD, "cswl", cattr,
752 if (h->style != NULL && !bl->norm->Bl.comp &&
753 (n->parent->prev == NULL ||
754 n->parent->prev->body->child != NULL)) {
755 t = print_otag(h, TAG_DT, "csWl",
756 cattr, bl->norm->Bl.width);
757 print_text(h, "\\ ");
759 t = print_otag(h, TAG_DD, "c", cattr);
760 print_text(h, "\\ ");
763 print_otag(h, TAG_DT, "csWl", cattr,
767 if (n->child == NULL) {
768 print_otag(h, TAG_DD, "css?", cattr,
770 print_text(h, "\\ ");
772 print_otag(h, TAG_DD, "c", cattr);
783 if (bl->norm->Bl.comp)
784 print_otag(h, TAG_TD, "csvt", cattr, 0);
786 print_otag(h, TAG_TD, "c", cattr);
789 print_otag(h, TAG_TR, "c", cattr);
799 mdoc_bl_pre(MDOC_ARGS)
805 enum htmltag elemtype;
814 if (bl->type != LIST_column || bl->ncols == 0)
818 * For each column, print out the <COL> tag with our
819 * suggested width. The last column gets min-width, as
820 * in terminal mode it auto-sizes to the width of the
821 * screen and we want to preserve that behaviour.
824 t = print_otag(h, TAG_COLGROUP, "");
825 for (i = 0; i < bl->ncols - 1; i++)
826 print_otag(h, TAG_COL, "sww", bl->cols[i]);
827 print_otag(h, TAG_COL, "swW", bl->cols[i]);
872 print_otag(h, TAG_DIV, "cswl", cattr, bl->offs);
873 print_otag(h, TAG_DL, "cswl", cattr, bl->width);
876 elemtype = TAG_TABLE;
882 print_otag(h, elemtype, "cswl", cattr, bl->offs);
887 mdoc_ex_pre(MDOC_ARGS)
890 print_otag(h, TAG_BR, "");
895 mdoc_st_pre(MDOC_ARGS)
897 print_otag(h, TAG_SPAN, "c", "St");
902 mdoc_em_pre(MDOC_ARGS)
904 print_otag(h, TAG_I, "c", "Em");
909 mdoc_d1_pre(MDOC_ARGS)
911 if (n->type != ROFFT_BLOCK)
914 print_otag(h, TAG_DIV, "c", "D1");
916 if (n->tok == MDOC_Dl)
917 print_otag(h, TAG_CODE, "c", "Li");
923 mdoc_sx_pre(MDOC_ARGS)
928 print_otag(h, TAG_A, "chR", "Sx", id);
934 mdoc_bd_pre(MDOC_ARGS)
937 struct roff_node *nn;
939 if (n->type == ROFFT_HEAD)
942 if (n->type == ROFFT_BLOCK) {
943 comp = n->norm->Bd.comp;
944 for (nn = n; nn && ! comp; nn = nn->parent) {
945 if (nn->type != ROFFT_BLOCK)
947 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
957 /* Handle the -offset argument. */
959 if (n->norm->Bd.offs == NULL ||
960 ! strcmp(n->norm->Bd.offs, "left"))
962 else if ( ! strcmp(n->norm->Bd.offs, "indent"))
964 else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
970 print_otag(h, TAG_DIV, "cswl", "Bd", n->norm->Bd.offs);
972 print_otag(h, TAG_DIV, "cshl", "Bd", offs);
974 if (n->norm->Bd.type != DISP_unfilled &&
975 n->norm->Bd.type != DISP_literal)
978 print_otag(h, TAG_PRE, "c", "Li");
980 /* This can be recursive: save & set our literal state. */
982 sv = h->flags & HTML_LITERAL;
983 h->flags |= HTML_LITERAL;
985 for (nn = n->child; nn; nn = nn->next) {
986 print_mdoc_node(meta, nn, h);
988 * If the printed node flushes its own line, then we
989 * needn't do it here as well. This is hacky, but the
990 * notion of selective eoln whitespace is pretty dumb
991 * anyway, so don't sweat it.
1006 if (h->flags & HTML_NONEWLINE ||
1007 (nn->next && ! (nn->next->flags & NODE_LINE)))
1010 print_text(h, "\n");
1012 h->flags |= HTML_NOSPACE;
1016 h->flags &= ~HTML_LITERAL;
1022 mdoc_pa_pre(MDOC_ARGS)
1024 print_otag(h, TAG_I, "c", "Pa");
1029 mdoc_ad_pre(MDOC_ARGS)
1031 print_otag(h, TAG_I, "c", "Ad");
1036 mdoc_an_pre(MDOC_ARGS)
1038 if (n->norm->An.auth == AUTH_split) {
1039 h->flags &= ~HTML_NOSPLIT;
1040 h->flags |= HTML_SPLIT;
1043 if (n->norm->An.auth == AUTH_nosplit) {
1044 h->flags &= ~HTML_SPLIT;
1045 h->flags |= HTML_NOSPLIT;
1049 if (h->flags & HTML_SPLIT)
1050 print_otag(h, TAG_BR, "");
1052 if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
1053 h->flags |= HTML_SPLIT;
1055 print_otag(h, TAG_SPAN, "c", "An");
1060 mdoc_cd_pre(MDOC_ARGS)
1063 print_otag(h, TAG_B, "c", "Cd");
1068 mdoc_dv_pre(MDOC_ARGS)
1070 print_otag(h, TAG_CODE, "c", "Dv");
1075 mdoc_ev_pre(MDOC_ARGS)
1077 print_otag(h, TAG_CODE, "c", "Ev");
1082 mdoc_er_pre(MDOC_ARGS)
1084 print_otag(h, TAG_CODE, "c", "Er");
1089 mdoc_fa_pre(MDOC_ARGS)
1091 const struct roff_node *nn;
1094 if (n->parent->tok != MDOC_Fo) {
1095 print_otag(h, TAG_VAR, "c", "Fa");
1099 for (nn = n->child; nn; nn = nn->next) {
1100 t = print_otag(h, TAG_VAR, "c", "Fa");
1101 print_text(h, nn->string);
1104 h->flags |= HTML_NOSPACE;
1109 if (n->child && n->next && n->next->tok == MDOC_Fa) {
1110 h->flags |= HTML_NOSPACE;
1118 mdoc_fd_pre(MDOC_ARGS)
1125 if (NULL == (n = n->child))
1128 assert(n->type == ROFFT_TEXT);
1130 if (strcmp(n->string, "#include")) {
1131 print_otag(h, TAG_B, "c", "Fd");
1135 print_otag(h, TAG_B, "c", "In");
1136 print_text(h, n->string);
1138 if (NULL != (n = n->next)) {
1139 assert(n->type == ROFFT_TEXT);
1141 if (h->base_includes) {
1143 if (*cp == '<' || *cp == '"')
1145 buf = mandoc_strdup(cp);
1146 cp = strchr(buf, '\0') - 1;
1147 if (cp >= buf && (*cp == '>' || *cp == '"'))
1149 t = print_otag(h, TAG_A, "chI", "In", buf);
1152 t = print_otag(h, TAG_A, "c", "In");
1154 print_text(h, n->string);
1160 for ( ; n; n = n->next) {
1161 assert(n->type == ROFFT_TEXT);
1162 print_text(h, n->string);
1169 mdoc_vt_pre(MDOC_ARGS)
1171 if (n->type == ROFFT_BLOCK) {
1174 } else if (n->type == ROFFT_ELEM) {
1176 } else if (n->type == ROFFT_HEAD)
1179 print_otag(h, TAG_VAR, "c", "Vt");
1184 mdoc_ft_pre(MDOC_ARGS)
1187 print_otag(h, TAG_VAR, "c", "Ft");
1192 mdoc_fn_pre(MDOC_ARGS)
1196 const char *sp, *ep;
1199 pretty = NODE_SYNPRETTY & n->flags;
1202 /* Split apart into type and name. */
1203 assert(n->child->string);
1204 sp = n->child->string;
1206 ep = strchr(sp, ' ');
1208 t = print_otag(h, TAG_VAR, "c", "Ft");
1211 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1212 (void)memcpy(nbuf, sp, (size_t)sz);
1214 print_text(h, nbuf);
1216 ep = strchr(sp, ' ');
1221 t = print_otag(h, TAG_B, "c", "Fn");
1228 h->flags |= HTML_NOSPACE;
1230 h->flags |= HTML_NOSPACE;
1232 for (n = n->child->next; n; n = n->next) {
1233 if (NODE_SYNPRETTY & n->flags)
1234 t = print_otag(h, TAG_VAR, "css?", "Fa",
1235 "white-space", "nowrap");
1237 t = print_otag(h, TAG_VAR, "c", "Fa");
1238 print_text(h, n->string);
1241 h->flags |= HTML_NOSPACE;
1246 h->flags |= HTML_NOSPACE;
1250 h->flags |= HTML_NOSPACE;
1258 mdoc_sm_pre(MDOC_ARGS)
1261 if (NULL == n->child)
1262 h->flags ^= HTML_NONOSPACE;
1263 else if (0 == strcmp("on", n->child->string))
1264 h->flags &= ~HTML_NONOSPACE;
1266 h->flags |= HTML_NONOSPACE;
1268 if ( ! (HTML_NONOSPACE & h->flags))
1269 h->flags &= ~HTML_NOSPACE;
1275 mdoc_skip_pre(MDOC_ARGS)
1282 mdoc_pp_pre(MDOC_ARGS)
1290 mdoc_sp_pre(MDOC_ARGS)
1294 SCALE_VS_INIT(&su, 1);
1296 if (MDOC_sp == n->tok) {
1297 if (NULL != (n = n->child)) {
1298 if ( ! a2roffsu(n->string, &su, SCALE_VS))
1300 else if (su.scale < 0.0)
1306 print_otag(h, TAG_DIV, "suh", &su);
1308 /* So the div isn't empty: */
1309 print_text(h, "\\~");
1316 mdoc_lk_pre(MDOC_ARGS)
1318 if (NULL == (n = n->child))
1321 assert(n->type == ROFFT_TEXT);
1323 print_otag(h, TAG_A, "ch", "Lk", n->string);
1325 if (NULL == n->next)
1326 print_text(h, n->string);
1328 for (n = n->next; n; n = n->next)
1329 print_text(h, n->string);
1335 mdoc_mt_pre(MDOC_ARGS)
1340 for (n = n->child; n; n = n->next) {
1341 assert(n->type == ROFFT_TEXT);
1343 mandoc_asprintf(&cp, "mailto:%s", n->string);
1344 t = print_otag(h, TAG_A, "ch", "Mt", cp);
1345 print_text(h, n->string);
1354 mdoc_fo_pre(MDOC_ARGS)
1358 if (n->type == ROFFT_BODY) {
1359 h->flags |= HTML_NOSPACE;
1361 h->flags |= HTML_NOSPACE;
1363 } else if (n->type == ROFFT_BLOCK) {
1368 if (n->child == NULL)
1371 assert(n->child->string);
1372 t = print_otag(h, TAG_B, "c", "Fn");
1373 print_text(h, n->child->string);
1379 mdoc_fo_post(MDOC_ARGS)
1382 if (n->type != ROFFT_BODY)
1384 h->flags |= HTML_NOSPACE;
1386 h->flags |= HTML_NOSPACE;
1391 mdoc_in_pre(MDOC_ARGS)
1396 print_otag(h, TAG_B, "c", "In");
1399 * The first argument of the `In' gets special treatment as
1400 * being a linked value. Subsequent values are printed
1401 * afterward. groff does similarly. This also handles the case
1405 if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
1406 print_text(h, "#include");
1409 h->flags |= HTML_NOSPACE;
1411 if (NULL != (n = n->child)) {
1412 assert(n->type == ROFFT_TEXT);
1414 if (h->base_includes)
1415 t = print_otag(h, TAG_A, "chI", "In", n->string);
1417 t = print_otag(h, TAG_A, "c", "In");
1418 print_text(h, n->string);
1424 h->flags |= HTML_NOSPACE;
1427 for ( ; n; n = n->next) {
1428 assert(n->type == ROFFT_TEXT);
1429 print_text(h, n->string);
1436 mdoc_ic_pre(MDOC_ARGS)
1438 print_otag(h, TAG_B, "c", "Ic");
1443 mdoc_va_pre(MDOC_ARGS)
1445 print_otag(h, TAG_VAR, "c", "Va");
1450 mdoc_ap_pre(MDOC_ARGS)
1453 h->flags |= HTML_NOSPACE;
1454 print_text(h, "\\(aq");
1455 h->flags |= HTML_NOSPACE;
1460 mdoc_bf_pre(MDOC_ARGS)
1464 if (n->type == ROFFT_HEAD)
1466 else if (n->type != ROFFT_BODY)
1469 if (FONT_Em == n->norm->Bf.font)
1471 else if (FONT_Sy == n->norm->Bf.font)
1473 else if (FONT_Li == n->norm->Bf.font)
1479 * We want this to be inline-formatted, but needs to be div to
1480 * accept block children.
1483 print_otag(h, TAG_DIV, "css?hl", cattr, "display", "inline", 1);
1488 mdoc_ms_pre(MDOC_ARGS)
1490 print_otag(h, TAG_B, "c", "Ms");
1495 mdoc_igndelim_pre(MDOC_ARGS)
1498 h->flags |= HTML_IGNDELIM;
1503 mdoc_pf_post(MDOC_ARGS)
1506 if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1507 h->flags |= HTML_NOSPACE;
1511 mdoc_rs_pre(MDOC_ARGS)
1513 if (n->type != ROFFT_BLOCK)
1516 if (n->prev && SEC_SEE_ALSO == n->sec)
1519 print_otag(h, TAG_CITE, "c", "Rs");
1524 mdoc_no_pre(MDOC_ARGS)
1526 print_otag(h, TAG_SPAN, "c", "No");
1531 mdoc_li_pre(MDOC_ARGS)
1533 print_otag(h, TAG_CODE, "c", "Li");
1538 mdoc_sy_pre(MDOC_ARGS)
1540 print_otag(h, TAG_B, "c", "Sy");
1545 mdoc_lb_pre(MDOC_ARGS)
1547 if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
1548 print_otag(h, TAG_BR, "");
1550 print_otag(h, TAG_SPAN, "c", "Lb");
1555 mdoc__x_pre(MDOC_ARGS)
1565 if (n->prev && MDOC__A == n->prev->tok)
1566 if (NULL == n->next || MDOC__A != n->next->tok)
1567 print_text(h, "and");
1606 print_otag(h, TAG_A, "ch", "RsU", n->child->string);
1615 print_otag(h, t, "c", cattr);
1620 mdoc__x_post(MDOC_ARGS)
1623 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1624 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1625 if (NULL == n->prev || MDOC__A != n->prev->tok)
1630 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1633 h->flags |= HTML_NOSPACE;
1634 print_text(h, n->next ? "," : ".");
1638 mdoc_bk_pre(MDOC_ARGS)
1647 if (n->parent->args != NULL || n->prev->child == NULL)
1648 h->flags |= HTML_PREKEEP;
1658 mdoc_bk_post(MDOC_ARGS)
1661 if (n->type == ROFFT_BODY)
1662 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1666 mdoc_quote_pre(MDOC_ARGS)
1668 if (n->type != ROFFT_BODY)
1674 print_text(h, n->child != NULL && n->child->next == NULL &&
1675 n->child->tok == MDOC_Mt ? "<" : "\\(la");
1679 print_text(h, "\\(lC");
1683 print_text(h, "\\(lB");
1687 print_text(h, "\\(lB");
1688 h->flags |= HTML_NOSPACE;
1689 print_otag(h, TAG_SPAN, "c", "Op");
1692 if (NULL == n->norm->Es ||
1693 NULL == n->norm->Es->child)
1695 print_text(h, n->norm->Es->child->string);
1701 print_text(h, "\\(lq");
1708 print_text(h, "\\(oq");
1709 h->flags |= HTML_NOSPACE;
1710 print_otag(h, TAG_CODE, "c", "Li");
1714 print_text(h, "\\(oq");
1720 h->flags |= HTML_NOSPACE;
1725 mdoc_quote_post(MDOC_ARGS)
1728 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1731 h->flags |= HTML_NOSPACE;
1736 print_text(h, n->child != NULL && n->child->next == NULL &&
1737 n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1741 print_text(h, "\\(rC");
1747 print_text(h, "\\(rB");
1750 if (n->norm->Es == NULL ||
1751 n->norm->Es->child == NULL ||
1752 n->norm->Es->child->next == NULL)
1753 h->flags &= ~HTML_NOSPACE;
1755 print_text(h, n->norm->Es->child->next->string);
1761 print_text(h, "\\(rq");
1770 print_text(h, "\\(cq");
1778 mdoc_eo_pre(MDOC_ARGS)
1781 if (n->type != ROFFT_BODY)
1784 if (n->end == ENDBODY_NOT &&
1785 n->parent->head->child == NULL &&
1787 n->child->end != ENDBODY_NOT)
1788 print_text(h, "\\&");
1789 else if (n->end != ENDBODY_NOT ? n->child != NULL :
1790 n->parent->head->child != NULL && (n->child != NULL ||
1791 (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1792 h->flags |= HTML_NOSPACE;
1797 mdoc_eo_post(MDOC_ARGS)
1801 if (n->type != ROFFT_BODY)
1804 if (n->end != ENDBODY_NOT) {
1805 h->flags &= ~HTML_NOSPACE;
1809 body = n->child != NULL || n->parent->head->child != NULL;
1810 tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1813 h->flags |= HTML_NOSPACE;
1815 h->flags &= ~HTML_NOSPACE;