xref: /netbsd-src/external/bsd/mdocml/dist/html.h (revision 544c191c349c1704c9d5e679d12ec15cff579663)
1*544c191cSchristos /*	Id: html.h,v 1.102 2019/03/01 10:57:18 schwarze Exp  */
24154958bSjoerg /*
3fec65c98Schristos  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4*544c191cSchristos  * Copyright (c) 2017, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
54154958bSjoerg  *
64154958bSjoerg  * Permission to use, copy, modify, and distribute this software for any
74154958bSjoerg  * purpose with or without fee is hereby granted, provided that the above
84154958bSjoerg  * copyright notice and this permission notice appear in all copies.
94154958bSjoerg  *
104154958bSjoerg  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
114154958bSjoerg  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
124154958bSjoerg  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
134154958bSjoerg  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
144154958bSjoerg  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
154154958bSjoerg  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
164154958bSjoerg  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
174154958bSjoerg  */
184154958bSjoerg 
194154958bSjoerg enum	htmltag {
204154958bSjoerg 	TAG_HTML,
214154958bSjoerg 	TAG_HEAD,
224154958bSjoerg 	TAG_BODY,
234154958bSjoerg 	TAG_META,
244154958bSjoerg 	TAG_TITLE,
254154958bSjoerg 	TAG_DIV,
26c9bcef03Schristos 	TAG_IDIV,
27*544c191cSchristos 	TAG_SECTION,
284154958bSjoerg 	TAG_H1,
294154958bSjoerg 	TAG_H2,
304154958bSjoerg 	TAG_SPAN,
314154958bSjoerg 	TAG_LINK,
324154958bSjoerg 	TAG_BR,
334154958bSjoerg 	TAG_A,
344154958bSjoerg 	TAG_TABLE,
354154958bSjoerg 	TAG_TR,
364154958bSjoerg 	TAG_TD,
374154958bSjoerg 	TAG_LI,
384154958bSjoerg 	TAG_UL,
394154958bSjoerg 	TAG_OL,
40c0d9444aSjoerg 	TAG_DL,
41c0d9444aSjoerg 	TAG_DT,
42c0d9444aSjoerg 	TAG_DD,
43*544c191cSchristos 	TAG_P,
44c0d9444aSjoerg 	TAG_PRE,
459508192eSchristos 	TAG_VAR,
469508192eSchristos 	TAG_CITE,
47c0d9444aSjoerg 	TAG_B,
48c0d9444aSjoerg 	TAG_I,
49c0d9444aSjoerg 	TAG_CODE,
50c0d9444aSjoerg 	TAG_SMALL,
51fec65c98Schristos 	TAG_STYLE,
52fec65c98Schristos 	TAG_MATH,
53fec65c98Schristos 	TAG_MROW,
54fec65c98Schristos 	TAG_MI,
55c9bcef03Schristos 	TAG_MN,
56fec65c98Schristos 	TAG_MO,
57fec65c98Schristos 	TAG_MSUP,
58fec65c98Schristos 	TAG_MSUB,
59fec65c98Schristos 	TAG_MSUBSUP,
60fec65c98Schristos 	TAG_MFRAC,
61fec65c98Schristos 	TAG_MSQRT,
62fec65c98Schristos 	TAG_MFENCED,
63fec65c98Schristos 	TAG_MTABLE,
64fec65c98Schristos 	TAG_MTR,
65fec65c98Schristos 	TAG_MTD,
66fec65c98Schristos 	TAG_MUNDEROVER,
67fec65c98Schristos 	TAG_MUNDER,
68fec65c98Schristos 	TAG_MOVER,
694154958bSjoerg 	TAG_MAX
704154958bSjoerg };
714154958bSjoerg 
727d71a621Sjoerg enum	htmlfont {
737d71a621Sjoerg 	HTMLFONT_NONE = 0,
747d71a621Sjoerg 	HTMLFONT_BOLD,
757d71a621Sjoerg 	HTMLFONT_ITALIC,
7670f041f9Sjoerg 	HTMLFONT_BI,
77*544c191cSchristos 	HTMLFONT_CW,
787d71a621Sjoerg 	HTMLFONT_MAX
797d71a621Sjoerg };
807d71a621Sjoerg 
814154958bSjoerg struct	tag {
8222af4063Sjoerg 	struct tag	 *next;
83*544c191cSchristos 	int		  refcnt;
84*544c191cSchristos 	int		  closed;
854154958bSjoerg 	enum htmltag	  tag;
864154958bSjoerg };
874154958bSjoerg 
884154958bSjoerg struct	html {
894154958bSjoerg 	int		  flags;
9048741257Sjoerg #define	HTML_NOSPACE	 (1 << 0) /* suppress next space */
9182361f10Sjoerg #define	HTML_IGNDELIM	 (1 << 1)
9282361f10Sjoerg #define	HTML_KEEP	 (1 << 2)
9382361f10Sjoerg #define	HTML_PREKEEP	 (1 << 3)
9448741257Sjoerg #define	HTML_NONOSPACE	 (1 << 4) /* never add spaces */
9570f041f9Sjoerg #define	HTML_SKIPCHAR	 (1 << 6) /* skip the next character */
96fec65c98Schristos #define	HTML_NOSPLIT	 (1 << 7) /* do not break line before .An */
97fec65c98Schristos #define	HTML_SPLIT	 (1 << 8) /* break line before .An */
98fec65c98Schristos #define	HTML_NONEWLINE	 (1 << 9) /* No line break in nofill mode. */
999508192eSchristos #define	HTML_BUFFER	 (1 << 10) /* Collect a word to see if it fits. */
100*544c191cSchristos #define	HTML_TOCDONE	 (1 << 11) /* The TOC was already written. */
1019508192eSchristos 	size_t		  indent; /* current output indentation level */
1029508192eSchristos 	int		  noindent; /* indent disabled by <pre> */
1039508192eSchristos 	size_t		  col; /* current output byte position */
1049508192eSchristos 	size_t		  bufcol; /* current buf byte position */
1059508192eSchristos 	char		  buf[80]; /* output buffer */
1069508192eSchristos 	struct tag	 *tag; /* last open tag */
107c0d9444aSjoerg 	struct rofftbl	  tbl; /* current table */
10848741257Sjoerg 	struct tag	 *tblt; /* current open table scope */
109*544c191cSchristos 	char		 *base_man1; /* bases for manpage href */
110*544c191cSchristos 	char		 *base_man2;
111c0d9444aSjoerg 	char		 *base_includes; /* base for include href */
112c0d9444aSjoerg 	char		 *style; /* style-sheet URI */
113c0d9444aSjoerg 	struct tag	 *metaf; /* current open font scope */
114c0d9444aSjoerg 	enum htmlfont	  metal; /* last used font */
115c0d9444aSjoerg 	enum htmlfont	  metac; /* current font mode */
116c5f73b34Sjoerg 	int		  oflags; /* output options */
117c5f73b34Sjoerg #define	HTML_FRAGMENT	 (1 << 0) /* don't emit HTML/HEAD/BODY */
118*544c191cSchristos #define	HTML_TOC	 (1 << 1) /* emit a table of contents */
1194154958bSjoerg };
1204154958bSjoerg 
121fec65c98Schristos 
122c9bcef03Schristos struct	roff_node;
123fec65c98Schristos struct	tbl_span;
124c9bcef03Schristos struct	eqn_box;
125fec65c98Schristos 
126c9bcef03Schristos void		  roff_html_pre(struct html *, const struct roff_node *);
127c9bcef03Schristos 
128c9bcef03Schristos void		  print_gen_comment(struct html *, struct roff_node *);
129d5e63c8dSjoerg void		  print_gen_decls(struct html *);
1304154958bSjoerg void		  print_gen_head(struct html *);
131*544c191cSchristos void		  print_metaf(struct html *, enum mandoc_esc);
1329508192eSchristos struct tag	 *print_otag(struct html *, enum htmltag, const char *, ...);
1334154958bSjoerg void		  print_tagq(struct html *, const struct tag *);
1344154958bSjoerg void		  print_stagq(struct html *, const struct tag *);
1354154958bSjoerg void		  print_text(struct html *, const char *);
13648741257Sjoerg void		  print_tblclose(struct html *);
137c0d9444aSjoerg void		  print_tbl(struct html *, const struct tbl_span *);
138c9bcef03Schristos void		  print_eqn(struct html *, const struct eqn_box *);
1399508192eSchristos void		  print_endline(struct html *);
1404154958bSjoerg 
141*544c191cSchristos void		  html_close_paragraph(struct html *);
142*544c191cSchristos enum roff_tok	  html_fillmode(struct html *, enum roff_tok);
143c9bcef03Schristos char		 *html_make_id(const struct roff_node *, int);
144