Expand description
File reference extraction and validation for markdown documents.
This module provides utilities to extract and validate markdown file references within markdown content. It helps catch broken cross-references before installation by checking that referenced files actually exist.
§Supported Reference Types
- Markdown links:
[text](path.md)- only.mdfiles - Direct file paths:
.agpm/snippets/file.md,docs/guide.md- only.mdfiles
§Extraction Rules
The extractor intelligently filters references to avoid false positives:
- Skips absolute URLs (http://, https://, etc.)
- Skips absolute filesystem paths (starting with /)
- Skips content inside YAML frontmatter (— delimited)
- Skips content inside code blocks (``` delimited)
- Skips content inside inline code (` delimited)
- Only extracts relative markdown file paths (.md extension)
§Usage
use agpm_cli::markdown::reference_extractor::{extract_file_references, validate_file_references};
use std::path::Path;
let markdown = r#"
See [documentation](../docs/guide.md) for details.
Also check `.agpm/snippets/example.md` for examples.
"#;
let references = extract_file_references(markdown);
// Returns: ["../docs/guide.md", ".agpm/snippets/example.md"]
// Validate references exist
let project_dir = Path::new("/path/to/project");
let missing = validate_file_references(&references, project_dir)?;Structs§
- Missing
Reference - A missing file reference found during validation.
Functions§
- extract_
file_ references - Extract markdown file references from markdown content.
- is_
valid_ file_ reference - Check if a path string is a valid file reference to validate.
- validate_
file_ references - Validate that file references exist on the filesystem.