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`
This commit is contained in:
parent
df2471bf4c
commit
f89cd3c1f3
@ -482,7 +482,9 @@ fn get_marker_length(trimmed: &str) -> Option<usize> {
|
|||||||
// allowed.
|
// allowed.
|
||||||
for suffix in [". ", ") "] {
|
for suffix in [". ", ") "] {
|
||||||
if let Some((prefix, _)) = trimmed.split_once(suffix) {
|
if let Some((prefix, _)) = trimmed.split_once(suffix) {
|
||||||
if prefix.len() <= 2 && prefix.chars().all(|c| char::is_ascii_digit(&c)) {
|
let has_leading_digits = (1..=2).contains(&prefix.len())
|
||||||
|
&& prefix.chars().all(|c| char::is_ascii_digit(&c));
|
||||||
|
if has_leading_digits {
|
||||||
return Some(prefix.len() + suffix.len());
|
return Some(prefix.len() + suffix.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2126,6 +2128,9 @@ fn test_itemized_block_nonobvious_markers_are_rejected() {
|
|||||||
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
|
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
|
||||||
"-1. Not a list item.",
|
"-1. Not a list item.",
|
||||||
"-1 Not a list item.",
|
"-1 Not a list item.",
|
||||||
|
// Marker without prefix are not recognized as item markers:
|
||||||
|
". Not a list item.",
|
||||||
|
") Not a list item.",
|
||||||
];
|
];
|
||||||
for line in test_inputs.iter() {
|
for line in test_inputs.iter() {
|
||||||
let maybe_block = ItemizedBlock::new(line);
|
let maybe_block = ItemizedBlock::new(line);
|
||||||
|
8
tests/source/issue-5835.rs
Normal file
8
tests/source/issue-5835.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// rustfmt-wrap_comments: true
|
||||||
|
|
||||||
|
/// . a
|
||||||
|
pub fn foo() {}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
// . a
|
||||||
|
}
|
8
tests/target/issue-5835.rs
Normal file
8
tests/target/issue-5835.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// rustfmt-wrap_comments: true
|
||||||
|
|
||||||
|
/// . a
|
||||||
|
pub fn foo() {}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
// . a
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user