Module:TOCstyle/doc

&#160;DRAFT

This template/module is far from being mature but aspires to become a standard means of building a table of contents suitable for use on WikiSource. Please note bugs/shortcomings/suggestions on the talk page.

Parameters
Enabling any of the five following flags causes generation of part of the output HTML to be suppressed. Specifically choosing either or  affects the operation of other parameters and will entirely disable the effect of, ,  or. In practice there is normally a related present which may be used to host any such orphaned specifications. The following parameters affect all output rows which involve any kind of variable leader, with the exception that the "CD.P" model selected leader pattern preempts :
 * Page&#x3A; space output control
 * : if set to any value (typically 'yes'), generates HTML usable as first page in set of multiple pages.
 * : if set to any value (typically 'yes'), generates HTML usable as middle (i.e. not first nor last) page in set of multiple pages.
 * : if set to any value (typically 'yes'), generates HTML usable as last page in set of multiple pages.
 * : if set to any value (typically 'yes'), generates HTML usable in header region of Page: in order to continue table of contents commenced on a prior page to this one.
 * : if set to any value (typically 'yes'), generates HTML usable in footer region of Page: in order to continue table of contents terminating on a successive page to this one.
 * Overall effect
 * : may be set to one of a number of standard mnemonic values (detailed below) intended to suggest a layout desired to be applied to each "row" of the generated table of contents. If no choice made model "D" (described below) is automatically applied.
 * : Name space prefix to be treated as equivalent to 'Page' when producing HTML which normally would not be available for transclusion (mainly affects page-crossing constructs e.g. the '/s', '/c' and '/e' model variants and page-ribbon effects.)
 * : User-specified class name(s) to be applied to the overall &lt;div&gt; which wraps output.
 * : User-specified CSS style directives to be applied to the overall &lt;div&gt; which wraps output.
 * One useful application might be to apply  which results in a block-centred TOC whose width automatically adapts to accommodate the longest internal row (only noticeable if all TOC items are relatively compact.)
 * : Preselect self-sizing centred output per above note on.
 * : Overall width limitation to be applied to output (if specified, automatic margin centring will be applied. The default is to utilise all available container width.)
 * : On models which make use of this, provides a user-specifiable hanging-indent factor. Default is 5em.
 * : On models which make use of this, provides a user-specifiable padding width. Default is 1em.
 * : On models which make use of this, provides a user-specifiable chapter width. Default is 5em.
 * : On models which make use of this, provides a user-specifiable page width. Default is 2em.
 * Leader Control
 * : a single or short sequence of symbols which will be repeated to form the leader. Default: period ".".
 * : repetition factor used by above. Reducing this from the default may materially assist in reducing "template include size" borderline cases, at the cost of catering for wide output screen widths. A rule-of-thumb for calculating a usable minimum value would be to divide the widest possible presentation width $$W$$ by the sum of the rendered width of a single instance of  ($$S_y$$: the default period "." is approximately 4px) and the value of  ($$S_p$$) viz. $$\scriptstyle{\frac{W}{S_y+S_p}}$$, and add a safety margin (say 10%). For example if  is set to 400px and other parameters left at their respective default values, setting this parameter to 55 (or better 60) ought to be adequate. Default: 384.
 * : Inter-symbol spacing to be applied across width of leader. Default: 4px.
 * (alias ): Background colour choice for descriptive text immediately preceding leader. Default: white.
 * Affects a single output row only
 * : as for above but affects the choice of layout specified for one row only.
 * : this row of output displays only in the 'Page' namespace (or any other name space nominated via .) This permits, for example column headings to appear on each individual page whilst not rendering into the final transclusion. This parameter is a flag (i.e. not a model) and can only be usefully set to a value such as "true" or "yes" in order to influence the interpretation of the model chosen for this row by other means.
 * : additional CSS styling to apply to a particular row. Typically used for indenting, e.g.
 * Affects multiple rows at once
 * : as for above but affects the choice of layout specified for every row between rows S and E inclusive. The selection is subordinate to  but overrules . An alternate format  is recognised without deterministic precedence. You were warned!
 * : as for . Subordinate to . Alternate format is recognised with similar provisos to above.
 * : macro form. Subordinate to . Alternate format is recognised with similar provisos to above.
 * : as for above but affects the choice of layout specified for every row nominated. The selection is subordinate to  but overrules  should their zones of influence overlap.
 * : as for . Subordinate to but may overrule  in cases of apparent conflict.
 * : as for . Subordinate to but may overrule  in cases of apparent conflict.
 * Of technical interest only
 * : dump content of entire LUA argument hash table into top of generated HTLM stream. This is desperate stuff: once experienced you will never be able to unsee the awful truth.

Available 'models'

 * D:("Description") default choice. Output row is constructed from a single unformatted item.
 * DP:("Description with Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an unformatted description and the latter as right-lower-aligned.
 * H5P:("Wide Hanging with Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an wide hanging indented description (field intended to align with CDP entries; overlapping Chapter region) and the latter as a right-lower-aligned page reference.
 * 2H3P:("Indented Hanging with Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an indented hanging indented description (field intended to align with CDP entries; overlapping Chapter region but with left margin offset) and the latter as a right-lower-aligned page reference.
 * CDP:("Chapter, Description, Page") Output row is constructed from triples of input fields. The first field is presented as right-aligned within a minimum-width (4em) column, followed by a description field. Finally the third field is presented right-lower-aligned.
 * D.P:("Description, dot-leader, Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an unformatted description and the latter as right-lower-aligned, separated by a variable-length "standard" dot-leader.
 * D?P:("Description, dot-leader-with arbitrary symbol, Page") Output row is constructed from triples of input fields. Within each, the first field is presented as an unformatted description and the third as right-lower-aligned, separated by a variable-length dot-leader composed by repeating the second field multiple times.
 * CD.P:("Chapter, Description, dot-leader, Page") Output row is constructed from triples of input fields. The first field is presented as right-aligned within a minimum-width (4em) column with 1em right-padding, followed by a description field with standard dot-leader trailing. Finally the third field is presented right-lower-aligned.
 * C5D.P:("Chapter, Description, dot-leader, Page") Variant of CD.P without padding following Chapter field; otherwise identical.
 * 2CD.P:("Indented Chapter, Description, dot-leader, Page") Variant of CD.P with inherent 2em indentation applied.
 * CD.P/s: variant of CD.P. Initial fragment to be continued on next page.
 * CD.P/e: Completion of fragment commenced by CD.P/s.
 * CH2.P:("Chapter, Large-hanging-indented description, dot-leader, Page") Output row is constructed from triples of input fields. The first field is presented as right-aligned within a minimum-width (4em) column, followed by a description field with 2em hanging indent and standard dot-leader trailing. Finally the third field is presented right-lower-aligned.
 * mCHn.pP:("Generalised-depth/width" variant) of CH2.P above. Associated with, and.
 * mCHn.upP:("Undercut page number" variant) of mCHn.pP above, and similarly associated with, and.
 * CD.uP:("Chapter, Description, dot-leader, undercut Page") Output row is constructed from triples of input fields. The first field is presented as right-aligned within a minimum-width (4em) column with 1em right-padding, followed by a description field with standard dot-leader trailing. Finally the third field is presented right-lower-aligned, undercut into the final line.
 * H5.P:("Wide Hanging with dot-lead Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an wide hanging indented description (field intended to align with CDP entries; overlapping Chapter region) and the latter as a leader-introduced right-lower-aligned page reference.
 * Hn.P:("Generalised-depth" variant) of H5.P above. Associated with.
 * Hn.upP:("Generalised-page width" undercut variant) of Hn.P above. Associated with and.
 * 2H3.P:("Indented Hanging with dot-lead Page") Output row is constructed from pairs of input fields. Within each pair the first field is presented as an indented hanging indented description (field intended to align with CDP entries; overlapping Chapter region but with left margin offset) and the latter as a right-lower-aligned dot-lead page reference. (N.B. there is currently an inherent weakness in the implementation of this model: descriptions which render on a single line may suffer blanking of initial characters. This needs to be addressed.)
 * 2H3P/s:("Indented Hanging Indent initial page crossing section") Build TOC fragment per 2H3P above but with expectation the fragment will continue on a later Page. (Differing HTML is constructed for demonstration and presentation name spaces.)
 * 2H3P/e:("Indented Hanging Indent terminal page crossing section") Continuation of TOC fragment commenced by 2H3P/s. (Differing HTML is constructed for demonstration and presentation name spaces.)
 * lcr:("left-centred-right") Output row is constructed from triples of input fields in a fashion reminiscent of running header with three parameters specified.
 * lccr:("left-centred-right") Output row is constructed from triples of input fields in a fashion reminiscent of running header with four parameters specified.
 * lcccr:("left-centred-right") Output row is constructed from triples of input fields in a fashion reminiscent of running header with five parameters specified.
 * c:("center") Output row is constructed from single field, centred.
 * h:("hanging") Output row is constructed from single field with short hanging indent applied.
 * 7h2:("indented hanging") Output row is constructed from single field with indent and clearances from both Chapter and Page columns when used in close association with (for example) CDP model lines.
 * j:("justify") Output row is constructed from single field, justified.
 * l:("left") Output row is constructed from single unformatted fields.
 * r:("right") Output row is constructed from single field, right-aligned.
 * lr:("left-right") Output row is constructed from pairs of input fields in a fashion reminiscent of running header with the "center" parameter omitted. (Degenerate form of model "lcr".)

The above list is all the models currently implemented and is intended to be expanded as cases/suggestions arise. See ahead. Detection of unusable models will result in the entire table being replaced by an error message.

Limitations

 * Owing to the complexity of the code generated by this template, it should not be used over an extended range of Page: if leader based models are used. (such as D.P, CD.P etc). If used for content such as an index,  then that index will need to be sectionalised (typically by inital letter) in transclusion.

Some notes on internals
It is hoped that the internal LUA code will be reasonably simple to augment. Any variable named with suffix &hellip; contains opening and closing HTML strings applicable to a given situation. For example  holds HTML specific to header- and footer- use and is used to "wrap" the entire output. holds a structure keyed upon model names. Within each element there are sub-elements to indicate how many fields a single output row will consume under this model, and the name of a routine and its parameters required to format that row.