xref: /minix3/external/bsd/mdocml/dist/eqn_html.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	Id: eqn_html.c,v 1.2 2011/07/24 10:09:03 kristaps Exp  */
292395e9cSLionel Sambuc /*
392395e9cSLionel Sambuc  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
492395e9cSLionel Sambuc  *
592395e9cSLionel Sambuc  * Permission to use, copy, modify, and distribute this software for any
692395e9cSLionel Sambuc  * purpose with or without fee is hereby granted, provided that the above
792395e9cSLionel Sambuc  * copyright notice and this permission notice appear in all copies.
892395e9cSLionel Sambuc  *
992395e9cSLionel Sambuc  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1092395e9cSLionel Sambuc  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1192395e9cSLionel Sambuc  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1292395e9cSLionel Sambuc  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1392395e9cSLionel Sambuc  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1492395e9cSLionel Sambuc  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1592395e9cSLionel Sambuc  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1692395e9cSLionel Sambuc  */
1792395e9cSLionel Sambuc #ifdef HAVE_CONFIG_H
1892395e9cSLionel Sambuc #include "config.h"
1992395e9cSLionel Sambuc #endif
2092395e9cSLionel Sambuc 
2192395e9cSLionel Sambuc #include <assert.h>
2292395e9cSLionel Sambuc #include <stdio.h>
2392395e9cSLionel Sambuc #include <stdlib.h>
2492395e9cSLionel Sambuc #include <string.h>
2592395e9cSLionel Sambuc 
2692395e9cSLionel Sambuc #include "mandoc.h"
2792395e9cSLionel Sambuc #include "out.h"
2892395e9cSLionel Sambuc #include "html.h"
2992395e9cSLionel Sambuc 
3092395e9cSLionel Sambuc static	const enum htmltag fontmap[EQNFONT__MAX] = {
3192395e9cSLionel Sambuc 	TAG_SPAN, /* EQNFONT_NONE */
3292395e9cSLionel Sambuc 	TAG_SPAN, /* EQNFONT_ROMAN */
3392395e9cSLionel Sambuc 	TAG_B, /* EQNFONT_BOLD */
3492395e9cSLionel Sambuc 	TAG_B, /* EQNFONT_FAT */
3592395e9cSLionel Sambuc 	TAG_I /* EQNFONT_ITALIC */
3692395e9cSLionel Sambuc };
3792395e9cSLionel Sambuc 
3892395e9cSLionel Sambuc 
3992395e9cSLionel Sambuc static void	eqn_box(struct html *, const struct eqn_box *);
4092395e9cSLionel Sambuc 
4192395e9cSLionel Sambuc void
print_eqn(struct html * p,const struct eqn * ep)4292395e9cSLionel Sambuc print_eqn(struct html *p, const struct eqn *ep)
4392395e9cSLionel Sambuc {
4492395e9cSLionel Sambuc 	struct htmlpair	 tag;
4592395e9cSLionel Sambuc 	struct tag	*t;
4692395e9cSLionel Sambuc 
4792395e9cSLionel Sambuc 	PAIR_CLASS_INIT(&tag, "eqn");
4892395e9cSLionel Sambuc 	t = print_otag(p, TAG_SPAN, 1, &tag);
4992395e9cSLionel Sambuc 
5092395e9cSLionel Sambuc 	p->flags |= HTML_NONOSPACE;
5192395e9cSLionel Sambuc 	eqn_box(p, ep->root);
5292395e9cSLionel Sambuc 	p->flags &= ~HTML_NONOSPACE;
5392395e9cSLionel Sambuc 
5492395e9cSLionel Sambuc 	print_tagq(p, t);
5592395e9cSLionel Sambuc }
5692395e9cSLionel Sambuc 
5792395e9cSLionel Sambuc static void
eqn_box(struct html * p,const struct eqn_box * bp)5892395e9cSLionel Sambuc eqn_box(struct html *p, const struct eqn_box *bp)
5992395e9cSLionel Sambuc {
6092395e9cSLionel Sambuc 	struct tag	*t;
6192395e9cSLionel Sambuc 
6292395e9cSLionel Sambuc 	t = EQNFONT_NONE == bp->font ? NULL :
6392395e9cSLionel Sambuc 		print_otag(p, fontmap[(int)bp->font], 0, NULL);
6492395e9cSLionel Sambuc 
6592395e9cSLionel Sambuc 	if (bp->left)
6692395e9cSLionel Sambuc 		print_text(p, bp->left);
6792395e9cSLionel Sambuc 
6892395e9cSLionel Sambuc 	if (bp->text)
6992395e9cSLionel Sambuc 		print_text(p, bp->text);
7092395e9cSLionel Sambuc 
7192395e9cSLionel Sambuc 	if (bp->first)
7292395e9cSLionel Sambuc 		eqn_box(p, bp->first);
7392395e9cSLionel Sambuc 
7492395e9cSLionel Sambuc 	if (NULL != t)
7592395e9cSLionel Sambuc 		print_tagq(p, t);
7692395e9cSLionel Sambuc 	if (bp->right)
7792395e9cSLionel Sambuc 		print_text(p, bp->right);
7892395e9cSLionel Sambuc 
7992395e9cSLionel Sambuc 	if (bp->next)
8092395e9cSLionel Sambuc 		eqn_box(p, bp->next);
8192395e9cSLionel Sambuc }
82