1 /* $Id: html.h,v 1.103 2019/04/30 15:53:00 schwarze Exp $ */ 2 /* 3 * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> 4 * Copyright (c) 2017, 2018, 2019 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 19 enum htmltag { 20 TAG_HTML, 21 TAG_HEAD, 22 TAG_BODY, 23 TAG_META, 24 TAG_TITLE, 25 TAG_DIV, 26 TAG_IDIV, 27 TAG_SECTION, 28 TAG_H1, 29 TAG_H2, 30 TAG_SPAN, 31 TAG_LINK, 32 TAG_BR, 33 TAG_A, 34 TAG_TABLE, 35 TAG_TR, 36 TAG_TD, 37 TAG_LI, 38 TAG_UL, 39 TAG_OL, 40 TAG_DL, 41 TAG_DT, 42 TAG_DD, 43 TAG_P, 44 TAG_PRE, 45 TAG_VAR, 46 TAG_CITE, 47 TAG_B, 48 TAG_I, 49 TAG_CODE, 50 TAG_SMALL, 51 TAG_STYLE, 52 TAG_MATH, 53 TAG_MROW, 54 TAG_MI, 55 TAG_MN, 56 TAG_MO, 57 TAG_MSUP, 58 TAG_MSUB, 59 TAG_MSUBSUP, 60 TAG_MFRAC, 61 TAG_MSQRT, 62 TAG_MFENCED, 63 TAG_MTABLE, 64 TAG_MTR, 65 TAG_MTD, 66 TAG_MUNDEROVER, 67 TAG_MUNDER, 68 TAG_MOVER, 69 TAG_MAX 70 }; 71 72 struct tag { 73 struct tag *next; 74 int refcnt; 75 int closed; 76 enum htmltag tag; 77 }; 78 79 struct html { 80 int flags; 81 #define HTML_NOSPACE (1 << 0) /* suppress next space */ 82 #define HTML_IGNDELIM (1 << 1) 83 #define HTML_KEEP (1 << 2) 84 #define HTML_PREKEEP (1 << 3) 85 #define HTML_NONOSPACE (1 << 4) /* never add spaces */ 86 #define HTML_SKIPCHAR (1 << 6) /* skip the next character */ 87 #define HTML_NOSPLIT (1 << 7) /* do not break line before .An */ 88 #define HTML_SPLIT (1 << 8) /* break line before .An */ 89 #define HTML_NONEWLINE (1 << 9) /* No line break in nofill mode. */ 90 #define HTML_BUFFER (1 << 10) /* Collect a word to see if it fits. */ 91 #define HTML_TOCDONE (1 << 11) /* The TOC was already written. */ 92 size_t indent; /* current output indentation level */ 93 int noindent; /* indent disabled by <pre> */ 94 size_t col; /* current output byte position */ 95 size_t bufcol; /* current buf byte position */ 96 char buf[80]; /* output buffer */ 97 struct tag *tag; /* last open tag */ 98 struct rofftbl tbl; /* current table */ 99 struct tag *tblt; /* current open table scope */ 100 char *base_man1; /* bases for manpage href */ 101 char *base_man2; 102 char *base_includes; /* base for include href */ 103 char *style; /* style-sheet URI */ 104 struct tag *metaf; /* current open font scope */ 105 enum mandoc_esc metal; /* last used font */ 106 enum mandoc_esc metac; /* current font mode */ 107 int oflags; /* output options */ 108 #define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ 109 #define HTML_TOC (1 << 1) /* emit a table of contents */ 110 }; 111 112 113 struct roff_node; 114 struct tbl_span; 115 struct eqn_box; 116 117 void roff_html_pre(struct html *, const struct roff_node *); 118 119 void print_gen_comment(struct html *, struct roff_node *); 120 void print_gen_decls(struct html *); 121 void print_gen_head(struct html *); 122 struct tag *print_otag(struct html *, enum htmltag, const char *, ...); 123 void print_tagq(struct html *, const struct tag *); 124 void print_stagq(struct html *, const struct tag *); 125 void print_text(struct html *, const char *); 126 void print_tblclose(struct html *); 127 void print_tbl(struct html *, const struct tbl_span *); 128 void print_eqn(struct html *, const struct eqn_box *); 129 void print_endline(struct html *); 130 131 void html_close_paragraph(struct html *); 132 enum roff_tok html_fillmode(struct html *, enum roff_tok); 133 char *html_make_id(const struct roff_node *, int); 134 int html_setfont(struct html *, enum mandoc_esc); 135