Module tpnote_lib::config

source ·
Expand description

Set configuration defaults, reads and writes Tp-Note’s configuration file and exposes the configuration as the static variable LIB_CFG 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();

Contract: although LIB_CFG is mutable at runtime, it is sourced only once at the start of Tp-Note. All modification terminates before accessing the high-level API in the workflow module of this crate.

Structs

  • Configuration of filename parsing, deserialized from the configuration file.
  • Global variable containing the filename and template 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.

Enums

  • Defines the way the HTML exporter rewrites local links.

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 the 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 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.
  • The apperance of a file with this filename marks the position of TMPL_VAR_ROOT_PATH.
  • 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 <path> 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 <path>.
  • A list of language tags, defining languages TP-Note tries to recognize in the filter input. The user’s default language subtag, as reported from the operating system, is automatically added to the present list. The language recognition feature is disabled, when the list is empty. It is also disabled, when the user’s default language, as reported from the operating system, is not supported by the external language guessing library Lingua. In both cases the filter returns the empty string.
  • Default values for the map_lang hash map filter, that is used to post process the language recognition subtag as defined in TMPL_GET_LANG. The key is the language subtag, the corresponding value adds a region subtag completing the language tag. The default region subtags are chosen to be compatible with the LanguageTool grammar checker. In case a language subtag has no key in the present hash map, the filter forwards the input unchanged, e.g. the filter input fr results in fr. One entry, derived from the user’s default language - as reported from the operating system - is automatically added to the present list. This happens only when this language is not listed yet. For example, consider the list TMPL_FILTER_MAP_LANG = &[&["en", "en-US"]]: In this case, the user’s default language fr_CA.UTF-8 is added as &["fr", "fr-CA"]. But, if the user’s default language were en_GB.UTF-8, then it is not added because an entry &["en", "en-US"] exists already. Note, that the empty input string results in the user’s default language tag - here fr-CA - as well.
  • 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 | link_text }}, {{ clipboard | link_dest }} 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.
  • A constant holding common CSS code, used as embedded code in the TMPL_HTML_EXPORTER template and as referenced code in the TMPL_HTML_VIEWER template.
  • 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 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.
  • HTML template variable name. The value contains the highlighting CSS code to be included in the HTML rendition produced by the exporter.
  • HTML template variable name. The value contains the path, for which the viewer delivers CSS code. Note, the viewer delivers the same CSS code which is stored as value for TMPL_VAR_NOTE_CSS.
  • The constant URL for which Tp-Note’s internal web server delivers the CSS stylesheet. In HTML templates, this constant can be accessed as value of the TMPL_VAR_NOTE_CSS_PATH variable.
  • 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.
  • 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.
  • 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 <sanit> 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 }}, {{ title_text | 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 strings. These variables are 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 synchronization 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 TPNOTE_LANG overwrites this value (all operating systems).
  • 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.
  • 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.
  • 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.
  • The root directory of the current note. This is the first directory, that upwards from TMPL_VAR_DIR_PATH, contains a file named FILENAME_ROOT_PATH_MARKER. The root directory is used by Tp-Note’s viewer as base 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.