Conversation
Reviewer's GuideIntroduces a new --renumber option that sequentially renumbers ordered Markdown lists via a helper function, integrates it into the CLI pipeline and test suite, and documents the feature in README. Class diagram for new renumber_lists helper and CLI integrationclassDiagram
class Cli {
+bool wrap
+bool renumber
+Vec<PathBuf> files
}
class Main {
+main()
+process_lines(lines, wrap, renumber)
+rewrite_path(path, wrap, renumber)
}
class Lib {
+renumber_lists(lines: &[String]) -> Vec<String>
+process_stream(lines: &[String]) -> Vec<String>
+process_stream_no_wrap(lines: &[String]) -> Vec<String>
}
Cli <.. Main : used by
Main ..> Lib : calls
Lib : +renumber_lists
Lib : +process_stream
Lib : +process_stream_no_wrap
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary by CodeRabbit
WalkthroughUpdate the CLI and documentation to introduce a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant Processor
participant Renumberer
User->>CLI: Run mdtablefix [--renumber] [file]
CLI->>Processor: process_lines(lines, wrap, renumber)
alt renumber is true
Processor->>Renumberer: renumber_lists(lines)
Renumberer-->>Processor: renumbered_lines
Processor-->>CLI: processed_lines
else renumber is false
Processor-->>CLI: processed_lines (unchanged)
end
CLI->>User: Output or rewrite file
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (2)**/*.mdInstructions used from: Sources: **/*.rsInstructions used from: Sources: 🧬 Code Graph Analysis (1)tests/integration.rs (1)
⏰ Context from checks skipped due to timeout of 240000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (17)
✨ 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.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/lib.rs:494` </location>
<code_context>
+/// Lines matching `^\s*[1-9][0-9]*\.\s+` are renumbered sequentially within
+/// their indentation level. Numbering continues across fenced code blocks
+/// without resetting.
+pub fn renumber_lists(lines: &[String]) -> Vec<String> {
+ let mut out = Vec::with_capacity(lines.len());
+ let mut counters: Vec<(usize, usize)> = Vec::new();
</code_context>
<issue_to_address>
Consider refactoring the list renumbering logic to use a stack and hash map for indentation and counters, and extract parsing into a helper function.
You can collapse most of the manual “push‐pop‐update” logic by
1. extracting your numbered-line parsing into a small helper,
2. keeping a `Vec<usize>` as your current indent-stack and a `HashMap<indent, next>` counter lookup,
3. dropping all deeper indents with one small `while` and the `HashMap::remove`,
4. using `entry(…).or_insert(1)` to seed new lists.
That gets you down from nested `is_some_and` checks + two loops into a single concise loop:
```rust
use std::collections::HashMap;
use lazy_static::lazy_static;
use regex::Regex;
lazy_static! {
static ref FENCE_RE: Regex = Regex::new(r"^(```|~~~).*").unwrap();
static ref NUMBERED_RE: Regex = Regex::new(r"^(\s*)([1-9][0-9]*)\.(\s+)(.*)").unwrap();
}
fn parse_numbered(line: &str) -> Option<(usize, &str, &str)> {
let caps = NUMBERED_RE.captures(line)?;
let indent = caps.get(1)?.as_str().len();
let sep = caps.get(3)?.as_str();
let rest = caps.get(4)?.as_str();
Some((indent, sep, rest))
}
pub fn renumber_lists(lines: &[String]) -> Vec<String> {
let mut out = Vec::with_capacity(lines.len());
let mut stack = Vec::<usize>::new();
let mut counters = HashMap::<usize, usize>::new();
let mut in_code = false;
for line in lines {
if FENCE_RE.is_match(line) {
in_code = !in_code;
out.push(line.clone());
continue;
}
if in_code {
out.push(line.clone());
continue;
}
if let Some((indent, sep, rest)) = parse_numbered(line) {
// drop all deeper‐indent lists
while stack.last().map_or(false, |&d| d > indent) {
counters.remove(&stack.pop().unwrap());
}
// start new list at this indent if needed
if stack.last().map_or(true, |&d| d < indent) {
stack.push(indent);
counters.insert(indent, 1);
}
// grab & bump our counter
let num = counters.get_mut(&indent).unwrap();
let current = *num;
*num += 1;
out.push(format!(
"{}{}.{}{}",
" ".repeat(indent), current, sep, rest
));
} else {
out.push(line.clone());
}
}
out
}
```
This:
- removes your manual `(usize,usize)` stack in favor of a single `Vec<usize>` + `HashMap`,
- collapses your two `while counters.last().…` loops into one small `while`,
- pulls out the regex logic to a helper for readability,
- keeps all functionality (fence toggling, in-code passthrough, cross-block counting) intact.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| /// Lines matching `^\s*[1-9][0-9]*\.\s+` are renumbered sequentially within | ||
| /// their indentation level. Numbering continues across fenced code blocks | ||
| /// without resetting. | ||
| pub fn renumber_lists(lines: &[String]) -> Vec<String> { |
There was a problem hiding this comment.
issue (complexity): Consider refactoring the list renumbering logic to use a stack and hash map for indentation and counters, and extract parsing into a helper function.
You can collapse most of the manual “push‐pop‐update” logic by
- extracting your numbered-line parsing into a small helper,
- keeping a
Vec<usize>as your current indent-stack and aHashMap<indent, next>counter lookup, - dropping all deeper indents with one small
whileand theHashMap::remove, - using
entry(…).or_insert(1)to seed new lists.
That gets you down from nested is_some_and checks + two loops into a single concise loop:
use std::collections::HashMap;
use lazy_static::lazy_static;
use regex::Regex;
lazy_static! {
static ref FENCE_RE: Regex = Regex::new(r"^(```|~~~).*").unwrap();
static ref NUMBERED_RE: Regex = Regex::new(r"^(\s*)([1-9][0-9]*)\.(\s+)(.*)").unwrap();
}
fn parse_numbered(line: &str) -> Option<(usize, &str, &str)> {
let caps = NUMBERED_RE.captures(line)?;
let indent = caps.get(1)?.as_str().len();
let sep = caps.get(3)?.as_str();
let rest = caps.get(4)?.as_str();
Some((indent, sep, rest))
}
pub fn renumber_lists(lines: &[String]) -> Vec<String> {
let mut out = Vec::with_capacity(lines.len());
let mut stack = Vec::<usize>::new();
let mut counters = HashMap::<usize, usize>::new();
let mut in_code = false;
for line in lines {
if FENCE_RE.is_match(line) {
in_code = !in_code;
out.push(line.clone());
continue;
}
if in_code {
out.push(line.clone());
continue;
}
if let Some((indent, sep, rest)) = parse_numbered(line) {
// drop all deeper‐indent lists
while stack.last().map_or(false, |&d| d > indent) {
counters.remove(&stack.pop().unwrap());
}
// start new list at this indent if needed
if stack.last().map_or(true, |&d| d < indent) {
stack.push(indent);
counters.insert(indent, 1);
}
// grab & bump our counter
let num = counters.get_mut(&indent).unwrap();
let current = *num;
*num += 1;
out.push(format!(
"{}{}.{}{}",
" ".repeat(indent), current, sep, rest
));
} else {
out.push(line.clone());
}
}
out
}This:
- removes your manual
(usize,usize)stack in favor of a singleVec<usize>+HashMap, - collapses your two
while counters.last().…loops into one smallwhile, - pulls out the regex logic to a helper for readability,
- keeps all functionality (fence toggling, in-code passthrough, cross-block counting) intact.
There was a problem hiding this comment.
Please create an issue for this
Summary
--renumberflag to CLIrenumber_listshelperTesting
cargo +nightly-2025-06-10 fmt --allcargo +nightly-2025-06-10 clippy -- -D warningsRUSTFLAGS="-D warnings" cargo +nightly-2025-06-10 testmarkdownlint README.md docs/html-table-support.md docs/release-process.md docs/rust-testing-with-rstest-fixtures.md src/**/*.rs tests/**/*.rsnixie README.md docs/html-table-support.md docs/release-process.md docs/rust-testing-with-rstest-fixtures.mdhttps://chatgpt.com/codex/tasks/task_e_68737ddcc5748322a24a6922938f2116
Summary by Sourcery
Introduce ordered list renumbering capability via a new --renumber flag, backed by a renumber_lists helper, with updated command processing, tests, and documentation.
New Features:
Enhancements:
Documentation:
Tests: