summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-10 12:18:48 +0300
committerA Farzat <a@farzat.xyz>2026-06-10 12:49:20 +0300
commit293a4d89654c67ef140aa588c92fcc634215a800 (patch)
treecaeda9bb9a1eb3b0d9ce1806b2993781870a846b /src
parent4d787ed64fef6bb3c1559ce4ee5663d4723a2558 (diff)
downloadrepo2markdown-293a4d89654c67ef140aa588c92fcc634215a800.tar.gz
repo2markdown-293a4d89654c67ef140aa588c92fcc634215a800.zip
Skip placeholder for binary files by default
Diffstat (limited to 'src')
-rw-r--r--src/renderer.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index f492f1e..c747df5 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -17,6 +17,7 @@ pub struct Renderer<W: Write> {
output: W,
max_file_size: u64,
logger: Logger,
+ placeholder_for_binary_files: bool,
}
impl<W: Write> Renderer<W> {
@@ -25,6 +26,7 @@ impl<W: Write> Renderer<W> {
output,
max_file_size: DEFAULT_MAX_FILE_SIZE,
logger: Logger::default(),
+ placeholder_for_binary_files: false,
}
}
@@ -38,6 +40,11 @@ impl<W: Write> Renderer<W> {
self
}
+ pub fn with_binary_file_placeholder(mut self, placeholder_for_binary_files: bool) -> Self {
+ self.placeholder_for_binary_files = placeholder_for_binary_files;
+ self
+ }
+
pub fn render_header(&mut self, project_title: &str) -> std::io::Result<()> {
writeln!(self.output, "# {}", project_title)
}
@@ -85,6 +92,9 @@ impl<W: Write> Renderer<W> {
}
fn render_binary_file(&mut self, filename: &Path) -> std::io::Result<()> {
+ if !self.placeholder_for_binary_files {
+ return Ok(());
+ }
let name = display_path(filename);
writeln!(self.output)?;
writeln!(self.output, "## File: {}", name)?;
@@ -184,12 +194,24 @@ mod tests {
}
#[test]
- fn renderer_places_a_placeholder_for_binary_files_by_default() {
+ fn binary_files_are_not_included_in_output_at_all_by_default() {
let mut output = Vec::new();
let mut renderer = Renderer::new(&mut output);
let input = Cursor::new(&[0x00, 0x01, 0x02, 0xc3]);
renderer.render_file(Path::new("image.png"), input).unwrap();
+ let expected = "";
+
+ assert_eq!(String::from_utf8(output).unwrap(), expected);
+ }
+
+ #[test]
+ fn renderer_can_place_a_placeholder_for_binary_files() {
+ let mut output = Vec::new();
+ let mut renderer = Renderer::new(&mut output).with_binary_file_placeholder(true);
+
+ let input = Cursor::new(&[0x00, 0x01, 0x02, 0xc3]);
+ renderer.render_file(Path::new("image.png"), input).unwrap();
let expected = "\n## File: image.png\n[BINARY FILE]\n";
assert_eq!(String::from_utf8(output).unwrap(), expected);