doctools:...port::json(3tcl)
π doctools::toc::import::json β the JSON import plugin π
okay so bestie, welcome to the 3tcl manual page for doctools::toc::import::json β it's part of the Documentation tools, and it's genuinely such a specific little guy. let's get into it π«Ά
β¨ NAME β¨
doctools::toc::import::json β the JSON import plugin. that's it, that's the whole name, and it ate π
πΈ 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. the requirements are requirement-ing. no cap β¨
π¦ DESCRIPTION π¦
This package implements the doctools table of contents import plugin for the parsing of JSON markup. it literally exists to read JSON and turn it into a ToC, that's the whole job, and it does it flawlessly π₯
So here's the tea: this is an internal package of doctools. It's for use by the higher level management packages handling tables of contents β especially doctools::toc::import, the import manager. iykyk.
π not me warning you about this: using it from a regular interpreter is possible, however only with contortions, and it is not recommended. The proper way to use this functionality is through the package doctools::toc::import and the import manager objects it provides. so like. do that instead bestie, please, for me π
π API π
The API provided by this package satisfies the specification of the doctoc import plugin API version 2. slay, spec-compliant, we love to see it β
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 (a dictionary). The result of the command is the canonical serialization of that table of contents, in the form specified in section ToC serialization format. like it just hands you back the glow-up version of your ToC π
π JSON NOTATION OF TABLES OF CONTENTS π
The JSON format used for tables of contents is a direct translation of the ToC serialization format, mapping Tcl dictionaries as JSON objects and Tcl lists as JSON arrays. so it's giving "same energy, different syntax" β¨
For example, the 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 ToC, two outfits. iconic π
π§ 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 a lil freeze-frame of your ToC, forever, no editing π
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 there's always That One Version that's 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. (yes bestie, two ways of saying the same thing, that's just how it is π)
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, labels have to be unique, that's the vibe check π¨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 as before, fr fr π«Ά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 divisions 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. sorted. orderly. perfectionist behavior, and honestly? valid π
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. (they said it, not me, but they're being real about it π)
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. bestie they want your thoughts, drop them in the tracker π
When proposing code changes, please provide unified diffs, i.e the output of diff -u. no vibe-based patches please, we need the actual 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. like, the left-most one. go click it π―
π₯ 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 that's the whole page bestie, you're fully caught up π«Ά this was tcllib, version 0.2.1, of the doctools:...port::json(3tcl) page β go forth and import some JSON, you're gonna do amazing πβ¨π
π¦ 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