[BACK]Return to mandoc_html.3 CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mandoc_html.3, Revision 1.4

1.4     ! schwarze    1: .\"    $Id: mandoc_html.3,v 1.3 2017/01/17 15:32:44 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.
1.4     ! schwarze  215: .It Cm W
        !           216: Similar to
        !           217: .Cm w ,
        !           218: but makes the width negative by multiplying it with \(mi1.
1.2       schwarze  219: .El
                    220: .Pp
                    221: Style name letters decide what to do with the preceding argument:
                    222: .Bl -tag -width 1n -offset indent
                    223: .It Cm b
                    224: Set
                    225: .Cm margin-bottom
                    226: to the given length.
                    227: .It Cm h
                    228: Set
                    229: .Cm height
                    230: to the given length.
                    231: .It Cm i
                    232: Set
                    233: .Cm text-indent
                    234: to the given length.
                    235: .It Cm l
                    236: Set
                    237: .Cm margin-left
                    238: to the given length.
                    239: .It Cm t
                    240: Set
                    241: .Cm margin-top
                    242: to the given length.
                    243: .It Cm w
                    244: Set
                    245: .Cm width
                    246: to the given length.
                    247: .It Cm W
                    248: Set
                    249: .Cm min-width
                    250: to the given length.
                    251: .It Cm \&?
                    252: The special pair
                    253: .Cm s?
                    254: requires two
                    255: .Vt char *
                    256: arguments.
                    257: The first is the style name, the second its value.
                    258: .El
                    259: .Pp
                    260: .Fn print_otag
                    261: uses the private function
1.1       schwarze  262: .Fn print_encode
                    263: to take care of HTML encoding.
                    264: If required by the element type, it remembers in
                    265: .Fa h
                    266: that the element is open.
                    267: The function
                    268: .Fn print_tagq
                    269: is used to close out all open elements up to and including
                    270: .Fa until ;
                    271: .Fn print_stagq
                    272: is a variant to close out all open elements up to but excluding
                    273: .Fa suntil .
                    274: .Pp
                    275: The function
                    276: .Fn print_text
                    277: prints HTML element content.
                    278: It uses the private function
                    279: .Fn print_encode
                    280: to take care of HTML encoding.
                    281: If the document has requested a non-standard font, for example using a
                    282: .Xr roff 7
                    283: .Ic \ef
                    284: font escape sequence,
                    285: .Fn print_text
                    286: wraps
                    287: .Fa word
                    288: in an HTML font selection element using the
                    289: .Fn print_otag
                    290: and
                    291: .Fn print_tagq
                    292: functions.
                    293: .Pp
                    294: The functions
                    295: .Fn html_strlen ,
                    296: .Fn print_eqn ,
                    297: .Fn print_tbl ,
                    298: and
                    299: .Fn print_tblclose
                    300: are not yet documented.
                    301: .Sh FILES
                    302: .Bl -tag -width mandoc_aux.c -compact
                    303: .It Pa main.h
                    304: declarations of public functions for use by the main program,
                    305: not yet documented
                    306: .It Pa html.h
                    307: declarations of data types and private functions
                    308: for use by language-specific HTML formatters
                    309: .It Pa html.c
                    310: main HTML formatting engine and utility functions
                    311: .It Pa mdoc_html.c
                    312: .Xr mdoc 7
                    313: HTML formatter
                    314: .It Pa man_html.c
                    315: .Xr man 7
                    316: HTML formatter
                    317: .It Pa tbl_html.c
                    318: .Xr tbl 7
                    319: HTML formatter
                    320: .It Pa eqn_html.c
                    321: .Xr eqn 7
                    322: HTML formatter
                    323: .It Pa out.h
                    324: declarations of data types and private functions
                    325: for shared use by all mandoc formatters,
                    326: not yet documented
                    327: .It Pa out.c
                    328: private functions for shared use by all mandoc formatters
                    329: .It Pa mandoc_aux.h
                    330: declarations of common mandoc utility functions, see
                    331: .Xr mandoc 3
                    332: .It Pa mandoc_aux.c
                    333: implementation of common mandoc utility functions
                    334: .El
                    335: .Sh SEE ALSO
                    336: .Xr mandoc 1 ,
                    337: .Xr mandoc 3 ,
                    338: .Xr man.cgi 8
                    339: .Sh AUTHORS
                    340: .An -nosplit
                    341: The mandoc HTML formatter was written by
                    342: .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
                    343: This manual was written by
                    344: .An Ingo Schwarze Aq Mt schwarze@openbsd.org .

CVSweb