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