doctools::toc::export(n)
π doctools::toc::export β from the Documentation tools manual, section (n) π
NAME β¨
doctools::toc::export β exporting tables of contents π
SYNOPSIS πΈ
package require doctools::toc::export ?0.2.2?
package require Tcl 8.5 9
package require struct::map
package require doctools::toc::structure
package require snit
package require pluginmgr
::doctools::toc::export objectName
objectName method ?arg arg ...?
objectName destroy
objectName export serial serial ?format?
objectName export object object ?format?
objectName config names
objectName config get
objectName config set name ?value?
objectName config unset pattern...
export serial configuration
DESCRIPTION π«
okay bestie, so this package hands you a class that manages the plugins for exporting tables of contents into other formats β as in, converting a ToC into stuff like doctoc, HTML, etc. iconic behaviour, no notes π
This is one of the three public pillars that all the table-of-contents management sits on. The other two pillars are:
- Importing tables of contents, and
- Holding tables of contents
Want the tea on the Concepts of tables of contents and all their little parts? That's the same-named section below π. And if you wanna know about the data structure that's the major input to the manager objects this package gives you, go read the section ToC serialization format.
The plugin system in our class is built on the package pluginmgr, and it's configured to go looking for plugins using:
- the environment variable
DOCTOOLS_TOC_EXPORT_PLUGINS, - the environment variable
DOCTOOLS_TOC_PLUGINS, - the environment variable
DOCTOOLS_PLUGINS, - the path
~/.doctools/toc/export/plugin - the path
~/.doctools/toc/plugin - the path
~/.doctools/plugin - the path
~/.doctools/toc/export/plugins - the path
~/.doctools/toc/plugins - the path
~/.doctools/plugins - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\EXPORT\PLUGINS" - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\PLUGINS" - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\PLUGINS"
heads up: those last three are only used when the package is running on a machine with a Windows(tm) operating system. so, like, not your problem on a macbook, bestie π
The whole system ships with six predefined export plugins, namely:
doctocβ See doctoc export plugin for details.htmlβ See html export plugin for details.jsonβ See json export plugin for details.nroffβ See nroff export plugin for details.textβ See text export plugin for details.wikiβ See wiki export plugin for details.
And if you're a reader who wants to write your own export plugin for some format β hello, plugin writer, main character energy π β then reading and actually understanding the section containing the Export plugin API v2 reference is an absolute necessity. it spells out the interaction between this package and its plugins in detail, so likeβ¦ don't skip it fr fr π
CONCEPTS π¦
- 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 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.
API π
PACKAGE COMMANDS π
::doctools::toc::export objectNameβ this command creates a brand-new export manager object, and it comes with an associated Tcl command whose name is objectName. That object command gets explained in full detail in the sections Object command and Object methods. The object command gets created under the current namespace if objectName isn't fully qualified, and in the specified namespace otherwise. slay β¨
OBJECT COMMAND π
Every single object created by the ::doctools::toc::export command has this general form:
objectName method ?arg arg ...?
- The method method and its arg'uments determine the exact behavior of the command. Peep the section Object methods for the detailed specifications.
OBJECT METHODS π
objectName destroyβ this method destroys the object it's invoked for. bye bestie πobjectName export serial serial ?format?β this method takes the canonical serialization of a table of contents stored in serial and converts it to the specified format, using the export plugin for that format. An error is thrown if no plugin could be found for the format. The string generated by the conversion process gets returned as the result of this method.- If no format is specified, the method defaults to
doctoc. - The specification of what a canonical serialization is can be found in the section ToC serialization format.
- The plugin has to conform to the interface specified in section Export plugin API v2 reference.
- If no format is specified, the method defaults to
objectName export object object ?format?β this method is a convenient little wrapper around theexport serialmethod described by the previous item. It expects that object is an object command supporting aserializemethod returning the canonical serialization of a table of contents. It invokes that method, feeds the result intoexport serial, and returns the resulting string as its own result. lowkey genius π§objectName config namesβ this method returns a list containing the names of all configuration variables currently known to the object.objectName config getβ this method returns a dictionary containing the names and values of all configuration variables currently known to the object.objectName config set name ?value?β this method sets the configuration variable name to the specified value and returns the new value of the variable.- If no value is specified it simply returns the current value, without changing it.
- > note: while the user can set the predefined configuration variables
userandformat, doing so will have no effect β these values will be internally overridden when invoking an import plugin. so don't waste your time, bestie π
objectName config unset pattern...β this method unsets all configuration variables matching the specified glob patterns. If no pattern is specified it will unset all currently defined configuration variables. gone. deleted. periodt π
EXPORT PLUGIN API V2 REFERENCE π₯
Plugins are what this package uses to manage the support for any output format beyond the ToC serialization format. Here we specify the API that the objects created by this package use to interact with their plugins. iykyk π
A plugin for this package has to follow the rules listed below:
- A plugin is a package.
- The name of a plugin package has the form
doctools::toc::export::FOO, whereFOOis the name of the format the plugin will generate output for. This name is also the argument to provide to the variousexportmethods of export manager objects to get a string encoding a table of contents in that format. - The plugin can expect that the package
doctools::toc::export::pluginis present, as indicator that it was invoked from a genuine plugin manager. - A plugin has to provide one command, with the signature shown below.
export serial configuration
- Whenever an export manager of
doctools::tochas to generate output for a table of contents it will invoke this command. string serialβ this argument will contain the canonical serialization of the table of contents for which to generate the output. The specification of what a canonical serialization is can be found in the section ToC serialization format.dictionary configurationβ this argument will contain the current configuration to apply to the generation, as a dictionary mapping from variable names to values.- The following configuration variables have a predefined meaning all plugins have to obey, although they can ignore this information at their discretion. Any other configuration variables recognized by a plugin will be described in the manpage for that plugin.
userβ this variable is expected to contain the name of the user owning the process invoking the plugin.formatβ this variable is expected to contain the name of the format whose plugin is invoked.fileβ this variable, if defined by the user of the table object, is expected to contain the name of the input file for which the plugin is generating its output for.mapβ this variable, if defined by the user of the table object, is expected to contain a dictionary mapping from symbolic document ids used in the table entries to actual paths (or urls). A plugin has to be able to handle the possibility that a document id is without entry in this mapping. π«Ά
- A single usage cycle of a plugin consists of the invokations of the command
export. This call has to leave the plugin in a state where another usage cycle can be run without problems.
π TOC SERIALIZATION FORMAT π
okay so this is where we spill the tea on the actual format the doctools v2 packages use to serialize tables of contents as immutable values, so they can be shipped around, compared, all that. β¨
we got two flavors here: regular serializations and canonical ones. a table of contents can have more than one regular serialization (she contains multitudes π ), but exactly one of them is the canonical one. one. singular. iconic.
π regular serialization π
- The serialization of any table of contents is a nested Tcl dictionary. yes bestie, it's dictionaries all the way down π«Ά
- This dictionary holds a single key,
doctools::toc, and its value. That 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
titleβ the value is a string containing the title of the table of contents.labelβ the value is a string containing a label for the table of contents.itemsβ 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. Another way to think about it: it's a Tcl dictionary holding a single key, the item type, mapped to the item description.
The two legal item types and their descriptions are
referenceβ 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 areidβ the value is a string containing the id of the document associated with the entry.labelβ 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. π¨ no duplicates, we do NOT do that here.descβ the value is a string containing a longer description for this entry.
divisionβ this item describes a group of entries in the table of contents, inducing a hierarchy of entries. so yes, nesting. matryoshka doll energy πͺ 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 areidβ the value is a string containing the id of the document associated with the whole group. This key is optional. optional bestie, she can ghost if she wants πlabelβ 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. same rule as before, no cap.itemsβ 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 keyworditemsused to describe the whole table of contents, see above. And that closes the recursive definition of the structure, with divisions holding the same type of elements as the whole table of contents, including other divisions. π it's turtles all the way down fr fr.
π¦ canonical serialization π¦
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. sorted, bestie. alphabetized. the way that every nested dictionary got its whole life together πβ¨
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. like, obviously. it's software. Please report such in the category doctools of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation. we love ideas, we're nosy, tell us everything π
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. π that one. the left-most one. don't make me say it again.
π KEYWORDS π
HTML, conversion, doctoc, documentation, export, formatting, generation, json, manpage, markup, nroff, plugin, reference, table, table of contents, tcler's wiki, text, url, wiki
π CATEGORY π
Documentation tools
π COPYRIGHT π
Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's a wrap bestie!! πΈ this whole thing came to you from tcllib, version 0.2.2, and it's the doctools::toc::export(n) page β date stamp and all, right there in the footer like a little signature. go forth and serialize responsibly. mwah ππ
β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms