doctools::t...import::json(n)
π doctools::toc::import::json β the JSON import plugin, bestie edition β¨
okay so you found the manual page for doctools::toc::import::json (that's the n one, Tcl-land π) and honestly? it's giving niche but important. let's get into it π
πΈ NAME πΈ
doctools::toc::import::json β literally the JSON import plugin. that's the whole vibe. no cap.
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require doctools::toc::import::json ?0.2.1?
package require doctools::toc::structure
package require json
import string configuration
like, yes, that's four package require lines and then a bare import command sitting there being mysterious. we'll get to it π«Ά
π DESCRIPTION π
so this package is the doctools table of contents import plugin for parsing JSON markup. that's the job. that's what it does. iconic behavior honestly.
here's the tea though: it's an internal package of doctools. it exists to be used by the higher-level management packages that handle tables of contents β especially doctools::toc::import, the import manager. π
can you use it from a regular interpreter? ...technically yes. but only with contortions, and it is not recommended. like, you'd be fighting the whole design. the proper way to use this functionality is through the package doctools::toc::import and the import manager objects it provides. do that instead. please. for me π
π₯ API π₯
the API this package provides satisfies the spec of the doctoc import plugin API version 2. slay.
importstring configuration β this command takes the string and parses it as JSON markup encoding a table of contents, in the context of the specified configuration (which is a dictionary, fyi). and the result? the result of the command is the canonical serialization of that table of contents, in the form specified in section ToC serialization format. so yeah, you give it a string, you get back the canonical thing. periodt. π
π¦ JSON NOTATION OF TABLES OF CONTENTS π¦
okay so the JSON format used for tables of contents is a direct translation of the ToC serialization format. the mapping is:
- Tcl dictionaries β JSON objects
- Tcl lists β JSON arrays
easy. clean. we love a bijection π§
for example, this Tcl serialization:
doctools::toc {
items {
{reference {
desc {DocTools - Tables of Contents}
id introduction.man
label doctools::toc::introduction
}}
{division {
id processing.man
items {
{reference {
desc {doctoc serialization utilities}
id structure.man
label doctools::toc::structure
}}
{reference {
desc {Parsing text in doctoc format}
id parse.man
label doctools::toc::parse
}}
}
label Processing
}}
}
label {Table of Contents}
title TOC
}
is equivalent to the JSON string:
{
"doctools::toc" : {
"items" : [{
"reference" : {
"desc" : "DocTools - Tables of Contents",
"id" : "introduction.man",
"label" : "doctools::toc::introduction"
}
},{
"division" : {
"id" : "processing.man",
"items" : [{
"reference" : {
"desc" : "doctoc serialization utilities",
"id" : "structure.man",
"label" : "doctools::toc::structure"
}
},{
"reference" : {
"desc" : "Parsing text in doctoc format",
"id" : "parse.man",
"label" : "doctools::toc::parse"
}
}],
"label" : "Processing"
}
}],
"label" : "Table of Contents",
"title" : "TOC"
}
}
same thing. different outfit. π
π TOC SERIALIZATION FORMAT π
here's where we specify the format used by the doctools v2 packages to serialize tables of contents as immutable values for transport, comparison, etc. y'know, the boring-but-essential infrastructure stuff.
we distinguish between regular and canonical serializations. a table of contents may have more than one regular serialization β but only exactly one of them will be canonical. only one. 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 (fancy!) 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 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. β οΈ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 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.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 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 π’
π« 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.
and that's it. that's the whole constraint. one line. absolute queen behavior β¨
π BUGS, IDEAS, FEEDBACK π
ngl, this document β and the package it describes β will undoubtedly contain bugs and other problems. it's software, babes. π
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 the package and/or the documentation. we want them fr fr π«Ά
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, that specific button. that one. π
π KEYWORDS π
JSON, deserialization, doctools, import, table of contents, toc
πΈ CATEGORY πΈ
Text formatter plugin
π COPYRIGHT π
Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay bestie that's the whole page π this one's brought to you by tcllib, version 0.2.1, and it lives under doctools::t...import::json(n) β now go use doctools::toc::import like a normal person and stop trying to call the internal package directly π π¦ β¨
π¦ 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