MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / strip_markdown_code_blocks

Function strip_markdown_code_blocks

atomic-agent/src/transcript/generator.rs:318–336  ·  view source on GitHub ↗

Strip markdown code block wrappers from a JSON string. Claude sometimes wraps JSON in ```json ... ``` blocks despite being asked not to. This strips those wrappers.

(s: &str)

Source from the content-addressed store, hash-verified

316/// Claude sometimes wraps JSON in ```json ... ``` blocks despite being
317/// asked not to. This strips those wrappers.
318pub(crate) fn strip_markdown_code_blocks(s: &str) -> String {
319 let trimmed = s.trim();
320
321 // Check for ```json ... ``` blocks
322 if let Some(rest) = trimmed.strip_prefix("```json") {
323 if let Some(idx) = rest.rfind("```") {
324 return rest[..idx].trim().to_string();
325 }
326 }
327
328 // Check for ``` ... ``` blocks
329 if let Some(rest) = trimmed.strip_prefix("```") {
330 if let Some(idx) = rest.rfind("```") {
331 return rest[..idx].trim().to_string();
332 }
333 }
334
335 trimmed.to_string()
336}
337
338/// Truncate a string for display in log messages and UI.
339///

Calls

no outgoing calls