(raw: &str)
| 623 | |
| 624 | #[cfg(test)] |
| 625 | fn extract_final_reply_markdown(raw: &str) -> Option<String> { |
| 626 | let mut candidates = Vec::new(); |
| 627 | |
| 628 | if let Ok(value) = serde_json::from_str::<Value>(raw) { |
| 629 | collect_markdown_candidates(&value, &mut candidates); |
| 630 | } |
| 631 | |
| 632 | for value in serde_json::Deserializer::from_str(raw) |
| 633 | .into_iter::<Value>() |
| 634 | .flatten() |
| 635 | { |
| 636 | collect_markdown_candidates(&value, &mut candidates); |
| 637 | } |
| 638 | |
| 639 | for line in raw.lines() { |
| 640 | let line = line.trim(); |
| 641 | if line.is_empty() { |
| 642 | continue; |
| 643 | } |
| 644 | if let Ok(value) = serde_json::from_str::<Value>(line) { |
| 645 | collect_markdown_candidates(&value, &mut candidates); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | candidates |
| 650 | .into_iter() |
| 651 | .rev() |
| 652 | .find(|item| !item.trim().is_empty()) |
| 653 | .map(|item| item.trim().to_string()) |
| 654 | } |
| 655 | |
| 656 | fn collect_markdown_candidates(value: &Value, output: &mut Vec<String>) { |
| 657 | match value { |
no test coverage detected