Skip to main content

strip_code_fence

Function strip_code_fence 

Source
pub fn strip_code_fence(text: &str) -> &str
Expand description

text without a surrounding Markdown code fence, for parsing the JSON a model wrapped in one.

Handles ```json\n…\n```, a bare ```\n…\n```, a fence on one line (```{"a":1}```), an unclosed fence, any language tag (```JSON), and surrounding whitespace. Text with no fence comes back trimmed.

use gemini_adk_rs::utils::text::strip_code_fence;

assert_eq!(strip_code_fence("```json\n{\"a\": 1}\n```"), "{\"a\": 1}");
assert_eq!(strip_code_fence("  {\"a\": 1}  "), "{\"a\": 1}");