1 /* $Id: roff_html.c,v 1.21 2020/06/22 19:20:40 schwarze Exp $ */
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2017, 2018, 2019 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 AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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>
31 #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
33 typedef void (*roff_html_pre_fp
)(ROFF_HTML_ARGS
);
35 static void roff_html_pre_br(ROFF_HTML_ARGS
);
36 static void roff_html_pre_ce(ROFF_HTML_ARGS
);
37 static void roff_html_pre_fi(ROFF_HTML_ARGS
);
38 static void roff_html_pre_ft(ROFF_HTML_ARGS
);
39 static void roff_html_pre_nf(ROFF_HTML_ARGS
);
40 static void roff_html_pre_sp(ROFF_HTML_ARGS
);
42 static const roff_html_pre_fp roff_html_pre_acts
[ROFF_MAX
] = {
43 roff_html_pre_br
, /* br */
44 roff_html_pre_ce
, /* ce */
45 roff_html_pre_fi
, /* fi */
46 roff_html_pre_ft
, /* ft */
49 roff_html_pre_nf
, /* nf */
51 roff_html_pre_ce
, /* rj */
52 roff_html_pre_sp
, /* sp */
59 roff_html_pre(struct html
*h
, const struct roff_node
*n
)
61 assert(n
->tok
< ROFF_MAX
);
62 if (roff_html_pre_acts
[n
->tok
] != NULL
)
63 (*roff_html_pre_acts
[n
->tok
])(h
, n
);
67 roff_html_pre_br(ROFF_HTML_ARGS
)
69 print_otag(h
, TAG_BR
, "");
73 roff_html_pre_ce(ROFF_HTML_ARGS
)
75 for (n
= n
->child
->next
; n
!= NULL
; n
= n
->next
) {
76 if (n
->type
== ROFFT_TEXT
) {
77 if (n
->flags
& NODE_LINE
)
78 roff_html_pre_br(h
, n
);
79 print_text(h
, n
->string
);
83 roff_html_pre_br(h
, n
);
87 roff_html_pre_fi(ROFF_HTML_ARGS
)
89 if (html_fillmode(h
, TOKEN_NONE
) == ROFF_fi
)
90 print_otag(h
, TAG_BR
, "");
94 roff_html_pre_ft(ROFF_HTML_ARGS
)
98 cp
= n
->child
->string
;
99 html_setfont(h
, mandoc_font(cp
, (int)strlen(cp
)));
103 roff_html_pre_nf(ROFF_HTML_ARGS
)
105 if (html_fillmode(h
, TOKEN_NONE
) == ROFF_nf
)
106 print_otag(h
, TAG_BR
, "");
110 roff_html_pre_sp(ROFF_HTML_ARGS
)
112 if (html_fillmode(h
, TOKEN_NONE
) == ROFF_nf
) {
116 html_close_paragraph(h
);
117 print_otag(h
, TAG_P
, "c", "Pp");