MANDOC_HTML(3) Library Functions Manual MANDOC_HTML(3)


mandoc_htmlinternals of the mandoc HTML formatter


#include <html.h>
print_gen_decls(struct html *h);
print_gen_head(struct html *h);
struct tag *
print_otag(struct html *h, enum htmltag tag, const char *fmt, ...);
print_tagq(struct html *h, const struct tag *until);
print_stagq(struct html *h, const struct tag *suntil);
print_text(struct html *h, const char *word);
char *
html_make_id(const struct roff_node *n);
html_strlen(const char *cp);


The mandoc HTML formatter is not a formal library. However, as it is compiled into more than one program, in particular mandoc(1) and man.cgi(8), and because it may be security-critical in some contexts, some documentation is useful to help to use it correctly and to prevent XSS vulnerabilities.
The formatter produces HTML output on the standard output. Since proper escaping is usually required and best taken care of at one central place, the language-specific formatters (*_html.c, see FILES) are not supposed to print directly to stdout using functions like printf(3), putc(3), puts(3), or write(2). Instead, they are expected to use the output functions declared in html.h and implemented as part of the main HTML formatting engine in html.c.

Data structures

These structures are declared in html.h.
struct html
Internal state of the HTML formatter.
struct tag
One entry for the LIFO stack of HTML elements. Members are enum htmltag tag and struct tag *next.

Private interface functions

The function print_gen_decls() prints the opening ⟨?xml?⟩ and ⟨!DOCTYPE⟩ declarations required for the current document type.
The function print_gen_head() prints the opening ⟨META⟩ and ⟨LINK⟩ elements for the document ⟨HEAD⟩, using the style member of h unless that is NULL. It uses print_otag() which takes care of properly encoding attributes, which is relevant for the style link in particular.
The function print_otag() prints the start tag of an HTML element with the name tag, optionally including the attributes specified by fmt. If fmt is the empty string, no attributes are written. Each letter of fmt specifies one attribute to write. Most attributes require one char * argument which becomes the value of the attribute. The arguments have to be given in the same order as the attribute letters. If an argument is NULL, the respective attribute is not written.
Print a class attribute. This attribute letter can optionally be followed by the modifier letter T. In that case, a title attribute with the same value is also printed.
Print a href attribute. This attribute letter can optionally be followed by a modifier letter. If followed by R, it formats the link as a local one by prefixing a ‘#’ character. If followed by I, it interpretes the argument as a header file name and generates a link using the mandoc(1) -O includes option. If followed by M, it takes two arguments instead of one, a manual page name and section, and formats them as a link to a manual page using the mandoc(1) -O man option.
Print an id attribute.
Print an arbitrary attribute. This format letter requires two char * arguments, the attribute name and the value. The name must not be NULL.
Print a style attribute. If present, it must be the last format letter. In contrast to the other format letters, this one does not yet print the value and does not take an argument. Instead, the rest of the format string consists of pairs of argument type letters and style name letters.
Argument type letters each require one argument as follows:
Requires one int argument, interpreted as a horizontal length in units of SCALE_EN.
Requires one char * argument, used as a style value.
Requires one struct roffsu * argument, used as a length.
Requires one char * argument, interpreted as an mdoc(7)-style width specifier. If the argument is NULL, nothing is printed for this pair.
The w argument type letter can optionally be followed by one, two, or three modifier letters. The modifier * suppresses printing of the pair if the argument matches 6n. The modifier + increases the width by 20% to make even bold text fit and adds three units for padding between columns. The modifier - makes the width negative by multiplying it with -1.
Style name letters decide what to do with the preceding argument:
Set height to the given length.
Set text-indent to the given length.
Set margin-left to the given length.
Set width to the given length.
Set min-width to the given length.
The special pair s? requires two char * arguments. The first is the style name, the second its value. The style name must not be NULL.
print_otag() uses the private function print_encode() to take care of HTML encoding. If required by the element type, it remembers in h that the element is open. The function print_tagq() is used to close out all open elements up to and including until; print_stagq() is a variant to close out all open elements up to but excluding suntil.
The function print_text() prints HTML element content. It uses the private function print_encode() to take care of HTML encoding. If the document has requested a non-standard font, for example using a roff(7) \f font escape sequence, print_text() wraps word in an HTML font selection element using the print_otag() and print_tagq() functions.
The function html_make_id() takes a node containing one or more text children and returns a newly allocated string containing the concatenation of the child strings, with blanks replaced by underscores. If the node n contains any non-text child node, html_make_id() returns NULL instead. The caller is responsible for freeing the returned string.
The function html_strlen() counts the number of characters in cp. It is used as a crude estimate of the width needed to display a string.
The functions print_eqn(), print_tbl(), and print_tblclose() are not yet documented.


declarations of public functions for use by the main program, not yet documented
declarations of data types and private functions for use by language-specific HTML formatters
main HTML formatting engine and utility functions
mdoc(7) HTML formatter
man(7) HTML formatter
tbl(7) HTML formatter
eqn(7) HTML formatter
declarations of data types and private functions for shared use by all mandoc formatters, not yet documented
private functions for shared use by all mandoc formatters
declarations of common mandoc utility functions, see mandoc(3)
implementation of common mandoc utility functions


mandoc(1), mandoc(3), man.cgi(8)


The mandoc HTML formatter was written by Kristaps Dzonsons <>. It is maintained by Ingo Schwarze <>, who also wrote this manual.
July 15, 2017 OpenBSD 5.8