doctools::toc::import(3tcl)
π doctools::toc::import π
okay bestie, buckle UP, because this is the manual page for doctools::toc::import from the Documentation tools corner of the Tcl universe, aka section 3tcl. it's a long one so we're doing it in chunks π«Ά
β¨ NAME β¨
doctools::toc::import β importing keyword indices π
β¨ SYNOPSIS β¨
package require doctools::toc::import ?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::import objectName
objectName method ?arg arg ...?
objectName destroy
objectName import text text ?format?
objectName import file path ?format?
objectName import object text object text ?format?
objectName import object file object path ?format?
objectName config names
objectName config get
objectName config set name ?value?
objectName config unset pattern...
objectName includes
objectName include add path
objectName include remove path
objectName include clear
IncludeFile currentfile path
import text configuration
like, look at all that. so many little entry points. it's giving menu of possibilities π
πΈ DESCRIPTION πΈ
so this package hands you a class that manages the plugins for importing tables of contents from other formats β meaning it converts them from stuff like doctoc, json, etc. into the good stuff.
this is one of the three public pillars that table-of-contents management stands on. the other two besties are:
- Exporting tables of contents, and
- Holding tables of contents
want the lore on what tables of contents actually are and what their parts are called? that's the same-named section, go look π. and for the data structure that's basically the whole point of the manager objects this package gives you, check the section ToC serialization format.
the plugin system of our class is built on the package pluginmgr, and it's configured to go hunting for plugins using:
- the environment variable
DOCTOOLS_TOC_IMPORT_PLUGINS, - the environment variable
DOCTOOLS_TOC_PLUGINS, - the environment variable
DOCTOOLS_PLUGINS, - the path
"~/.doctools/toc/import/plugin" - the path
"~/.doctools/toc/plugin" - the path
"~/.doctools/plugin" - the path
"~/.doctools/toc/import/plugins" - the path
"~/.doctools/toc/plugins" - the path
"~/.doctools/plugins" - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\IMPORT\PLUGINS" - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\PLUGINS" - the registry entry
"HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\PLUGINS"
the last three only get used when this package is running on a machine with the Windows(tm) operating system. so if you're on Linux, items 10-12 are just sitting there, decorative, iconic but unemployed π
the whole system ships with two predefined import plugins, namely:
doctocβ see doctoc import plugin for details.jsonβ see json import plugin for details.
and if you're the kind of person who wants to write their own import plugin for some format? first of all, main character energy π. second of all, reading and understanding the section containing the Import plugin API v2 reference is an absolute necessity β it spells out the interaction between this package and its plugins in full detail. no skipping, 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::import objectNameβ this command creates a brand new import manager object, and that object comes with a Tcl command attached whose name isobjectName. the full tea on that object command lives in the sections Object command and Object methods. heads up on the naming: ifobjectNameisn't fully qualified, the object command gets created under the current namespace, and if it is fully qualified, it lands in whatever namespace you specified. β¨
OBJECT COMMAND
every object made by the ::doctools::toc::import command has this general shape:
objectName method ?arg arg ...?β the methodmethodand its arg'uments decide exactly what the command does. see section Object methods for the nitty-gritty specs.
OBJECT METHODS
objectName destroyβ this method destroys the object it's invoked for. bye bestie πobjectName import text text ?format?β takes thetextand converts it from the specifiedformatinto the canonical serialization of a table of contents, using the import plugin for that format. if no plugin can be found for the format, it throws an error. the serialization produced by the conversion comes back as the result of this method. π
if you don't specify a format, the method defaults to doctoc.
what "canonical serialization" even means is spelled out in the section ToC serialization format.
and the plugin has to conform to the interface specified in section Import plugin API v2 reference. no freelancing.
objectName import file path ?format?β this one is a cozy little wrapper around theimport textmethod from the item above. it reads the contents of the file atpathinto memory, feeds the result intoimport text, and returns the resulting serialization as its own result. πobjectName import object text object text ?format?β another wrapper aroundimport text, same deal. it expectsobjectto be an object command that supports adeserializemethod expecting the canonical serialization of a table of contents. it imports thetextusingimport text, then feeds the resulting serialization into the object viadeserialize. this method returns the empty string as its result.objectName import object file object path ?format?β behaves just likeimport object text, except it reads the text to convert from the specified file instead of getting it handed to it as an argument. ποΈobjectName config namesβ returns a list containing the names of all configuration variables currently known to the object.objectName config getβ returns a dictionary containing the names and values of all configuration variables currently known to the object. πobjectName config set name ?value?β sets the configuration variablenameto the specifiedvalue, and returns the new value of the variable.
if you don't give a value, it just returns the current value and changes absolutely nothing. no touchy.
okay important: the user can set the predefined configuration variablesuserandformat, but doing so has no effect β those values get internally overridden when an import plugin is invoked. so like, don't bother. π
objectName config unset pattern...β unsets every configuration variable matching the specified glob patterns. if you give no pattern at all, it unsets all currently defined configuration variables. scorched earth, slay.objectName includesβ returns a list containing the currently specified paths used to search for include files when processing input. the order of the paths in the list matches the order they're used in, first to last, and it also matches the order they were added to the object. πΈobjectName include add pathβ adds the specifiedpathto the list of paths to search for include files when processing input. it goes at the end of the list, so it gets searched after every path added before it. the result of the command is the empty string.
if the path is already known, the method does nothing. we don't do duplicates here.
objectName include remove pathβ removes the specifiedpathfrom the list of paths to search for include files when processing input. the result of the command is the empty string.
if the path isn't known, the method does nothing. no drama, no error.
objectName include clearβ clears the whole list of paths used to search for include files when processing input. the result of the command is the empty string. poof, gone β¨
and bestie, that is genuinely only the beginning β there's way more of this page coming π
β¨ IMPORT PLUGIN API V2 REFERENCE β¨
Okay so plugins are literally the whole personality of this package when it comes to handling any input format that isn't the ToC serialization format. Below is the API that the objects this package creates use to talk to their plugins. Bestie, if you're writing a plugin, this is your blueprint π
A plugin for this package has to follow the rules listed below:
- A plugin is a package. no cap.
- The name of a plugin package has the form
doctools::toc::import::FOO, whereFOOis the name of the format the plugin will generate output for. This name is also the argument you hand over to the various import methods of import 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 β it's basically the little "yes this is a genuine plugin manager, not a scam" badge. π - The plugin can expect that a command named
IncludeFileis present, with the signature
IncludeFile currentfile path
This command has to be invoked by the plugin when it has to process an included file, if the format has the concept of such. An example of such a format would be doctoc. π¦
The plugin has to supply the following arguments
string currentfileβ the path of the file it is currently processing. This may be the empty string if no such is known.string pathβ the path of the include file as specified in the include directive being processed.
The result of the command will be a 5-element list containing
- A boolean flag indicating the success (
True) or failure (False) of the operation. - In case of success the contents of the included file, and the empty string otherwise.
- The resolved, i.e. absolute path of the included file, if possible, or the unchanged path argument. This is for display in an error message, or as the
currentfileargument of another call toIncludeFileshould this file contain more files. π«Ά - In case of success an empty string, and for failure a code indicating the reason for it, one of
notfoundβ the specified file could not be found.notreadβ the specified file was found, but not be read into memory.
- An empty string in case of success of a
notfoundfailure, and an additional error message describing the reason for anotreaderror in more detail.
- A plugin has to provide one command, with the signature shown below.
import text configuration
Whenever an import manager of doctools::toc has to parse input for a table of contents it will invoke this command.
string textβ this argument will contain the text encoding the table of contents per the format the plugin is for.dictionary configurationβ this argument will contain the current configuration to apply to the parsing, 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 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.
- A single usage cycle of a plugin consists of the invokations of the command
import. This call has to leave the plugin in a state where another usage cycle can be run without problems. Like, clean up after yourself bestie, leave the plugin fresh for round two. β¨
π TOC SERIALIZATION FORMAT π
Here we specify the format used by the doctools v2 packages to serialize tables of contents as immutable values for transport, comparison, etc. Fr fr, it's giving "frozen in time so nothing can mess with it" energy. π§
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 canonical one is the main character. π
π regular serialization π
- 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
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. 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
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. π― So like, every label in that list has to be unique β no twinning, periodt.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. 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.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, still no duplicates.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. This 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 bestie, divisions inside divisions inside divisions.
β¨ 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.
π BUGS, IDEAS, FEEDBACK π
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 [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
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. π«Ά (yes, the left-most one. it's right there. you got this.)
π KEYWORDS π
conversion, doctoc, documentation, import, json, manpage, markup, parsing, plugin, reference, table, table of contents, url
π CATEGORY π
Documentation tools
β¨ COPYRIGHT β¨
okay bestie, legal moment, but make it cute π this whole page is somebody's actual work and we're gonna respect it:
Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>
that's it, that's the vibe β Andreas Kupries held it down from 2009 all the way to 2019, and honestly? iconic π
and that's a wrap on doctools::toc::import, bestie π you made it to the end, I'm so proud, this was a long one and you ate it fr fr π
this lil gem lives in tcllib, version 0.2.2, page doctools::toc::import(3tcl) β go forth, import your tables of contents, and slay π¦β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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