use super::heading_analyzer::HeadingConfig;
use crate::cleanup::CleanupOptions;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct RenderOptions {
pub image_dir: Option<PathBuf>,
pub image_path_prefix: String,
pub table_fallback: TableFallback,
pub max_heading_level: u8,
pub include_frontmatter: bool,
pub preserve_line_breaks: bool,
pub include_empty_paragraphs: bool,
pub list_marker: char,
pub use_atx_headers: bool,
pub paragraph_spacing: bool,
pub escape_special_chars: bool,
pub cleanup: Option<CleanupOptions>,
pub heading_config: Option<HeadingConfig>,
}
impl Default for RenderOptions {
fn default() -> Self {
Self {
image_dir: None,
image_path_prefix: "assets/".to_string(),
table_fallback: TableFallback::default(),
max_heading_level: 4,
include_frontmatter: false,
preserve_line_breaks: true,
include_empty_paragraphs: false,
list_marker: '-',
use_atx_headers: true,
paragraph_spacing: true,
escape_special_chars: false,
cleanup: None,
heading_config: Some(super::heading_analyzer::HeadingConfig::default()),
}
}
}
impl RenderOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_image_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.image_dir = Some(dir.into());
self
}
pub fn with_image_prefix(mut self, prefix: impl Into<String>) -> Self {
self.image_path_prefix = prefix.into();
self
}
pub fn with_table_fallback(mut self, fallback: TableFallback) -> Self {
self.table_fallback = fallback;
self
}
pub fn with_frontmatter(mut self) -> Self {
self.include_frontmatter = true;
self
}
pub fn without_paragraph_spacing(mut self) -> Self {
self.paragraph_spacing = false;
self
}
pub fn with_cleanup(mut self) -> Self {
self.cleanup = Some(CleanupOptions::default());
self
}
pub fn with_cleanup_options(mut self, options: CleanupOptions) -> Self {
self.cleanup = Some(options);
self
}
pub fn with_minimal_cleanup(mut self) -> Self {
self.cleanup = Some(CleanupOptions::minimal());
self
}
pub fn with_aggressive_cleanup(mut self) -> Self {
self.cleanup = Some(CleanupOptions::aggressive());
self
}
pub fn with_max_heading_level(mut self, level: u8) -> Self {
self.max_heading_level = level.clamp(1, 6);
self
}
pub fn with_heading_analysis(mut self) -> Self {
self.heading_config = Some(HeadingConfig::default());
self
}
pub fn with_heading_config(mut self, config: HeadingConfig) -> Self {
self.heading_config = Some(config);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TableFallback {
Html,
#[default]
SimplifiedMarkdown,
Skip,
}