(4c516e6) Preserve paragraph breaks in ticket descriptions, and bump to 0.4.1
The opencode add tool split the description on newlines and then dropped the empty ones with filter(Boolean), so every multi paragraph description arrived as a single paragraph, against the tool's own instruction to separate paragraphs with newlines. cmd_add needed no change for this. Joining the values with a single newline is what makes an empty value a paragraph break, so the capability was already there and only the wrapper was throwing it away. Verified by hand before touching anything. The wrapper now keeps interior blanks and trims only the ends, and only trims trailing whitespace within a line, since leading whitespace is what makes a nested list or an indented block survive. --acceptance and --plan keep dropping blanks: each value there is one criterium or step, so an empty line is spacing. trim_blank_ends in cmd_add makes the second criterion hold whoever calls it, not just the wrapper: blank values at either end are dropped so a break never lands against a section heading, and an all-blank description reads as none. Interior runs are kept verbatim rather than collapsed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5a7cfeb849
commit
39ee86e308
@@ -136,6 +136,9 @@ pub fn cmd_add(
|
||||
return Err(anyhow!("A ticket with this title already exists."));
|
||||
}
|
||||
|
||||
// Joined with a single newline, so an empty value is how a caller spells a
|
||||
// paragraph break and an all-blank description is no description at all.
|
||||
let description = trim_blank_ends(description);
|
||||
let description_text = if description.is_empty() {
|
||||
"_No description provided._".to_string()
|
||||
} else {
|
||||
|
||||
+49
@@ -625,6 +625,27 @@ pub fn format_created_at(created_at: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// The slice with blank values trimmed from both ends, interior ones kept.
|
||||
///
|
||||
/// Description values are joined with a single newline, so an empty value is how a
|
||||
/// caller spells a paragraph break. That makes the interior blanks content, while a
|
||||
/// blank at either end would only open or close the section with a gap.
|
||||
pub fn trim_blank_ends(values: &[String]) -> &[String] {
|
||||
let first = values.iter().position(|v| !v.trim().is_empty());
|
||||
|
||||
match first {
|
||||
None => &[],
|
||||
Some(first) => {
|
||||
// Guaranteed to find one, since `first` is itself non-blank.
|
||||
let last = match values.iter().rposition(|v| !v.trim().is_empty()) {
|
||||
Some(last) => last,
|
||||
None => first,
|
||||
};
|
||||
&values[first..=last]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_dirs() -> Vec<&'static str> {
|
||||
vec!["backlog", "committed", "reviewing", "done"]
|
||||
}
|
||||
@@ -1115,6 +1136,34 @@ mod tests {
|
||||
assert!(rendered.ends_with("after\n"), "{rendered:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blank_values_are_trimmed_from_the_ends_but_kept_inside() {
|
||||
let owned = |values: &[&str]| -> Vec<String> {
|
||||
values.iter().map(|v| v.to_string()).collect()
|
||||
};
|
||||
|
||||
// A break between paragraphs is content
|
||||
let two_paragraphs = owned(&["First.", "", "Second."]);
|
||||
assert_eq!(trim_blank_ends(&two_paragraphs), two_paragraphs.as_slice());
|
||||
|
||||
// A run of them is kept verbatim rather than collapsed
|
||||
let wide = owned(&["A", "", "", "B"]);
|
||||
assert_eq!(trim_blank_ends(&wide), wide.as_slice());
|
||||
|
||||
// The ends are not
|
||||
assert_eq!(
|
||||
trim_blank_ends(&owned(&["", " ", "Only.", "", ""])),
|
||||
owned(&["Only."]).as_slice()
|
||||
);
|
||||
|
||||
// Nothing but blanks is nothing at all
|
||||
assert!(trim_blank_ends(&owned(&["", " ", ""])).is_empty());
|
||||
assert!(trim_blank_ends(&[]).is_empty());
|
||||
|
||||
// A single value survives either way
|
||||
assert_eq!(trim_blank_ends(&owned(&["One."])), owned(&["One."]).as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_level_in_range_parses() {
|
||||
for level in 1..=5u8 {
|
||||
|
||||
Reference in New Issue
Block a user