]> git.cameronkatri.com Git - mandoc.git/blob - roff_html.c
Implement the roff(7) .mc (right margin character) request.
[mandoc.git] / roff_html.c
1 /* $Id: roff_html.c,v 1.6 2017/06/04 22:44:15 schwarze Exp $ */
2 /*
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2017 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 <stddef.h>
22
23 #include "roff.h"
24 #include "out.h"
25 #include "html.h"
26
27 #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
28
29 typedef void (*roff_html_pre_fp)(ROFF_HTML_ARGS);
30
31 static void roff_html_pre_br(ROFF_HTML_ARGS);
32 static void roff_html_pre_sp(ROFF_HTML_ARGS);
33
34 static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
35 roff_html_pre_br, /* br */
36 NULL, /* ft */
37 NULL, /* ll */
38 NULL, /* mc */
39 roff_html_pre_sp, /* sp */
40 NULL, /* ta */
41 NULL, /* ti */
42 };
43
44
45 void
46 roff_html_pre(struct html *h, const struct roff_node *n)
47 {
48 assert(n->tok < ROFF_MAX);
49 if (roff_html_pre_acts[n->tok] != NULL)
50 (*roff_html_pre_acts[n->tok])(h, n);
51 }
52
53 static void
54 roff_html_pre_br(ROFF_HTML_ARGS)
55 {
56 print_otag(h, TAG_DIV, "");
57 print_text(h, "\\~"); /* So the div isn't empty. */
58 }
59
60 static void
61 roff_html_pre_sp(ROFF_HTML_ARGS)
62 {
63 struct roffsu su;
64
65 SCALE_VS_INIT(&su, 1);
66 if ((n = n->child) != NULL) {
67 if (a2roffsu(n->string, &su, SCALE_VS) == 0)
68 su.scale = 1.0;
69 else if (su.scale < 0.0)
70 su.scale = 0.0;
71 }
72 print_otag(h, TAG_DIV, "suh", &su);
73 print_text(h, "\\~"); /* So the div isn't empty. */
74 }