Module frontmatter

Module frontmatter 

Source
Expand description

Frontmatter parsing with grey_matter Engine trait and Tera templating.

This module provides a custom grey_matter Engine that applies Tera templating to frontmatter content before parsing it as YAML. This enables dynamic frontmatter with template variables while maintaining compatibility with standard YAML frontmatter.

§Example

use agpm_cli::markdown::frontmatter::FrontmatterParser;
use agpm_cli::manifest::DependencyMetadata;
use agpm_cli::manifest::ProjectConfig;
use std::path::Path;
use std::str::FromStr;
use toml;

let mut parser = FrontmatterParser::new();
let content = r#"---
dependencies:
  agents:
    - path: helper.md
      version: "{{ project.version }}"
---
"#;

// Create a test project config
let toml_content = r#"
name = "test-project"
version = "1.0.0"
language = "rust"
"#;
let project_config = {
    let value = toml::Value::from_str(toml_content).unwrap();
    if let toml::Value::Table(table) = value {
        ProjectConfig::from(table)
    } else {
        ProjectConfig::default()
    }
};

let result = parser.parse_with_templating::<DependencyMetadata>(
    content,
    Some(&project_config.to_json_value()),
    Path::new("test.md"),
    None
).unwrap_or_else(|e| panic!("Failed to parse: {}", e));

assert!(result.has_frontmatter());
assert!(result.data.is_some());

Structs§

FrontmatterBoundaries
Byte boundaries of frontmatter section in content.
FrontmatterParser
Unified frontmatter parser with templating support.
FrontmatterTemplating
Helper functions for frontmatter templating.
ParsedFrontmatter
Result of parsing frontmatter from content.
RenderedFrontmatter
Rendered frontmatter with accurate line number information.