Annotation of mandoc/mandoc_html.3, Revision 1.3
1.3 ! schwarze 1: .\" $Id: mandoc_html.3,v 1.2 2017/01/17 01:47:51 schwarze Exp $
1.1 schwarze 2: .\"
1.3 ! schwarze 3: .\" Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
1.1 schwarze 4: .\"
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.
8: .\"
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.
16: .\"
1.3 ! schwarze 17: .Dd $Mdocdate: January 17 2017 $
1.1 schwarze 18: .Dt MANDOC_HTML 3
19: .Os
20: .Sh NAME
21: .Nm mandoc_html
22: .Nd internals of the mandoc HTML formatter
23: .Sh SYNOPSIS
24: .In "html.h"
25: .Ft void
26: .Fn print_gen_decls "struct html *h"
27: .Ft void
28: .Fn print_gen_head "struct html *h"
29: .Ft struct tag *
30: .Fo print_otag
31: .Fa "struct html *h"
32: .Fa "enum htmltag tag"
1.2 schwarze 33: .Fa "const char *fmt"
34: .Fa ...
1.1 schwarze 35: .Fc
36: .Ft void
37: .Fo print_tagq
38: .Fa "struct html *h"
39: .Fa "const struct tag *until"
40: .Fc
41: .Ft void
42: .Fo print_stagq
43: .Fa "struct html *h"
44: .Fa "const struct tag *suntil"
45: .Fc
46: .Ft void
47: .Fo print_text
48: .Fa "struct html *h"
49: .Fa "const char *word"
50: .Fc
51: .Sh DESCRIPTION
52: The mandoc HTML formatter is not a formal library.
53: However, as it is compiled into more than one program, in particular
54: .Xr mandoc 1
55: and
56: .Xr man.cgi 8 ,
57: and because it may be security-critical in some contexts,
58: some documentation is useful to help to use it correctly and
59: to prevent XSS vulnerabilities.
60: .Pp
61: The formatter produces HTML output on the standard output.
62: Since proper escaping is usually required and best taken care of
63: at one central place, the language-specific formatters
64: .Po
65: .Pa *_html.c ,
66: see
67: .Sx FILES
68: .Pc
69: are not supposed to print directly to
70: .Dv stdout
71: using functions like
72: .Xr printf 3 ,
73: .Xr putc 3 ,
74: .Xr puts 3 ,
75: or
76: .Xr write 2 .
77: Instead, they are expected to use the output functions declared in
78: .Pa html.h
79: and implemented as part of the main HTML formatting engine in
80: .Pa html.c .
81: .Ss Data structures
82: These structures are declared in
83: .Pa html.h .
84: .Bl -tag -width Ds
85: .It Vt struct html
86: Internal state of the HTML formatter.
87: .It Vt struct tag
88: One entry for the LIFO stack of HTML elements.
89: Members are
90: .Fa "enum htmltag tag"
91: and
92: .Fa "struct tag *next" .
93: .El
94: .Ss Private interface functions
95: The function
96: .Fn print_gen_decls
97: prints the opening
98: .Ao Pf \&? Ic xml ? Ac
99: and
100: .Aq Pf \&! Ic DOCTYPE
101: declarations required for the current document type.
102: .Pp
103: The function
104: .Fn print_gen_head
105: prints the opening
106: .Aq Ic META
107: and
108: .Aq Ic LINK
109: elements for the document
110: .Aq Ic HEAD ,
111: using the
112: .Fa style
113: member of
114: .Fa h
115: unless that is
116: .Dv NULL .
117: It uses
118: .Fn print_otag
119: which takes care of properly encoding attributes,
120: which is relevant for the
121: .Fa style
122: link in particular.
123: .Pp
124: The function
125: .Fn print_otag
126: prints the start tag of an HTML element with the name
127: .Fa tag ,
1.2 schwarze 128: optionally including the attributes specified by
129: .Fa fmt .
130: If
131: .Fa fmt
132: is the empty string, no attributes are written.
133: Each letter of
134: .Fa fmt
135: specifies one attribute to write.
136: Most attributes require one
137: .Va char *
138: argument which becomes the value of the attribute.
139: The arguments have to be given in the same order as the attribute letters.
140: .Bl -tag -width 1n -offset indent
141: .It Cm c
142: Print a
143: .Cm class
144: attribute.
145: .It Cm h
146: Print a
147: .Cm href
148: attribute.
1.3 ! schwarze 149: This attribute letter can optionally be followed by a modifier letter.
! 150: If followed by
! 151: .Cm R ,
! 152: it formats the link as a local one by prefixing a
! 153: .Sq #
! 154: character.
! 155: If followed by
! 156: .Cm I ,
! 157: it interpretes the argument as a header file name
! 158: and generates a link using the
! 159: .Xr mandoc 1
! 160: .Fl O Cm includes
! 161: option.
! 162: If followed by
! 163: .Cm M ,
! 164: it takes two arguments instead of one, a manual page name and
! 165: section, and formats them as a link to a manual page using the
! 166: .Xr mandoc 1
! 167: .Fl O Cm man
! 168: option.
1.2 schwarze 169: .It Cm i
170: Print an
171: .Cm id
172: attribute.
173: .It Cm \&?
174: Print an arbitrary attribute.
175: This format letter requires two
176: .Vt char *
177: arguments, the attribute name and the value.
178: .It Cm s
179: Print a
180: .Cm style
181: attribute.
182: If present, it must be the last format letter.
183: In contrast to the other format letters, this one does not yet
184: print the value and does not require an argument.
185: Instead, the rest of the format string consists of pairs of
186: argument type letters and style name letters.
187: .El
188: .Pp
189: Argument type letters each require on argument as follows:
190: .Bl -tag -width 1n -offset indent
191: .It Cm h
192: Requires one
193: .Vt int
194: argument, interpreted as a horizontal length in units of
195: .Dv SCALE_EN .
196: .It Cm s
197: Requires one
198: .Vt char *
199: argument, used as a style value.
200: .It Cm u
201: Requires one
202: .Vt struct roffsu *
203: argument, used as a length.
204: .It Cm v
205: Requires one
206: .Vt int
207: argument, interpreted as a vertical length in units of
208: .Dv SCALE_VS .
209: .It Cm w
210: Requires one
211: .Vt char *
212: argument, interpreted as an
213: .Xr mdoc 7 Ns -style
214: width specifier.
215: .El
216: .Pp
217: Style name letters decide what to do with the preceding argument:
218: .Bl -tag -width 1n -offset indent
219: .It Cm b
220: Set
221: .Cm margin-bottom
222: to the given length.
223: .It Cm h
224: Set
225: .Cm height
226: to the given length.
227: .It Cm i
228: Set
229: .Cm text-indent
230: to the given length.
231: .It Cm l
232: Set
233: .Cm margin-left
234: to the given length.
235: .It Cm t
236: Set
237: .Cm margin-top
238: to the given length.
239: .It Cm w
240: Set
241: .Cm width
242: to the given length.
243: .It Cm W
244: Set
245: .Cm min-width
246: to the given length.
247: .It Cm \&?
248: The special pair
249: .Cm s?
250: requires two
251: .Vt char *
252: arguments.
253: The first is the style name, the second its value.
254: .El
255: .Pp
256: .Fn print_otag
257: uses the private function
1.1 schwarze 258: .Fn print_encode
259: to take care of HTML encoding.
260: If required by the element type, it remembers in
261: .Fa h
262: that the element is open.
263: The function
264: .Fn print_tagq
265: is used to close out all open elements up to and including
266: .Fa until ;
267: .Fn print_stagq
268: is a variant to close out all open elements up to but excluding
269: .Fa suntil .
270: .Pp
271: The function
272: .Fn print_text
273: prints HTML element content.
274: It uses the private function
275: .Fn print_encode
276: to take care of HTML encoding.
277: If the document has requested a non-standard font, for example using a
278: .Xr roff 7
279: .Ic \ef
280: font escape sequence,
281: .Fn print_text
282: wraps
283: .Fa word
284: in an HTML font selection element using the
285: .Fn print_otag
286: and
287: .Fn print_tagq
288: functions.
289: .Pp
290: The functions
291: .Fn html_strlen ,
292: .Fn print_eqn ,
293: .Fn print_tbl ,
294: and
295: .Fn print_tblclose
296: are not yet documented.
297: .Sh FILES
298: .Bl -tag -width mandoc_aux.c -compact
299: .It Pa main.h
300: declarations of public functions for use by the main program,
301: not yet documented
302: .It Pa html.h
303: declarations of data types and private functions
304: for use by language-specific HTML formatters
305: .It Pa html.c
306: main HTML formatting engine and utility functions
307: .It Pa mdoc_html.c
308: .Xr mdoc 7
309: HTML formatter
310: .It Pa man_html.c
311: .Xr man 7
312: HTML formatter
313: .It Pa tbl_html.c
314: .Xr tbl 7
315: HTML formatter
316: .It Pa eqn_html.c
317: .Xr eqn 7
318: HTML formatter
319: .It Pa out.h
320: declarations of data types and private functions
321: for shared use by all mandoc formatters,
322: not yet documented
323: .It Pa out.c
324: private functions for shared use by all mandoc formatters
325: .It Pa mandoc_aux.h
326: declarations of common mandoc utility functions, see
327: .Xr mandoc 3
328: .It Pa mandoc_aux.c
329: implementation of common mandoc utility functions
330: .El
331: .Sh SEE ALSO
332: .Xr mandoc 1 ,
333: .Xr mandoc 3 ,
334: .Xr man.cgi 8
335: .Sh AUTHORS
336: .An -nosplit
337: The mandoc HTML formatter was written by
338: .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
339: This manual was written by
340: .An Ingo Schwarze Aq Mt schwarze@openbsd.org .
CVSweb