-
Notifications
You must be signed in to change notification settings - Fork 0
docs(footnotes): document parse_definition and is_definition_continuation (#367) #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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`]. | ||
| /// | ||
| /// # 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()?; | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This new function documentation does not include an example demonstrating which inputs return 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse_definitionThis new function documentation describes the grammar but never provides an example showing how a representative definition is parsed into
prefix,number, andrest, or how invalid input yieldsNone. Add a concise usage-and-outcome example as required for all function documentation.AGENTS.md reference: AGENTS.md:L27-L30
Useful? React with 👍 / 👎.