eqn_html.c revision 241675
1116743Ssam/*	$Id: eqn_html.c,v 1.2 2011/07/24 10:09:03 kristaps Exp $ */
2186904Ssam/*
3116743Ssam * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4116743Ssam *
5116743Ssam * Permission to use, copy, modify, and distribute this software for any
6116743Ssam * purpose with or without fee is hereby granted, provided that the above
7116743Ssam * copyright notice and this permission notice appear in all copies.
8116743Ssam *
9116743Ssam * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10116743Ssam * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11116743Ssam * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12116743Ssam * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13116743Ssam * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14116743Ssam * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15116743Ssam * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16116743Ssam */
17116743Ssam#ifdef HAVE_CONFIG_H
18116743Ssam#include "config.h"
19116743Ssam#endif
20116743Ssam
21116743Ssam#include <assert.h>
22116743Ssam#include <stdio.h>
23116743Ssam#include <stdlib.h>
24116743Ssam#include <string.h>
25116743Ssam
26116743Ssam#include "mandoc.h"
27116743Ssam#include "out.h"
28116743Ssam#include "html.h"
29116743Ssam
30116743Ssamstatic	const enum htmltag fontmap[EQNFONT__MAX] = {
31116743Ssam	TAG_SPAN, /* EQNFONT_NONE */
32116743Ssam	TAG_SPAN, /* EQNFONT_ROMAN */
33116743Ssam	TAG_B, /* EQNFONT_BOLD */
34116743Ssam	TAG_B, /* EQNFONT_FAT */
35116743Ssam	TAG_I /* EQNFONT_ITALIC */
36116743Ssam};
37116743Ssam
38227327Sadrian
39227327Sadrianstatic void	eqn_box(struct html *, const struct eqn_box *);
40227327Sadrian
41227327Sadrianvoid
42227327Sadrianprint_eqn(struct html *p, const struct eqn *ep)
43227327Sadrian{
44227327Sadrian	struct htmlpair	 tag;
45227327Sadrian	struct tag	*t;
46233989Sadrian
47227327Sadrian	PAIR_CLASS_INIT(&tag, "eqn");
48227327Sadrian	t = print_otag(p, TAG_SPAN, 1, &tag);
49234090Sadrian
50234090Sadrian	p->flags |= HTML_NONOSPACE;
51234090Sadrian	eqn_box(p, ep->root);
52234090Sadrian	p->flags &= ~HTML_NONOSPACE;
53116743Ssam
54116743Ssam	print_tagq(p, t);
55116743Ssam}
56116743Ssam
57155492Ssamstatic void
58138570Ssameqn_box(struct html *p, const struct eqn_box *bp)
59116743Ssam{
60116743Ssam	struct tag	*t;
61116743Ssam
62138570Ssam	t = EQNFONT_NONE == bp->font ? NULL :
63116743Ssam		print_otag(p, fontmap[(int)bp->font], 0, NULL);
64138570Ssam
65116743Ssam	if (bp->left)
66116743Ssam		print_text(p, bp->left);
67116743Ssam
68116743Ssam	if (bp->text)
69116743Ssam		print_text(p, bp->text);
70116743Ssam
71116743Ssam	if (bp->first)
72116743Ssam		eqn_box(p, bp->first);
73116743Ssam
74116743Ssam	if (NULL != t)
75116743Ssam		print_tagq(p, t);
76116743Ssam	if (bp->right)
77116743Ssam		print_text(p, bp->right);
78116743Ssam
79116743Ssam	if (bp->next)
80116743Ssam		eqn_box(p, bp->next);
81116743Ssam}
82116743Ssam