xref: /openbsd-src/usr.bin/mandoc/html.h (revision 00b92a3f667b1b2e3a2ae04c788cc2b374cbd0ba)
1*00b92a3fSschwarze /* $OpenBSD: html.h,v 1.74 2022/07/06 14:27:55 schwarze Exp $ */
24175bdabSschwarze /*
30ac7e6ecSschwarze  * Copyright (c) 2017, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org>
4d649d931Sschwarze  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
54175bdabSschwarze  *
64175bdabSschwarze  * Permission to use, copy, modify, and distribute this software for any
74175bdabSschwarze  * purpose with or without fee is hereby granted, provided that the above
84175bdabSschwarze  * copyright notice and this permission notice appear in all copies.
94175bdabSschwarze  *
104175bdabSschwarze  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
114175bdabSschwarze  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
124175bdabSschwarze  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
134175bdabSschwarze  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
144175bdabSschwarze  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
154175bdabSschwarze  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
164175bdabSschwarze  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
170ac7e6ecSschwarze  *
180ac7e6ecSschwarze  * Internal interfaces for mandoc(1) HTML formatters.
190ac7e6ecSschwarze  * For use by the individual HTML formatters only.
204175bdabSschwarze  */
214175bdabSschwarze 
224175bdabSschwarze enum	htmltag {
234175bdabSschwarze 	TAG_HTML,
244175bdabSschwarze 	TAG_HEAD,
254175bdabSschwarze 	TAG_META,
26635fddedSschwarze 	TAG_LINK,
27635fddedSschwarze 	TAG_STYLE,
284175bdabSschwarze 	TAG_TITLE,
29635fddedSschwarze 	TAG_BODY,
306774f271Sschwarze 	TAG_MAIN,
314175bdabSschwarze 	TAG_DIV,
321a2b7b3cSschwarze 	TAG_SECTION,
3388e033f9Sschwarze 	TAG_NAV,
344175bdabSschwarze 	TAG_TABLE,
354175bdabSschwarze 	TAG_TR,
364175bdabSschwarze 	TAG_TD,
374175bdabSschwarze 	TAG_LI,
384175bdabSschwarze 	TAG_UL,
394175bdabSschwarze 	TAG_OL,
40467b61c6Sschwarze 	TAG_DL,
41467b61c6Sschwarze 	TAG_DT,
42467b61c6Sschwarze 	TAG_DD,
43635fddedSschwarze 	TAG_H2,
44*00b92a3fSschwarze 	TAG_H3,
457f442bfeSschwarze 	TAG_P,
46467b61c6Sschwarze 	TAG_PRE,
47635fddedSschwarze 	TAG_A,
48b009ccebSschwarze 	TAG_B,
49635fddedSschwarze 	TAG_CITE,
503a7b861cSschwarze 	TAG_CODE,
51635fddedSschwarze 	TAG_I,
523a7b861cSschwarze 	TAG_SMALL,
53635fddedSschwarze 	TAG_SPAN,
54635fddedSschwarze 	TAG_VAR,
55635fddedSschwarze 	TAG_BR,
561ae734e3Sschwarze 	TAG_HR,
5792929bf6Sschwarze 	TAG_MARK,
58933d2e00Sschwarze 	TAG_MATH,
59933d2e00Sschwarze 	TAG_MROW,
60933d2e00Sschwarze 	TAG_MI,
6172fef9e3Sschwarze 	TAG_MN,
62933d2e00Sschwarze 	TAG_MO,
63933d2e00Sschwarze 	TAG_MSUP,
64933d2e00Sschwarze 	TAG_MSUB,
65933d2e00Sschwarze 	TAG_MSUBSUP,
66933d2e00Sschwarze 	TAG_MFRAC,
67933d2e00Sschwarze 	TAG_MSQRT,
68933d2e00Sschwarze 	TAG_MFENCED,
69933d2e00Sschwarze 	TAG_MTABLE,
70933d2e00Sschwarze 	TAG_MTR,
71933d2e00Sschwarze 	TAG_MTD,
72a3108a0aSschwarze 	TAG_MUNDEROVER,
73a3108a0aSschwarze 	TAG_MUNDER,
74a3108a0aSschwarze 	TAG_MOVER,
754175bdabSschwarze 	TAG_MAX
764175bdabSschwarze };
774175bdabSschwarze 
784175bdabSschwarze struct	tag {
79b822ca0dSschwarze 	struct tag	 *next;
80520a575cSschwarze 	int		  refcnt;
81520a575cSschwarze 	int		  closed;
824175bdabSschwarze 	enum htmltag	  tag;
834175bdabSschwarze };
844175bdabSschwarze 
854175bdabSschwarze struct	html {
864175bdabSschwarze 	int		  flags;
87ab6d46e5Sschwarze #define	HTML_NOSPACE	 (1 << 0) /* suppress next space */
88769ee804Sschwarze #define	HTML_IGNDELIM	 (1 << 1)
89769ee804Sschwarze #define	HTML_KEEP	 (1 << 2)
90769ee804Sschwarze #define	HTML_PREKEEP	 (1 << 3)
91ab6d46e5Sschwarze #define	HTML_NONOSPACE	 (1 << 4) /* never add spaces */
927eac745dSschwarze #define	HTML_SKIPCHAR	 (1 << 6) /* skip the next character */
93bf997c2cSschwarze #define	HTML_NOSPLIT	 (1 << 7) /* do not break line before .An */
94bf997c2cSschwarze #define	HTML_SPLIT	 (1 << 8) /* break line before .An */
9564c3401cSschwarze #define	HTML_NONEWLINE	 (1 << 9) /* No line break in nofill mode. */
96d5746e42Sschwarze #define	HTML_BUFFER	 (1 << 10) /* Collect a word to see if it fits. */
973327fa00Sschwarze #define	HTML_TOCDONE	 (1 << 11) /* The TOC was already written. */
98d5746e42Sschwarze 	size_t		  indent; /* current output indentation level */
99b1eea027Sschwarze 	int		  noindent; /* indent disabled by <pre> */
100d5746e42Sschwarze 	size_t		  col; /* current output byte position */
101d5746e42Sschwarze 	size_t		  bufcol; /* current buf byte position */
102d5746e42Sschwarze 	char		  buf[80]; /* output buffer */
1034614a369Sschwarze 	struct tag	 *tag; /* last open tag */
104ec04407bSschwarze 	struct rofftbl	  tbl; /* current table */
105366f22eeSschwarze 	struct tag	 *tblt; /* current open table scope */
1063f160fd1Sschwarze 	char		 *base_man1; /* bases for manpage href */
1073f160fd1Sschwarze 	char		 *base_man2;
108ec04407bSschwarze 	char		 *base_includes; /* base for include href */
109ec04407bSschwarze 	char		 *style; /* style-sheet URI */
1103a7b861cSschwarze 	struct tag	 *metaf; /* current open font scope */
111cefe8974Sschwarze 	enum mandoc_esc	  metal; /* last used font */
112cefe8974Sschwarze 	enum mandoc_esc	  metac; /* current font mode */
113ca0ce676Sschwarze 	int		  oflags; /* output options */
114ca0ce676Sschwarze #define	HTML_FRAGMENT	 (1 << 0) /* don't emit HTML/HEAD/BODY */
1153327fa00Sschwarze #define	HTML_TOC	 (1 << 1) /* emit a table of contents */
1164175bdabSschwarze };
1174175bdabSschwarze 
118dd617d76Sschwarze 
1196ef173c4Sschwarze struct	roff_node;
120dd617d76Sschwarze struct	tbl_span;
121bf9acac6Sschwarze struct	eqn_box;
122dd617d76Sschwarze 
12396a5de47Sschwarze void		  roff_html_pre(struct html *, const struct roff_node *);
12496a5de47Sschwarze 
125cc202ecaSschwarze void		  print_gen_comment(struct html *, struct roff_node *);
1268521b0bcSschwarze void		  print_gen_decls(struct html *);
1274175bdabSschwarze void		  print_gen_head(struct html *);
128229cc7fdSschwarze struct tag	 *print_otag(struct html *, enum htmltag, const char *, ...);
1290ac7e6ecSschwarze struct tag	 *print_otag_id(struct html *, enum htmltag, const char *,
1300ac7e6ecSschwarze 			struct roff_node *);
1314175bdabSschwarze void		  print_tagq(struct html *, const struct tag *);
1324175bdabSschwarze void		  print_stagq(struct html *, const struct tag *);
1336e2a0df9Sschwarze void		  print_tagged_text(struct html *, const char *,
1346e2a0df9Sschwarze 			struct roff_node *);
1354175bdabSschwarze void		  print_text(struct html *, const char *);
136366f22eeSschwarze void		  print_tblclose(struct html *);
1372791bd1cSschwarze void		  print_tbl(struct html *, const struct tbl_span *);
138bf9acac6Sschwarze void		  print_eqn(struct html *, const struct eqn_box *);
1390692510cSschwarze void		  print_endline(struct html *);
1404175bdabSschwarze 
1417f442bfeSschwarze void		  html_close_paragraph(struct html *);
142275804acSschwarze enum roff_tok	  html_fillmode(struct html *, enum roff_tok);
143762c1016Sschwarze char		 *html_make_id(const struct roff_node *, int);
144cefe8974Sschwarze int		  html_setfont(struct html *, enum mandoc_esc);
145