From 1b75b3473ed856166b055895decbd685b843a7f5 Mon Sep 17 00:00:00 2001 From: JohanVonElectrum Date: Fri, 1 Nov 2024 18:14:03 +0100 Subject: [PATCH] fix(derive): split paragraphs on list items --- clap_derive/src/utils/doc_comments.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/clap_derive/src/utils/doc_comments.rs b/clap_derive/src/utils/doc_comments.rs index 58a61633cb5..5da9a4e7ac1 100644 --- a/clap_derive/src/utils/doc_comments.rs +++ b/clap_derive/src/utils/doc_comments.rs @@ -94,7 +94,7 @@ fn split_paragraphs(lines: &[String]) -> Vec { .iter() .enumerate() .find_map(|(i, s)| { - if is_blank(s) { + if is_blank(s) || (i > 0 && is_list_item(s)) { Some(i) } else if new_line(s) { Some(i + 1) @@ -132,6 +132,17 @@ fn new_line(s: &str) -> bool { s.ends_with('\\') || s.ends_with(" ") } +fn is_list_item(s: &str) -> bool { + let s = s.trim_start(); + if s.starts_with("- ") || s.starts_with("* ") || s.starts_with("+ ") { + return true; + } + + let mut chars = s.chars(); + chars.next().map_or(false, |c| c.is_digit(10)) + && chars.skip_while(|c| c.is_digit(10)).next() == Some('.') +} + fn merge_lines(lines: impl IntoIterator>) -> String { lines .into_iter()