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:
xxchan 2023-08-29 20:46:44 +08:00 committed by GitHub
parent df2471bf4c
commit f89cd3c1f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -482,7 +482,9 @@ fn get_marker_length(trimmed: &str) -> Option<usize> {
// allowed.
for suffix in [". ", ") "] {
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());
}
}
@ -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":
"-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() {
let maybe_block = ItemizedBlock::new(line);

View File

@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true
/// . a
pub fn foo() {}
pub fn main() {
// . a
}

View File

@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true
/// . a
pub fn foo() {}
pub fn main() {
// . a
}