summaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-07 18:33:26 +0300
committerA Farzat <a@farzat.xyz>2026-06-07 18:33:26 +0300
commitf759052ad0c97fccca67fa7e1a31eebd9c1bf3c4 (patch)
treee3ec6f41a52cb17d2a5bfb0770ce5282b56a240d /src/renderer.rs
parent674b1715510f74b36b4c7df4f138284cb24536e7 (diff)
downloadrepo2markdown-f759052ad0c97fccca67fa7e1a31eebd9c1bf3c4.tar.gz
repo2markdown-f759052ad0c97fccca67fa7e1a31eebd9c1bf3c4.zip
Detect python and json files
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs26
1 files changed, 26 insertions, 0 deletions
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",
_ => "",
}
}
@@ -239,6 +241,30 @@ mod tests {
}
#[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();
let mut renderer = Renderer::new(&mut output).with_max_file_size(5); // smaller than file