diff options
| author | A Farzat <a@farzat.xyz> | 2026-06-07 20:53:20 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2026-06-07 20:58:37 +0300 |
| commit | 99d21463574bb88fa86f176c2e4ad154be5e1353 (patch) | |
| tree | 9404c38049ab95082eb36814730363a2dbc9de35 /src/renderer.rs | |
| parent | 2e8b176c5f4d93bc614cb9ff6808e5011bb2e103 (diff) | |
| download | repo2markdown-99d21463574bb88fa86f176c2e4ad154be5e1353.tar.gz repo2markdown-99d21463574bb88fa86f176c2e4ad154be5e1353.zip | |
Refactor language detection in a util module
Diffstat (limited to 'src/renderer.rs')
| -rw-r--r-- | src/renderer.rs | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index ad5201f..f492f1e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -4,7 +4,11 @@ use std::{ path::Path, }; -use crate::{logger::Logger, normalizer::NormalizedPath, util::path_display::display_path}; +use crate::{ + logger::Logger, + normalizer::NormalizedPath, + util::{language::detect_language, path_display::display_path}, +}; const DEFAULT_MAX_FILE_SIZE: u64 = 1_000_000; @@ -142,31 +146,6 @@ fn human_readable_size(bytes: u64) -> String { } } -fn detect_language(filename: &Path, contents: &str) -> &'static str { - let ext = filename - .extension() - .and_then(|e| e.to_str()) - .map(|e| e.to_ascii_lowercase()); - let ext_str = ext.as_deref(); - match ext_str { - Some("rs") => "rust", - Some("py") => "python", - Some("json") => "json", - _ => { - if let Some(first_line) = contents.lines().next() { - if first_line.contains("python") - { - return "python"; - } - if first_line.contains("bash") { - return "bash"; - } - } - "" - } - } -} - #[cfg(test)] mod tests { use std::{ |
