Skip to main content

drft/parsers/
mod.rs

1//! Text parsers: the link/metadata extractors the text builders wrap.
2//! `markdown` extracts body links; `frontmatter` extracts YAML frontmatter links
3//! and the metadata block.
4
5pub mod frontmatter;
6pub mod markdown;
7
8/// One link discovered by a parser: its raw target string as it appears in the
9/// source, plus the 1-based source line where it occurs (`None` when the parser
10/// cannot locate it). The builder handles normalization (fragment stripping,
11/// anchor filtering, URI detection) and aggregates lines onto the edge.
12#[derive(Debug, Clone)]
13pub struct Link {
14    pub target: String,
15    pub line: Option<usize>,
16}
17
18/// Combined output from parsing a single file: links + optional metadata.
19#[derive(Debug, Clone, Default)]
20pub struct ParseResult {
21    pub links: Vec<Link>,
22    /// Structured metadata extracted from the file.
23    pub metadata: Option<serde_json::Value>,
24}
25
26/// Trait implemented by the built-in text parsers.
27pub trait Parser {
28    /// Check whether this parser should run on a given file path.
29    fn matches(&self, path: &str) -> bool;
30    /// Parse a file's content and return discovered links + optional metadata.
31    fn parse(&self, path: &str, content: &str) -> ParseResult;
32}