Skip to content

Rust Library API

agent-md can be used as a high-performance, zero-external-parser Rust library.


Add to Cargo.toml:

[dependencies]
agent-md = "0.5.0"

Formats a Markdown string in accordance with token-efficiency standards:

use agent_md::format_markdown;
let raw = "# Header\n\n| Col A | Col B |\n|---|---|\n| 1 | 2 |\n";
let formatted = format_markdown(raw);
println!("{}", formatted);

Validates a Markdown document string against AI-friendly validation rules:

use agent_md::validate_markdown;
let text = "# Title\n\nThis is **bold** text.";
let report = validate_markdown(text);
if !report.valid {
for err in report.errors {
println!("Line {}: {} ({})", err.line, err.message, err.rule);
}
}

Parses a Markdown document into structured MarkdownBlock elements:

use agent_md::parse_markdown;
let document = parse_markdown("# Title\n\nParagraph text.");
println!("Word count: {}", document.word_count);
println!("Line count: {}", document.line_count);
println!("Headings: {:?}", document.headings);

  • Zero External Parser: Eliminates pulldown-cmark and heavy AST trees, keeping compile times fast and binary size minimal.
  • Hardware SIMD Acceleration: Uses ARM NEON and x86_64 AVX2/SSE2 vectorization for rapid newline scanning and ASCII pattern recognition.
  • Allocation Efficiency: Operates largely over string slices without redundant buffer duplication.