calternal_notes_core::templates
Pure Note template rendering and frontmatter merging.
Template YAML is parsed before variable replacement. This keeps a title or date value from changing YAML structure, and the shared Note writer remains the only code that emits app-managed frontmatter fields.
Source: crates/calternal-notes-core/src/templates.rs
Structs
Section titled “Structs”NoteTemplateOutput
Section titled “NoteTemplateOutput”pub struct NoteTemplateOutputA complete Note body produced from a template.
Fields
pub content: String: Markdown with the merged, canonical Note frontmatter.pub cursor_offset: Option<usize>: Position of the first cursor marker in the Markdown body.
Implements: Clone, Debug, PartialEq, Eq
Source: crates/calternal-notes-core/src/templates.rs:52
RenderedTemplate
Section titled “RenderedTemplate”pub struct RenderedTemplateRendered template text and the first cursor marker’s UTF-8 byte offset.
Fields
pub text: String: Text after known variables and all cursor markers are resolved.pub cursor_offset: Option<usize>: Position of the first{{cursor}}, measured in bytes from the start.
Implements: Clone, Debug, PartialEq, Eq
Source: crates/calternal-notes-core/src/templates.rs:43
TemplateVariables
Section titled “TemplateVariables”pub struct TemplateVariables<'a>Values available to a Note template. The Notes plugin supplies the local date and time so this pure crate never reads the system clock.
Fields
pub date: &'a str: Local date inYYYY-MM-DDform.pub time: &'a str: Local time inHH:MMform.pub title: &'a str: The new Note title.pub week: &'a str: ISO week inYYYY-Wwwform.
Implements: Clone, Copy, Debug, PartialEq, Eq
Source: crates/calternal-notes-core/src/templates.rs:30
TemplateError
Section titled “TemplateError”pub enum TemplateErrorAn invalid or oversized Note template.
Variants
TooLarge: Rendering exceeded the bounded output size.InvalidFrontmatter: Frontmatter is not a YAML mapping with string property names.InvalidPropertyKey: A custom frontmatter property has an invalid name.InvalidTags:tagsmust be a string or a list of strings.
Implements: Clone, Debug, PartialEq, Eq, fmt::Display, std::error::Error
Source: crates/calternal-notes-core/src/templates.rs:61
Functions
Section titled “Functions”build_note_from_template
Section titled “build_note_from_template”pub fn build_note_from_template( source: &str, variables: TemplateVariables<'_>, patch: &NoteFrontmatterPatch,) -> Result<NoteTemplateOutput, TemplateError>Build a Note from a Markdown template and app-owned frontmatter patch. Template identity and timestamp fields are ignored; custom YAML keys and tags are retained through the shared frontmatter writer.
Source: crates/calternal-notes-core/src/templates.rs:130
render_template
Section titled “render_template”pub fn render_template( source: &str, variables: TemplateVariables<'_>,) -> Result<RenderedTemplate, TemplateError>Render the five supported variables. Unknown variables remain byte-for-byte unchanged. All cursor markers are removed; only the first position is kept.