6 releases (breaking)
Uses new Rust 2024
| 0.7.0 | Mar 2, 2026 |
|---|---|
| 0.6.0 | Feb 27, 2026 |
| 0.5.0 | Feb 25, 2026 |
| 0.4.0 | Feb 25, 2026 |
| 0.2.1 | Feb 24, 2026 |
#279 in Development tools
57 downloads per month
Used in 3 crates
435KB
8K
SLoC
mdt_core
core library for mdt (manage markdown templates)
mdt_core is the core library for the mdt template engine. It provides the lexer, parser, project scanner, and template engine for processing markdown template tags. Content defined once in provider blocks can be distributed to consumer blocks across markdown files, code documentation comments, READMEs, and more.
Processing Pipeline
Markdown / source file
→ Lexer (tokenizes HTML comments into TokenGroups)
→ Pattern matcher (validates token sequences)
→ Parser (classifies groups, extracts names + transformers, matches open/close into Blocks)
→ Project scanner (walks directory tree, builds provider→content map + consumer list)
→ Engine (matches consumers to providers, applies transformers, replaces content)
Modules
config— Configuration loading frommdt.toml, including data source mappings, exclude/include patterns, and template paths.project— Project scanning and directory walking. Discovers provider and consumer blocks across all files in a project.source_scanner— Source file scanning for consumer tags inside code comments (Rust, TypeScript, Python, Go, Java, etc.).
Key Types
Block— A parsed template block (provider or consumer) with its name, type, position, and transformers.Transformer— A pipe-delimited content filter (e.g.,trim,indent,linePrefix) applied during injection.ProjectContext— A scanned project together with its loaded template data, ready for checking or updating.MdtConfig— Configuration loaded frommdt.toml.CheckResult— Result of checking a project for stale consumers.UpdateResult— Result of computing updates for consumer blocks.
Data Interpolation
Provider content supports minijinja template variables populated from project files. The mdt.toml config maps source files to namespaces:
[data]
pkg = "package.json"
cargo = "Cargo.toml"
Then in provider blocks: {{ pkg.version }} or {{ cargo.package.edition }}.
Supported sources: files and script commands. Supported formats: text, JSON, TOML, YAML, KDL, and INI.
Quick Start
use mdt_core::project::scan_project_with_config;
use mdt_core::{check_project, compute_updates, write_updates};
use std::path::Path;
let ctx = scan_project_with_config(Path::new(".")).unwrap();
// Check for stale consumers
let result = check_project(&ctx).unwrap();
if !result.is_ok() {
eprintln!("{} stale consumer(s) found", result.stale.len());
}
// Update all consumer blocks
let updates = compute_updates(&ctx).unwrap();
write_updates(&updates).unwrap();
Installation
[dependencies]
mdt_core = "0.7.0"
Dependencies
~20MB
~400K SLoC