summaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-10 20:04:12 +0300
committerA Farzat <a@farzat.xyz>2026-06-10 20:04:12 +0300
commitf11361ee359c1eaccc36559a2fa5b1b98da10ba8 (patch)
treeefda27736f85f233cd348933ce67eab8b8c2a777 /src/renderer.rs
parent4a35607263f87d10fd196f9ee4260040bbdc54d9 (diff)
downloadrepo2markdown-f11361ee359c1eaccc36559a2fa5b1b98da10ba8.tar.gz
repo2markdown-f11361ee359c1eaccc36559a2fa5b1b98da10ba8.zip
Move outer_backticks to a util module
This is because it shall be used by other functions later on. It was made more generic by accepting raw bytes instead of strictly UTF-8 strings. This allows future functions to call it without having to convert the contents to UTF-8 strings first.
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 6f13f59..d9cf7b4 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -7,7 +7,9 @@ use std::{
use crate::{
logger::Logger,
normalizer::NormalizedPath,
- util::{language::detect_language, path_display::display_path},
+ util::{
+ fence::generate_outer_backticks, language::detect_language, path_display::display_path,
+ },
};
const DEFAULT_MAX_FILE_SIZE: u64 = 1_000_000;
@@ -81,7 +83,7 @@ impl<W: Write> Renderer<W> {
fn write_file(&mut self, filename: &Path, contents: &str) -> std::io::Result<()> {
let name = display_path(filename);
- let fence = outer_backticks(contents);
+ let fence = generate_outer_backticks(contents);
let language = detect_language(filename, contents);
self.log_file_render(filename);
writeln!(self.output)?;
@@ -131,23 +133,6 @@ impl<W: Write> Renderer<W> {
}
}
-fn outer_backticks(contents: &str) -> String {
- let mut max_ticks = 0;
- let mut current_count = 0;
- for char in contents.chars() {
- if char == '`' {
- current_count += 1;
- if current_count > max_ticks {
- max_ticks = current_count;
- }
- } else {
- current_count = 0;
- }
- }
- let fence_len = std::cmp::max(3, max_ticks + 1);
- "`".repeat(fence_len)
-}
-
fn human_readable_size(bytes: u64) -> String {
const UNITS: [&str; 5] = ["B", "KiB", "MiB", "GiB", "TiB"];