Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/footnotes/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ pub(super) struct DefinitionParts<'a> {
pub(super) rest: &'a str,
}

/// Parses a footnote definition line into its constituent [`DefinitionParts`].
///
/// A definition matches [`DEF_RE`]: an optional blockquote prefix (`>`
/// markers with surrounding whitespace), a `[^N]:` marker bearing a decimal
/// footnote number, and the trailing text following the colon. The borrowed
/// `prefix` and `rest` fields point into `line`.
///
/// Returns [`None`] when `line` is not a definition, or when the captured
/// number does not parse as a [`usize`].
Comment on lines +24 to +32

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add an input/output example for parse_definition

This new function documentation describes the grammar but never provides an example showing how a representative definition is parsed into prefix, number, and rest, or how invalid input yields None. Add a concise usage-and-outcome example as required for all function documentation.

AGENTS.md reference: AGENTS.md:L27-L30

Useful? React with 👍 / 👎.

///
/// # Examples
///
/// ```text
/// "[^1]: See the note." => Some { prefix: "", number: 1, rest: " See the note." }
/// "> > [^2]: Nested." => Some { prefix: "> > ", number: 2, rest: " Nested." }
/// " indented body" => None // no `[^N]:` marker
/// ```
pub(super) fn parse_definition(line: &str) -> Option<DefinitionParts<'_>> {
DEF_RE.captures(line).and_then(|caps| {
let number = caps["num"].parse::<usize>().ok()?;
Expand All @@ -32,6 +49,21 @@ pub(super) fn parse_definition(line: &str) -> Option<DefinitionParts<'_>> {
})
}

/// Reports whether `line` continues the preceding footnote definition.
///
/// A continuation is any line whose first character is whitespace, marking
/// indented body text that belongs to the definition above it rather than
/// beginning a new construct. An empty `line` has no leading character and so
/// returns `false`.
Comment on lines +52 to +57

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add an input/output example for continuation detection

This new function documentation does not include an example demonstrating which inputs return true or false; in particular, an indented line and an empty or unindented line would make the whitespace-based contract immediately clear. Add a concise usage-and-outcome example as required for all function documentation.

AGENTS.md reference: AGENTS.md:L27-L30

Useful? React with 👍 / 👎.

///
/// # Examples
///
/// ```text
/// " continued text" => true // leading whitespace
/// "\tcontinued text" => true // leading tab
/// "[^1]: definition" => false // starts a new definition
/// "" => false // no leading character
/// ```
#[inline]
pub(super) fn is_definition_continuation(line: &str) -> bool {
line.chars().next().is_some_and(char::is_whitespace)
Expand Down
Loading