xref: /freebsd/contrib/mandoc/mandoc_html.3 (revision 7295610f5da64ab1818458ce007d9eb924496330)
1*7295610fSBaptiste Daroussin.\"	$Id: mandoc_html.3,v 1.19 2019/01/11 12:56:43 schwarze Exp $
261d06d6bSBaptiste Daroussin.\"
361d06d6bSBaptiste Daroussin.\" Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
461d06d6bSBaptiste Daroussin.\"
561d06d6bSBaptiste Daroussin.\" Permission to use, copy, modify, and distribute this software for any
661d06d6bSBaptiste Daroussin.\" purpose with or without fee is hereby granted, provided that the above
761d06d6bSBaptiste Daroussin.\" copyright notice and this permission notice appear in all copies.
861d06d6bSBaptiste Daroussin.\"
961d06d6bSBaptiste Daroussin.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1061d06d6bSBaptiste Daroussin.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1161d06d6bSBaptiste Daroussin.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1261d06d6bSBaptiste Daroussin.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1361d06d6bSBaptiste Daroussin.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1461d06d6bSBaptiste Daroussin.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1561d06d6bSBaptiste Daroussin.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1661d06d6bSBaptiste Daroussin.\"
17*7295610fSBaptiste Daroussin.Dd $Mdocdate: January 11 2019 $
1861d06d6bSBaptiste Daroussin.Dt MANDOC_HTML 3
1961d06d6bSBaptiste Daroussin.Os
2061d06d6bSBaptiste Daroussin.Sh NAME
2161d06d6bSBaptiste Daroussin.Nm mandoc_html
2261d06d6bSBaptiste Daroussin.Nd internals of the mandoc HTML formatter
2361d06d6bSBaptiste Daroussin.Sh SYNOPSIS
2461d06d6bSBaptiste Daroussin.In "html.h"
2561d06d6bSBaptiste Daroussin.Ft void
2661d06d6bSBaptiste Daroussin.Fn print_gen_decls "struct html *h"
2761d06d6bSBaptiste Daroussin.Ft void
2861d06d6bSBaptiste Daroussin.Fn print_gen_comment "struct html *h" "struct roff_node *n"
2961d06d6bSBaptiste Daroussin.Ft void
3061d06d6bSBaptiste Daroussin.Fn print_gen_head "struct html *h"
3161d06d6bSBaptiste Daroussin.Ft struct tag *
3261d06d6bSBaptiste Daroussin.Fo print_otag
3361d06d6bSBaptiste Daroussin.Fa "struct html *h"
3461d06d6bSBaptiste Daroussin.Fa "enum htmltag tag"
3561d06d6bSBaptiste Daroussin.Fa "const char *fmt"
3661d06d6bSBaptiste Daroussin.Fa ...
3761d06d6bSBaptiste Daroussin.Fc
3861d06d6bSBaptiste Daroussin.Ft void
3961d06d6bSBaptiste Daroussin.Fo print_tagq
4061d06d6bSBaptiste Daroussin.Fa "struct html *h"
4161d06d6bSBaptiste Daroussin.Fa "const struct tag *until"
4261d06d6bSBaptiste Daroussin.Fc
4361d06d6bSBaptiste Daroussin.Ft void
4461d06d6bSBaptiste Daroussin.Fo print_stagq
4561d06d6bSBaptiste Daroussin.Fa "struct html *h"
4661d06d6bSBaptiste Daroussin.Fa "const struct tag *suntil"
4761d06d6bSBaptiste Daroussin.Fc
4861d06d6bSBaptiste Daroussin.Ft void
4961d06d6bSBaptiste Daroussin.Fo print_text
5061d06d6bSBaptiste Daroussin.Fa "struct html *h"
5161d06d6bSBaptiste Daroussin.Fa "const char *word"
5261d06d6bSBaptiste Daroussin.Fc
5361d06d6bSBaptiste Daroussin.Ft char *
5461d06d6bSBaptiste Daroussin.Fo html_make_id
5561d06d6bSBaptiste Daroussin.Fa "const struct roff_node *n"
5661d06d6bSBaptiste Daroussin.Fc
5761d06d6bSBaptiste Daroussin.Ft int
5861d06d6bSBaptiste Daroussin.Fo html_strlen
5961d06d6bSBaptiste Daroussin.Fa "const char *cp"
6061d06d6bSBaptiste Daroussin.Fc
6161d06d6bSBaptiste Daroussin.Sh DESCRIPTION
6261d06d6bSBaptiste DaroussinThe mandoc HTML formatter is not a formal library.
6361d06d6bSBaptiste DaroussinHowever, as it is compiled into more than one program, in particular
6461d06d6bSBaptiste Daroussin.Xr mandoc 1
6561d06d6bSBaptiste Daroussinand
6661d06d6bSBaptiste Daroussin.Xr man.cgi 8 ,
6761d06d6bSBaptiste Daroussinand because it may be security-critical in some contexts,
6861d06d6bSBaptiste Daroussinsome documentation is useful to help to use it correctly and
6961d06d6bSBaptiste Daroussinto prevent XSS vulnerabilities.
7061d06d6bSBaptiste Daroussin.Pp
7161d06d6bSBaptiste DaroussinThe formatter produces HTML output on the standard output.
7261d06d6bSBaptiste DaroussinSince proper escaping is usually required and best taken care of
7361d06d6bSBaptiste Daroussinat one central place, the language-specific formatters
7461d06d6bSBaptiste Daroussin.Po
7561d06d6bSBaptiste Daroussin.Pa *_html.c ,
7661d06d6bSBaptiste Daroussinsee
7761d06d6bSBaptiste Daroussin.Sx FILES
7861d06d6bSBaptiste Daroussin.Pc
7961d06d6bSBaptiste Daroussinare not supposed to print directly to
8061d06d6bSBaptiste Daroussin.Dv stdout
8161d06d6bSBaptiste Daroussinusing functions like
8261d06d6bSBaptiste Daroussin.Xr printf 3 ,
8361d06d6bSBaptiste Daroussin.Xr putc 3 ,
8461d06d6bSBaptiste Daroussin.Xr puts 3 ,
8561d06d6bSBaptiste Daroussinor
8661d06d6bSBaptiste Daroussin.Xr write 2 .
8761d06d6bSBaptiste DaroussinInstead, they are expected to use the output functions declared in
8861d06d6bSBaptiste Daroussin.Pa html.h
8961d06d6bSBaptiste Daroussinand implemented as part of the main HTML formatting engine in
9061d06d6bSBaptiste Daroussin.Pa html.c .
9161d06d6bSBaptiste Daroussin.Ss Data structures
9261d06d6bSBaptiste DaroussinThese structures are declared in
9361d06d6bSBaptiste Daroussin.Pa html.h .
9461d06d6bSBaptiste Daroussin.Bl -tag -width Ds
9561d06d6bSBaptiste Daroussin.It Vt struct html
9661d06d6bSBaptiste DaroussinInternal state of the HTML formatter.
9761d06d6bSBaptiste Daroussin.It Vt struct tag
9861d06d6bSBaptiste DaroussinOne entry for the LIFO stack of HTML elements.
9961d06d6bSBaptiste DaroussinMembers are
10061d06d6bSBaptiste Daroussin.Fa "enum htmltag tag"
10161d06d6bSBaptiste Daroussinand
10261d06d6bSBaptiste Daroussin.Fa "struct tag *next" .
10361d06d6bSBaptiste Daroussin.El
10461d06d6bSBaptiste Daroussin.Ss Private interface functions
10561d06d6bSBaptiste DaroussinThe function
10661d06d6bSBaptiste Daroussin.Fn print_gen_decls
10761d06d6bSBaptiste Daroussinprints the opening
10861d06d6bSBaptiste Daroussin.Ao Pf \&? Ic xml ? Ac
10961d06d6bSBaptiste Daroussinand
11061d06d6bSBaptiste Daroussin.Aq Pf \&! Ic DOCTYPE
11161d06d6bSBaptiste Daroussindeclarations required for the current document type.
11261d06d6bSBaptiste Daroussin.Pp
11361d06d6bSBaptiste DaroussinThe function
11461d06d6bSBaptiste Daroussin.Fn print_gen_comment
11561d06d6bSBaptiste Daroussinprints the leading comments, usually containing a Copyright notice
11661d06d6bSBaptiste Daroussinand license, as an HTML comment.
11761d06d6bSBaptiste DaroussinIt is intended to be called right after opening the
11861d06d6bSBaptiste Daroussin.Aq Ic HTML
11961d06d6bSBaptiste Daroussinelement.
12061d06d6bSBaptiste DaroussinPass the first
12161d06d6bSBaptiste Daroussin.Dv ROFFT_COMMENT
12261d06d6bSBaptiste Daroussinnode in
12361d06d6bSBaptiste Daroussin.Fa n .
12461d06d6bSBaptiste Daroussin.Pp
12561d06d6bSBaptiste DaroussinThe function
12661d06d6bSBaptiste Daroussin.Fn print_gen_head
12761d06d6bSBaptiste Daroussinprints the opening
12861d06d6bSBaptiste Daroussin.Aq Ic META
12961d06d6bSBaptiste Daroussinand
13061d06d6bSBaptiste Daroussin.Aq Ic LINK
13161d06d6bSBaptiste Daroussinelements for the document
13261d06d6bSBaptiste Daroussin.Aq Ic HEAD ,
13361d06d6bSBaptiste Daroussinusing the
13461d06d6bSBaptiste Daroussin.Fa style
13561d06d6bSBaptiste Daroussinmember of
13661d06d6bSBaptiste Daroussin.Fa h
13761d06d6bSBaptiste Daroussinunless that is
13861d06d6bSBaptiste Daroussin.Dv NULL .
13961d06d6bSBaptiste DaroussinIt uses
14061d06d6bSBaptiste Daroussin.Fn print_otag
14161d06d6bSBaptiste Daroussinwhich takes care of properly encoding attributes,
14261d06d6bSBaptiste Daroussinwhich is relevant for the
14361d06d6bSBaptiste Daroussin.Fa style
14461d06d6bSBaptiste Daroussinlink in particular.
14561d06d6bSBaptiste Daroussin.Pp
14661d06d6bSBaptiste DaroussinThe function
14761d06d6bSBaptiste Daroussin.Fn print_otag
14861d06d6bSBaptiste Daroussinprints the start tag of an HTML element with the name
14961d06d6bSBaptiste Daroussin.Fa tag ,
15061d06d6bSBaptiste Daroussinoptionally including the attributes specified by
15161d06d6bSBaptiste Daroussin.Fa fmt .
15261d06d6bSBaptiste DaroussinIf
15361d06d6bSBaptiste Daroussin.Fa fmt
15461d06d6bSBaptiste Daroussinis the empty string, no attributes are written.
15561d06d6bSBaptiste DaroussinEach letter of
15661d06d6bSBaptiste Daroussin.Fa fmt
15761d06d6bSBaptiste Daroussinspecifies one attribute to write.
15861d06d6bSBaptiste DaroussinMost attributes require one
15961d06d6bSBaptiste Daroussin.Va char *
16061d06d6bSBaptiste Daroussinargument which becomes the value of the attribute.
16161d06d6bSBaptiste DaroussinThe arguments have to be given in the same order as the attribute letters.
16261d06d6bSBaptiste DaroussinIf an argument is
16361d06d6bSBaptiste Daroussin.Dv NULL ,
16461d06d6bSBaptiste Daroussinthe respective attribute is not written.
16561d06d6bSBaptiste Daroussin.Bl -tag -width 1n -offset indent
16661d06d6bSBaptiste Daroussin.It Cm c
16761d06d6bSBaptiste DaroussinPrint a
16861d06d6bSBaptiste Daroussin.Cm class
16961d06d6bSBaptiste Daroussinattribute.
17061d06d6bSBaptiste Daroussin.It Cm h
17161d06d6bSBaptiste DaroussinPrint a
17261d06d6bSBaptiste Daroussin.Cm href
17361d06d6bSBaptiste Daroussinattribute.
17461d06d6bSBaptiste DaroussinThis attribute letter can optionally be followed by a modifier letter.
17561d06d6bSBaptiste DaroussinIf followed by
17661d06d6bSBaptiste Daroussin.Cm R ,
17761d06d6bSBaptiste Daroussinit formats the link as a local one by prefixing a
17861d06d6bSBaptiste Daroussin.Sq #
17961d06d6bSBaptiste Daroussincharacter.
18061d06d6bSBaptiste DaroussinIf followed by
18161d06d6bSBaptiste Daroussin.Cm I ,
18261d06d6bSBaptiste Daroussinit interpretes the argument as a header file name
18361d06d6bSBaptiste Daroussinand generates a link using the
18461d06d6bSBaptiste Daroussin.Xr mandoc 1
18561d06d6bSBaptiste Daroussin.Fl O Cm includes
18661d06d6bSBaptiste Daroussinoption.
18761d06d6bSBaptiste DaroussinIf followed by
18861d06d6bSBaptiste Daroussin.Cm M ,
18961d06d6bSBaptiste Daroussinit takes two arguments instead of one, a manual page name and
19061d06d6bSBaptiste Daroussinsection, and formats them as a link to a manual page using the
19161d06d6bSBaptiste Daroussin.Xr mandoc 1
19261d06d6bSBaptiste Daroussin.Fl O Cm man
19361d06d6bSBaptiste Daroussinoption.
19461d06d6bSBaptiste Daroussin.It Cm i
19561d06d6bSBaptiste DaroussinPrint an
19661d06d6bSBaptiste Daroussin.Cm id
19761d06d6bSBaptiste Daroussinattribute.
19861d06d6bSBaptiste Daroussin.It Cm \&?
19961d06d6bSBaptiste DaroussinPrint an arbitrary attribute.
20061d06d6bSBaptiste DaroussinThis format letter requires two
20161d06d6bSBaptiste Daroussin.Vt char *
20261d06d6bSBaptiste Daroussinarguments, the attribute name and the value.
20361d06d6bSBaptiste DaroussinThe name must not be
20461d06d6bSBaptiste Daroussin.Dv NULL .
20561d06d6bSBaptiste Daroussin.It Cm s
20661d06d6bSBaptiste DaroussinPrint a
20761d06d6bSBaptiste Daroussin.Cm style
20861d06d6bSBaptiste Daroussinattribute.
20961d06d6bSBaptiste DaroussinIf present, it must be the last format letter.
21061d06d6bSBaptiste DaroussinIt requires two
21161d06d6bSBaptiste Daroussin.Va char *
21261d06d6bSBaptiste Daroussinarguments.
21361d06d6bSBaptiste DaroussinThe first is the name of the style property, the second its value.
214*7295610fSBaptiste DaroussinThe name must not be
215*7295610fSBaptiste Daroussin.Dv NULL .
216*7295610fSBaptiste DaroussinThe
217*7295610fSBaptiste Daroussin.Cm s
218*7295610fSBaptiste Daroussin.Ar fmt
219*7295610fSBaptiste Daroussinletter can be repeated, each repetition requiring an additional pair of
220*7295610fSBaptiste Daroussin.Va char *
221*7295610fSBaptiste Daroussinarguments.
22261d06d6bSBaptiste Daroussin.El
22361d06d6bSBaptiste Daroussin.Pp
22461d06d6bSBaptiste Daroussin.Fn print_otag
22561d06d6bSBaptiste Daroussinuses the private function
22661d06d6bSBaptiste Daroussin.Fn print_encode
22761d06d6bSBaptiste Daroussinto take care of HTML encoding.
22861d06d6bSBaptiste DaroussinIf required by the element type, it remembers in
22961d06d6bSBaptiste Daroussin.Fa h
23061d06d6bSBaptiste Daroussinthat the element is open.
23161d06d6bSBaptiste DaroussinThe function
23261d06d6bSBaptiste Daroussin.Fn print_tagq
23361d06d6bSBaptiste Daroussinis used to close out all open elements up to and including
23461d06d6bSBaptiste Daroussin.Fa until ;
23561d06d6bSBaptiste Daroussin.Fn print_stagq
23661d06d6bSBaptiste Daroussinis a variant to close out all open elements up to but excluding
23761d06d6bSBaptiste Daroussin.Fa suntil .
23861d06d6bSBaptiste Daroussin.Pp
23961d06d6bSBaptiste DaroussinThe function
24061d06d6bSBaptiste Daroussin.Fn print_text
24161d06d6bSBaptiste Daroussinprints HTML element content.
24261d06d6bSBaptiste DaroussinIt uses the private function
24361d06d6bSBaptiste Daroussin.Fn print_encode
24461d06d6bSBaptiste Daroussinto take care of HTML encoding.
24561d06d6bSBaptiste DaroussinIf the document has requested a non-standard font, for example using a
24661d06d6bSBaptiste Daroussin.Xr roff 7
24761d06d6bSBaptiste Daroussin.Ic \ef
24861d06d6bSBaptiste Daroussinfont escape sequence,
24961d06d6bSBaptiste Daroussin.Fn print_text
25061d06d6bSBaptiste Daroussinwraps
25161d06d6bSBaptiste Daroussin.Fa word
25261d06d6bSBaptiste Daroussinin an HTML font selection element using the
25361d06d6bSBaptiste Daroussin.Fn print_otag
25461d06d6bSBaptiste Daroussinand
25561d06d6bSBaptiste Daroussin.Fn print_tagq
25661d06d6bSBaptiste Daroussinfunctions.
25761d06d6bSBaptiste Daroussin.Pp
25861d06d6bSBaptiste DaroussinThe function
25961d06d6bSBaptiste Daroussin.Fn html_make_id
26061d06d6bSBaptiste Daroussintakes a node containing one or more text children
26161d06d6bSBaptiste Daroussinand returns a newly allocated string containing the concatenation
26261d06d6bSBaptiste Daroussinof the child strings, with blanks replaced by underscores.
26361d06d6bSBaptiste DaroussinIf the node
26461d06d6bSBaptiste Daroussin.Fa n
26561d06d6bSBaptiste Daroussincontains any non-text child node,
26661d06d6bSBaptiste Daroussin.Fn html_make_id
26761d06d6bSBaptiste Daroussinreturns
26861d06d6bSBaptiste Daroussin.Dv NULL
26961d06d6bSBaptiste Daroussininstead.
27061d06d6bSBaptiste DaroussinThe caller is responsible for freeing the returned string.
27161d06d6bSBaptiste Daroussin.Pp
27261d06d6bSBaptiste DaroussinThe function
27361d06d6bSBaptiste Daroussin.Fn html_strlen
27461d06d6bSBaptiste Daroussincounts the number of characters in
27561d06d6bSBaptiste Daroussin.Fa cp .
27661d06d6bSBaptiste DaroussinIt is used as a crude estimate of the width needed to display a string.
27761d06d6bSBaptiste Daroussin.Pp
27861d06d6bSBaptiste DaroussinThe functions
27961d06d6bSBaptiste Daroussin.Fn print_eqn ,
28061d06d6bSBaptiste Daroussin.Fn print_tbl ,
28161d06d6bSBaptiste Daroussinand
28261d06d6bSBaptiste Daroussin.Fn print_tblclose
28361d06d6bSBaptiste Daroussinare not yet documented.
28461d06d6bSBaptiste Daroussin.Sh FILES
28561d06d6bSBaptiste Daroussin.Bl -tag -width mandoc_aux.c -compact
28661d06d6bSBaptiste Daroussin.It Pa main.h
28761d06d6bSBaptiste Daroussindeclarations of public functions for use by the main program,
28861d06d6bSBaptiste Daroussinnot yet documented
28961d06d6bSBaptiste Daroussin.It Pa html.h
29061d06d6bSBaptiste Daroussindeclarations of data types and private functions
29161d06d6bSBaptiste Daroussinfor use by language-specific HTML formatters
29261d06d6bSBaptiste Daroussin.It Pa html.c
29361d06d6bSBaptiste Daroussinmain HTML formatting engine and utility functions
29461d06d6bSBaptiste Daroussin.It Pa mdoc_html.c
29561d06d6bSBaptiste Daroussin.Xr mdoc 7
29661d06d6bSBaptiste DaroussinHTML formatter
29761d06d6bSBaptiste Daroussin.It Pa man_html.c
29861d06d6bSBaptiste Daroussin.Xr man 7
29961d06d6bSBaptiste DaroussinHTML formatter
30061d06d6bSBaptiste Daroussin.It Pa tbl_html.c
30161d06d6bSBaptiste Daroussin.Xr tbl 7
30261d06d6bSBaptiste DaroussinHTML formatter
30361d06d6bSBaptiste Daroussin.It Pa eqn_html.c
30461d06d6bSBaptiste Daroussin.Xr eqn 7
30561d06d6bSBaptiste DaroussinHTML formatter
30661d06d6bSBaptiste Daroussin.It Pa out.h
30761d06d6bSBaptiste Daroussindeclarations of data types and private functions
30861d06d6bSBaptiste Daroussinfor shared use by all mandoc formatters,
30961d06d6bSBaptiste Daroussinnot yet documented
31061d06d6bSBaptiste Daroussin.It Pa out.c
31161d06d6bSBaptiste Daroussinprivate functions for shared use by all mandoc formatters
31261d06d6bSBaptiste Daroussin.It Pa mandoc_aux.h
31361d06d6bSBaptiste Daroussindeclarations of common mandoc utility functions, see
31461d06d6bSBaptiste Daroussin.Xr mandoc 3
31561d06d6bSBaptiste Daroussin.It Pa mandoc_aux.c
31661d06d6bSBaptiste Daroussinimplementation of common mandoc utility functions
31761d06d6bSBaptiste Daroussin.El
31861d06d6bSBaptiste Daroussin.Sh SEE ALSO
31961d06d6bSBaptiste Daroussin.Xr mandoc 1 ,
32061d06d6bSBaptiste Daroussin.Xr mandoc 3 ,
32161d06d6bSBaptiste Daroussin.Xr man.cgi 8
32261d06d6bSBaptiste Daroussin.Sh AUTHORS
32361d06d6bSBaptiste Daroussin.An -nosplit
32461d06d6bSBaptiste DaroussinThe mandoc HTML formatter was written by
32561d06d6bSBaptiste Daroussin.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
32661d06d6bSBaptiste DaroussinIt is maintained by
32761d06d6bSBaptiste Daroussin.An Ingo Schwarze Aq Mt schwarze@openbsd.org ,
32861d06d6bSBaptiste Daroussinwho also wrote this manual.
329