diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 7b360534ec..2aaf75ae39 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -3216,7 +3216,8 @@ fn strip_markdown_codeblock( let text = if starts_with_fenced_code_block { buffer - .strip_suffix("\n```") + .strip_suffix("\n```\n") + .or_else(|| buffer.strip_suffix("\n```")) .or_else(|| buffer.strip_suffix("\n``")) .or_else(|| buffer.strip_suffix("\n`")) .or_else(|| buffer.strip_suffix('\n')) @@ -3636,6 +3637,13 @@ mod tests { .await, "Lorem ipsum dolor" ); + assert_eq!( + strip_markdown_codeblock(chunks("```\nLorem ipsum dolor\n```\n", 2)) + .map(|chunk| chunk.unwrap()) + .collect::() + .await, + "Lorem ipsum dolor" + ); assert_eq!( strip_markdown_codeblock(chunks("```html\n```js\nLorem ipsum dolor\n```\n```", 2)) .map(|chunk| chunk.unwrap())