pub fn extract_file_references(content: &str) -> Vec<String>Expand description
Extract markdown file references from markdown content.
This function scans markdown content for markdown file path references and returns a deduplicated list of relative markdown file paths. It intelligently filters out URLs, absolute paths, non-markdown files, and references inside code blocks.
§Extracted Reference Types
- Markdown links:
[text](path.md)→ extractspath.md(only.mdfiles) - Direct file paths:
.agpm/snippets/file.md→ extracts.agpm/snippets/file.md(only.mdfiles)
§Filtering Rules
References are excluded if they:
- Start with URL schemes (http://, https://, ftp://, etc.)
- Are absolute paths (starting with /)
- Appear inside YAML frontmatter (— delimited at file start)
- Appear inside code blocks (``` delimited)
- Appear inside inline code (` delimited)
- Don’t have the .md extension
- Contain URL-like patterns (://)
§Arguments
content- The markdown content to scan
§Returns
A vector of unique relative file paths found in the content
§Examples
let markdown = r#"
Check [docs](./guide.md) and `.agpm/snippets/example.md`.
But not this [external link](https://example.com) or `inline code .md`.
"#;
let refs = extract_file_references(markdown);
assert_eq!(refs.len(), 2);
assert!(refs.contains(&"./guide.md".to_string()));
assert!(refs.contains(&".agpm/snippets/example.md".to_string()));