Expand description

Set configuration defaults, reads and writes Tp-Note’s configuration file and exposes the configuration as static variable behind a mutex. This makes it possible to modify all configuration defaults (and templates) at runtime.

use tpnote_lib::config::LIB_CFG;

let mut lib_cfg = LIB_CFG.write().unwrap();
(*lib_cfg).filename.copy_counter_extra_separator = '@'.to_string();

Structs

Configuration of filename parsing, deserialized from the configuration file.

Global variable containing the filename related configuration data.

Configuration data, deserialized from the configuration file.

Filename templates and content templates, deserialized from the configuration file.

Configuration for the HTML exporter feature, deserialized from the configuration file.

Constants

Tp-Note may add a counter at the end of the filename when it can not save a file because the name is taken already. This is the closing bracket search pattern. Some examples: "-", “‘_’”“, "_-","-_", "(" Can be empty.

If the stem of a filename ends with a pattern, that is similar to a copy counter, add this extra separator. It must be one of TRIM_LINE_CHARS (see definition in crate: sanitize_filename_reader_friendly) because they are known not to appear at the end of sanitze()’d strings. This is why they are suitable here.

When a filename is taken already, Tp-Note adds a copy counter number in the range of 0..COPY_COUNTER_MAX at the end.

Tp-Note may add a counter at the end of the filename when it can not save a file because the name is taken already. This is the opening bracket search pattern. Some examples: "-", “‘_’”“, "_-","-_", "(" Can be empty.

This a dot by definition.

The present list contains file extensions of HTML encoded Tp-Note files. For these file types their content is forwarded to the web browser without modification.

The variables FILENAME_EXTENSIONS_* list file extensions that Tp-Note considers as its own note files. Tp-Note opens these files, reads their their YAML header and launches an external file editor and an file viewer (web browser). According to the markup language used, the appropriate renderer is called to convert the note’s content into HTML. The rendered HTML is then shown to the user with his web browser.

The present list contains file extensions of Tp-Note files for which no viewer is opened (unless Tp-Note is invoked with --view).

The present list contains file extensions of RestructuredText encoded Tp-Note files.

The present list contains file extensions of Text encoded Tp-Note files that the viewer shows literally without (almost) any additional rendering. Only hyperlinks in Markdown, reStructuredText, Asciidoc and HTML are rendered, thus clickable.

File extension of new Tp-Note files.

Maximum length of a note’s filename in bytes. If a filename template produces a longer string, it will be truncated.

List of characters that can be part of a sort tag. This list must not include SORT_TAG_EXTRA_SEPARATOR. The first character in the filename which is not in this list, marks the end of the sort tag.

In case the file stem starts with a character in SORT_TAG_CHARS the SORT_TAG_EXTRA_SEPARATOR character is inserted in order to separate both parts when the filename is read next time.

Default template used when the command line parameter points to an existing non-.md-file. Can be modified through editing the configuration file.

Filename of a new note, that annotates an existing file on disk given in .

Default template used, when the clipboard or the input stream stdin contains a string and this string has no valid YAML front matter section. The clipboards content is in {{ clipboard }}, its truncated version in {{ clipboard | heading }} When the clipboard contains a hyperlink in Markdown or reStruncturedText format. See crate parse-hyperlinks for details. For example: [<link-name>](<link-url> "link-title"), can be accessed with the variables: {{ clipboard | linkname }}, {{ clipboard | linktarget }} and {{ clipboard | linkttitle }}.

Default filename template used when the stdin ~ clipboard contains a string.

Default template used, when the clipboard or the input stream stdin contains a string and one the of these strings contains a valid YAML front matter section. The clipboards body is in {{ clipboard }}, the header is in {{ clipboard_header }}. The stdin’s body is in {{ stdin }}, the header is in {{ stdin_header }}. First all variables defined in the clipboard’s front matter are registered, the ones defined in the input stream stdin. The latter can overwrite the former. One of the front matters must define the title variable, which is then available in this template as {{ fm_title }}. When placed in YAML front matter, the filter | json_encode must be appended to each variable.

Default filename template used when the stdin or the clipboard contains a string and one of them has a valid YAML header.

Default template used, when the opened text file (with a known file extension) is missing a YAML front matter section. This template prepends such a section. The template inserts information extracted from the input filename and its creation date.

Default filename template used when the input file (with a known file extension) is missing a YAML front matter section. The text file’s sort-tag and file extension are preserved.

HTML template used to render a note into html when the rendition is saved to disk. Similar to HTML_VIEWER_TMPL but does not inject JavaScript code.

HTML template to render regular viewer pages. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

HTML template to render the viewer-error page. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

Default content template used when the command line argument is a directory. Can be changed through editing the configuration file. The following variables are defined: {{ sanit | stem }}, {{ path | stem }}, {{ path | ext }}, {{ extension_default }} {{ file | tag }}, {{ username }}, {{ date }}, {{ lang }}, {{ dir_path }}. In addition all environment variables can be used, e.g. {{ get_env(name=\"LOGNAME\") }} When placed in YAML front matter, the filter | json_encode must be appended to each variable.

Default filename template for a new note file on disk. It implements the sync criteria for note metadata in front matter and filename. Useful variables in this context are: {{ title| sanit }}, {{ subtitle| sanit }}, {{ extension_default }}, All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. The first non-numerical variable must be some {{ <var>| sanit(alpha) }} variant. Note, as this is filename template, all variables (except now and extension_default must be filtered by a sanit or sanit(force_alpha=true) filter.

Default filename template to test, if the filename of an existing note file on disk, corresponds to the note’s meta data stored in its front matter. If it is not the case, the note’s filename will be renamed. Can be modified through editing the configuration file.

If there is a YAML header in the clipboard content, this contains the body only. Otherwise, it contains the whole clipboard content.

Contains the YAML header (if any) of the clipboard content. Otherwise the empty string.

Contains the fully qualified directory path of the <path> command line argument. If <path> points to a file, the last component (the file name) is omitted. If it points to a directory, the content of this variable is identical to TMPL_VAR_PATH,

Contains the default file extension for new note files as defined in the configuration file.

Prefix prepended to front matter field names when a template variable is generated with the same name.

Contains a Hash Map with all front matter fields. Lists are flattened into a strings. Only available in the TMPL_FROM_TEXT_FILE_CONTENT, TMPL_SYNC_FILENAME and HTML templates.

Contains the value of the front matter field filename_sync. When set to filename_sync: false, the filename synchronisation mechanism is disabled for this note file. Default value is true.

By default, the template TMPL_SYNC_FILENAME defines the function of of this variable as follows: Contains the value of the front matter field file_ext and determines the markup language used to render the document. When the field is missing the markup language is derived from the note’s filename extension.

Contains the value of the front matter field no_filename_sync. When set to no_filename_sync: or no_filename_sync: true, the filename synchronisation mechanism is disabled for this note file. Depreciated in favour of TMPL_VAR_FM_FILENAME_SYNC.

By default, the template TMPL_SYNC_FILENAME defines the function of of this variable as follows: If this variable is defined, the sort tag of the filename is replaced with the value of this variable next time the filename is synchronized. If not defined, the sort tag of the filename is never changed.

Contains the user’s language tag as defined in RFC 5646. Not to be confused with the UNIX LANG environment variable from which this value is derived under Linux/MacOS. Under Windows, the user’s language tag is queried through the WinAPI. If defined, the environment variable TPNOTELANG overwrites this value (all operating systems).

HTML template variable containing the note’s body. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

Contains the body of the file the command line option <path> points to. Only available in the TMPL_FROM_TEXT_FILE_CONTENT, TMPL_SYNC_FILENAME and HTML templates.

HTML template variable used in the error page containing a verbatim HTML rendition with hyperlinks of the erroneous note file. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

HTML template variable used in the error page containing the error message explaining why this page could not be rendered. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

Contains the date of the file the command line option <path> points to. The date is represented as an integer the way std::time::SystemTime resolves to on the platform. Only available in the TMPL_FROM_TEXT_FILE_CONTENT, TMPL_SYNC_FILENAME and HTML templates.

All the front matter fields serialized as text, exactly as they appear in the front matter.

HTML template variable containing the automatically generated JavaScript code to be included in the HTML rendition. We could set #[cfg(feature = "viewer")], but we prefer the same config file structure independent of the enabled features.

The template variable contains the fully qualified path of the <path> command line argument. If <path> points to a file, the variable contains the file path. If it points to a directory, it contains the directory path, or - if no path is given - the current working directory.

If there is a YAML header in the stdin input stream, this contains the body only. Otherwise, it contains the whole input stream.

Contains the YAML header (if any) of the stdin input stream. Otherwise the empty string.

Contains the content of the first non empty environment variable LOGNAME, USERNAME or USER.