doctools::i...export::json(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ NAME ✨

doctools::idx::export::json β€” the JSON export plugin, bestie πŸ’– (that's the n manual, from the tcllib squad, in case you were wondering where this whole thing lives)


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require doctools::idx::export::json ?0.2?

package require textutil::adjust

export serial configuration

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this package is literally the doctools keyword index export plugin, and its whole job is generating JSON markup. that's it, that's the vibe.

it's an internal package of doctools, for use by the higher level management packages that handle keyword indices β€” especially doctools::idx::export, aka the export manager. so like, it's the backstage crew, not the main character πŸ‘‘

and yes, you could use it from a regular interpreter, but only with contortions 😭 and it is not recommended. the proper way to get at this functionality is through the package doctools::idx::export and the export manager objects it provides. periodt.


πŸ’… API πŸ’…

the API this package hands you satisfies the spec of the docidx export plugin API version 2. no cap.

  • export serial configuration β€” this command takes the canonical serialization of a keyword index (as specified down in the section Keyword index serialization format, bestie), and that serialization is contained in serial; then there's the configuration, which is a dictionary; and it generates JSON markup encoding the index. the created string is then returned as the result of the command. slay ✨

πŸŽ€ JSON NOTATION OF KEYWORD INDICES πŸŽ€

the JSON format used for keyword indices is a direct translation of the Keyword index serialization format β€” Tcl dictionaries map to JSON objects and Tcl lists map to JSON arrays. simple as that 🫢

for example, this Tcl serialization:

doctools::idx {
  label {Keyword Index}
  keywords {
     changelog  {changelog.man cvs.man}
     conversion {doctools.man docidx.man doctoc.man apps/dtplite.man mpexpand.man}
     cvs        cvs.man
  }
  references {
     apps/dtplite.man {manpage dtplite}
     changelog.man    {manpage doctools::changelog}
     cvs.man          {manpage doctools::cvs}
     docidx.man       {manpage doctools::idx}
     doctoc.man       {manpage doctools::toc}
     doctools.man     {manpage doctools}
     mpexpand.man     {manpage mpexpand}
  }
  title {}
}

is equivalent to the JSON string:

{
    "doctools::idx" : {
        "label"      : "Keyword Index",
        "keywords"   : {
            "changelog"  : ["changelog.man","cvs.man"],
            "conversion" : ["doctools.man","docidx.man","doctoc.man","apps\/dtplite.man","mpexpand.man"],
            "cvs"        : ["cvs.man"],
        },
        "references" : {
            "apps\/dtplite.man" : ["manpage","dtplite"],
            "changelog.man"     : ["manpage","doctools::changelog"],
            "cvs.man"           : ["manpage","doctools::cvs"],
            "docidx.man"        : ["manpage","doctools::idx"],
            "doctoc.man"        : ["manpage","doctools::toc"],
            "doctools.man"      : ["manpage","doctools"],
            "mpexpand.man"      : ["manpage","mpexpand"]
        },
        "title"      : ""
    }
}

see how clean that is?? iconic 🌈


πŸ“ CONFIGURATION πŸ“

the JSON export plugin recognizes the following configuration variables and changes its behaviour as they specify. iykyk.

  • boolean indented β€” if this flag is set, the plugin will break the generated JSON code across lines and indent it according to its inner structure, with each key of a dictionary on a separate line ✨

if this flag is not set (the default), the whole JSON object gets written on a single line, with minimum spacing between all elements. one long line, no thoughts, head empty πŸ’€

  • boolean aligned β€” if this flag is set, the generator makes sure that the values for the keys in a dictionary are vertically aligned with each other, for a nice table effect. to make that work, this also implies that indented is set.

if this flag is not set (the default), the output is formatted as per the value of indented, without trying to align the values for dictionary keys.

heads up bestie: this plugin ignores the standard configuration variables user, format, file, and map and their values. it just does not care πŸ’…

🧚 KEYWORD INDEX SERIALIZATION FORMAT 🧚

here we specify the format used by the doctools v2 packages to serialize keyword indices as immutable values for transport, comparison, etc.

we distinguish between regular and canonical serializations. while a keyword index may have more than one regular serialization, only exactly one of them will be canonical. so like, one of them is that girl and the rest are just vibing.

regular serialization

  1. an index serialization is a nested Tcl dictionary.
  2. this dictionary holds a single key, doctools::idx, and its value. this value holds the contents of the index.
  3. the contents of the index are a Tcl dictionary holding the title of the index, a label, and the keywords and references. the relevant keys and their values are:
    • title β€” the value is a string containing the title of the index.
    • label β€” the value is a string containing a label for the index.
    • keywords β€” the value is a Tcl dictionary, using the keywords known to the index as keys. the associated values are lists containing the identifiers of the references associated with that particular keyword.

any reference identifier used in these lists has to exist as a key in the references dictionary, see the next item for its definition.

  • references β€” the value is a Tcl dictionary, using the identifiers for the references known to the index as keys. the associated values are 2-element lists containing the type and label of the reference, in this order.

any key here has to be associated with at least one keyword, i.e. occur in at least one of the reference lists which are the values in the keywords dictionary, see previous item for its definition.

  1. the type of a reference can be one of two values:
    • manpage β€” the identifier of the reference is interpreted as symbolic file name, referring to one of the documents the index was made for.
    • url β€” the identifier of the reference is interpreted as an url, referring to some external location, like a website, etc.

canonical serialization

the canonical serialization of a keyword index 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 the keyword index. she's the only one πŸ’–

  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.
  2. the references listed for each keyword of the index, if any, are listed in ascending dictionary order of their labels, 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. it's giving humble, but fr fr. 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. we want the glow-up 🫢

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. look with your eyes πŸ‘€)


⭐ KEYWORDS ⭐

JSON, doctools, export, index, serialization


πŸ‘‘ CATEGORY πŸ‘‘

Text formatter plugin


Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>


okay that's the whole page bestie, you ate that 🌸 this was tcllib, version 0.2, and the manual is doctools::i...export::json(n) β€” now go generate some JSON and be the main character of your own keyword index πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from