diff options
| author | A Farzat <a@farzat.xyz> | 2026-06-20 09:32:43 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2026-06-20 10:53:33 +0300 |
| commit | 142c0b8a78d490882981c58988c6825d3f842036 (patch) | |
| tree | 3ddca8160744315fbe17711d78eba0aac5cea503 /src/renderer.rs | |
| parent | 366e00a8198cb63077bddad997e3386bfa6c06b9 (diff) | |
| download | repo2markdown-142c0b8a78d490882981c58988c6825d3f842036.tar.gz repo2markdown-142c0b8a78d490882981c58988c6825d3f842036.zip | |
Add module/function docs to renderer
Diffstat (limited to 'src/renderer.rs')
| -rw-r--r-- | src/renderer.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 90162e6..1db1215 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,3 +1,8 @@ +//! Markdown rendering primitives. +//! +//! This module renders project headers and normalized file paths into Markdown. +//! Rendering behavior is controlled by [`RenderOptions`]. + use std::{ fs::File, io::{Read, Write}, @@ -12,8 +17,10 @@ use crate::{ }, }; +/// Default maximum file size, in bytes. Larger files are not included in Markdown output. pub const DEFAULT_MAX_FILE_SIZE: u64 = 1_000_000; +/// Renders files and project metadata as Markdown. #[derive(Debug)] pub struct Renderer<W: Write> { output: W, @@ -24,10 +31,12 @@ pub struct Renderer<W: Write> { } impl<W: Write> Renderer<W> { + /// Creates a renderer with default [`RenderOptions`]. pub fn new_with_defaults(output: W) -> Self { Self::new(output, RenderOptions::default()) } + /// Creates a renderer with explicit rendering options. pub fn new(output: W, config: RenderOptions) -> Self { Self { output, @@ -38,30 +47,39 @@ impl<W: Write> Renderer<W> { } } + /// Sets the maximum file size, in bytes, that will be rendered. pub fn with_max_file_size(mut self, max_file_size: u64) -> Self { self.max_file_size = max_file_size; self } + /// Sets the logger used for warnings and informational messages. pub fn with_logger(mut self, logger: Logger) -> Self { self.logger = logger; self } + /// Controls whether skipped binary files are represented by placeholders. pub fn with_binary_file_placeholder(mut self, placeholder_for_binary_files: bool) -> Self { self.placeholder_for_binary_files = placeholder_for_binary_files; self } + /// Controls whether skipped large files are represented by placeholders. pub fn with_large_file_placeholder(mut self, placeholder_for_large_files: bool) -> Self { self.placeholder_for_large_files = placeholder_for_large_files; self } + /// Renders the top-level project heading. pub fn render_header(&mut self, project_title: &str) -> std::io::Result<()> { writeln!(self.output, "# {}", project_title) } + /// Renders a normalized path. + /// + /// Text files are rendered as fenced Markdown code blocks. Large files and binary files are + /// skipped unless their corresponding placeholder options are enabled. pub fn render_path(&mut self, normalized_path: &NormalizedPath) -> std::io::Result<()> { let metadata = std::fs::metadata(&normalized_path.absolute)?; if metadata.len() > self.max_file_size { @@ -137,10 +155,14 @@ impl<W: Write> Renderer<W> { } } +/// Options controlling how files are rendered. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct RenderOptions { + /// Maximum file size, in bytes, to include in Markdown output. pub max_file_size: u64, + /// Whether skipped binary files should be shown as `[BINARY FILE]`. pub placeholder_for_binary_files: bool, + /// Whether skipped large files should be shown as `[FILE TOO LARGE]`. pub placeholder_for_large_files: bool, } |
