Module reference_extractor

Module reference_extractor 

Source
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 .md files
  • Direct file paths: .agpm/snippets/file.md, docs/guide.md - only .md files

§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§

MissingReference
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.