doctools::toc - Holding tables of contents
This package provides a class to contain and programmatically manipulate tables of contents.
This is one of the three public pillars the management of tables of contents resides on. The other two pillars are
Importing tables of contents
For information about the Concepts of tables of contents, and their parts, see the same-named section. For information about the data structure which is used to encode tables of contents as values see the section ToC serialization format. This is the only format directly known to this class. Conversions from and to any other format are handled by export and import manager objects. These may be attached to a container, but do not have to be, it is merely a convenience.
A table of contents consists of a (possibly empty) list of elements.
Each element in the list is identified by its label.
Each element is either a reference, or a division.
Each reference has an associated document, identified by a symbolic id, and a textual description.
Each division may have an associated document, identified by a symbolic id.
Each division consists consists of a (possibly empty) list of elements, with each element following the rules as specified in item 2 and above.
A few notes
The above rules span up a tree of elements, with references as the leaf nodes, and divisions as the inner nodes, and each element representing an entry in the whole table of contents.
The identifying labels of any element E are unique within their division (or toc), and the full label of any element E is the list of labels for all nodes on the unique path from the root of the tree to E, including E.
This command creates a new container object with an associated Tcl command whose name is objectName. This object command is explained in full detail in the sections Object command and Object methods. The object command will be created under the current namespace if the objectName is not fully qualified, and in the specified namespace otherwise.
All objects created by the ::doctools::toc command have the following general form:
The method method and its arg'uments determine the exact behavior of the command. See section Object methods for the detailed specifications.
This method destroys the object it is invoked for.
This method adds a new reference element to the table of contents, under the element specified via its handle id. This parent element has to be a division element, or the root. An error is thrown otherwise. The new element will be externally identified by its label, which has to be be unique within the parent element. An error is thrown otherwise.
As a reference element it will refer to a document identified by the symbolic docid. This reference must not be the empty string, an error is thrown otherwise. Beyond the label the element also has a longer descriptive string, supplied via desc.
The result of the method is the handle (id) of the new element.
This method adds a new division element to the table of contents, under the element specified via its handle id. This parent element has to be a division element, or the root. An error is thrown otherwise. The new element will be externally identified by its label, which has to be be unique within the parent element. An error is thrown otherwise.
As a division element it is can refer to a document, identified by the symbolic docid, but may choose not to.
The result of the method is the handle (id) of the new element.
This method removes the element identified by the handle id from the table of contents. If the element is a division all of its children, if any, are removed as well. The root element/division of the table of contents cannot be removed however, only its children.
The result of the method is the empty string.
This method returns the handle of the parent for the element identified by its handle id, or the empty string if id refered to the root element.
This method returns the handle of the right sibling for the element identified by its handle id, or the handle of the parent if the element has no right sibling, or the empty string if id refered to the root element.
This method returns the handle of the left sibling for the element identified by its handle id, or the handle of the parent if the element has no left sibling, or the empty string if id refered to the root element.
This method returns the handle of a child of the element identified by its handle id. The child itself is identified by a series of labels.
This method returns the handle of the element identified by a series of labels, starting from the root of the table of contents. The series of labels is allowed to be empty, in which case the handle of the root element is returned.
This method returns a list containing the handles of all children of the element identified by the handle id, from first to last, in that order.
This method returns the type of the element, either reference, or division.
This method is the complement of the method element, converting the handle id of an element into a list of labels full identifying the element within the whole table of contents.
This method queries and/or changes the label of the element identified by the handle id. If the argument newlabel is present then the label is changed to that value. Regardless of this, the result of the method is the current value of the label.
If the label is changed the new label has to be unique within the containing division, or an error is thrown.
Further, of the id refers to the root element of the table of contents, then using this method is equivalent to using the method label, i.e. it is accessing the global label for the whole table.
This method queries and/or changes the description of the element identified by the handle id. If the argument newdesc is present then the description is changed to that value. Regardless of this, the result of the method is the current value of the description.
The element this method operates on has to be a reference element, or an error will be thrown.
This method queries and/or changes the document reference of the element identified by the handle id. If the argument newdocid is present then the description is changed to that value. Regardless of this, the result of the method is the current value of the document reference.
Setting the reference to the empty string means unsetting it, and is allowed only for division elements. Conversely, if the result is the empty string then the element has no document reference, and this can happen only for division elements.
Returns the currently defined title of the table of contents.
Sets the title of the table of contents to text, and returns it as the result of the command.
Returns the currently defined label of the table of contents.
Sets the label of the table of contents to text, and returns it as the result of the command.
Returns the import manager object currently attached to the container, if any.
Attaches the object as import manager to the container, and returns it as the result of the command. Note that the object is not put into ownership of the container. I.e., destruction of the container will not destroy the object.
It is expected that object provides a method named import text which takes a text and a format name, and returns the canonical serialization of the table of contents contained in the text, assuming the given format.
Returns the export manager object currently attached to the container, if any.
Attaches the object as export manager to the container, and returns it as the result of the command. Note that the object is not put into ownership of the container. I.e., destruction of the container will not destroy the object.
It is expected that object provides a method named export object which takes the container and a format name, and returns a text encoding table of contents stored in the container, in the given format. It is further expected that the object will use the container's method serialize to obtain the serialization of the table of contents from which to generate the text.
This method replaces the contents of the table object with the table contained in the data. If no format was specified it is assumed to be the regular serialization of a table of contents.
Otherwise the object will use the attached import manager to convert the data from the specified format to a serialization it can handle. In that case an error will be thrown if the container has no import manager attached to it.
The result of the method is the empty string.
This method behaves like deserialize = in its essentials, except that it merges the table of contents in the data to its contents instead of replacing it. The method will throw an error if merging is not possible, i.e. would produce an invalid table. The existing content is left unchanged in that case.
The result of the method is the empty string.
This method returns the table of contents contained in the object. If no format is not specified the returned result is the canonical serialization of its contents.
Otherwise the object will use the attached export manager to convert the data to the specified format. In that case an error will be thrown if the container has no export manager attached to it.
Here we specify the format used by the doctools v2 packages to serialize tables of contents as immutable values for transport, comparison, etc.
We distinguish between regular and canonical serializations. While a table of contents may have more than one regular serialization only exactly one of them will be canonical.
The serialization of any table of contents is a nested Tcl dictionary.
This dictionary holds a single key, doctools::toc, and its value. This value holds the contents of the table of contents.
The contents of the table of contents are a Tcl dictionary holding the title of the table of contents, a label, and its elements. The relevant keys and their values are
The value is a string containing the title of the table of contents.
The value is a string containing a label for the table of contents.
The value is a Tcl list holding the elements of the table, in the order they are to be shown.
Each element is a Tcl list holding the type of the item, and its description, in this order. An alternative description would be that it is a Tcl dictionary holding a single key, the item type, mapped to the item description.
The two legal item types and their descriptions are
This item describes a single entry in the table of contents, referencing a single document. To this end its value is a Tcl dictionary containing an id for the referenced document, a label, and a longer textual description which can be associated with the entry. The relevant keys and their values are
The value is a string containing the id of the document associated with the entry.
The value is a string containing a label for this entry. This string also identifies the entry, and no two entries (references and divisions) in the containing list are allowed to have the same label.
The value is a string containing a longer description for this entry.
This item describes a group of entries in the table of contents, inducing a hierarchy of entries. To this end its value is a Tcl dictionary containing a label for the group, an optional id to a document for the whole group, and the list of entries in the group. The relevant keys and their values are
The value is a string containing the id of the document associated with the whole group. This key is optional.
The value is a string containing a label for the group. This string also identifies the entry, and no two entries (references and divisions) in the containing list are allowed to have the same label.
The value is a Tcl list holding the elements of the group, in the order they are to be shown. This list has the same structure as the value for the keyword items used to describe the whole table of contents, see above. This closes the recusrive definition of the structure, with divisions holding the same type of elements as the whole table of contents, including other divisions.
The canonical serialization of a table of contents has the format as specified in the previous item, and then additionally satisfies the constraints below, which make it unique among all the possible serializations of this table of contents.
The keys found in all the nested Tcl dictionaries are sorted in ascending dictionary order, as generated by Tcl's builtin command lsort -increasing -dict.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category doctools of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.
HTML, TMML, conversion, doctoc markup, documentation, formatting, generation, json, latex, markup, nroff, parsing, plugin, reference, table, table of contents, tcler's wiki, text, wiki
Documentation tools
Copyright © 2009 Andreas Kupries <[email protected]>