]> git.cameronkatri.com Git - mandoc.git/blob - roff_html.c
Bugfix:
[mandoc.git] / roff_html.c
1 /* $Id: roff_html.c,v 1.15 2018/12/16 00:17:02 schwarze Exp $ */
2 /*
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
5 *
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.
9 *
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.
17 */
18 #include <sys/types.h>
19
20 #include <assert.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "mandoc.h"
25 #include "roff.h"
26 #include "out.h"
27 #include "html.h"
28
29 #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
30
31 typedef void (*roff_html_pre_fp)(ROFF_HTML_ARGS);
32
33 static void roff_html_pre_br(ROFF_HTML_ARGS);
34 static void roff_html_pre_ce(ROFF_HTML_ARGS);
35 static void roff_html_pre_ft(ROFF_HTML_ARGS);
36 static void roff_html_pre_sp(ROFF_HTML_ARGS);
37
38 static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
39 roff_html_pre_br, /* br */
40 roff_html_pre_ce, /* ce */
41 roff_html_pre_ft, /* ft */
42 NULL, /* ll */
43 NULL, /* mc */
44 NULL, /* po */
45 roff_html_pre_ce, /* rj */
46 roff_html_pre_sp, /* sp */
47 NULL, /* ta */
48 NULL, /* ti */
49 };
50
51
52 void
53 roff_html_pre(struct html *h, const struct roff_node *n)
54 {
55 assert(n->tok < ROFF_MAX);
56 if (roff_html_pre_acts[n->tok] != NULL)
57 (*roff_html_pre_acts[n->tok])(h, n);
58 }
59
60 static void
61 roff_html_pre_br(ROFF_HTML_ARGS)
62 {
63 print_otag(h, TAG_BR, "");
64 }
65
66 static void
67 roff_html_pre_ce(ROFF_HTML_ARGS)
68 {
69 for (n = n->child->next; n != NULL; n = n->next) {
70 if (n->type == ROFFT_TEXT) {
71 if (n->flags & NODE_LINE)
72 roff_html_pre_br(h, n);
73 print_text(h, n->string);
74 } else
75 roff_html_pre(h, n);
76 }
77 roff_html_pre_br(h, n);
78 }
79
80 static void
81 roff_html_pre_ft(ROFF_HTML_ARGS)
82 {
83 const char *cp;
84
85 cp = n->child->string;
86 print_metaf(h, mandoc_font(cp, (int)strlen(cp)));
87 }
88
89 static void
90 roff_html_pre_sp(ROFF_HTML_ARGS)
91 {
92 print_paragraph(h);
93 }