doctools::toc::import(n)
πΈ doctools::toc::import πΈ
okay bestie, welcome to the doctools::toc::import(n) page β yes it's from the Documentation tools manual, and yes it's a lot, but we're gonna get through it together π
β¨ 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
π« DESCRIPTION π«
So this package hands you a class that manages the plugins for importing tables of contents from other formats β like, converting them from stuff such as doctoc, json, etc. it's giving translator energy β¨
This is one of the three public pillars that the whole management of tables of contents sits on. The other two pillars are:
- Exporting tables of contents, and
- Holding tables of contents
Wanna know about the Concepts of tables of contents, and all their little parts? Go look at the same-named section. And if you want the tea on the data structure that's the major output of the manager objects this package gives you, hit up the section ToC serialization format π¦
The plugin system of our class is built on the pluginmgr package, and it's configured to look 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? those are only used when the package is run on a machine using the Windows(tm) operating system. not us on a Tuesday, but okay π
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 a reader who wants to write their own import plugin for some format? i.e. you're a plugin writer? Then reading and understanding the section containing the Import plugin API v2 reference is an absolute necessity, bestie β no skimming β because it specifies the interaction between this package and its plugins in detail π
π 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 new import manager object with an associated Tcl command whose name is objectName. That 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. slay π
π§ OBJECT COMMAND π§
All objects created by the ::doctools::toc::import command have the following general form:
objectName method ?arg arg ...?
The method method and its arg'uments determine the exact behavior of the command. See section Object methods for the detailed specifications.
π OBJECT METHODS π
objectName destroy
This method destroys the object it is invoked for. bye bestie π«Ά
objectName import text text ?format?
This method takes the text and converts it from the specified format to the canonical serialization of a table of contents using the import plugin for the format. An error is thrown if no plugin could be found for the format. The serialization generated by the conversion process is 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 Import plugin API v2 reference.
objectName import file path ?format?
This method is a convenient wrapper around the import text method described by the previous item. It reads the contents of the specified file into memory, feeds the result into import text and returns the resulting serialization as its own result. π
objectName import object text object text ?format?
This method is a convenient wrapper around the import text method described by the previous item. It expects that object is an object command supporting a deserialize method expecting the canonical serialization of a table of contents. It imports the text using import text and then feeds the resulting serialization into the object via deserialize. This method returns the empty string as it result.
objectName import object file object path ?format?
This method behaves like import object text, except that it reads the text to convert from the specified file instead of being given it as argument.
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 that while the user can set the predefined configuration variablesuserandformat, doing so will have no effect β these values will be internally overridden when invoking an import plugin. it's giving "you can try but the system said no" π
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.
objectName includes
This method returns a list containing the currently specified paths to use to search for include files when processing input. The order of paths in the list corresponds to the order in which they are used, from first to last, and also corresponds to the order in which they were added to the object. π¦
objectName include add path
This methods adds the specified path to the list of paths to use to search for include files when processing input. The path is added to the end of the list, causing it to be searched after all previously added paths. The result of the command is the empty string.
The method does nothing if the path is already known.
objectName include remove path
This methods removes the specified path from the list of paths to use to search for include files when processing input. The result of the command is the empty string.
The method does nothing if the path is not known.
objectName include clear
This method clears the list of paths to use to search for include files when processing input. The result of the command is the empty string. π§Ήβ¨
β¨ IMPORT PLUGIN API V2 REFERENCE β¨
okay bestie, so plugins are literally the whole reason this package can handle any input format that isn't the ToC serialization format. Here we specify the API that the objects created by this package use to interact with their plugins. No cap, this is the vibe.
A plugin for this package has to follow the rules listed below:
- A plugin is a package. periodt. π
- 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 to provide to the various import methods of import manager objects to get a string encoding a table of contents in that format. soFOOis basically the plugin's whole identity. β¨ - The plugin can expect that the package
doctools::toc::export::pluginis present, as indicator that it was invoked from a genuine plugin manager. like a secret handshake, but for code. π€ - 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. yes, doctoc is that girl. π
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. so if you don't know, just""and move on. πstring pathβ the path of the include file as specified in the include directive being processed. the literal path, no edits.
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. true = slay, false = not slay. π₯ - In case of success the contents of the included file, and the empty string otherwise. so either the tea or nothing. β
- The resolved, i.e. absolute path of the included file, if possible, or the unchanged
pathargument. This is for display in an error message, or as thecurrentfileargument of another call toIncludeFileshould this file contain more files. nested includes? we love a recursive moment. π - 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. she's missing, bestie. πnotreadβ the specified file was found, but not be read into memory. like, found her but she's not opening up. π
- An empty string in case of success of a
notfoundfailure, and an additional error message describing the reason for anotreaderror in more detail. yes, that's exactly what it says. π
- 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. so this is the main character command, for real. π
string textβ this argument will contain the text encoding the table of contents per the format the plugin is for. the raw data, the material. πdictionary configurationβ this argument will contain the current configuration to apply to the parsing, as a dictionary mapping from variable names to values. it's giving settings, but make it Tcl. π§
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. (yes, "other other" β we keep it exactly as the original, no editing the lore.)
userβ this variable is expected to contain the name of the user owning the process invoking the plugin. who dis? πformatβ this variable is expected to contain the name of the format whose plugin is invoked. like, what format are we in? π
- 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. so clean up after yourself, bestie. no messy plugin energy. β¨
π 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. like, turning your ToC into a little portable snack that never changes. π
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. so regular is giving options, canonical is the one true queen. π
regular serialization
- The serialization of any table of contents is a nested Tcl dictionary. nested? we love layers. π§
- 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. the name of the whole vibe.labelβ the value is a string containing a label for the table of contents. a little tag, a little name tag. π·οΈitemsβ the value is a Tcl list holding the elements of the table, in the order they are to be shown. order matters, bestie. no chaos.
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. either way, it's a little package. π
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 anidfor the referenced document, alabel, and a longer textual description which can be associated with the entry. The relevant keys and their values are:idβ 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 no duplicate labels, that's the rule. π«descβ the value is a string containing a longer description for this entry. the yapping section, if you will. π
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 alabelfor the group, an optionalidto a document for the whole group, and the list of entries in the group. The relevant keys and their values are:idβ the value is a string containing the id of the document associated with the whole group. This key is optional. optional? she's flexible. π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. again, no duplicates. periodt.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 recusrive definition of the structure, with divisions holding the same type of elements as the whole table of contents, including other divisions. yes, it's recursive. divisions in divisions in divisions. it's giving inception. π
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. so it's the one and only, no competition. π
- 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 = organized = slay. β¨
π 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 at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation. like, if you find a bug, tell them. if you have a glow-up idea, also tell them. we listen. π«Ά
When proposing code changes, please provide unified diffs, i.e the output of diff -u. no vibes-based patches, bestie. show the diff.
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. so attach that file, don't just paste it in the chat. π
π KEYWORDS π
conversion, doctoc, documentation, import, json, manpage, markup, parsing, plugin, reference, table, table of contents, url
π CATEGORY π
Documentation tools
π COPYRIGHT π
Okay bestie, final section, the legal glow-up β¨ β this whole page is:
- Copyright (c) 2009-2019 Andreas Kupries
<andreas_kupries@users.sourceforge.net>
That's it, that's the whole vibe. Give the man his credit, he earned it π π«Ά
And that's a wrap on doctools::toc::import(n), fr fr πΈ This iconic little page comes to you from tcllib, version 0.2.2, and it lives at section n like the queen it is π
β the date line on this one is just the source/version footer doing its thing, so no extra calendar tea to spill. Go forth, import those tables of contents, and slay π¦β¨
π¦ 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