Annotation of mandoc/roff_html.c, Revision 1.21
1.21 ! schwarze 1: /* $Id: roff_html.c,v 1.20 2019/04/30 15:53:01 schwarze Exp $ */
1.1 schwarze 2: /*
1.3 schwarze 3: * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.17 schwarze 4: * Copyright (c) 2014, 2017, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
1.1 schwarze 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: */
1.21 ! schwarze 18: #include "config.h"
! 19:
1.1 schwarze 20: #include <sys/types.h>
21:
22: #include <assert.h>
1.15 schwarze 23: #include <stdio.h>
24: #include <string.h>
1.1 schwarze 25:
1.15 schwarze 26: #include "mandoc.h"
1.1 schwarze 27: #include "roff.h"
28: #include "out.h"
29: #include "html.h"
30:
31: #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
32:
33: typedef void (*roff_html_pre_fp)(ROFF_HTML_ARGS);
34:
35: static void roff_html_pre_br(ROFF_HTML_ARGS);
1.7 schwarze 36: static void roff_html_pre_ce(ROFF_HTML_ARGS);
1.17 schwarze 37: static void roff_html_pre_fi(ROFF_HTML_ARGS);
1.15 schwarze 38: static void roff_html_pre_ft(ROFF_HTML_ARGS);
1.17 schwarze 39: static void roff_html_pre_nf(ROFF_HTML_ARGS);
1.3 schwarze 40: static void roff_html_pre_sp(ROFF_HTML_ARGS);
1.1 schwarze 41:
42: static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
43: roff_html_pre_br, /* br */
1.7 schwarze 44: roff_html_pre_ce, /* ce */
1.17 schwarze 45: roff_html_pre_fi, /* fi */
1.15 schwarze 46: roff_html_pre_ft, /* ft */
1.3 schwarze 47: NULL, /* ll */
1.6 schwarze 48: NULL, /* mc */
1.17 schwarze 49: roff_html_pre_nf, /* nf */
1.10 schwarze 50: NULL, /* po */
1.9 schwarze 51: roff_html_pre_ce, /* rj */
1.3 schwarze 52: roff_html_pre_sp, /* sp */
1.4 schwarze 53: NULL, /* ta */
1.5 schwarze 54: NULL, /* ti */
1.1 schwarze 55: };
56:
57:
58: void
59: roff_html_pre(struct html *h, const struct roff_node *n)
60: {
61: assert(n->tok < ROFF_MAX);
1.2 schwarze 62: if (roff_html_pre_acts[n->tok] != NULL)
63: (*roff_html_pre_acts[n->tok])(h, n);
1.1 schwarze 64: }
65:
66: static void
67: roff_html_pre_br(ROFF_HTML_ARGS)
68: {
1.13 schwarze 69: print_otag(h, TAG_BR, "");
1.7 schwarze 70: }
71:
72: static void
73: roff_html_pre_ce(ROFF_HTML_ARGS)
74: {
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);
80: } else
81: roff_html_pre(h, n);
82: }
83: roff_html_pre_br(h, n);
1.15 schwarze 84: }
85:
86: static void
1.17 schwarze 87: roff_html_pre_fi(ROFF_HTML_ARGS)
88: {
89: if (html_fillmode(h, TOKEN_NONE) == ROFF_fi)
90: print_otag(h, TAG_BR, "");
91: }
92:
93: static void
1.15 schwarze 94: roff_html_pre_ft(ROFF_HTML_ARGS)
95: {
96: const char *cp;
97:
98: cp = n->child->string;
1.20 schwarze 99: html_setfont(h, mandoc_font(cp, (int)strlen(cp)));
1.17 schwarze 100: }
101:
102: static void
103: roff_html_pre_nf(ROFF_HTML_ARGS)
104: {
105: if (html_fillmode(h, TOKEN_NONE) == ROFF_nf)
106: print_otag(h, TAG_BR, "");
1.3 schwarze 107: }
108:
109: static void
110: roff_html_pre_sp(ROFF_HTML_ARGS)
111: {
1.18 schwarze 112: if (html_fillmode(h, TOKEN_NONE) == ROFF_nf) {
113: h->col++;
114: print_endline(h);
1.19 schwarze 115: } else {
116: html_close_paragraph(h);
1.18 schwarze 117: print_otag(h, TAG_P, "c", "Pp");
1.19 schwarze 118: }
1.1 schwarze 119: }
CVSweb