From f759052ad0c97fccca67fa7e1a31eebd9c1bf3c4 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 7 Jun 2026 18:33:26 +0300 Subject: Detect python and json files --- src/renderer.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/renderer.rs b/src/renderer.rs index 6193680..eb39c76 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -145,6 +145,8 @@ fn human_readable_size(bytes: u64) -> String { fn detect_language(filename: &Path) -> &'static str { match filename.extension().and_then(|e| e.to_str()) { Some("rs") => "rust", + Some("py") => "python", + Some("json") => "json", _ => "", } } @@ -238,6 +240,30 @@ mod tests { assert_eq!(String::from_utf8(output).unwrap(), expected); } + #[test] + fn python_file_has_python_language_fence() { + let mut output = Vec::new(); + let mut renderer = Renderer::new(&mut output); + + let input = Cursor::new("print('hello')"); + renderer.render_file(Path::new("main.py"), input).unwrap(); + let expected = "\n## File: main.py\n```python\nprint('hello')\n```\n"; + + assert_eq!(String::from_utf8(output).unwrap(), expected); + } + + #[test] + fn json_file_has_json_language_fence() { + let mut output = Vec::new(); + let mut renderer = Renderer::new(&mut output); + + let input = Cursor::new("{\"key\":\"value\"}"); + renderer.render_file(Path::new("main.json"), input).unwrap(); + let expected = "\n## File: main.json\n```json\n{\"key\":\"value\"}\n```\n"; + + assert_eq!(String::from_utf8(output).unwrap(), expected); + } + #[test] fn renderer_places_placeholder_for_large_files_by_default() { let mut output = Vec::new(); -- cgit v1.3.1