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