Add footnote docs and improve conversion helper#112
Conversation
Reviewer's GuideRefactored block conversion by introducing a generic trimmed_range helper, improved footnote conversion helper with better trimming logic, documented the behavior with examples, and expanded tests to ignore numeric patterns in inline code and parentheses. Class diagram for footnote conversion helpersclassDiagram
class FootnoteConverter {
+convert_inline(text: &str) -> String
+convert_block(lines: &mut [String])
+trimmed_range(lines: &[String], pred: F) -> (usize, usize)
}
FootnoteConverter : convert_inline
FootnoteConverter : convert_block
FootnoteConverter : trimmed_range
%% Note: trimmed_range is a new generic helper used by convert_block
convert_block --> trimmed_range : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary by CodeRabbit
WalkthroughIntroduce a new documentation file explaining the footnote conversion feature, refactor the block detection logic in the footnote conversion module by adding a reusable helper function, and expand the test suite with cases ensuring numbers in code or parentheses are not incorrectly converted to footnotes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant mdtablefix
participant convert_footnotes
participant trimmed_range
User->>mdtablefix: Run with footnote conversion enabled
mdtablefix->>convert_footnotes: Process document lines
convert_footnotes->>trimmed_range: Identify trailing footnote block
trimmed_range-->>convert_footnotes: Return (start, end) range
convert_footnotes->>mdtablefix: Convert references & definitions
mdtablefix-->>User: Output with footnotes transformed
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (3)docs/**/*.mdInstructions used from: Sources:
**/*.mdInstructions used from: Sources:
⚙️ CodeRabbit Configuration File **/*.rsInstructions used from: Sources:
⚙️ CodeRabbit Configuration File 🪛 LanguageTooldocs/footnote-conversion.md[typographical] ~37-~37: Consider inserting a comma for improved readability. (INITIAL_ADVP_COMMA) [uncategorized] ~37-~37: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA) 🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
- Consider adding a Rust doc comment on the new
trimmed_rangehelper to explain its inputs, predicate and the meaning of the returned (start, end) tuple for maintainability. - It would be great to update the
docs/footnote-conversion.mdfile with examples showing the new behavior of ignoring numbers inside inline code and parentheses so users can see those edge cases documented.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a Rust doc comment on the new `trimmed_range` helper to explain its inputs, predicate and the meaning of the returned (start, end) tuple for maintainability.
- It would be great to update the `docs/footnote-conversion.md` file with examples showing the new behavior of ignoring numbers inside inline code and parentheses so users can see those edge cases documented.
## Individual Comments
### Comment 1
<location> `tests/footnotes.rs:30` </location>
<code_context>
}
+#[test]
+fn test_ignores_numbers_in_inline_code() {
+ let input = lines_vec!("Look at `code 1` for details.");
+ assert_eq!(convert_footnotes(&input), input);
+}
+
</code_context>
<issue_to_address>
Consider adding tests for numbers in multi-line code blocks.
Please add tests for numbers inside multi-line code blocks (e.g., triple backticks or indented blocks) to verify consistent handling.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
#[test]
fn test_ignores_numbers_in_inline_code() {
let input = lines_vec!("Look at `code 1` for details.");
assert_eq!(convert_footnotes(&input), input);
}
=======
#[test]
fn test_ignores_numbers_in_inline_code() {
let input = lines_vec!("Look at `code 1` for details.");
assert_eq!(convert_footnotes(&input), input);
}
#[test]
fn test_ignores_numbers_in_fenced_code_block() {
let input = lines_vec!(
"Here is a code block:",
"```",
"let x = 42; // number 1",
"let y = 2;",
"```",
"Outside code block (1)."
);
assert_eq!(convert_footnotes(&input), input);
}
#[test]
fn test_ignores_numbers_in_indented_code_block() {
let input = lines_vec!(
" let a = 1;",
" let b = 2; // number 2",
"",
"Outside indented code block (2)."
);
assert_eq!(convert_footnotes(&input), input);
}
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| #[test] | ||
| fn test_ignores_numbers_in_inline_code() { | ||
| let input = lines_vec!("Look at `code 1` for details."); | ||
| assert_eq!(convert_footnotes(&input), input); | ||
| } |
There was a problem hiding this comment.
suggestion (testing): Consider adding tests for numbers in multi-line code blocks.
Please add tests for numbers inside multi-line code blocks (e.g., triple backticks or indented blocks) to verify consistent handling.
| #[test] | |
| fn test_ignores_numbers_in_inline_code() { | |
| let input = lines_vec!("Look at `code 1` for details."); | |
| assert_eq!(convert_footnotes(&input), input); | |
| } | |
| #[test] | |
| fn test_ignores_numbers_in_inline_code() { | |
| let input = lines_vec!("Look at `code 1` for details."); | |
| assert_eq!(convert_footnotes(&input), input); | |
| } | |
| #[test] | |
| fn test_ignores_numbers_in_fenced_code_block() { | |
| let input = lines_vec!( | |
| "Here is a code block:", | |
| "```", | |
| "let x = 42; // number 1", | |
| "let y = 2;", | |
| "```", | |
| "Outside code block (1)." | |
| ); | |
| assert_eq!(convert_footnotes(&input), input); | |
| } | |
| #[test] | |
| fn test_ignores_numbers_in_indented_code_block() { | |
| let input = lines_vec!( | |
| " let a = 1;", | |
| " let b = 2; // number 2", | |
| "", | |
| "Outside indented code block (2)." | |
| ); | |
| assert_eq!(convert_footnotes(&input), input); | |
| } |
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
tests/footnotes.rs (2)
41-51: Approve the fenced code block test but note partial coverage.The test correctly verifies that numbers within fenced code blocks are ignored. This addresses part of the past review comment requesting tests for multi-line code blocks.
53-62: Approve the indented code block test.The test appropriately validates that numbers in indented code blocks are not converted. This completes the coverage for different code block types alongside the fenced code block test.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
docs/footnote-conversion.md(1 hunks)src/footnotes.rs(1 hunks)tests/footnotes.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
docs/**/*.md
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- AGENTS.md
**/*.md
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- AGENTS.md
⚙️ CodeRabbit Configuration File
**/*.rs
Instructions used from:
Sources:
📄 CodeRabbit Inference Engine
- AGENTS.md
⚙️ CodeRabbit Configuration File
🧬 Code Graph Analysis (1)
tests/footnotes.rs (1)
src/footnotes.rs (1)
convert_footnotes(80-101)
🪛 LanguageTool
docs/footnote-conversion.md
[typographical] ~37-~37: Consider inserting a comma for improved readability.
Context: ... When the final lines of a document form a numbered list, they are replaced with f...
(INITIAL_ADVP_COMMA)
🔇 Additional comments (7)
src/footnotes.rs (1)
64-66: Approve the refactoring to use the helper function.The refactoring improves code organisation by extracting the trailing block detection logic into a reusable helper function. The implementation correctly delegates to
trimmed_rangewith the footnote line regex predicate.tests/footnotes.rs (2)
29-33: Approve the inline code test.The test correctly verifies that numbers inside inline code spans are not converted to footnotes. This aligns with the documented behaviour and addresses the conversion logic's need to preserve code content.
35-39: Approve the parentheses test.The test properly validates that numbers enclosed in parentheses remain unchanged during footnote conversion. This prevents false positives for mathematical expressions and citations.
docs/footnote-conversion.md (4)
1-6: Approve the introduction and overview.The documentation clearly introduces the footnote conversion feature and explains how to access it via the public API. The description accurately reflects the functionality provided by
convert_footnotes.
7-20: Approve the inline conversion example.The before/after example accurately demonstrates how bare numeric references following punctuation are converted to footnote links. The example aligns with the actual behaviour of the
convert_inlinefunction.
21-36: Approve the exclusion examples.The documentation correctly explains that numbers in inline code and parentheses are ignored, with appropriate examples that match the test cases added to verify this behaviour.
58-59: Approve the final clarification.The explanation that only the final contiguous list is processed accurately describes the behaviour implemented by the
trimmed_rangehelper function in the refactored code.
Summary
Testing
make fmtmake lintmake testmake markdownlintmake nixiehttps://chatgpt.com/codex/tasks/task_e_687ceaa54214832288d664165df9eeda
Summary by Sourcery
Add documentation for footnote conversion, introduce a trimmed_range helper for block processing, and improve footnote detection by ignoring inline numbers in code or parentheses.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: