doctools::toc::export(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ doctools::toc::export ✨

okay bestie, welcome to the doctools::toc::export page, straight out of the Documentation tools manual, section 3tcl πŸ’– this is where tables of contents get shipped out to other formats and it's genuinely iconic. sit down, grab a boba, we're doing this. πŸ§‹


🌸 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 πŸ’…

so basically this package hands you a class that manages all the plugins for exporting tables of contents into other formats β€” like converting them to doctoc, HTML, whatever, the whole glow-up pipeline. ✨

this is one of the three public pillars that the management of tables of contents rests on, no cap. the other two pillars are:

  1. importing tables of contents, and
  2. holding tables of contents 🫢

wanna know about the Concepts of tables of contents and their parts? check out the same-named section, it's right down there. and for the data structure that is the main character input to the manager objects this package gives you, go read the section ToC serialization format. πŸ“–

the plugin system of our class is built on the package pluginmgr, and it's configured to go looking for plugins using:

  1. the environment variable DOCTOOLS_TOC_EXPORT_PLUGINS,
  2. the environment variable DOCTOOLS_TOC_PLUGINS,
  3. the environment variable DOCTOOLS_PLUGINS,
  4. the path ~/.doctools/toc/export/plugin
  5. the path ~/.doctools/toc/plugin
  6. the path ~/.doctools/plugin
  7. the path ~/.doctools/toc/export/plugins
  8. the path ~/.doctools/toc/plugins
  9. the path ~/.doctools/plugins
  10. the registry entry HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\EXPORT\PLUGINS
  11. the registry entry HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\TOC\PLUGINS
  12. the registry entry HKEY_CURRENT_USER\SOFTWARE\DOCTOOLS\PLUGINS
the last three (that's 10, 11 and 12 bestie) are only used when the package is running on a machine with the Windows(tm) operating system. πŸ’€

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 their own export plugin for some format? okay plugin writer, main character energy πŸ‘‘ β€” reading and understanding the section with the Export plugin API v2 reference is an absolute necessity, because it spells out the interaction between this package and its plugins in full detail. periodt.


πŸŽ€ CONCEPTS πŸŽ€

  1. a table of contents consists of a (possibly empty) list of elements.
  2. each element in the list is identified by its label.
  3. each element is either a reference, or a division.
  4. each reference has an associated document, identified by a symbolic id, and a textual description.
  5. each division may have an associated document, identified by a symbolic id.
  6. 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 πŸ“

  1. 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. it's giving family tree but make it documentation. 🌳
  2. 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 itself. πŸ’–

πŸ”₯ API πŸ”₯

🌟 PACKAGE COMMANDS 🌟

  • ::doctools::toc::export objectName β€” this command creates a brand new export 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 (they're right below, don't worry). 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 object created by the ::doctools::toc::export command has the following general form:

  • objectName method ?arg arg ...? β€” the method method and its arg'uments determine the exact behavior of the command. see the section Object methods for the detailed specifications. iykyk. πŸ‘‘

🌈 OBJECT METHODS 🌈

  • objectName destroy β€” this method destroys the object it is 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. if no plugin could be found for the format, an error is thrown. the string 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 the section Export plugin API v2 reference.

  • objectName export object object ?format? β€” this method is a convenient lil wrapper around the export serial method described in the previous item. 🫢 it expects that object is an object command supporting a serialize method returning the canonical serialization of a table of contents. it invokes that method, feeds the result into export serial, and returns the resulting string as its own result. chef's kiss.
  • 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.

heads up: while the user can set the predefined configuration variables user and format, doing so will have no effect β€” these values will be internally overridden when invoking an import plugin. πŸ™ˆ
  • 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. clean slate bestie 🧹

πŸ‘‘ EXPORT PLUGIN API V2 REFERENCE πŸ‘‘

plugins are what this package uses to manage the support for any output format beyond the ToC serialization format. so here we specify the API that the objects created by this package use to interact with their plugins. πŸ¦‹

a plugin for this package has to follow the rules listed below:

  1. a plugin is a package.
  2. the name of a plugin package has the form doctools::toc::export::FOO, where FOO is the name of the format the plugin will generate output for. this name is also the argument to provide to the various export methods of export manager objects to get a string encoding a table of contents in that format. 🎯
  3. the plugin can expect that the package doctools::toc::export::plugin is present, as indicator that it was invoked from a genuine plugin manager. πŸ’…
  4. a plugin has to provide one command, with the signature shown below.
export serial configuration

whenever an export manager of doctools::toc has 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. 🧭
  1. 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. πŸ”

okay so that's the vibe so far bestie, and there's more coming β€” this page is long so it comes in parts, and we are not done yet πŸ’–

🌸 TOC SERIALIZATION FORMAT 🌸

Okay bestie, so here's the tea on how the doctools v2 packages serialize tables of contents into immutable values for transport, comparison, and all that good stuff. πŸ’…

We got two flavors: regular and canonical. A table of contents can have more than one regular serialization, but only exactly one of them will be canonical. periodt. ✨


✨ regular serialization ✨

  1. The serialization of any table of contents is a nested Tcl dictionary. πŸͺΊ
  2. This dictionary holds a single key, doctools::toc, and its value. This value holds the contents of the table of contents.
  3. 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 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.
    • 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 are:
    • id β€” 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.
    • 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 keyword items used 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.

πŸ’– 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. πŸ‘‘

  1. 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. πŸ’…


πŸ”‘ 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 (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>


And that's the whole vibe, bestie. This was tcllib 0.2.2, page doctools::toc::export(3tcl) β€” go forth and serialize those tables of contents like the main character you are. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from