1 .\" $Id: mandoc_html.3,v 1.20 2020/03/13 15:32:28 schwarze Exp $
3 .\" Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
17 .Dd $Mdocdate: March 13 2020 $
22 .Nd internals of the mandoc HTML formatter
26 .Fn print_gen_decls "struct html *h"
28 .Fn print_gen_comment "struct html *h" "struct roff_node *n"
30 .Fn print_gen_head "struct html *h"
34 .Fa "enum htmltag tag"
41 .Fa "const struct tag *until"
46 .Fa "const struct tag *suntil"
51 .Fa "const char *word"
55 .Fa "const struct roff_node *n"
61 .Fa "enum htmltag tag"
62 .Fa "const char *cattr"
63 .Fa "struct roff_node *n"
66 The mandoc HTML formatter is not a formal library.
67 However, as it is compiled into more than one program, in particular
71 and because it may be security-critical in some contexts,
72 some documentation is useful to help to use it correctly and
73 to prevent XSS vulnerabilities.
75 The formatter produces HTML output on the standard output.
76 Since proper escaping is usually required and best taken care of
77 at one central place, the language-specific formatters
83 are not supposed to print directly to
91 Instead, they are expected to use the output functions declared in
93 and implemented as part of the main HTML formatting engine in
96 These structures are declared in
100 Internal state of the HTML formatter.
102 One entry for the LIFO stack of HTML elements.
104 .Fa "enum htmltag tag"
106 .Fa "struct tag *next" .
108 .Ss Private interface functions
112 .Ao Pf \&? Ic xml ? Ac
114 .Aq Pf \&! Ic DOCTYPE
115 declarations required for the current document type.
118 .Fn print_gen_comment
119 prints the leading comments, usually containing a Copyright notice
120 and license, as an HTML comment.
121 It is intended to be called right after opening the
135 elements for the document
145 which takes care of properly encoding attributes,
146 which is relevant for the
152 prints the start tag of an HTML element with the name
154 optionally including the attributes specified by
158 is the empty string, no attributes are written.
161 specifies one attribute to write.
162 Most attributes require one
164 argument which becomes the value of the attribute.
165 The arguments have to be given in the same order as the attribute letters.
168 the respective attribute is not written.
169 .Bl -tag -width 1n -offset indent
178 This attribute letter can optionally be followed by a modifier letter.
181 it formats the link as a local one by prefixing a
186 it interpretes the argument as a header file name
187 and generates a link using the
193 it takes two arguments instead of one, a manual page name and
194 section, and formats them as a link to a manual page using the
203 Print an arbitrary attribute.
204 This format letter requires two
206 arguments, the attribute name and the value.
213 If present, it must be the last format letter.
217 The first is the name of the style property, the second its value.
223 letter can be repeated, each repetition requiring an additional pair of
229 uses the private function
231 to take care of HTML encoding.
232 If required by the element type, it remembers in
234 that the element is open.
237 is used to close out all open elements up to and including
240 is a variant to close out all open elements up to but excluding
245 prints HTML element content.
246 It uses the private function
248 to take care of HTML encoding.
249 If the document has requested a non-standard font, for example using a
252 font escape sequence,
256 in an HTML font selection element using the
264 allocates a string to be used for the
266 attribute of an HTML element and/or as a segment identifier for a URI in an
273 attribute, it is used; otherwise, child nodes are used.
283 node, the resulting string is the concatenation of the child strings;
284 for other node types, only the first child is used.
285 Bytes not permitted in URI-fragment strings are replaced by underscores.
286 If any of the children to be used is not a text node,
287 no string is generated and
292 argument is non-zero, deduplication is performed by appending an
293 underscore and a decimal integer, if necessary.
307 it attempts to generate an
313 attribute is written,
321 generates a phrasing element, or inside otherwise.
322 This function is a wrapper around
328 argument to 1 and the
341 are not yet documented.
347 return a pointer to a new element on the stack of HTML elements.
350 opens two elements, a pointer to the outer one is returned.
351 The memory pointed to is owned by the library and is automatically
355 is called on it or when
357 is called on a parent element.
361 returns a newly allocated string or
365 lacks text data to create the attribute from.
368 argument is 0, the caller is responsible for
370 the returned string after using it.
373 argument is non-zero, the
375 ohash table is used for de-duplication and owns the returned string.
376 In this case, it will be freed automatically by
383 failure, these functions do not return but call
386 .Bl -tag -width mandoc_aux.c -compact
388 declarations of public functions for use by the main program,
391 declarations of data types and private functions
392 for use by language-specific HTML formatters
394 main HTML formatting engine and utility functions
408 declarations of data types and private functions
409 for shared use by all mandoc formatters,
412 private functions for shared use by all mandoc formatters
414 declarations of common mandoc utility functions, see
417 implementation of common mandoc utility functions
425 The mandoc HTML formatter was written by
426 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
428 .An Ingo Schwarze Aq Mt schwarze@openbsd.org ,
429 who also wrote this manual.