1*544c191cSchristos.\" Id: mandoc_html.3,v 1.19 2019/01/11 12:56:43 schwarze Exp 2fec65c98Schristos.\" 3c9bcef03Schristos.\" Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> 4fec65c98Schristos.\" 5fec65c98Schristos.\" Permission to use, copy, modify, and distribute this software for any 6fec65c98Schristos.\" purpose with or without fee is hereby granted, provided that the above 7fec65c98Schristos.\" copyright notice and this permission notice appear in all copies. 8fec65c98Schristos.\" 9fec65c98Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10fec65c98Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11fec65c98Schristos.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12fec65c98Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13fec65c98Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14fec65c98Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15fec65c98Schristos.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16fec65c98Schristos.\" 17*544c191cSchristos.Dd January 11, 2019 18fec65c98Schristos.Dt MANDOC_HTML 3 19fec65c98Schristos.Os 20fec65c98Schristos.Sh NAME 21fec65c98Schristos.Nm mandoc_html 22fec65c98Schristos.Nd internals of the mandoc HTML formatter 23fec65c98Schristos.Sh SYNOPSIS 24fec65c98Schristos.In "html.h" 25fec65c98Schristos.Ft void 26fec65c98Schristos.Fn print_gen_decls "struct html *h" 27fec65c98Schristos.Ft void 28c9bcef03Schristos.Fn print_gen_comment "struct html *h" "struct roff_node *n" 29c9bcef03Schristos.Ft void 30fec65c98Schristos.Fn print_gen_head "struct html *h" 31fec65c98Schristos.Ft struct tag * 32fec65c98Schristos.Fo print_otag 33fec65c98Schristos.Fa "struct html *h" 34fec65c98Schristos.Fa "enum htmltag tag" 359508192eSchristos.Fa "const char *fmt" 369508192eSchristos.Fa ... 37fec65c98Schristos.Fc 38fec65c98Schristos.Ft void 39fec65c98Schristos.Fo print_tagq 40fec65c98Schristos.Fa "struct html *h" 41fec65c98Schristos.Fa "const struct tag *until" 42fec65c98Schristos.Fc 43fec65c98Schristos.Ft void 44fec65c98Schristos.Fo print_stagq 45fec65c98Schristos.Fa "struct html *h" 46fec65c98Schristos.Fa "const struct tag *suntil" 47fec65c98Schristos.Fc 48fec65c98Schristos.Ft void 49fec65c98Schristos.Fo print_text 50fec65c98Schristos.Fa "struct html *h" 51fec65c98Schristos.Fa "const char *word" 52fec65c98Schristos.Fc 53c9bcef03Schristos.Ft char * 54c9bcef03Schristos.Fo html_make_id 55c9bcef03Schristos.Fa "const struct roff_node *n" 56c9bcef03Schristos.Fc 57c9bcef03Schristos.Ft int 58c9bcef03Schristos.Fo html_strlen 59c9bcef03Schristos.Fa "const char *cp" 60c9bcef03Schristos.Fc 61fec65c98Schristos.Sh DESCRIPTION 62fec65c98SchristosThe mandoc HTML formatter is not a formal library. 63fec65c98SchristosHowever, as it is compiled into more than one program, in particular 64fec65c98Schristos.Xr mandoc 1 65fec65c98Schristosand 66fec65c98Schristos.Xr man.cgi 8 , 67fec65c98Schristosand because it may be security-critical in some contexts, 68fec65c98Schristossome documentation is useful to help to use it correctly and 69fec65c98Schristosto prevent XSS vulnerabilities. 70fec65c98Schristos.Pp 71fec65c98SchristosThe formatter produces HTML output on the standard output. 72fec65c98SchristosSince proper escaping is usually required and best taken care of 73fec65c98Schristosat one central place, the language-specific formatters 74fec65c98Schristos.Po 75fec65c98Schristos.Pa *_html.c , 76fec65c98Schristossee 77fec65c98Schristos.Sx FILES 78fec65c98Schristos.Pc 79fec65c98Schristosare not supposed to print directly to 80fec65c98Schristos.Dv stdout 81fec65c98Schristosusing functions like 82fec65c98Schristos.Xr printf 3 , 83fec65c98Schristos.Xr putc 3 , 84fec65c98Schristos.Xr puts 3 , 85fec65c98Schristosor 86fec65c98Schristos.Xr write 2 . 87fec65c98SchristosInstead, they are expected to use the output functions declared in 88fec65c98Schristos.Pa html.h 89fec65c98Schristosand implemented as part of the main HTML formatting engine in 90fec65c98Schristos.Pa html.c . 91fec65c98Schristos.Ss Data structures 92fec65c98SchristosThese structures are declared in 93fec65c98Schristos.Pa html.h . 94fec65c98Schristos.Bl -tag -width Ds 95fec65c98Schristos.It Vt struct html 96fec65c98SchristosInternal state of the HTML formatter. 97fec65c98Schristos.It Vt struct tag 98fec65c98SchristosOne entry for the LIFO stack of HTML elements. 99fec65c98SchristosMembers are 100fec65c98Schristos.Fa "enum htmltag tag" 101fec65c98Schristosand 102fec65c98Schristos.Fa "struct tag *next" . 103fec65c98Schristos.El 104fec65c98Schristos.Ss Private interface functions 105fec65c98SchristosThe function 106fec65c98Schristos.Fn print_gen_decls 107fec65c98Schristosprints the opening 108fec65c98Schristos.Ao Pf \&? Ic xml ? Ac 109fec65c98Schristosand 110fec65c98Schristos.Aq Pf \&! Ic DOCTYPE 111fec65c98Schristosdeclarations required for the current document type. 112fec65c98Schristos.Pp 113fec65c98SchristosThe function 114c9bcef03Schristos.Fn print_gen_comment 115c9bcef03Schristosprints the leading comments, usually containing a Copyright notice 116c9bcef03Schristosand license, as an HTML comment. 117c9bcef03SchristosIt is intended to be called right after opening the 118c9bcef03Schristos.Aq Ic HTML 119c9bcef03Schristoselement. 120c9bcef03SchristosPass the first 121c9bcef03Schristos.Dv ROFFT_COMMENT 122c9bcef03Schristosnode in 123c9bcef03Schristos.Fa n . 124c9bcef03Schristos.Pp 125c9bcef03SchristosThe function 126fec65c98Schristos.Fn print_gen_head 127fec65c98Schristosprints the opening 128fec65c98Schristos.Aq Ic META 129fec65c98Schristosand 130fec65c98Schristos.Aq Ic LINK 131fec65c98Schristoselements for the document 132fec65c98Schristos.Aq Ic HEAD , 133fec65c98Schristosusing the 134fec65c98Schristos.Fa style 135fec65c98Schristosmember of 136fec65c98Schristos.Fa h 137fec65c98Schristosunless that is 138fec65c98Schristos.Dv NULL . 139fec65c98SchristosIt uses 140fec65c98Schristos.Fn print_otag 141fec65c98Schristoswhich takes care of properly encoding attributes, 142fec65c98Schristoswhich is relevant for the 143fec65c98Schristos.Fa style 144fec65c98Schristoslink in particular. 145fec65c98Schristos.Pp 146fec65c98SchristosThe function 147fec65c98Schristos.Fn print_otag 148fec65c98Schristosprints the start tag of an HTML element with the name 149fec65c98Schristos.Fa tag , 1509508192eSchristosoptionally including the attributes specified by 1519508192eSchristos.Fa fmt . 1529508192eSchristosIf 1539508192eSchristos.Fa fmt 1549508192eSchristosis the empty string, no attributes are written. 1559508192eSchristosEach letter of 1569508192eSchristos.Fa fmt 1579508192eSchristosspecifies one attribute to write. 1589508192eSchristosMost attributes require one 1599508192eSchristos.Va char * 1609508192eSchristosargument which becomes the value of the attribute. 1619508192eSchristosThe arguments have to be given in the same order as the attribute letters. 1629508192eSchristosIf an argument is 1639508192eSchristos.Dv NULL , 1649508192eSchristosthe respective attribute is not written. 1659508192eSchristos.Bl -tag -width 1n -offset indent 1669508192eSchristos.It Cm c 1679508192eSchristosPrint a 1689508192eSchristos.Cm class 1699508192eSchristosattribute. 1709508192eSchristos.It Cm h 1719508192eSchristosPrint a 1729508192eSchristos.Cm href 1739508192eSchristosattribute. 1749508192eSchristosThis attribute letter can optionally be followed by a modifier letter. 1759508192eSchristosIf followed by 1769508192eSchristos.Cm R , 1779508192eSchristosit formats the link as a local one by prefixing a 1789508192eSchristos.Sq # 1799508192eSchristoscharacter. 1809508192eSchristosIf followed by 1819508192eSchristos.Cm I , 1829508192eSchristosit interpretes the argument as a header file name 1839508192eSchristosand generates a link using the 1849508192eSchristos.Xr mandoc 1 1859508192eSchristos.Fl O Cm includes 1869508192eSchristosoption. 1879508192eSchristosIf followed by 1889508192eSchristos.Cm M , 1899508192eSchristosit takes two arguments instead of one, a manual page name and 1909508192eSchristossection, and formats them as a link to a manual page using the 1919508192eSchristos.Xr mandoc 1 1929508192eSchristos.Fl O Cm man 1939508192eSchristosoption. 1949508192eSchristos.It Cm i 1959508192eSchristosPrint an 1969508192eSchristos.Cm id 1979508192eSchristosattribute. 1989508192eSchristos.It Cm \&? 1999508192eSchristosPrint an arbitrary attribute. 2009508192eSchristosThis format letter requires two 2019508192eSchristos.Vt char * 2029508192eSchristosarguments, the attribute name and the value. 2039508192eSchristosThe name must not be 2049508192eSchristos.Dv NULL . 2059508192eSchristos.It Cm s 2069508192eSchristosPrint a 2079508192eSchristos.Cm style 2089508192eSchristosattribute. 2099508192eSchristosIf present, it must be the last format letter. 210c9bcef03SchristosIt requires two 211c9bcef03Schristos.Va char * 2129508192eSchristosarguments. 213c9bcef03SchristosThe first is the name of the style property, the second its value. 214*544c191cSchristosThe name must not be 215*544c191cSchristos.Dv NULL . 216*544c191cSchristosThe 217*544c191cSchristos.Cm s 218*544c191cSchristos.Ar fmt 219*544c191cSchristosletter can be repeated, each repetition requiring an additional pair of 220*544c191cSchristos.Va char * 221*544c191cSchristosarguments. 2229508192eSchristos.El 2239508192eSchristos.Pp 2249508192eSchristos.Fn print_otag 2259508192eSchristosuses the private function 226fec65c98Schristos.Fn print_encode 227fec65c98Schristosto take care of HTML encoding. 228fec65c98SchristosIf required by the element type, it remembers in 229fec65c98Schristos.Fa h 230fec65c98Schristosthat the element is open. 231fec65c98SchristosThe function 232fec65c98Schristos.Fn print_tagq 233fec65c98Schristosis used to close out all open elements up to and including 234fec65c98Schristos.Fa until ; 235fec65c98Schristos.Fn print_stagq 236fec65c98Schristosis a variant to close out all open elements up to but excluding 237fec65c98Schristos.Fa suntil . 238fec65c98Schristos.Pp 239fec65c98SchristosThe function 240fec65c98Schristos.Fn print_text 241fec65c98Schristosprints HTML element content. 242fec65c98SchristosIt uses the private function 243fec65c98Schristos.Fn print_encode 244fec65c98Schristosto take care of HTML encoding. 245fec65c98SchristosIf the document has requested a non-standard font, for example using a 246fec65c98Schristos.Xr roff 7 247fec65c98Schristos.Ic \ef 248fec65c98Schristosfont escape sequence, 249fec65c98Schristos.Fn print_text 250fec65c98Schristoswraps 251fec65c98Schristos.Fa word 252fec65c98Schristosin an HTML font selection element using the 253fec65c98Schristos.Fn print_otag 254fec65c98Schristosand 255fec65c98Schristos.Fn print_tagq 256fec65c98Schristosfunctions. 257fec65c98Schristos.Pp 258c9bcef03SchristosThe function 259c9bcef03Schristos.Fn html_make_id 260c9bcef03Schristostakes a node containing one or more text children 261c9bcef03Schristosand returns a newly allocated string containing the concatenation 262c9bcef03Schristosof the child strings, with blanks replaced by underscores. 263c9bcef03SchristosIf the node 264c9bcef03Schristos.Fa n 265c9bcef03Schristoscontains any non-text child node, 266c9bcef03Schristos.Fn html_make_id 267c9bcef03Schristosreturns 268c9bcef03Schristos.Dv NULL 269c9bcef03Schristosinstead. 270c9bcef03SchristosThe caller is responsible for freeing the returned string. 271c9bcef03Schristos.Pp 272c9bcef03SchristosThe function 273c9bcef03Schristos.Fn html_strlen 274c9bcef03Schristoscounts the number of characters in 275c9bcef03Schristos.Fa cp . 276c9bcef03SchristosIt is used as a crude estimate of the width needed to display a string. 277c9bcef03Schristos.Pp 278fec65c98SchristosThe functions 279fec65c98Schristos.Fn print_eqn , 280fec65c98Schristos.Fn print_tbl , 281fec65c98Schristosand 282fec65c98Schristos.Fn print_tblclose 283fec65c98Schristosare not yet documented. 284fec65c98Schristos.Sh FILES 285fec65c98Schristos.Bl -tag -width mandoc_aux.c -compact 286fec65c98Schristos.It Pa main.h 287fec65c98Schristosdeclarations of public functions for use by the main program, 288fec65c98Schristosnot yet documented 289fec65c98Schristos.It Pa html.h 290fec65c98Schristosdeclarations of data types and private functions 291fec65c98Schristosfor use by language-specific HTML formatters 292fec65c98Schristos.It Pa html.c 293fec65c98Schristosmain HTML formatting engine and utility functions 294fec65c98Schristos.It Pa mdoc_html.c 295fec65c98Schristos.Xr mdoc 7 296fec65c98SchristosHTML formatter 297fec65c98Schristos.It Pa man_html.c 298fec65c98Schristos.Xr man 7 299fec65c98SchristosHTML formatter 300fec65c98Schristos.It Pa tbl_html.c 301fec65c98Schristos.Xr tbl 7 302fec65c98SchristosHTML formatter 303fec65c98Schristos.It Pa eqn_html.c 304fec65c98Schristos.Xr eqn 7 305fec65c98SchristosHTML formatter 306fec65c98Schristos.It Pa out.h 307fec65c98Schristosdeclarations of data types and private functions 308fec65c98Schristosfor shared use by all mandoc formatters, 309fec65c98Schristosnot yet documented 310fec65c98Schristos.It Pa out.c 311fec65c98Schristosprivate functions for shared use by all mandoc formatters 312fec65c98Schristos.It Pa mandoc_aux.h 313fec65c98Schristosdeclarations of common mandoc utility functions, see 314fec65c98Schristos.Xr mandoc 3 315fec65c98Schristos.It Pa mandoc_aux.c 316fec65c98Schristosimplementation of common mandoc utility functions 317fec65c98Schristos.El 318fec65c98Schristos.Sh SEE ALSO 319fec65c98Schristos.Xr mandoc 1 , 320fec65c98Schristos.Xr mandoc 3 , 321fec65c98Schristos.Xr man.cgi 8 322fec65c98Schristos.Sh AUTHORS 323fec65c98Schristos.An -nosplit 324fec65c98SchristosThe mandoc HTML formatter was written by 325fec65c98Schristos.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv . 3269508192eSchristosIt is maintained by 3279508192eSchristos.An Ingo Schwarze Aq Mt schwarze@openbsd.org , 3289508192eSchristoswho also wrote this manual. 329