summaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 164012e..ad5201f 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -153,10 +153,14 @@ fn detect_language(filename: &Path, contents: &str) -> &'static str {
Some("py") => "python",
Some("json") => "json",
_ => {
- if let Some(first_line) = contents.lines().next()
- && first_line.contains("python")
- {
- return "python";
+ if let Some(first_line) = contents.lines().next() {
+ if first_line.contains("python")
+ {
+ return "python";
+ }
+ if first_line.contains("bash") {
+ return "bash";
+ }
}
""
}
@@ -301,6 +305,18 @@ mod tests {
}
#[test]
+ fn bash_file_detected_from_shebang() {
+ let mut output = Vec::new();
+ let mut renderer = Renderer::new(&mut output);
+
+ let input = Cursor::new("#! /bin/bash\necho hello");
+ renderer.render_file(Path::new("hello"), input).unwrap();
+ let expected = "\n## File: hello\n```bash\n#! /bin/bash\necho hello\n```\n";
+
+ assert_eq!(String::from_utf8(output).unwrap(), expected);
+ }
+
+ #[test]
fn python_file_detected_from_shebang() {
let mut output = Vec::new();
let mut renderer = Renderer::new(&mut output);