Skip to content

Commit f89cd3c

Browse files
authored
Don't treat lines starting with . or ) as ordered markdown lists (#5839)
Fixes 5835 Ordered markdown lists start with 0-9 digits followed by a `.` or a `)`. Now, rustfmt ensure that the `.` or `)` is only preceded by numeric characters before deciding that it's reached an `ItemizedBlock`
1 parent df2471b commit f89cd3c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Diff for: src/comment.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ impl ItemizedBlock {
482482
// allowed.
483483
for suffix in [". ", ") "] {
484484
if let Some((prefix, _)) = trimmed.split_once(suffix) {
485-
if prefix.len() <= 2 && prefix.chars().all(|c| char::is_ascii_digit(&c)) {
485+
let has_leading_digits = (1..=2).contains(&prefix.len())
486+
&& prefix.chars().all(|c| char::is_ascii_digit(&c));
487+
if has_leading_digits {
486488
return Some(prefix.len() + suffix.len());
487489
}
488490
}
@@ -2126,6 +2128,9 @@ fn main() {
21262128
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
21272129
"-1. Not a list item.",
21282130
"-1 Not a list item.",
2131+
// Marker without prefix are not recognized as item markers:
2132+
". Not a list item.",
2133+
") Not a list item.",
21292134
];
21302135
for line in test_inputs.iter() {
21312136
let maybe_block = ItemizedBlock::new(line);

Diff for: tests/source/issue-5835.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// . a
4+
pub fn foo() {}
5+
6+
pub fn main() {
7+
// . a
8+
}

Diff for: tests/target/issue-5835.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// . a
4+
pub fn foo() {}
5+
6+
pub fn main() {
7+
// . a
8+
}

0 commit comments

Comments
 (0)