1*95c635efSGarrett D'Amore /* $Id: eqn_html.c,v 1.2 2011/07/24 10:09:03 kristaps Exp $ */ 2*95c635efSGarrett D'Amore /* 3*95c635efSGarrett D'Amore * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*95c635efSGarrett D'Amore * 5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 8*95c635efSGarrett D'Amore * 9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*95c635efSGarrett D'Amore */ 17*95c635efSGarrett D'Amore #ifdef HAVE_CONFIG_H 18*95c635efSGarrett D'Amore #include "config.h" 19*95c635efSGarrett D'Amore #endif 20*95c635efSGarrett D'Amore 21*95c635efSGarrett D'Amore #include <assert.h> 22*95c635efSGarrett D'Amore #include <stdio.h> 23*95c635efSGarrett D'Amore #include <stdlib.h> 24*95c635efSGarrett D'Amore #include <string.h> 25*95c635efSGarrett D'Amore 26*95c635efSGarrett D'Amore #include "mandoc.h" 27*95c635efSGarrett D'Amore #include "out.h" 28*95c635efSGarrett D'Amore #include "html.h" 29*95c635efSGarrett D'Amore 30*95c635efSGarrett D'Amore static const enum htmltag fontmap[EQNFONT__MAX] = { 31*95c635efSGarrett D'Amore TAG_SPAN, /* EQNFONT_NONE */ 32*95c635efSGarrett D'Amore TAG_SPAN, /* EQNFONT_ROMAN */ 33*95c635efSGarrett D'Amore TAG_B, /* EQNFONT_BOLD */ 34*95c635efSGarrett D'Amore TAG_B, /* EQNFONT_FAT */ 35*95c635efSGarrett D'Amore TAG_I /* EQNFONT_ITALIC */ 36*95c635efSGarrett D'Amore }; 37*95c635efSGarrett D'Amore 38*95c635efSGarrett D'Amore 39*95c635efSGarrett D'Amore static void eqn_box(struct html *, const struct eqn_box *); 40*95c635efSGarrett D'Amore 41*95c635efSGarrett D'Amore void 42*95c635efSGarrett D'Amore print_eqn(struct html *p, const struct eqn *ep) 43*95c635efSGarrett D'Amore { 44*95c635efSGarrett D'Amore struct htmlpair tag; 45*95c635efSGarrett D'Amore struct tag *t; 46*95c635efSGarrett D'Amore 47*95c635efSGarrett D'Amore PAIR_CLASS_INIT(&tag, "eqn"); 48*95c635efSGarrett D'Amore t = print_otag(p, TAG_SPAN, 1, &tag); 49*95c635efSGarrett D'Amore 50*95c635efSGarrett D'Amore p->flags |= HTML_NONOSPACE; 51*95c635efSGarrett D'Amore eqn_box(p, ep->root); 52*95c635efSGarrett D'Amore p->flags &= ~HTML_NONOSPACE; 53*95c635efSGarrett D'Amore 54*95c635efSGarrett D'Amore print_tagq(p, t); 55*95c635efSGarrett D'Amore } 56*95c635efSGarrett D'Amore 57*95c635efSGarrett D'Amore static void 58*95c635efSGarrett D'Amore eqn_box(struct html *p, const struct eqn_box *bp) 59*95c635efSGarrett D'Amore { 60*95c635efSGarrett D'Amore struct tag *t; 61*95c635efSGarrett D'Amore 62*95c635efSGarrett D'Amore t = EQNFONT_NONE == bp->font ? NULL : 63*95c635efSGarrett D'Amore print_otag(p, fontmap[(int)bp->font], 0, NULL); 64*95c635efSGarrett D'Amore 65*95c635efSGarrett D'Amore if (bp->left) 66*95c635efSGarrett D'Amore print_text(p, bp->left); 67*95c635efSGarrett D'Amore 68*95c635efSGarrett D'Amore if (bp->text) 69*95c635efSGarrett D'Amore print_text(p, bp->text); 70*95c635efSGarrett D'Amore 71*95c635efSGarrett D'Amore if (bp->first) 72*95c635efSGarrett D'Amore eqn_box(p, bp->first); 73*95c635efSGarrett D'Amore 74*95c635efSGarrett D'Amore if (NULL != t) 75*95c635efSGarrett D'Amore print_tagq(p, t); 76*95c635efSGarrett D'Amore if (bp->right) 77*95c635efSGarrett D'Amore print_text(p, bp->right); 78*95c635efSGarrett D'Amore 79*95c635efSGarrett D'Amore if (bp->next) 80*95c635efSGarrett D'Amore eqn_box(p, bp->next); 81*95c635efSGarrett D'Amore } 82