summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-05 12:12:43 +0300
committerA Farzat <a@farzat.xyz>2026-06-05 16:05:42 +0300
commit7894f6954f3810fdc6e2b2ed1b507c232c168d59 (patch)
tree785e8dad04db5b5ae2262380ab1e5720798acb38 /src
parent58d6afbd8bb02890106f84621a1cda94c7b5d3bf (diff)
downloadrepo2markdown-7894f6954f3810fdc6e2b2ed1b507c232c168d59.tar.gz
repo2markdown-7894f6954f3810fdc6e2b2ed1b507c232c168d59.zip
Remove quotations around filenames
Apparently they consume tokens and dilute attention for no benefit.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs4
-rw-r--r--src/renderer.rs25
2 files changed, 19 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index bb01e47..92b84c4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -140,7 +140,7 @@ mod tests {
let output_str = String::from_utf8(output).unwrap();
- assert!(output_str.contains("## File: \"test_main.rs\""));
+ assert!(output_str.contains("## File: test_main.rs"));
assert!(output_str.contains("fn main() {}"));
}
@@ -181,7 +181,7 @@ mod tests {
let output = String::from_utf8(output).unwrap();
- assert!(output.contains("## File: \"test/main.rs\""));
+ assert!(output.contains("## File: test/main.rs"));
}
#[test]
diff --git a/src/renderer.rs b/src/renderer.rs
index 6407b04..76a87f0 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -23,12 +23,13 @@ impl std::error::Error for RenderError {}
pub fn render(project_name: &str, files: &[(&Path, &[u8])]) -> Result<String, RenderError> {
let mut output = format!("# {}\n", project_name);
for (filename, bytes) in files {
+ let printable_filename = render_filename(filename);
let content = std::str::from_utf8(bytes)
.map_err(|_| RenderError::BinaryFile(filename.to_path_buf()))?;
let outer_backticks = outer_backticks(content);
output.push_str(&format!(
- "\n## File: {:?}\n{}\n{}\n{}\n",
- filename, outer_backticks, content, outer_backticks
+ "\n## File: {}\n{}\n{}\n{}\n",
+ printable_filename, outer_backticks, content, outer_backticks
));
}
Ok(output)
@@ -51,6 +52,14 @@ fn outer_backticks(contents: &str) -> String {
"`".repeat(fence_len)
}
+fn render_filename(path: &Path) -> String {
+ let s = format!("{:?}", path);
+ s.strip_prefix('"')
+ .and_then(|s| s.strip_suffix('"'))
+ .unwrap_or(&s)
+ .to_string()
+}
+
#[cfg(test)]
mod tests {
use std::{ffi::OsStr, os::unix::ffi::OsStrExt, path::Path};
@@ -72,7 +81,7 @@ mod tests {
assert_eq!(
output.unwrap(),
"# Project name\n\n\
- ## File: \"main.rs\"\n\
+ ## File: main.rs\n\
```\n\
fn main() {}\n\
```\n"
@@ -91,11 +100,11 @@ mod tests {
assert_eq!(
output.unwrap(),
"# Project name\n\n\
- ## File: \"main.rs\"\n\
+ ## File: main.rs\n\
```\n\
fn main() {}\n\
```\n\n\
- ## File: \"lib.rs\"\n\
+ ## File: lib.rs\n\
```\n\
pub fn hello() {}\n\
```\n"
@@ -114,7 +123,7 @@ mod tests {
assert_eq!(
output.unwrap(),
"# Project name\n\n\
- ## File: \"example.rs\"\n\
+ ## File: example.rs\n\
````\n\
fn main() { println!(\"``` inside\"); }\n\
````\n"
@@ -135,7 +144,7 @@ mod tests {
#[test]
fn filename_with_linebreaks_and_invalid_chars_handled_properly() {
let files: Vec<(&Path, &[u8])> = vec![(
- Path::new(OsStr::from_bytes(b"some\nma\xc3in.rs")),
+ Path::new(OsStr::from_bytes(b"jap\xE3\x81\x82dir/some\nma\xc3in.rs")),
b"fn main() {}",
)];
@@ -144,7 +153,7 @@ mod tests {
assert_eq!(
output.unwrap(),
"# Project name\n\n\
- ## File: \"some\\nma\\xC3in.rs\"\n\
+ ## File: japあdir/some\\nma\\xC3in.rs\n\
```\n\
fn main() {}\n\
```\n"