Skip to content

Commit

Permalink
fix(derive): split paragraphs on list items
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanVonElectrum committed Nov 1, 2024
1 parent c6a2bb3 commit 1b75b34
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion clap_derive/src/utils/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn split_paragraphs(lines: &[String]) -> Vec<String> {
.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)
Expand Down Expand Up @@ -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<Item = impl AsRef<str>>) -> String {
lines
.into_iter()
Expand Down

0 comments on commit 1b75b34

Please sign in to comment.