mdt_core
core library for mdt (manage markdown templates)
[![Crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] [![Status][ci-status-image]][ci-status-link] [![Coverage][coverage-image]][coverage-link] [![Unlicense][unlicense-image]][unlicense-link]
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 source blocks can be distributed to target 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 source→content map + target list)
→ Engine (matches targets to sources, 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 target blocks across all files in a project. - [
source_scanner] — Source file scanning for target tags inside code comments (Rust, TypeScript, Python, Go, Java, etc.).
Key Types
- [
Block] — A parsed template block (source or target) 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 targets. - [
UpdateResult] — Result of computing updates for target blocks.
Data Interpolation
Provider content supports minijinja template variables populated from project files. The mdt.toml config maps source files to namespaces:
[]
= "package.json"
= "Cargo.toml"
Then in source 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 scan_project_with_config;
use ;
use Path;
let ctx = scan_project_with_config.unwrap;
// Check for stale targets
let result = check_project.unwrap;
if !result.is_ok
// Update all target blocks
let updates = compute_updates.unwrap;
write_updates.unwrap;
Installation
[]
= "0.9.0"
[crate-image]: https://img.shields.io/crates/v/mdt_core.svg [crate-link]: https://crates.io/crates/mdt_core [docs-image]: https://docs.rs/mdt_core/badge.svg [docs-link]: https://docs.rs/mdt_core/ [ci-status-image]: https://github.com/ifiokjr/mdt/workflows/ci/badge.svg [ci-status-link]: https://github.com/ifiokjr/mdt/actions?query=workflow:ci [coverage-image]: https://codecov.io/gh/ifiokjr/mdt/branch/main/graph/badge.svg [coverage-link]: https://codecov.io/gh/ifiokjr/mdt [unlicense-image]: https://img.shields.io/badge/license-Unlicence-blue.svg [unlicense-link]: https://opensource.org/license/unlicense