noteinstance

Name

noteinstance -- Tcl encapsulation of a note

Synopsis


package require logbook
set book [logbook::logbook open logbook-file]
set notes [$book listAllNotes]
set note [lindex $notes 0]
      

$note destroy

set id [$note id]

set run [$note run]

set noteTime [clock seconds [$note timestamp]]

set rawContents [$note contents]

set embeddedImageList [$note images]

set renderableMarkdown [$note substituteImages]

DESCRIPTION

A note instance is a Tcl command ensemble that provides access to all of the information contained in a note. In general, as shown, you don't directly create a note ensemble but use one of the subcommands of a logbook instance to generate one or more instances. See logbookinstance for subcommands that can generate notess

Each note instance is a unique Tcl interpreter command and encapsulates specific resources. As such, when no longer necessaryy, a note instance and its resources should be freed using its destroy subcommand.

SUBCOMMANDS

$note destroy

This subcommand destroys the note instance. All resources owned by the instance are destroyed. Once the command returns, the instance command is no longer a valid interpreter command.

set id [$note id]

Returns the primary key associated with the note instance. This is a unique integer assigned to a note when it is created in the database.

set run [$note run]

If the note has an associated run, this subcommand returns that run encapsulated in a run instance. See runinstance for more on run instances. If ther eis no associated run, an empty string is returned.

set noteTime [clock seconds [$note timestamp]]

Returns a clock timestamp at which the note was entered in the database. As shown, this timestamp is compatible input for clock format, which allows a time string to be produced.

set rawContents [$note contents]

Returns the raw contents of the note. In general; this is not usable as a source of data for rendering the note unless the note has no associated images. See the substituteImages subcommand if you want note text as a source for markdown rendering.

set embeddedImageList [$note images]

Returns a list of dicts. Each dict describes an image that's sucked into the database to fulfil an image link in the note. See IMAGE DICTS below for the contents of these dicts.

set renderableMarkdown [$note substituteImages]

Returns markdown text that can be rendered by a markdown processor. This subcommand exports the images that are are in the database, associated with this note to files. It then modifies all image references to point to the exported files. The result is the modified note text.

If the resulting text is passed to a markdown processor (e.g. the Tcl Markdown package or the pandoc filter), the image links will be processed properly to either include or reference the images.

IMAGE DICTS

The images subcommand returns a list of dicts. Each dict describes a single image that's referenced by the markdown note text and sucked into the database so that the log is fully portable as a single file. The dicts have the following key/value pairs:

offset

The offset into the note text at which the ! that leads of an image reference begins.

originalFilename

Contains the original file path of the image. This can be used to check the integrity of the image list.

imageLength

The number of bytes in the original image data.

imageData

Binary object containing the image data. This can be written to file to re-create the image file.